A cross-project instant software defect prediction method, device and readable storage medium
Through kernel variance matching and covariance alignment technology, the probability distribution of the source project and the target project is adjusted, and combined with the classification improvement algorithm, the problem of feature distribution mismatch in cross-project software defect prediction is solved, and the prediction accuracy is significantly improved.
Patent Information
- Application Number
- CN202410929743.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-11
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-07-11
AI Technical Summary
Existing real-time software defect prediction technology cannot accurately predict software defects in a cross-project situation, especially when the feature distribution of the source project and the target project does not match, resulting in low accuracy of prediction results.
Through kernel variance matching and covariance alignment, the marginal probability distribution and conditional probability distribution of the source item and the target item are adjusted to make them similar, and an SDP model is built through the classification improvement algorithm, and multiple iterative trainings are performed to improve the prediction accuracy.
The accuracy of cross-project real-time software defect prediction is significantly improved. Through multiple iterations and dynamic fusion, the prediction results are more accurate. Especially when the marginal probability distribution and conditional probability distribution match, the prediction ability of the model is improved.
Smart Images

Figure CN118445215B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software defect prediction, and in particular to a method, a device and a readable storage medium for cross-project instant software defect prediction. Background Art
[0002] The earlier software defects are discovered, the lower the cost of repairing them. Software Defect Prediction (SDP) technology can identify software defects at an earlier stage, helping software developers and testers to narrow the scope of investigation and optimize the allocation of testing resources. Traditional SDP technology mainly focuses on the module level, and this technology mainly locates defective files, packages or subsystems. Since this technology cannot accurately locate defects, lacks a timely feedback mechanism, and cannot quickly locate defect repairers, in order to meet these challenges, researchers have proposed Just-in-Time Software Defect Prediction (JIT-SDP) technology.
[0003] However, when the target project and source project of just-in-time software defect prediction are cross-projects, that is, when the target project in software defect prediction is a new project, or for existing projects, change training data is often scarce, the annotation cost is high and error-prone, the existing JIT-SDP technology cannot meet the prediction requirements.
[0004] In the related art, for cross-project instant software defect prediction, in order to solve the mismatch between the feature distribution of the source project and the target project, the marginal probability distribution or the conditional probability distribution problem is considered separately. That is, when considering the entire source project and the target project, one of the marginal probability distribution or the conditional probability distribution is regarded as the same, and the model training is completed by adjusting the other, which leads to very low accuracy of the software defect prediction results.
[0005] The above problems need to be solved urgently. Summary of the invention
[0006] The purpose of the present invention is to provide a cross-project instant software defect prediction method, device and readable storage medium.
[0007] In order to solve the above technical problems, the present invention provides a cross-project instant software defect prediction method, comprising:
[0008] Get labeled samples of source items;
[0009] Get a sample of the target item;
[0010] Adjust the marginal probability distributions of the source item's label samples and the target item's samples by kernel variance matching;
[0011] Adjust the conditional probability distribution of source items and target items by designing covariance as the loss function and aligning the labeled samples of the source items with the samples of the target items;
[0012] The SDP model is constructed through the classification improvement algorithm and loss function. The source items and target items are dynamically integrated through multiple iterations until the marginal probability distribution and conditional probability distribution of the two items are similar, completing the model training.
[0013] Through the trained SDP model, defects are predicted for samples of the target project.
[0014] Furthermore, the label sample of the source project is ;
[0015] In the formula, S S represents a collection of labeled samples of the source project, N s represents the number of samples, i Represents the i-th data in the label sample, Respectively represent all the data and corresponding labels in the source project, Indicates the first label sample i data and corresponding labels.
[0016] Furthermore, the sample of the target project is ;
[0017] In the formula, S t represents the sample set of the target project, N t represents the number of samples, j Indicates the sample j data, Respectively represent all the data in the target project and the corresponding labels to be predicted, Indicates the first j data and the corresponding labels to be predicted.
[0018] Furthermore, the step of adjusting the marginal probability distribution of the label samples of the source project and the samples of the target project by kernel variance matching includes:
[0019] Set the kernel bandwidth bd and the boundary value wb of the weight w;
[0020] Get a sample of labels for the source project The number of samples N s ;
[0021] Get a sample of the target project The number of samples N t ;
[0022] Calculate the kernel variance sb of the source item using the following formula:
[0023] ;
[0024] Calculate the kernel matrix km of the source project based on the kernel function and kernel bandwidth bd.
[0025] Get a sample of labels for the source project and a sample of the target project The inner product kp of the source project is to use the kernel function to and a sample of the target project Map to the feature space and calculate the inner product kp;
[0026] Create a constraint matrix cm to constrain the value of weight w;
[0027] Create a constraint vector cv to constrain the value of the weight w;
[0028] Minimize the gap between the inner product kp and the weight w through the quadratic programming solver, and constrain the weight w through the constraint matrix cm and the constraint vector cv to obtain the optimal weight w value;
[0029] The label samples of the source project are updated through the weight w to complete the kernel variance matching.
[0030] Furthermore, the conditional probability distribution of the source item and the target item is adjusted by designing the covariance as the loss function and aligning the label sample of the source item with the sample of the target item, that is:
[0031] Calculate the sample covariance matrix of the source project's label sample and the target project's sample respectively;
[0032] Perform whitening operation on the labeled samples of the source project;
[0033] The label samples of the whitened source items are aligned with the samples of the target items to complete the adjustment of the conditional probability distribution of the source items and the target items.
[0034] Furthermore, the SDP model is constructed through the classification improvement algorithm and the loss function, and the source project and the target project are dynamically integrated through multiple iterations until the marginal probability distribution and the conditional probability distribution of the two are similar, and the model training is completed, that is:
[0035] After each training and iteration, the label samples of the source project are aligned with the samples of the target project by using the covariance matrix. The weights of the label samples of the source project and the target project are recalculated using covariance matching after the alignment, and then new training and optimization iterations are started until the marginal probability distribution and conditional probability distribution of the two are similar.
[0036] Furthermore, the cross-project instant software defect prediction method also includes:
[0037] The evaluation of the prediction results includes the following steps:
[0038] Obtain the accuracy of the prediction results;
[0039] Calculate the G-Mean index and MCC index of the accuracy of all prediction results;
[0040] The SDP model is evaluated using the G-Mean and MCC indicators.
[0041] The present invention also provides a cross-project instant software defect prediction device, comprising:
[0042] A first acquisition module, adapted to acquire label samples of source items;
[0043] A second acquisition module, adapted to acquire a sample of a target item;
[0044] A kernel variance matching module, adapted to adjust the marginal probability distribution of the label samples of the source item and the samples of the target item through kernel variance matching;
[0045] A covariance alignment module, adapted to adjust the conditional probability distribution of source items and target items by designing covariance as a loss function and aligning the labeled samples of the source items with the samples of the target items;
[0046] The model training and iteration module is suitable for building the SDP model through the classification improvement algorithm and loss function. The source project and the target project are dynamically integrated through multiple iterations until the marginal probability distribution and conditional probability distribution of the two are similar, completing the model training.
[0047] The prediction module is suitable for predicting defects on samples of target projects through the trained SDP model.
[0048] The present invention also provides a computer-readable storage medium, wherein at least one instruction is stored in the computer-readable storage medium, and when the instruction is executed by a processor, the cross-project instant software defect prediction method as described above is implemented.
[0049] 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 cross-project instant software defect prediction method by loading and executing the at least one instruction.
[0050] The beneficial effects of the present invention are as follows: the present invention provides a cross-project instant software defect prediction method, device and storable medium, wherein the cross-project instant software defect prediction method includes: obtaining label samples of the source project; obtaining samples of the target project; adjusting the marginal probability distribution of the label samples of the source project and the samples of the target project by kernel variance matching; adjusting the conditional probability distribution of the source project and the target project by designing the covariance as a loss function and aligning the label samples of the source project with the samples of the target project; constructing an SDP model by a classification boosting algorithm and a loss function, dynamically fusing the source project and the target project through multiple iterations until the marginal probability distribution and conditional probability distribution of the two are close, completing model training; and performing defect prediction on the samples of the target project through the trained SDP model. For cross-project instant software defect prediction, the marginal probability distribution and conditional probability distribution are considered at the same time, and the marginal probability distribution and conditional probability distribution of the label samples of the source project and the samples of the target project are close at the same time through multiple iterations of dynamic fusion, and the SDP model is trained, and then the defect prediction is performed on the target project, so that the prediction is more accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 It is a flow chart of the cross-project instant software defect prediction method provided by an embodiment of the present invention.
[0052] Figure 2 It is a comparison result diagram of the average values of the G-Mean indicator provided by the embodiment of the present invention on the target project.
[0053] Figure 3 It is a comparison result diagram of the average values of the MCC indicators provided by the embodiment of the present invention on the target project.
[0054] Figure 4 It is a structural diagram of a software defect prediction device provided by an embodiment of the present invention.
[0055] Figure 5 It is a partial structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0056] The following is a further detailed description of the implementation of the present invention in conjunction with the accompanying drawings and embodiments. 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.
[0057] Example 1
[0058] See also Figure 1 A cross-project instant software defect prediction method is proposed. For cross-project instant software defect prediction, the marginal probability distribution and conditional probability distribution are considered at the same time. Through multiple iterations of dynamic fusion, the marginal probability distribution and conditional probability distribution of the label samples of the source project and the samples of the target project are made close at the same time. The SDP model is trained, and then the defect prediction is performed on the target project. The prediction result is more accurate.
[0059] Specifically, the cross-project instant software defect prediction method includes:
[0060] S110: Obtain label samples of source items.
[0061] Among them, the label sample of the source project is ;
[0062] In the formula, S S represents a collection of labeled samples of the source project, N s represents the number of samples, i Represents the i-th data in the label sample, Respectively represent all the data and corresponding labels in the source project, Indicates the first label sample i data and corresponding labels.
[0063] S120: Obtain a sample of the target item.
[0064] Among them, the sample of the target project is ;
[0065] In the formula, S t represents the sample set of the target project, N t represents the number of samples, j Indicates the sample j data, Respectively represent all the data in the target project and the corresponding labels to be predicted, Indicates the first j data and the corresponding labels to be predicted.
[0066] S130: Adjusting the marginal probability distributions of the label samples of the source item and the samples of the target item by kernel variance matching.
[0067] Specifically, step S130 includes the following steps:
[0068] S131: Setting the kernel bandwidth bd and the boundary value wb of the weight w;
[0069] S132: Get label samples of source items The number of samples N s ;
[0070] S133: Get a sample of the target project The number of samples N t ;
[0071] S134: Calculate the kernel variance sb of the source item using the following formula:
[0072] S135: ;
[0073] S136: Calculate the kernel matrix km of the source project based on the kernel function and the kernel bandwidth bd.
[0074] S137: Get label samples of source items and a sample of the target project The inner product kp of the source project is to use the kernel function to and a sample of the target project Map to the feature space and calculate the inner product kp;
[0075] S138: Create a constraint matrix cm to constrain the value of the weight w;
[0076] S139: creating a constraint vector cv to constrain the value of the weight w;
[0077] S1310: Minimize the gap between the inner product kp and the weight w through a quadratic programming solver, and constrain the weight w through a constraint matrix cm and a constraint vector cv, so as to obtain an optimal weight w value;
[0078] S1311: Update the label samples of the source project through the weight w to complete the kernel variance matching.
[0079] S140: Adjust the conditional probability distribution of the source item and the target item by designing the covariance as the loss function and aligning the label samples of the source item with the samples of the target item.
[0080] Specifically, step S140 includes the following steps:
[0081] S141: Calculate the sample covariance matrix of the source project label sample and the target project sample respectively;
[0082] S142: performing a whitening operation on the label samples of the source project;
[0083] S143: Align the whitened label samples of the source items with the samples of the target items to complete the adjustment of the conditional probability distributions of the source items and the target items.
[0084] S150: Build the SDP model through the classification improvement algorithm and loss function, and dynamically fuse the source project and the target project through multiple iterations until the marginal probability distribution and conditional probability distribution of the two are similar, and then complete the model training.
[0085] Specifically, after each training and iteration, the label samples of the source project are aligned with the samples of the target project by using the covariance matrix. The aligned source project uses covariance matching to recalculate the weights of the label samples of the source project and the target project, and then new training and optimization iterations are started until the marginal probability distribution and conditional probability distribution of the two are similar.
[0086] S160: Defect prediction is performed on samples of the target project using the trained SDP model.
[0087] The cross-project instant software defect prediction method further includes:
[0088] S170: Evaluate the prediction result, including the following steps:
[0089] Obtain the accuracy of the prediction results;
[0090] Calculate the G-Mean index and MCC index of the accuracy of all prediction results;
[0091] The SDP model is evaluated using the G-Mean and MCC indicators.
[0092] Specifically, the cross-project instant software defect prediction method (hereinafter referred to as KCC), WV method and CB method (the latest benchmark method) proposed in this invention are used to build the SDP model and perform predictions, and the average value of the 10 running results is taken for comparison.
[0093] Regarding the G-Mean index, the comparison results of the KCC method, the WV method and the CB method are shown in Table 1, and the best value in each row is shown in bold.
[0094] Table 1
[0095]
[0096] According to the results in Table 1, the KCC method performed best in each run. Compared with the WV method, the KCC average value exceeded 21.2%. Compared with the CB method, the KCC average value exceeded 17.7%. Although the KCC method achieved the best performance, the final results were different when the source project or the target project changed. In order to further evaluate the migration effect of the KCC method, this application uses the average value of the G-Mean indicator on the target project as the comparison object. The comparison results are as follows: Figure 2 shown.
[0097] pass Figure 2 , it can be observed that the G-Mean index is related to different methods and projects. Among the six projects, the KCC method performed best, and the CB method was slightly better than the WV method. Further comparison of the average values of the G-Mean index of the three methods of WV, CB and KCC in the six target projects showed that their ranges of variation were ±0.078, ±0.074, and ±0.062, respectively. This shows that the three methods are relatively stable in the G-Mean index, and the KCC method still performs best.
[0098] Regarding the MCC index, the comparison results of the KCC method, the WV method and the CB method are shown in Table 2, and the best value in each row is shown in bold.
[0099] Table 2
[0100]
[0101] According to the data in Table 2, it can be seen that the KCC method performs best in each run. Although the KCC method achieves the best results, the final results are different when the source project or the target project changes. In order to further evaluate the migration effect of the KCC method, this application uses the average value of the MCC indicator on the target project as the comparison object. The comparison results are as follows: Figure 3 shown.
[0102] according to Figure 3 , it can be seen that the MCC index is related to different methods and projects. Among the six projects, the KCC method performed best and far exceeded the baseline method, and the CB method was slightly better than the WV method. Further comparison of the average values of the MCC index of the three methods of WV, CB and KCC in the six target projects showed that their ranges of variation were ±0.162, ±0.159, and ±0.152, respectively. This shows that the three methods are relatively stable in the MCC index, and the KCC method still performs best.
[0103] Example 2
[0104] See also Figure 4This embodiment also provides a cross-project instant software defect prediction device, including the following modules:
[0105] The first acquisition module is adapted to acquire label samples of source items and is used to perform the following steps:
[0106] S110: Obtain label samples of source items.
[0107] Among them, the label sample of the source project is ;
[0108] In the formula, S S represents a collection of labeled samples of the source project, N s represents the number of samples, i Represents the i-th data in the label sample, Respectively represent all the data and corresponding labels in the source project, Indicates the first label sample i data and corresponding labels.
[0109] The second acquisition module is adapted to acquire a sample of the target item and is used to perform the following steps:
[0110] S120: Obtain a sample of the target item.
[0111] Among them, the sample of the target project is ;
[0112] In the formula, S t represents the sample set of the target project, N t represents the number of samples, j Indicates the first j data, Respectively represent all the data in the target project and the corresponding labels to be predicted, Indicates the first j data and the corresponding labels to be predicted.
[0113] The kernel variance matching module is suitable for adjusting the marginal probability distribution of the label samples of the source item and the samples of the target item through kernel variance matching. It is used to perform the following steps:
[0114] S131: Setting the kernel bandwidth bd and the boundary value wb of the weight w;
[0115] S132: Get label samples of source items The number of samples N s ;
[0116] S133: Get a sample of the target project The number of samples N t ;
[0117] S134: Calculate the kernel variance sb of the source item using the following formula:
[0118] S135: ;
[0119] S136: Calculate the kernel matrix km of the source project based on the kernel function and the kernel bandwidth bd.
[0120] S137: Get label samples of source items and a sample of the target project The inner product kp of the source project is to use the kernel function to and a sample of the target project Map to the feature space and calculate the inner product kp;
[0121] S138: Create a constraint matrix cm to constrain the value of the weight w;
[0122] S139: creating a constraint vector cv to constrain the value of the weight w;
[0123] S1310: Minimize the gap between the inner product kp and the weight w through a quadratic programming solver, and constrain the weight w through a constraint matrix cm and a constraint vector cv, so as to obtain an optimal weight w value;
[0124] S1311: Update the label samples of the source project through the weight w to complete the kernel variance matching.
[0125] The covariance alignment module is suitable for adjusting the conditional probability distribution of the source item and the target item by designing the covariance as the loss function and aligning the labeled samples of the source item with the samples of the target item. It is used to perform the following steps:
[0126] S141: Calculate the sample covariance matrix of the source project label sample and the target project sample respectively;
[0127] S142: performing a whitening operation on the label samples of the source project;
[0128] S143: Align the whitened label samples of the source items with the samples of the target items to complete the adjustment of the conditional probability distributions of the source items and the target items.
[0129] The model training and iteration module is suitable for constructing the SDP model through the classification improvement algorithm and the loss function, and dynamically fusing the source project and the target project through multiple iterations until the marginal probability distribution and conditional probability distribution of the two are similar, and then completing the model training. That is, after each training and iteration, the label samples of the source project are aligned with the samples of the target project by using the covariance matrix, and the weights of the label samples of the source project and the target project are recalculated by the covariance matching of the aligned source project, and then new training and optimization iterations are started until the marginal probability distribution and conditional probability distribution of the two are similar.
[0130] The prediction module is suitable for predicting defects on samples of target projects through the trained SDP model.
[0131] Example 3
[0132] 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 cross-project instant software defect prediction method provided in Embodiment 1 is implemented.
[0133] Obtain label samples of the source project; obtain samples of the target project; adjust the marginal probability distribution of the label samples of the source project and the samples of the target project through kernel variance matching; adjust the conditional probability distribution of the source project and the target project by designing the covariance as the loss function and aligning the label samples of the source project with the samples of the target project; construct the SDP model through the classification boosting algorithm and the loss function, and dynamically fuse the source project and the target project through multiple iterations until the marginal probability distribution and conditional probability distribution of the two are close, and complete the model training; use the trained SDP model to predict defects for the samples of the target project. For cross-project instant software defect prediction, the marginal probability distribution and conditional probability distribution are considered at the same time, and the marginal probability distribution and conditional probability distribution of the label samples of the source project and the samples of the target project are close at the same time through multiple iterations of dynamic fusion, and the SDP model is trained, and then the defect prediction is performed on the target project, and the prediction result is more accurate.
[0134] Example 4
[0135] See also Figure 5 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 cross-project instant software defect prediction method provided in Example 1.
[0136] 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.
[0137] 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.
[0138] In summary, the present invention provides a method, device and storable medium for cross-project instant software defect prediction, wherein the label samples of the source project are obtained; the samples of the target project are obtained; the marginal probability distribution of the label samples of the source project and the samples of the target project are adjusted by kernel variance matching; the conditional probability distribution of the source project and the target project is adjusted by designing the covariance as a loss function and aligning the label samples of the source project with the samples of the target project; the SDP model is constructed by a classification boosting algorithm and a loss function, and the source project and the target project are dynamically fused through multiple iterations until the marginal probability distribution and conditional probability distribution of the two are close, completing the model training; and the samples of the target project are defect predicted through the trained SDP model. For cross-project instant software defect prediction, the problems of marginal probability distribution and conditional probability distribution are considered at the same time, and the marginal probability distribution and conditional probability distribution of the label samples of the source project and the samples of the target project are close at the same time through multiple iterations of dynamic fusion, and the SDP model is trained, and then the target project is defect predicted, and the prediction result is more accurate.
[0139] 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.
[0140] 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.
[0141] 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.
[0142] 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.
[0143] 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.
[0144] 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.
[0145] 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 cross-project instant software defect prediction method, characterized in that: include: Get labeled samples of source items; Get a sample of the target item; Adjust the marginal probability distributions of the source item's label samples and the target item's samples by kernel variance matching; Adjust the conditional probability distribution of source items and target items by designing covariance as the loss function and aligning the labeled samples of the source items with the samples of the target items; The SDP model is constructed through the classification improvement algorithm and loss function. The source project and the target project are dynamically integrated through multiple iterations until the difference between the marginal probability distribution and the conditional probability distribution of the two is less than the preset value, completing the model training. Through the trained SDP model, defects are predicted for samples of the target project; The label samples of the source items are ; In the formula, S S represents a collection of labeled samples of the source project, N s represents the number of samples, i Represents the i-th data in the label sample, Respectively represent all the data and corresponding labels in the source project, Indicates the first label sample i data and corresponding labels; A sample of the target items is ; In the formula, S t represents the sample set of the target project, N t represents the number of samples, j Indicates the sample j data, Respectively represent all the data in the target project and the corresponding labels to be predicted, Indicates the first j data and the corresponding labels to be predicted; The step of adjusting the marginal probability distribution of the label sample of the source item and the sample of the target item by kernel variance matching comprises: Set the kernel bandwidth bd and the boundary value wb of the weight w; Get a sample of labels for the source project The number of samples N s ; Get a sample of the target project The number of samples N t ; Calculate the kernel variance sb of the source item using the following formula: ; Calculate the kernel matrix km of the source project based on the kernel function and kernel bandwidth bd. Get a sample of labels for the source project and a sample of the target project The inner product kp of the source project is to use the kernel function to and a sample of the target project Map to the feature space and calculate the inner product kp; Create a constraint matrix cm to constrain the value of weight w; Create a constraint vector cv to constrain the value of the weight w; Minimize the gap between the inner product kp and the weight w through the quadratic programming solver, and constrain the weight w through the constraint matrix cm and the constraint vector cv to obtain the optimal weight w value; Update the label samples of the source project through the weight w to complete the kernel variance matching; The conditional probability distribution of the source item and the target item is adjusted by designing the covariance as the loss function and aligning the label sample of the source item with the sample of the target item, that is: Calculate the sample covariance matrix of the source project's label sample and the target project's sample respectively; Perform whitening operation on the labeled samples of the source project; The label samples of the whitened source items are aligned with the samples of the target items to complete the adjustment of the conditional probability distribution of the source items and the target items.
2. The cross-project instant software defect prediction method according to claim 1, characterized in that: The SDP model is constructed by using the classification improvement algorithm and the loss function, and the source project and the target project are dynamically integrated through multiple iterations until the marginal probability distribution and the conditional probability distribution of the two are similar, and the model training is completed, that is: After each training and iteration, the label samples of the source project are aligned with the samples of the target project by using the covariance matrix. The weights of the label samples of the source project and the target project are recalculated using covariance matching after the alignment, and then new training and optimization iterations are started until the difference between the marginal probability distribution and the conditional probability distribution of the two is less than the preset value.
3. The cross-project instant software defect prediction method according to claim 1, characterized in that: The method further includes evaluating the prediction results, wherein the evaluation of the prediction results specifically includes the following steps: Obtain the accuracy of the prediction results; Calculate the G-Mean index and MCC index of the accuracy of all prediction results; The SDP model is evaluated using the G-Mean and MCC indicators.
4. A cross-project instant software defect prediction device for implementing the cross-project instant software defect prediction method according to claim 1, characterized in that: include: A first acquisition module, used to acquire label samples of source items; The second acquisition module is used to acquire samples of the target project; A kernel variance matching module, used to adjust the marginal probability distribution of the label samples of the source item and the samples of the target item through kernel variance matching; A covariance alignment module is used to adjust the conditional probability distribution of the source item and the target item by designing the covariance as the loss function and aligning the labeled samples of the source item with the samples of the target item; The model training and iteration module is used to build the SDP model through the classification improvement algorithm and the loss function, and dynamically fuse the source project and the target project through multiple iterations until the difference between the marginal probability distribution and the conditional probability distribution of the two is less than the preset value, completing the model training; The prediction module is used to predict defects of samples of the target project through the trained SDP 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 cross-project instant 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 cross-project instant 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
Cross-project software aging defect prediction method and device
CN117112399A
Method for determining defects and vulnerabilities in software code
WO2017181286A1
