Real-time software defect prediction method and device based on workload perception

By constructing an initial software defect prediction model and using weighted code changes and multi-objective SMA to optimize hyper-parameters, the problems of inaccurate workload representation and inefficient multi-objective optimization in traditional methods are solved, and the performance and accuracy of the software defect prediction model are improved. Spend.

CN118394664BActive Publication Date: 2024-10-29SOUTH CHINA UNIV OF TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410853223.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-28
Publication Date
2024-10-29
Estimated Expiration
2044-06-28

AI Technical Summary

Technical Problem

Traditional software defect prediction methods based on the module level ignore the issue of software quality assurance workload, resulting in poor performance of real-time software defect prediction models and low multi-objective optimization efficiency, which cannot meet actual requirements.

Method used

By building an initial software defect prediction model, using weighted code changes to calculate change workload, and using multi-objective Slime Mold Algorithm (SMA) to optimize hyperparameters, the Accuracy (ACC) and Popt values ​​can be optimized at the same time, thereby obtaining the final software defects Predictive model.

Benefits of technology

It improves the accuracy of workload representation and the performance of software defect prediction models, enhances the accuracy of prediction, and meets the needs of practical applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118394664B_ABST
    Figure CN118394664B_ABST
Patent Text Reader

Abstract

The present invention belongs to the field of software defect prediction, and specifically provides a method and device for real-time software defect prediction based on workload perception, by constructing an initial software defect prediction model; calculating the change workload by weighted code change amount; calculating the ACC and Popt values ​​of the initial software defect prediction model according to the change workload; optimizing the hyperparameters of the initial software defect prediction model by a multi-objective slime mold algorithm (Slime Mould Algorithm, SMA), and performing multiple iterations to make the ACC and Popt values ​​simultaneously reach the optimal. The weighted code change amount is used to calculate the change workload, so that the workload is associated with specific programming technology, code distribution, problem complexity and other factors, thereby improving the rationality of the workload. At the same time, by using multi-objective SMA, the maximum value of the two performance evaluation indicators ACC and Popt is solved as the optimization target, and the software defect prediction model is optimized, thereby improving the accuracy of the prediction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of software defect prediction, and in particular to a method and device for real-time software defect prediction based on workload perception. Background Art

[0002] The relationship between software defects and software is like the relationship between diseases and people. If they are not repaired in time, they may cause economic losses or even lead to unpredictable consequences. The quality of software depends on the number of defects in it. The more defects there are, the worse the quality of the software is, and the more maintenance costs are required.

[0003] Most of the traditional module-level Software Defect Prediction (SDP) research ignores the issue of Software Quality Assurance (SQA) workload ("workload" for short) and assumes that the cost of applying SQA activities to each module is the same. In the field of Just-in-Time Software Defect Prediction (JIT-SDP), different changes usually require different workloads. Even if two changes have the same amount of code changes, the workload they require may be significantly different. For example, Change A and Change B have the same amount of code changes, but Change A involves 5 files, while Change B only involves 1 file. The difficulty of locating, fixing, reviewing, and verifying Change A is generally higher than that of Change B, so the workload required for Change A is greater than that for Change B. If the workload is not considered, the JIT-SDP model designed by researchers may perform very poorly in practical applications. Therefore, when designing a workload-aware JIT-SDP model, workload becomes an important metric, and how to effectively represent the workload has a decisive influence on the performance of the model.

[0004] The workload-aware JIT-SDP technologies in related technologies are commonly EALR, MULTI, and DEJIT. These methods currently have the following defects:

[0005] (1) Inaccurate representation of workload. Using only the amount of code changes to represent workload ignores the impact of factors such as programming technology, code distribution, and problem complexity on workload.

[0006] (2) Multi-objective optimization problems. When faced with complex combinatorial optimization problems, traditional optimization methods are often inefficient and cannot meet actual requirements.

[0007] The above problems need to be solved urgently. Summary of the invention

[0008] The purpose of the present invention is to provide a method and device for real-time software defect prediction based on workload perception.

[0009] In order to solve the above technical problems, the present invention provides a workload-aware real-time software defect prediction method, comprising:

[0010] Build an initial software defect prediction model;

[0011] Calculate the change effort by weighting the amount of code changes;

[0012] The ACC and Popt values ​​of the initial software defect prediction model are calculated based on the change workload. The full name of ACC is Accuracy, which indicates the ratio of the number of defect changes that can be detected to the total number of changes when 20% of the workload is used. The full name of Popt is comparing a prediction model with an optimal mode, which indicates the area between the optimal model and the prediction model in the cumulative lift diagram based on the number of lines of code.

[0013] The hyperparameters of the initial software defect prediction model are optimized through the multi-objective SMA algorithm (Slime Mould Algorithm) and multiple iterations are performed to achieve the optimal ACC and Popt values ​​at the same time.

[0014] Substitute the optimized hyperparameters into the initial software defect prediction model to obtain the final software defect prediction model;

[0015] Defect prediction is performed through the final software defect prediction model.

[0016] Furthermore, the step of calculating the change workload by weighted code change amount includes:

[0017] Get the code change CC of each change in the historical data. The calculation formula is as follows:

[0018]

[0019] Where LA is the number of lines of code added by the change, and LD is the number of lines of code deleted;

[0020] The difficulty coefficient of the change is calculated by changing the number of modified files NF and the distribution of modified codes in the files Entropy ;

[0021] Calculating Change Effort , the calculation formula is as follows: .

[0022] Furthermore, the difficulty coefficient of the change is calculated by changing the number of modified files NF and the distribution of the modified code in the file Entropy The steps include:

[0023] The minimum and maximum value normalization method is used to normalize the number of changed and modified files. The calculation formula is as follows:

[0024]

[0025] Where: Indicates the minimum number of files to be modified. Indicates the maximum number of files that have been modified, and NF indicates the original value. Represents the normalized result, which is between [0,1];

[0026] Using Shannon entropy The entropy of the distribution of modified files is calculated as follows:

[0027]

[0028] In the formula, represents the probability of file k appearing, ≥0, and , n represents the number of modified files;

[0029] The Shannon entropy is normalized using logarithm, and the calculation formula is as follows:

[0030]

[0031] In the formula, 0≤Entropy≤1,Entropy The larger the value, the wider the distribution of the changed files;

[0032] Difficulty level of change The calculation formula is as follows: .

[0033] Furthermore, the step of optimizing the hyperparameters of the initial software defect prediction model by the multi-objective SMA algorithm and performing multiple iterations to optimize the ACC and Popt values ​​at the same time includes:

[0034] Define hyperparameter configuration space;

[0035] Initialize multi-target population;

[0036] Design SMA multi-objective synchronization and conflict mechanism to complete hyperparameter optimization.

[0037] Furthermore, the step of initializing the multi-target population is:

[0038] The population search space range is the hyperparameter configuration space, and the dimension is the number of hyperparameters that need to be tuned for the software defect prediction model;

[0039] The multi-target population is initialized according to a random method.

[0040] Furthermore, the step of initializing the multi-target population according to the random method, that is, using the random method to generate random numbers within a specified range, will generate pop rows and dim columns of random numbers, where pop represents the number of populations and dim represents the number of hyperparameters;

[0041] The random number calculation formula is as follows:

[0042]

[0043] In the formula, x represents the hyperparameter, ub represents the upper boundary of the hyperparameter range, lb represents the lower boundary of the hyperparameter range, and random() represents the generation of random numbers in the interval [0,1].

[0044] Furthermore, the steps of designing the SMA multi-objective synchronization and conflict mechanism to complete the optimization of hyperparameters are:

[0045] In the multi-objective optimization task, N groups of slime molds simultaneously approach the optimal hyperparameter group for ACC and POPT, and their approximation behavior is expressed by the following formula:

[0046]

[0047] Where X represents the position of the slime mold, that is, the parameter in the hyperparameter space, t represents the current iteration number, X(t) and X(t+1) represent the positions of the slime mold at the tth and t+1th iterations, and X A and X B denotes two different individuals randomly selected from the slime mold, vb is the oscillation parameter, It oscillates randomly within the interval and gradually approaches zero as the number of iterations increases. Xb(t) represents the location with the highest food concentration at the tth iteration. vc represents the slime mold parameter, which decreases linearly from 1 to 0. The synergistic interaction between vb and vc mimics the selective behavior of slime mold. The P value ranges from [-1, 1], and r is a random number ranging from [0, 1].

[0048] The value is calculated as follows:

[0049]

[0050] In the formula, max_t represents the maximum number of iterations, and t represents the current number of iterations;

[0051] The calculation process of P value is as follows:

[0052]

[0053] Where i∈1,2,…n, S(i) represents the fitness value of the i-th group of slime molds, and DF represents the combination of the best fitness values ​​obtained in all iterations;

[0054] W is the weight parameter, calculated as follows:

[0055]

[0056]

[0057] In the formula, condition represents the slime mold individuals whose fitness values ​​rank in the first half of the population, and others represents the slime mold individuals whose fitness values ​​rank in the second half of the population. F ( j ) represents the optimal fitness value obtained by the jth optimization objective in the current iteration process, wxya (j) represents the worst fitness value obtained by the jth optimization objective in the current iteration process, S (i)(j) represents the fitness value of the jth optimization target of the i-th group of slime molds, SortIndex Represents the sequence after sorting of fitness values;

[0058] When the food concentration is high, the weight near this area is large; when the food concentration is low, the weight of this area will decrease, thereby changing the search direction and exploring other areas. Therefore, in the first half of the population, the maximum value of the weight parameters of different slime mold individuals is selected; in the second half of the population, the minimum value of the weight parameters of different slime mold individuals is selected. The formula for updating the position of slime mold is as follows:

[0059]

[0060] Where z represents the position update parameter, ACC and Popt correspond to two different slime mold individuals with different fitness values.

[0061] The present invention also provides a workload-aware real-time software defect prediction device, comprising:

[0062] A building module suitable for building an initial software defect prediction model;

[0063] A workload calculation module, suitable for calculating the change workload by weighted code changes;

[0064] An evaluation value calculation module, suitable for calculating the ACC and Popt values ​​of the initial software defect prediction model based on the change workload;

[0065] The optimization module is suitable for optimizing the hyperparameters of the initial software defect prediction model through the multi-objective SMA algorithm, and performing multiple iterations to optimize the ACC and Popt values ​​at the same time;

[0066] An updating module, adapted to substitute the optimized hyperparameters into the initial software defect prediction model to obtain a final software defect prediction model;

[0067] The prediction module is suitable for performing defect prediction through the final software defect prediction model.

[0068] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores at least one instruction, and when the instruction is executed by a processor, the above-mentioned workload-aware based real-time software defect prediction method is implemented.

[0069] The present invention also provides an electronic device, comprising a memory and a processor; the memory stores at least one instruction; the processor implements the above-mentioned workload-aware based real-time software defect prediction method by loading and executing the at least one instruction.

[0070] The beneficial effect of the present invention is that the present invention provides a workload-aware instant software defect prediction method and device, wherein the workload-aware instant software defect prediction method includes: constructing an initial software defect prediction model; calculating the change workload by weighted code change amount; calculating the ACC and Popt values ​​of the initial software defect prediction model according to the change workload; optimizing the hyperparameters of the initial software defect prediction model by a multi-objective SMA algorithm, performing multiple iterations, so that the ACC and Popt values ​​simultaneously reach the optimum; substituting the optimized hyperparameters into the initial software defect prediction model to obtain a final software defect prediction model; and performing defect prediction by the final software defect prediction model. The weighted code change amount is used to calculate the change workload, thereby associating the workload with specific programming technology, code distribution, problem complexity and other factors, thereby improving the rationality of the workload. At the same time, by using a multi-objective SMA algorithm, the maximum value of the two performance evaluation indicators ACC and Popt is solved as the optimization target, the software defect prediction model is optimized, and the prediction accuracy is improved, thereby improving the performance of the software defect prediction model. BRIEF DESCRIPTION OF THE DRAWINGS

[0071] Figure 1 It is a flow chart of a workload-aware real-time software defect prediction method provided by an embodiment of the present invention.

[0072] Figure 2It is the comparison result of the Scott-Knott test provided by the embodiment of the present invention.

[0073] Figure 3 It is a principle block diagram of the workload-aware real-time software defect prediction provided by an embodiment of the present invention.

[0074] Figure 4 It is a principle block diagram of some electronic devices provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0075] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, which only illustrate the basic structure of the present invention in a schematic manner, and therefore only show the components related to the present invention.

[0076] Example 1

[0077] See also Figure 1 This embodiment provides an instant software defect prediction method based on workload perception, which uses weighted code change amount to calculate the change workload, thereby associating the workload with specific programming technology, code distribution, problem complexity and other factors, improving the rationality of the workload, and at the same time, through the multi-objective SMA algorithm, the maximum value of the two performance evaluation indicators ACC and Popt is solved as the optimization goal, the software defect prediction model is optimized, the prediction accuracy is improved, and thus the performance of the software defect prediction model is improved.

[0078] Specifically, the workload-aware real-time software defect prediction method includes the following steps:

[0079] S110: Construct an initial software defect prediction model.

[0080] Specifically, the initial software defect prediction model can be built through the Random Forest algorithm (RF), the eXtreme Gradient Boosting algorithm (XGBoost), and the Light Gradient Boosting Machine algorithm (LightGBM).

[0081] S120: Calculate the change workload by weighting the code change amount.

[0082] Specifically, step S120 includes the following steps:

[0083] S121: Obtain the code change CC of each change in the historical data, and the calculation formula is as follows:

[0084]

[0085] Where LA is the number of lines of code added by the change, and LD is the number of lines of code deleted;

[0086] S122: Calculate the difficulty coefficient of the change by changing the number of modified files NF and the distribution of modified codes in the files Entropy .

[0087] Specifically, step S122 includes:

[0088] The minimum and maximum value normalization method is used to normalize the number of changed and modified files. The calculation formula is as follows:

[0089]

[0090] Where: Indicates the minimum number of files to be modified. Indicates the maximum number of files that have been modified, and NF indicates the original value. Represents the normalized result, which is between [0,1];

[0091] Using Shannon entropy The entropy of the distribution of modified files is calculated as follows:

[0092]

[0093] In the formula, represents the probability of file k appearing, ≥0, and , n represents the number of modified files;

[0094] The Shannon entropy is normalized using logarithm, and the calculation formula is as follows:

[0095]

[0096] In the formula, 0≤Entropy≤1,Entropy The larger the value, the wider the distribution of the changed files;

[0097] Difficulty level of change The calculation formula is as follows: .

[0098] S123: Calculate the change workload , the calculation formula is as follows: .

[0099] S130: Calculate ACC and Popt values ​​of the initial software defect prediction model according to the change workload.

[0100] Specifically, ACC refers to the ratio of the number of defective changes that can be found to the total number of defective changes when 20% of the workload is used, and Popt is the first standardized indicator proposed in the literature for evaluating the workload-aware SDP model, which provides an objective evaluation of the model performance. The calculation process of ACC and Popt is a prior art, and the specific calculation process is not described in this embodiment.

[0101] S140: The hyperparameters of the initial software defect prediction model are optimized through the multi-objective SMA algorithm, and multiple iterations are performed to make the ACC and Popt values ​​reach the optimal value at the same time.

[0102] Specifically, step S140 includes the following steps:

[0103] S141: Define hyperparameter configuration space.

[0104] S142: Initialize the multi-target population.

[0105] Specifically, step S142 includes:

[0106] The population search space range is the hyperparameter configuration space, and the dimension is the number of hyperparameters that need to be tuned for the software defect prediction model;

[0107] Initialize the multi-target population using a random method. That is, use a random method to generate random numbers within a specified range, and generate pop rows and dim columns of random numbers, where pop represents the number of populations and dim represents the number of hyperparameters;

[0108] The random number calculation formula is as follows:

[0109]

[0110] In the formula, x represents the hyperparameter, ub represents the upper boundary of the hyperparameter range, lb represents the lower boundary of the hyperparameter range, and random() represents the generation of random numbers in the interval [0,1].

[0111] S143: Design SMA multi-objective synchronization and conflict mechanism to complete the optimization of hyperparameters.

[0112] Specifically, in the multi-objective optimization task, N groups of slime molds simultaneously approach the optimal hyperparameter group for ACC and POPT, and their approximation behavior is expressed by the following formula:

[0113]

[0114] Where X represents the position of the slime mold, that is, the parameter in the hyperparameter space, t represents the current iteration number, X(t) and X(t+1) represent the positions of the slime mold at the tth and t+1th iterations, and X A and X B denotes two different individuals randomly selected from the slime mold, vb is the oscillation parameter, It oscillates randomly within the interval and gradually approaches zero as the number of iterations increases. Xb(t) represents the location with the highest food concentration at the tth iteration. vc represents the slime mold parameter, which decreases linearly from 1 to 0. The synergistic interaction between vb and vc mimics the selective behavior of slime mold. The P value ranges from [-1, 1], and r is a random number ranging from [0, 1].

[0115] The value is calculated as follows:

[0116]

[0117] In the formula, max_t represents the maximum number of iterations, and t represents the current number of iterations;

[0118] The calculation process of P value is as follows:

[0119]

[0120] Where, i∈1,2,…n, S( i ) represents the fitness value of the i-th group of slime molds, DF represents the combination of the best fitness values ​​obtained in all iterations;

[0121] W is the weight parameter, calculated as follows:

[0122]

[0123]

[0124] In the formula, condition represents the slime mold individuals whose fitness values ​​rank in the first half of the population, and others represents the slime mold individuals whose fitness values ​​rank in the second half of the population. F ( j ) represents the optimal fitness value obtained by the jth optimization objective in the current iteration process, wxya ( j ) represents the worst fitness value obtained by the jth optimization objective in the current iteration. S (i)(j) represents the fitness value of the jth optimization target of the i-th group of slime molds, SortIndex Represents the sequence after sorting of fitness values;

[0125] When the food concentration is high, the weight near this area is large; when the food concentration is low, the weight of this area will decrease, thereby changing the search direction and exploring other areas. Therefore, in the first half of the population, the maximum value of the weight parameters of different slime mold individuals is selected; in the second half of the population, the minimum value of the weight parameters of different slime mold individuals is selected. The formula for updating the position of slime mold is as follows:

[0126]

[0127] Where z represents the position update parameter, ACC and Popt correspond to two different slime mold individuals with different fitness values.

[0128] S150: Substitute the optimized hyperparameters into the initial software defect prediction model to obtain a final software defect prediction model.

[0129] S160: Perform defect prediction using the final software defect prediction model.

[0130] In order to verify the workload-aware real-time software defect prediction method (hereinafter referred to as WCMS) of this embodiment, the same set of historical data is used to compare the prediction results with those of the benchmark method, and the ACC value and Popt value are calculated.

[0131] Table 1 Comparison of ACC index of WCMS method and benchmark method in cross-validation scenario

[0132]

[0133] According to the results in Table 1, the average values ​​of XGB and LGBM in the FI stage are better than those of LT, AGE, and EALR methods, and slightly worse than the best performing DEJIT and CCUM methods. The ACC indicator of the WCMS method achieved the best results in the four projects of JDT, PLA, MOZ, and POS. In the COL project, it is similar to the two methods of the best performing DEJIT and CCUM. In the BUG project, it is slightly worse than the best performing DEJIT and CCUM methods. The results of RF in the FI stage are better than those of XGB and LGBM, and the results of XGB and LGBM in the FI stage are similar.

[0134] Table 2 Comparison of Popt index of WCMS method and benchmark method in cross-validation scenario

[0135]

[0136] According to the results in Table 2, the average values ​​of XGB and LGBM in the FI stage are better than those of LT, AGE, and EALR methods, but slightly worse than the best performing DEJIT and CCUM methods. The Popt indicator of the WCMS method achieved the best results in the five projects of COL, JDT, PLA, MOZ, and POS. In the BUG project, similar to the MULTI method, it is slightly worse than the best performing DEJIT and CCUM methods, but better than EALR, LT, and AGE methods. The results of RF in the FI stage are better than those of XGB and LGBM, and the results of XGB and LGBM in the FI stage are similar.

[0137] In order to better evaluate the performance of different methods in the ten-fold cross validation scenario, the embodiment performed a Scott-Knott test based on the experimental results. Figure 2 As shown, it can be seen that the WCMS method of the present application is better than the benchmark method and the prediction results are more accurate.

[0138] Example 2

[0139] See also Figure 3 This embodiment provides a workload-aware real-time software defect prediction device, comprising the following modules:

[0140] The construction module is suitable for constructing an initial software defect prediction model, and is used to execute step S110 in embodiment 1. The initial software defect prediction model can be constructed by using random forest RF, extreme gradient boosting algorithm XGB and light gradient boosting machine algorithm LGBM.

[0141] The workload calculation module is adapted to calculate the change workload by weighting the code change amount, and is used to execute step S120 in the first embodiment.

[0142] Step S120 includes the following steps:

[0143] S121: Obtain the code change CC of each change in the historical data, and the calculation formula is as follows:

[0144]

[0145] Where LA is the number of lines of code added by the change, and LD is the number of lines of code deleted;

[0146] S122: Calculate the difficulty coefficient of the change by changing the number of modified files NF and the distribution of modified codes in the files Entropy .

[0147] Specifically, step S122 includes:

[0148] The minimum and maximum value normalization method is used to normalize the number of changed and modified files. The calculation formula is as follows:

[0149]

[0150] Where: Indicates the minimum number of files to be modified. Indicates the maximum number of files that have been modified, and NF indicates the original value. Represents the normalized result, which is between [0,1];

[0151] Using Shannon entropy The entropy of the distribution of modified files is calculated as follows:

[0152]

[0153] In the formula, represents the probability of file k appearing, ≥0, and , n represents the number of modified files;

[0154] The Shannon entropy is normalized using logarithm, and the calculation formula is as follows:

[0155]

[0156] In the formula, 0≤Entropy≤1,Entropy The larger the value, the wider the distribution of the changed files;

[0157] Difficulty level of change The calculation formula is as follows: .

[0158] S123: Calculate the change workload , the calculation formula is as follows: .

[0159] The evaluation value calculation module is adapted to calculate the ACC and Popt values ​​of the initial software defect prediction model according to the change workload, and is used to execute step S130 in embodiment 1.

[0160] The optimization module is adapted to optimize the hyperparameters of the initial software defect prediction model through a multi-objective SMA algorithm, and perform multiple iterations to optimize the ACC and Popt values ​​at the same time.

[0161] Step S140 includes the following steps:

[0162] S141: Define hyperparameter configuration space.

[0163] S142: Initialize the multi-target population.

[0164] Specifically, step S142 includes:

[0165] The population search space range is the hyperparameter configuration space, and the dimension is the number of hyperparameters that need to be tuned for the software defect prediction model;

[0166] Initialize the multi-target population according to the random method. That is, use the random number within the specified range of the sound field to generate pop rows and dim columns of random numbers, where pop represents the number of populations and dim represents the number of hyperparameters;

[0167] The random number calculation formula is as follows:

[0168]

[0169] In the formula, x represents the hyperparameter, ub represents the upper boundary of the hyperparameter range, lb represents the lower boundary of the hyperparameter range, and random() represents the generation of random numbers in the interval [0,1].

[0170] S143: Design SMA multi-objective synchronization and conflict mechanism to complete the optimization of hyperparameters.

[0171] Specifically, in the multi-objective optimization task, N groups of slime molds simultaneously approach the optimal hyperparameter group for ACC and POPT, and their approximation behavior is expressed by the following formula:

[0172]

[0173] Where X represents the position of the slime mold, that is, the parameter in the hyperparameter space, t represents the current iteration number, X(t) and X(t+1) represent the positions of the slime mold at the tth and t+1th iterations, and X A and X B denotes two different individuals randomly selected from the slime mold, vb is the oscillation parameter, It oscillates randomly within the interval and gradually approaches zero as the number of iterations increases. Xb(t) represents the location with the highest food concentration at the tth iteration. vc represents the slime mold parameter, which decreases linearly from 1 to 0. The synergistic interaction between vb and vc mimics the selective behavior of slime mold. The P value ranges from [-1, 1], and r is a random number ranging from [0, 1].

[0174] The value is calculated as follows:

[0175]

[0176] In the formula, max_t represents the maximum number of iterations, and t represents the current number of iterations;

[0177] The calculation process of P value is as follows:

[0178]

[0179] Where i∈1,2,…n, S(i) represents the fitness value of the i-th group of slime molds, and DF represents the combination of the best fitness values ​​obtained in all iterations;

[0180] W is the weight parameter, calculated as follows:

[0181]

[0182]

[0183] In the formula, condition represents the slime mold individuals whose fitness values ​​rank in the first half of the population, and others represents the slime mold individuals whose fitness values ​​rank in the second half of the population. F (j) represents the optimal fitness value obtained by the jth optimization objective in the current iteration process, wxya (j) represents the worst fitness value obtained by the jth optimization objective in the current iteration process, S (i)(j) represents the fitness value of the jth optimization target of the i-th group of slime molds, SortIndex Represents the sequence after sorting of fitness values;

[0184] When the food concentration is high, the weight near this area is large; when the food concentration is low, the weight of this area will decrease, thereby changing the search direction and exploring other areas. Therefore, in the first half of the population, the maximum value of the weight parameters of different slime mold individuals is selected; in the second half of the population, the minimum value of the weight parameters of different slime mold individuals is selected. The formula for updating the position of slime mold is as follows:

[0185]

[0186] Where z represents the position update parameter, ACC and Popt correspond to two different slime mold individuals with different fitness values.

[0187] The updating module is adapted to substitute the optimized hyperparameters into the initial software defect prediction model to obtain the final software defect prediction model.

[0188] The prediction module is adapted to perform defect prediction using the final software defect prediction model and is used to execute step S160 in the first embodiment.

[0189] Example 3

[0190] This embodiment provides a computer-readable storage medium, in which at least one instruction is stored. When the instruction is executed by a processor, the workload-aware real-time software defect prediction method provided in Embodiment 1 is implemented.

[0191] Construct an initial software defect prediction model; calculate the change workload by weighting the code change amount; calculate the ACC and Popt values ​​of the initial software defect prediction model based on the change workload; optimize the hyperparameters of the initial software defect prediction model through the multi-objective SMA algorithm, perform multiple iterations, and make the ACC and Popt values ​​reach the optimal value at the same time; substitute the optimized hyperparameters into the initial software defect prediction model to obtain the final software defect prediction model; perform defect prediction through the final software defect prediction model. The weighted code change amount is used to calculate the change workload, thereby associating the workload with specific programming technology, code distribution, problem complexity and other factors, improving the rationality of the workload. At the same time, the multi-objective SMA algorithm is used to solve the maximum value of the two performance evaluation indicators ACC and Popt as the optimization target, optimize the software defect prediction model, improve the accuracy of the prediction, and thus improve the performance of the software defect prediction model.

[0192] Example 4

[0193] See also Figure 4 This embodiment provides an electronic device, including: a memory 502 and a processor 501; the memory 502 stores at least one program instruction; the processor 501 loads and executes the at least one program instruction to implement the workload-aware real-time software defect prediction method provided in Example 1.

[0194] The memory 502 and the processor 501 are connected in a bus manner, and the bus may include any number of interconnected buses and bridges, and the bus connects various circuits of one or more processors 501 and the memory 502 together. The bus can also connect various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. The data processed by the processor 501 is transmitted on a wireless medium via an antenna, and further, the antenna also receives data and transmits the data to the processor 501.

[0195] The processor 501 is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management and other control functions. The memory 502 can be used to store data used by the processor 501 when performing operations.

[0196] In summary, the present invention provides a workload-aware instant software defect prediction method and device, wherein the workload-aware instant software defect prediction method includes: constructing an initial software defect prediction model; calculating the change workload by weighted code change amount; calculating the ACC and Popt values ​​of the initial software defect prediction model according to the change workload; optimizing the hyperparameters of the initial software defect prediction model by a multi-objective SMA algorithm, performing multiple iterations, so that the ACC and Popt values ​​simultaneously reach the optimum; substituting the optimized hyperparameters into the initial software defect prediction model to obtain a final software defect prediction model; and performing defect prediction by the final software defect prediction model. The weighted code change amount is used to calculate the change workload, thereby associating the workload with specific programming techniques, code distribution, problem complexity and other factors, thereby improving the rationality of the workload. At the same time, the multi-objective SMA algorithm is used to solve the maximum value of the two performance evaluation indicators ACC and Popt as the optimization target, thereby optimizing the software defect prediction model, improving the accuracy of the prediction, and thus improving the performance of the software defect prediction model.

[0197] All devices (parts without specific structure) selected in this application are universal standard parts or parts known to those skilled in the art, and their structures and principles can be known by those skilled in the art through technical manuals or conventional experimental methods. In addition, the software programs involved in this application are all prior art, and this application does not involve any improvement to the software programs.

[0198] In the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0199] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.

[0200] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.

[0201] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0202] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0203] Based on the above ideal embodiments of the present invention, the relevant staff can make various changes and modifications without departing from the technical concept of the present invention through the above description. The technical scope of the present invention is not limited to the contents of the specification, and its technical scope must be determined according to the scope of the claims.

Claims

1. A workload-aware real-time software defect prediction method, characterized in that: include: Build an initial software defect prediction model; Calculate the change effort by weighting the amount of code changes; The step of calculating the change workload by weighted code change amount comprises: Get the code change CC of each change in the historical data. The calculation formula is as follows: Where LA is the number of lines of code added by the change, and LD is the number of lines of code deleted; The difficulty coefficient of the change is calculated by changing the number of modified files NF and the distribution of modified codes in the files Entropy ; Calculating Change Effort , the calculation formula is as follows: ; The difficulty coefficient of the change is calculated by changing the number of modified files NF and the distribution of modified codes in the files Entropy The steps include: The minimum and maximum value normalization method is used to normalize the number of changed and modified files. The calculation formula is as follows: Where: Indicates the minimum number of files to be modified. Indicates the maximum number of files that have been modified, and NF indicates the original value. Represents the normalized result, which is between [0,1]; Using Shannon entropy The entropy of the distribution of modified files is calculated as follows: In the formula, represents the probability of file k appearing, ≥0, and , n represents the number of modified files; The Shannon entropy is normalized using logarithm, and the calculation formula is as follows: In the formula, 0≤Entropy≤1,Entropy The larger the value, the wider the distribution of the changed files; Difficulty level of change The calculation formula is as follows: ; Calculate the ACC and Popt values ​​of the initial software defect prediction model based on the change workload; The hyperparameters of the initial software defect prediction model are optimized by using the multi-objective slime mold algorithm, namely the SMA algorithm, and multiple iterations are performed to optimize the ACC and Popt values ​​at the same time. The specific steps include: Define hyperparameter configuration space; Initialize multi-target population; Design SMA multi-objective synchronization and conflict mechanism to complete the optimization of hyperparameters. The specific steps include: In the multi-objective optimization task, N groups of slime molds simultaneously approach the optimal hyperparameter group for ACC and POPT, and their approximation behavior is expressed by the following formula: Where X represents the position of the slime mold, that is, the parameter in the hyperparameter space, t represents the current iteration number, X(t) and X(t+1) represent the positions of the slime mold at the tth and t+1th iterations, and X A and X B represents two different individuals randomly selected from the slime mold, vb is the oscillation parameter, The random oscillation in the interval gradually approaches zero with the increase of the number of iterations. b (t) represents the location with the highest food concentration at the tth iteration, vc represents the slime mold parameter, which decreases linearly from 1 to 0, and the synergistic interaction between vb and vc mimics the selective behavior of the slime mold, where the P value ranges from [-1, 1], and r is a random number ranging from [0, 1]; The value is calculated as follows: In the formula, max_t represents the maximum number of iterations, and t represents the current number of iterations; The calculation process of P value is as follows: Where i∈1,2,…N, S(i) represents the fitness value of the i-th group of slime molds, and DF represents the combination of the best fitness values ​​obtained in all iterations; W is the weight parameter, calculated as follows: In the formula, condition represents the slime mold individuals whose fitness values ​​rank in the first half of the population, and others represents the slime mold individuals whose fitness values ​​rank in the second half of the population. F (j) represents the optimal fitness value obtained by the jth optimization objective in the current iteration process, wxya (j) represents the worst fitness value obtained by the jth optimization objective in the current iteration process, S (i)(j) represents the fitness value of the jth optimization target of the i-th group of slime molds, SortIndex Represents the sequence after sorting of fitness values; When the food concentration is higher, the corresponding weight W When the food concentration is lower, the corresponding weight will decrease, thus changing the search direction and exploring other food concentrations. Therefore, in the first half of the population, the maximum value of the weight parameters of different slime mold individuals is selected; in the second half of the population, the minimum value of the weight parameters of different slime mold individuals is selected. The formula for updating the position of slime mold is as follows: Where z represents the position update parameter, ub represents the upper boundary of the hyperparameter range, and lb represents the lower boundary of the hyperparameter range; Substitute the optimized hyperparameters into the initial software defect prediction model to obtain the final software defect prediction model; Defect prediction is performed through the final software defect prediction model.

2. The workload-aware real-time software defect prediction method according to claim 1, characterized in that: In the step of initializing the multi-target population, The population search space range is the hyperparameter configuration space, and the dimension is the number of hyperparameters that need to be tuned for the software defect prediction model; The multi-target population is initialized according to a random method.

3. The workload-aware real-time software defect prediction method according to claim 2, characterized in that: The step of initializing the multi-target population according to the random method, that is, using the random method to generate random numbers within a specified range, generating pop rows and dim columns of random numbers, where pop represents the number of populations and dim represents the number of hyperparameters; The random number calculation formula is as follows: In the formula, x represents the hyperparameter, ub represents the upper boundary of the hyperparameter range, lb represents the lower boundary of the hyperparameter range, and random() represents the generation of random numbers in the interval [0,1].

4. A device for implementing the workload-aware real-time software defect prediction method according to any one of claims 1 to 3, characterized in that: include: A building module suitable for building an initial software defect prediction model; A workload calculation module is used to calculate the workload of the change by weighting the amount of code changes; An evaluation value calculation module is used to calculate the ACC and Popt values ​​of the initial software defect prediction model based on the change workload; The optimization module is used to optimize the hyperparameters of the initial software defect prediction model through the multi-objective SMA algorithm, and perform multiple iterations to optimize the ACC and Popt values ​​at the same time; An updating module is used to substitute the optimized hyperparameters into the initial software defect prediction model to obtain the final software defect prediction model; The prediction module is used to perform defect prediction through the final software defect prediction model.

5. A computer-readable storage medium, wherein at least one instruction is stored in the computer-readable storage medium, characterized in that: When the instructions are executed by a processor, the workload-aware real-time software defect prediction method described in any one of claims 1 to 3 is implemented.

6. An electronic device, characterized in that: It comprises a memory and a processor; the memory stores at least one instruction; the processor implements the workload-aware real-time software defect prediction method according to any one of claims 1 to 3 by loading and executing the at least one instruction.

Citation Information

Patent Citations

  • Workload perception defect prediction method based on weighted software network

    CN112711543A

  • Workload perception instant software defect prediction method based on linear programming

    CN115033493A

  • Workload perception instant defect prediction method based on evolution feature construction

    CN117743803A

  • Cross-project software defect prediction method and system thereof

    WO2021093140A1