Cross-project defect prediction method and system based on similarity matching and heterogeneous graph
By selecting the source project that is most similar to the target project and building a heterogeneous graph, using graph convolution network and cross-attention mechanism, the feature difference problem in cross-project defect prediction is solved, and the generalization performance and expression ability of the prediction model are improved.
Patent Information
- Application Number
- CN202411915691.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-24
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2044-12-24
AI Technical Summary
Existing cross-project defect prediction methods are difficult to effectively deal with the characteristic differences between source projects and target projects, especially when the source projects are not essentially suitable for target projects, resulting in a degradation in predictive model performance.
By calculating the difference in feature distribution and instance similarity between source items and target items, selecting the most similar source items as training data, constructing heterogeneous graphs and using graph convolution networks and cross-attention mechanisms to improve the expression ability of defect prediction models.
The generalization performance of the defect prediction model and the ability to express the defect characteristics of the code are improved, ensuring high correlation and representativeness of the training data.
Smart Images

Figure CN119690846A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of cross-project software defect prediction, and in particular, relates to a cross-project defect prediction method and system based on similarity matching and heterogeneous graphs. Background Art
[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.
[0003] The results of software defect prediction can help testers focus on the predicted defect modules, playing an important role in allocating test resources and improving test efficiency. However, for new software projects, due to the lack of sufficient labeled data, it is difficult to build an effective prediction model based on the historical defect data set collected in the software project. This makes cross-project defect prediction a viable solution. Building a prediction model based on historical defect data collected from other projects and applying it to the target project can make up for the limitation of insufficient data. However, this process faces many challenges.
[0004] On the one hand, due to differences in technical levels of development teams and inconsistent code specifications, there are significant feature differences between different projects. This difference is particularly prominent in cross-project defect prediction, which directly affects the performance of the prediction model. Existing methods usually directly use one or more source projects to build models and apply them to target projects through techniques such as transfer learning. However, even if the differences are reduced by means of feature alignment, these methods still find it difficult to effectively deal with the large feature differences between source and target projects, especially when the source project is essentially not applicable to the target project; while instance selection-based methods attempt to improve prediction accuracy by screening source data instances that are more similar to the target project, but this strategy may discard some potentially valuable source data instances, resulting in insufficient coverage of training data, which ultimately affects the prediction performance on the target project.
[0005] On the other hand, existing methods also have shortcomings in utilizing code structure information. Code structure graphs such as abstract syntax trees, control flow graphs, and data flow graphs contain rich global and local information, but existing models do not make sufficient use of multiple types of edges and cannot fully capture the global information of code graphs, resulting in a lot of important information not being effectively mined. Summary of the invention
[0006] In order to overcome the shortcomings of the above-mentioned prior art, the present invention provides a cross-project defect prediction method and system based on similarity matching and heterogeneous graphs, which selects the source project most similar to the target project as the source project for training, ensuring the high relevance and representativeness of the defect prediction model training data, thereby improving the generalization performance of the defect prediction model; by constructing a heterogeneous graph, based on graph convolution and cross-attention mechanism, the defect prediction model's ability to express code defect features is improved.
[0007] In order to achieve the above object, the present invention adopts the following technical solution:
[0008] In a first aspect, the present invention provides a cross-project defect prediction method based on similarity matching and heterogeneous graphs, comprising:
[0009] Calculate the distribution difference and instance feature similarity between each source project and the target project, and obtain the distribution difference score and instance feature similarity score of each source project;
[0010] Calculate the weighted similarity scores corresponding to each source project according to the distribution difference scores and instance feature similarity scores of each source project, and determine the source project for training;
[0011] A code structure diagram is constructed for the source project used for training, and a defect prediction model is trained using the constructed code structure diagram. The target project obtains a defect prediction result through the trained defect prediction model; wherein the defect prediction model is constructed by a graph convolutional network and a cross-attention mechanism.
[0012] In a second aspect, the present invention provides a cross-project defect prediction system based on similarity matching and heterogeneous graphs, comprising:
[0013] A calculation module is configured to: calculate the distribution difference and instance feature similarity of each source project and the target project, and obtain the distribution difference score and instance feature similarity score of each source project;
[0014] A determination module is configured to: calculate the weighted similarity scores corresponding to the respective source items according to the distribution difference scores and instance feature similarity scores of the respective source items, and determine the source items for training;
[0015] The training and prediction module is configured to: construct a code structure diagram for the source project used for training, use the constructed code structure diagram to train the defect prediction model, and obtain a defect prediction result for the target project through the trained defect prediction model; wherein the defect prediction model is constructed by a graph convolutional network and a cross-attention mechanism.
[0016] In a third aspect, the present invention provides an electronic device comprising a memory and a processor, and computer instructions stored in the memory and executed on the processor, wherein when the computer instructions are executed by the processor, the method described in the first aspect is performed.
[0017] In a fourth aspect, the present invention provides a computer-readable storage medium for storing computer instructions, wherein when the computer instructions are executed by a processor, the method described in the first aspect is performed.
[0018] In a fifth aspect, the present invention provides a computer program product, comprising a computer program, which, when executed by a processor, implements the method described in the first aspect.
[0019] One or more of the above technical solutions have the following beneficial effects:
[0020] In the present invention, by calculating the feature distribution difference and instance similarity between the source project and the target project, the source project most similar to the target project is selected as the source project for training, ensuring the high relevance and representativeness of the defect prediction model training data, thereby improving the generalization performance of the defect prediction model.
[0021] In the present invention, a heterogeneous graph is constructed, and based on graph convolution and cross-attention mechanism, the information of multiple types of edges is effectively aggregated into the node representation of the graph, so that the nodes not only contain local characteristics but also reflect the global dependencies of the code structure, significantly improving the expression ability of the defect prediction model for code defect characteristics.
[0022] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0024] Figure 1 An overall flow chart of cross-project defect prediction provided by the first embodiment of the present invention;
[0025] Figure 2 A data flow processing diagram of a cross-project defect prediction method based on project similarity matching and heterogeneous graphs provided in the first embodiment of the present invention;
[0026] Figure 3 A flow chart of a cross-project defect prediction embodiment provided in Embodiment 1 of the present invention;
[0027] Figure 4 A schematic diagram of a cross-project defect prediction structure provided in Embodiment 2 of the present invention. DETAILED DESCRIPTION
[0028] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.
[0029] It should be noted that the terms used herein are for describing specific embodiments only and are not intended to be limiting of exemplary embodiments according to the present invention.
[0030] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.
[0031] Embodiment 1
[0032] This embodiment discloses a cross-project defect prediction method based on similarity matching and heterogeneous graphs, including:
[0033] Calculate the distribution difference and instance feature similarity between each source project and the target project, and obtain the distribution difference score and instance feature similarity score of each source project;
[0034] Calculate the weighted similarity scores corresponding to each source project according to the distribution difference scores and instance feature similarity scores of each source project, and determine the source project for training;
[0035] Performing balancing processing on the source projects determined for training, and constructing a code structure diagram for the balanced training data set obtained after the balancing processing;
[0036] The defect prediction model is trained using the constructed code structure graph, and the target project obtains a defect prediction result based on the trained defect prediction model; wherein the defect prediction model is constructed by a graph convolutional network and a cross-attention mechanism.
[0037] In this embodiment, first, by comprehensively analyzing the difference in feature distribution between the source project and the target project, as well as the similarity between the source project instance and the target project instance, the most appropriate source project is selected by combining the weights of the two to ensure high correlation of the data. Then, a graph convolutional network module is designed. Graph Convolutional Networks (GCN), as a deep learning model that can process heterogeneous graphs, shows great potential in the field of software defect prediction. GCN can capture complex dependencies by modeling the relationship between nodes and edges. By introducing multiple types of edges in the code structure graph, including abstract syntax tree (AST), control flow graph (CFG), data flow graph (DFG), call graph (CG), program dependency graph (PDG) and other types of edges, the overall structure and functional information of the code are fully captured. In order to more accurately integrate the semantic information of multiple edges, the model adopts a cross-attention mechanism to make the node representation more accurate. Finally, the trained model is used for the target project to predict the defects of the target project.
[0038] Combine the following Figure 1-Figure 3 The cross-project defect prediction method based on similarity matching and heterogeneous graph proposed in this embodiment is described in detail, including:
[0039] Step 1: Calculate the distribution difference and instance feature similarity between each source project and the target project, and obtain the distribution difference score and instance feature similarity score of each source project.
[0040] This embodiment is based on an existing public project dataset. Each source project has multiple features, such as statistical features (number of code lines, number of comment lines, etc.), string features (variable name, class name, etc.), etc., covering a rich range of code attributes.
[0041] The acquired source project code data is preprocessed, including data cleaning, missing data completion, feature definition and storage, to ensure the accuracy and stability of subsequent model training and prediction.
[0042] Based on the data of each source project, the distribution difference between each source project and the target project is calculated to obtain the distribution difference score of each source project, which provides a basis for the subsequent source project selection. In order to quantify this distribution difference, a calculation method based on Kullback-Leibler (KL) divergence is used to evaluate the difference in feature distribution between the source project and the target project.
[0043] For the feature distributions P(u) and Q(u) of source item S and target item T, the KL divergence is defined as:
[0044]
[0045] Among them, u is a discrete feature, U is the feature set of the union of the source project S and the target project T, P(u) and Q(u) are the feature distribution probabilities of the source project S and the target project T respectively, and the calculation method of P(u) and Q(u) is the number of samples with feature value u in the project divided by the total number of samples in the project. The larger the result of KL divergence, the greater the difference in distribution between the source project and the target project; on the contrary, the smaller the KL divergence, the closer the distribution of the two is.
[0046] Among them, when u is a unique feature of the source project S, Q(u) in formula (1) is replaced by a smoothing term, that is, a very small positive number, to avoid the denominator being 0; when u is a unique feature of the target project T, P(u) in formula (1) is 0.
[0047] Based on the data of each source project, the instance feature similarity of each source project and the target project is calculated to obtain the instance feature similarity score of each source project.
[0048] Assume that the instances in the target project dataset can be represented as in, Represents the i-th target instance The kth feature of , d represents the total number of features, and the maximum and minimum values of the kth feature of the target project dataset can be expressed as:
[0049]
[0050] Among them, n t Indicates the number of instances in the target project dataset.
[0051] This gives us two d-dimensional vectors:
[0052]
[0053] Given a source project dataset D S , use the maximum information coefficient MIC to calculate the kth feature The feature importance θ k , and normalize it:
[0054]
[0055] Among them, θ k represents the importance of the kth feature, and C∈{0,1} is the class label.
[0056] The importance of the same features of the source item S and the target item T is calculated by formula (6).
[0057] For the i-th instance of the source project, its feature weighted similarity with the target project dataset is defined as follows:
[0058]
[0059] in, represents the value of the kth feature of the i-th instance of source item S, It represents the feature weighted similarity, and fw is the feature weight.
[0060] Accumulate the weighted similarity of features of all instances of the source project, and then divide it by the number of all instances of the source project n s , get the instance feature similarity score of the source project:
[0061]
[0062] Among them, Score s represents the instance feature similarity score of the source project S, n s The number of all instances of the source project.
[0063] Step 2: Calculate the weighted similarity score corresponding to each source item according to the distribution difference score and instance feature similarity score of each source item, and determine the source item for training.
[0064] Specifically, the obtained distribution difference score and instance feature similarity score are used to calculate the similarity weight of each source item, and the weighted similarity score w of each source item is obtained. s The weight calculation method is as follows:
[0065]
[0066] Wherein, S={1, 2, ..., M}, M represents the number of source items, and α is a weight factor for adjusting the contribution of the two components.
[0067] Using the obtained weighted similarity score w s , select the source items with the highest scores as the training dataset.
[0068] Step 3: Perform balancing processing on the source projects determined for training, and construct a code structure diagram for the balanced training data set obtained after the balancing processing.
[0069] In this embodiment, according to the selected source project, the SMOTE algorithm is used to balance the data of the source project to obtain a balanced training data set.
[0070] SMOTE (Synthetic Minority Oversampling Technique) is an oversampling method for class imbalance. It generates synthetic samples between minority class samples to balance the class distribution of the data set. It first extracts all minority class samples in the data set, sets the target balance ratio between the majority class and minority class samples, and determines the number of minority class samples to be generated. For each minority class sample, calculate the m nearest neighbor samples of the sample, which also belong to the minority class. Randomly select a neighbor from these neighbors and synthesize a new sample by interpolation. Repeat the above steps until the number of samples reaches the set target.
[0071] For the balanced training data set, the Joern tool is used to generate an abstract syntax tree (AST) for each method (function); using the obtained AST tree, the starting point and end point of the control flow graph (CFG) are added to the AST tree, and according to the edge addition rules of the control flow graph, call graph (CG), data flow graph (DFG), and program dependency graph (PDG), various types of edges are added to the graph to construct a heterogeneous graph containing multiple types of edges, and all methods in a Java source code file in a Java software project are connected to form a code structure graph G = {V, E, R}, where V is the set of nodes in the graph, E is the combination of edges in the graph, and R is the set of edge types in the graph, where nodes are AST nodes, each node is represented by a vector, which includes source code, node type and other information; edges are the above-mentioned types of edges, representing the relationship between nodes, and each edge is represented by a vector, which includes edge type, start and end nodes and other information.
[0072] Joern is a powerful code parsing and analysis tool that supports multiple programming languages and helps researchers and engineers perform in-depth analysis of code by converting source code into multiple graph representations.
[0073] Step 3: Train the defect prediction model using the constructed code structure diagram, and obtain defect prediction results for the target project based on the trained defect prediction model; wherein the defect prediction model is constructed by a graph convolutional network and a cross-attention mechanism.
[0074] In this embodiment, the obtained code structure graph is used to train a prediction model, which includes a graph convolutional network and a cross-attention mechanism. The information of different types of edges in the code structure graph is aggregated through a graph convolutional network (GCN). During the aggregation process, the cross-attention mechanism is combined to enhance the semantic information of the edges and generate richer node representations.
[0075] The graph convolution process can be expressed as: for each edge type r∈R in the code structure graph, a separate graph convolution is performed:
[0076]
[0077] in, is the weight matrix of the edge of type r, is the set of neighbor nodes with edge type r, c i,r is the number of neighbor nodes with edge type r, is the representation vector of the neighbor node, σ is the activation function, here the ReL U activation function is used, and l is the number of convolution layers.
[0078] Aggregate information of different edge types:
[0079]
[0080] Among them, β r is the edge type weight calculated based on the cross-attention mechanism, is the cross attention score, r′ is an edge of another type different from r. The representation of each node in the graph is updated through two layers of GCN, H( l + 1 ) is a matrix containing the representation vectors of multiple nodes.
[0081] Using the code structure diagram after graph convolution, global pooling is performed to generate a feature vector for each graph. The goal of global pooling is to compress the nodes in the graph into a feature vector of a fixed size through pooling operations. Global average pooling is used here, and for each dimension, the features of all nodes are averaged:
[0082]
[0083] Among them, v mean ∈R D is the final eigenvector of the graph, N represents the number of nodes in the graph, is the representation vector of the i-th node after convolution, where l=2.
[0084] Using the obtained feature vector, the defect probability value is output through the fully connected layer calculation and softmax activation function. The calculation process is as follows:
[0085] h fc =W fc v mean +b fc (14)
[0086] y=softmax(h fc ) (15)
[0087] Among them, h fc is the output of the fully connected layer, W fc is the weight matrix of the fully connected layer, b fc is the bias term, and y is the final output.
[0088] The gradient back-propagation algorithm is used to adjust the parameters in the defect prediction model and continuously optimize the defect prediction results.
[0089] After the defect prediction model training is completed, the data of the target project is used to build the graph and predict defects, and the predicted defect probability value of each file in the target project is output to complete the cross-project defect prediction task.
[0090] This embodiment uses accuracy, precision, recall and F1-Score as evaluation indicators, trains on a dataset with labels, and tests on a dataset without labels. The experimental comparison results are shown in Table 1.
[0091] Table 1 Comparison of defect prediction methods across projects
[0092] Model Accuracy Accuracy Recall F1-Score Logistic Regression 0.75 0.72 0.68 0.70 Support Vector Machine 0.78 0.74 0.73 0.73 Random Forest 0.82 0.80 0.75 0.77 Convolutional Neural Networks 0.83 0.81 0.80 0.80 Graph Convolutional Networks 0.85 0.84 0.81 0.82 This embodiment 0.88 0.87 0.85 0.86
[0093] Based on the results in Table 1, it can be seen that the performance of the cross-project defect prediction method proposed in this embodiment is better than other methods.
[0094] Embodiment 2
[0095] The purpose of this embodiment is to provide a cross-project defect prediction system based on similarity matching and heterogeneous graphs, including:
[0096] A calculation module is configured to: calculate the distribution difference and instance feature similarity of each source project and the target project, and obtain the distribution difference score and instance feature similarity score of each source project;
[0097] A determination module is configured to: calculate the weighted similarity scores corresponding to the respective source items according to the distribution difference scores and instance feature similarity scores of the respective source items, and determine the source items for training;
[0098] The training and prediction module is configured to: construct a code structure diagram for the source project used for training, use the constructed code structure diagram to train the defect prediction model, and obtain a defect prediction result for the target project through the trained defect prediction model; wherein the defect prediction model is constructed by a graph convolutional network and a cross-attention mechanism.
[0099] In further embodiments, there is also provided:
[0100] An electronic device includes a memory and a processor, and computer instructions stored in the memory and executed on the processor, wherein when the computer instructions are executed by the processor, the method described in Embodiment 1 is performed. For the sake of brevity, no further description is given here.
[0101] It should be understood that in this embodiment, the processor may be a central processing unit CPU, and the processor may also be other general-purpose processors, digital signal processors DSP, application-specific integrated circuits ASIC, off-the-shelf programmable gate arrays FPGA or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0102] The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the device type.
[0103] A computer-readable storage medium is used to store computer instructions. When the computer instructions are executed by a processor, the method described in embodiment 1 is completed.
[0104] The method in the first embodiment can be directly embodied as a hardware processor, or a combination of hardware and software modules in the processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware. To avoid repetition, it will not be described in detail here.
[0105] A computer program product includes a computer program, and when the computer program is executed by a processor, the method described in the first embodiment is implemented.
[0106] The present invention also provides at least one computer program product tangibly stored on a non-transitory computer-readable storage medium. The computer program product includes computer executable instructions, such as instructions included in a program module, which are executed in a device on a real or virtual processor of the target to perform the process / method as described above. Typically, program modules include routines, programs, libraries, objects, classes, components, data structures, etc. that perform specific tasks or implement specific abstract data types. In various embodiments, the functions of program modules can be combined or divided between program modules as needed. Machine executable instructions for program modules can be executed in local or distributed devices. In distributed devices, program modules can be located in local and remote storage media.
[0107] The computer program code for implementing the method of the present invention can be written in one or more programming languages. These computer program codes can be provided to the processor of a general-purpose computer, a special-purpose computer or other programmable data processing device, so that the program code, when executed by the computer or other programmable data processing device, causes the function / operation specified in the flow chart and / or block diagram to be implemented. The program code can be executed completely on a computer, partially on a computer, as an independent software package, partially on a computer and partially on a remote computer or completely on a remote computer or server.
[0108] In the context of the present invention, computer program codes or related data may be carried by any appropriate carrier to enable a device, apparatus or processor to perform the various processes and operations described above. Examples of carriers include signals, computer readable media, etc. Examples of signals may include electrical, optical, radio, acoustic or other forms of propagation signals, such as carrier waves, infrared signals, etc.
[0109] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with this embodiment can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0110] Although the above describes the specific implementation mode of the present invention in conjunction with the accompanying drawings, it is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art on the basis of the technical solution of the present invention without creative work are still within the scope of protection of the present invention.
Claims
1. A cross-project defect prediction method based on similarity matching and heterogeneous graphs, characterized in that: include: Calculate the distribution difference and instance feature similarity between each source project and the target project, and obtain the distribution difference score and instance feature similarity score of each source project; Calculate the weighted similarity scores corresponding to each source project according to the distribution difference scores and instance feature similarity scores of each source project, and determine the source project for training; A code structure diagram is constructed for the source project used for training, and a defect prediction model is trained using the constructed code structure diagram. The target project obtains a defect prediction result through the trained defect prediction model; wherein the defect prediction model is constructed by a graph convolutional network and a cross-attention mechanism.
2. The cross-project defect prediction method based on similarity matching and heterogeneous graphs according to claim 1, characterized in that: Calculate the distribution difference and instance feature similarity between each source project and the target project, and obtain the distribution difference score and instance feature similarity score of each source project, specifically: According to the feature distribution probability of the source project and the target project, the distribution difference between the source project and the target project is calculated by KL divergence calculation method; The maximum information coefficient is used to calculate the feature importance of the same features in the source project and the target project, and normalized. Based on the normalized feature importance, the weighted similarity of the features between the source project instance and the target project is calculated, and the weighted similarity of the features corresponding to each instance of the source project is averaged to obtain the instance feature similarity score corresponding to the source project.
3. The cross-project defect prediction method based on similarity matching and heterogeneous graphs according to claim 1, characterized in that: The weighted similarity scores corresponding to each source item are calculated according to the distribution difference scores and instance feature similarity scores of each source item, and the source items used for training are determined, specifically: Assign corresponding weights to the distribution difference score and instance feature similarity score of each source item, and calculate the weighted similarity score corresponding to each source item; The source items are arranged according to the weighted similarity scores, and the source item corresponding to the highest weighted similarity score is selected as the source item for training.
4. The cross-project defect prediction method based on similarity matching and heterogeneous graphs according to claim 1, characterized in that: Before constructing the code structure diagram for the source project used for training, it also includes: using the SMOTE algorithm to balance the source project used for training to obtain a balanced training data set, and constructing a code structure diagram for the balanced training data set.
5. The cross-project defect prediction method based on similarity matching and heterogeneous graphs according to claim 1 or 4, characterized in that: The code structure diagram is as follows: Use the parsing analysis tool to generate an abstract syntax tree for each method; Using the obtained abstract syntax tree, add the start and end points of the control flow graph to the abstract syntax tree; According to the edge adding rules of the control flow graph, call graph, data flow graph, and program dependency graph, various types of edges are added to the graph, all methods in the file are connected, and a code structure graph containing multiple types of edges is constructed.
6. The cross-project defect prediction method based on similarity matching and heterogeneous graphs according to claim 1, characterized in that: The processing process of the prediction model on the code structure diagram is as follows: Perform graph convolution on each edge type in the heterogeneous graph separately, and obtain the graph convolution results of different edge types by edge type weight aggregation based on the cross attention mechanism; The aggregated code structure graph is globally pooled to generate a feature vector, which is then processed through a fully connected layer and an activation function to obtain a defect probability value.
7. A cross-project defect prediction system based on similarity matching and heterogeneous graphs, characterized by: include: A calculation module is configured to: calculate the distribution difference and instance feature similarity of each source project and the target project, and obtain the distribution difference score and instance feature similarity score of each source project; A determination module is configured to: calculate the weighted similarity scores corresponding to the respective source items according to the distribution difference scores and instance feature similarity scores of the respective source items, and determine the source items for training; The training and prediction module is configured to: construct a code structure diagram for the source project used for training, use the constructed code structure diagram to train the defect prediction model, and obtain a defect prediction result for the target project through the trained defect prediction model; wherein the defect prediction model is constructed by a graph convolutional network and a cross-attention mechanism.
8. An electronic device, characterized in that: The method comprises a memory and a processor and computer instructions stored in the memory and executed on the processor, wherein when the computer instructions are executed by the processor, the method according to any one of claims 1 to 6 is completed.
9. A computer-readable storage medium, characterized in that: Used to store computer instructions, which, when executed by a processor, complete the method described in any one of claims 1 to 6.
10. A computer program product, characterized in that The invention comprises a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method based on KL divergence for predicting multi-source software defects
CN106569954A
Software defect prediction method and system based on heterogeneous class relation graph neural network
CN117290238A
Software defect prediction result uncertainty quantification method
CN118132436A
Software defect prediction method and system
CN118672594A
Method for determining defects and vulnerabilities in software code
WO2017181286A1