Cross-project defect prediction method and system based on similarity matching and heterogeneous graph

By selecting source items with high similarity and constructing heterogeneous graphs, and utilizing graph convolutional networks and cross-attention mechanisms, the problems of feature differences and insufficient information utilization in cross-item defect prediction are solved, thereby improving the model's prediction performance and accuracy.

CN119690846BActive Publication Date: 2026-02-03SHANDONG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411915691.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-24
Publication Date
2026-02-03
Estimated Expiration
2044-12-24

AI Technical Summary

Technical Problem

Existing cross-project defect prediction methods struggle to build effective prediction models when faced with differences in features and insufficient utilization of code structure information between different projects, resulting in insufficient training data coverage and poor prediction performance.

Method used

By calculating the distribution differences and instance feature similarities between source and target items, the most similar source item is selected for training, and a heterogeneous graph is constructed. Graph convolutional networks and cross-attention mechanisms are then used to enhance the expressive power of the defect prediction model.

Benefits of technology

It improves the generalization performance and prediction accuracy of the defect prediction model, significantly enhances the ability to express code defect features, and strengthens the representativeness and accuracy of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690846B_ABST
    Figure CN119690846B_ABST
Patent Text Reader

Abstract

The application provides a cross-project defect prediction method and system based on similarity matching and a heterogeneous graph, selects a source project most similar to a target project as a source project for training by calculating feature distribution differences and instance similarities of the source project and the target project, ensures high correlation and representativeness of defect prediction model training data, and thus improves generalization performance of the defect prediction model. A heterogeneous graph is constructed, information of multiple types of edges is effectively aggregated into node representation of the graph based on graph convolution and a cross attention mechanism, so that the node not only contains local characteristics, but also reflects global dependence of a code structure, and thus expression ability of the defect prediction model on code defect characteristics is significantly improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the technical field of cross-project software defect prediction, and particularly relates to a cross-project defect prediction method and system based on similarity matching and heterogeneous graphs. BACKGROUND

[0002] The statements in this section merely provide background information related to the present application and do not necessarily constitute prior art.

[0003] The results of software defect prediction can help testers focus on predicted defect modules, and play an important role in allocating testing resources and improving testing efficiency. However, for new software projects, it is difficult to build an effective prediction model based on the historical defect data set collected in the software project due to the lack of sufficient labeled data. This makes cross-project defect prediction a viable solution. Building a prediction model from the historical defect data collected from other projects and applying it to the target project can make up for the limitations of insufficient data. However, this process faces many challenges.

[0004] On the one hand, due to the differences in the technical level of the development team and the inconsistency of the code specifications, there are significant feature differences between different projects. This difference is particularly prominent in cross-project defect prediction and directly affects the performance of the prediction model. Existing methods usually directly use one or more source projects to build the model and apply it to the target project through transfer learning and other techniques. However, even with feature alignment and other methods to reduce differences, these methods still struggle to effectively deal with the large feature differences between source and target projects, especially when the source project is not inherently suitable for the target project; and instance selection-based methods attempt to improve prediction accuracy by filtering 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 the training data and ultimately affecting the prediction performance on the target project.

[0005] On the other hand, existing methods also have deficiencies 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 full use of multiple types of edges, and cannot fully capture the global information of the code graph, resulting in many important information not being effectively mined. SUMMARY

[0006] To overcome the deficiencies of the above-mentioned prior art, the present application provides a cross-project defect prediction method and system based on similarity matching and heterogeneous graphs, which selects the most similar source project 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 expression ability of the defect prediction model for code defect features is improved.

[0007] To achieve the above object, the present application adopts the following technical solutions:

[0008] In a first aspect, the present application provides a cross-project defect prediction method based on similarity matching and heterogeneous graphs, comprising:

[0009] calculating the distribution difference and instance feature similarity of each source project with the target project respectively, to obtain the distribution difference score and instance feature similarity score of each source project;

[0010] calculating the weighted similarity score corresponding to each source project respectively according to the distribution difference score and instance feature similarity score of each source project, and determining the source project for training;

[0011] constructing a code structure graph for the source project for training, training a defect prediction model using the constructed code structure graph, and obtaining a defect prediction result for the target project through the trained defect prediction model; wherein the defect prediction model is constructed by a graph convolution network and a cross-attention mechanism.

[0012] In a second aspect, the present application provides a cross-project defect prediction system based on similarity matching and heterogeneous graphs, comprising:

[0013] a calculation module configured to calculate the distribution difference and instance feature similarity of each source project with the target project respectively, to obtain the distribution difference score and instance feature similarity score of each source project;

[0014] a determination module configured to calculate the weighted similarity score corresponding to each source project respectively according to the distribution difference score and instance feature similarity score of each source project, and determine the source project for training;

[0015] a training and prediction module configured to construct a code structure graph for the source project for training, train a defect prediction model using the constructed code structure graph, 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 convolution network and a cross-attention mechanism.

[0016] In a third aspect, the present application provides an electronic device comprising a memory and a processor, and computer instructions stored in the memory and running on the processor, wherein when the computer instructions are run by the processor, the method of the first aspect is completed.

[0017] In a fourth aspect, the present application provides a computer readable storage medium for storing computer instructions, wherein when the computer instructions are executed by a processor, the method of the first aspect is completed.

[0018] In a fifth aspect, the present application provides a computer program product comprising a computer program which, when executed by a processor, implements the method of the first aspect.

[0019] The above one or more technical solutions have the following beneficial effects:

[0020] In the present application, by calculating the feature distribution difference and instance similarity of 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 application, a heterogeneous graph is constructed, and information of multiple types of edges is effectively aggregated into the node representation of the graph based on graph convolution and cross-attention mechanism, so that the node not only contains local characteristics, but also reflects the global dependency relationship of the code structure, significantly improving the expression ability of the defect prediction model for code defect features.

[0022] The advantages of the additional aspects of the present application will be partially given in the following description, partially will become obvious from the following description, or will be understood through the practice of the present application. BRIEF DESCRIPTION OF DRAWINGS

[0023] The accompanying drawings, which form a part of the present application, are intended to provide further understanding of the present application, and the illustrative embodiments of the present application and their description serve the purpose of explaining the present application. The present application should not be limited by the accompanying drawings.

[0024] Figure 1 A cross-project defect prediction overall flowchart is provided for the first embodiment of the present application;

[0025] Figure 2 A data flow processing process chart of the cross-project defect prediction method based on project similarity matching and heterogeneous graph is provided for the first embodiment of the present application;

[0026] Figure 3 A cross-project defect prediction embodiment flowchart is provided for the first embodiment of the present application;

[0027] Figure 4 A cross-project defect prediction structure schematic diagram is provided for the second embodiment of the present application. DETAILED DESCRIPTION

[0028] It should be noted that the following detailed description is exemplary and is intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as generally understood by those skilled in the art to which the present application belongs.

[0029] It is to be noted that the terms used herein are merely for describing specific embodiments and are not intended to limit exemplary embodiments according to the present application.

[0030] In the case of no conflict, the embodiments in the present application and the features in the embodiments can be combined with each other.

[0031] Embodiment one

[0032] The embodiment discloses a cross-project defect prediction method based on similarity matching and a heterogeneous graph, comprising:

[0033] Calculate the distribution difference and instance feature similarity of each source project with the target project respectively, to obtain the distribution difference score and instance feature similarity score of each source project;

[0034] According to the distribution difference score and instance feature similarity score of each source project, calculate the weighted similarity score corresponding to each source project respectively, and determine the source project for training;

[0035] Balance processing is performed on the determined source project for training, and a code structure graph is constructed based on the balanced training data set obtained after the balance processing.

[0036] The defect prediction model is trained using the constructed code structure graph, and the target project is based on the trained defect prediction model to obtain a defect prediction result; wherein the defect prediction model is constructed by a graph convolutional network and a cross attention mechanism.

[0037] In the embodiment, first, by comprehensively analyzing the feature distribution difference of the source project and the target project, and the similarity of the source project instance and the target project instance, combined with the weights of the two, the most suitable source project is selected to ensure the high correlation of the data. Then, a graph convolutional network module is designed, the graph convolutional network (GCN) is a deep learning model capable of processing heterogeneous graphs, which shows great potential in the field of software defect prediction. GCN can capture complex dependency relationships through node and edge relationship modeling, and can fully capture the overall structure and functional information of the code by introducing various 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 the like. In order to more accurately fuse the semantic information of multiple edges, the model adopts a cross attention mechanism, which makes the node representation more accurate. Finally, the trained model is used for the target project to perform defect prediction of the target project.

[0038] The following will be described in combination with Figures 1-3 The cross-project defect prediction method based on similarity matching and a heterogeneous graph proposed in the embodiment will be described in detail, which specifically comprises:

[0039] Step 1: Calculate the distribution difference and instance feature similarity of each source project with the target project respectively, to obtain the distribution difference score and instance feature similarity score of each source project.

[0040] This embodiment is based on the 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.), and covers rich code attributes.

[0041] The obtained code data of the source project 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 of each source project and the target project is calculated to obtain the distribution difference score of each source project, which provides a basis for subsequent source project selection. 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 distribution P(u) and Q(u) of the source project S and the target project T, the KL divergence is defined as:

[0044]

[0045] Where 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 KL divergence, the greater the distribution difference between the source project and the target project; on the contrary, the smaller the KL divergence, the closer the distribution of the two.

[0046] Where when u is a feature unique to the source project S, replace Q(u) in formula (1) with a smoothing term, which is a very small positive number, to avoid a denominator of 0; when u is a feature unique to 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 Where, represents the i-th target instance The k-th feature, where d represents the total number of features, can be represented by the maximum and minimum values ​​of the k-th feature in the target project dataset as follows:

[0049]

[0050] Where, n t This represents the number of instances in the target project dataset.

[0051] This yields two d-dimensional vectors:

[0052]

[0053] Given a source project dataset D S The maximum information coefficient (MIC) is used to calculate the k-th feature. Feature importance θ k And normalize it:

[0054]

[0055] Where, θ k Let C represent the importance of the k-th feature, and C∈{0,1} be the class label.

[0056] The importance of the same features between the source item S and the target item T is calculated using 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, This represents the value of the k-th feature of the i-th instance of the source project S. This represents the feature-weighted similarity, where fw is the feature weight.

[0060] Sum the feature-weighted similarities of all instances in the source project, then divide by the total number of instances in the source project, n. s The similarity score of the instance features of the source project is obtained:

[0061]

[0062] Among them, Score s n represents the instance feature similarity score of source item S. s This represents the total number of instances in the source project.

[0063] Step 2: Calculate the weighted similarity score for each source item based on the distribution difference score and instance feature similarity score, and determine the source items to be used for training.

[0064] Specifically, using the obtained distribution difference score and instance feature similarity score, the similarity weight of each source item is calculated, resulting in a weighted similarity score w for each source item. s The weight calculation method is as follows:

[0065]

[0066] Where S = {1, 2, ..., M}, M represents the number of source items, and α is a weighting factor that adjusts the contribution of the two components.

[0067] Using the obtained weighted similarity score w s The source project with the highest score was selected as the training dataset.

[0068] Step 3: Balance the source items determined for training, and construct a code structure diagram for the balanced training dataset obtained after balancing.

[0069] In this embodiment, the SMOTE algorithm is used to balance the data of the selected source items to obtain a balanced training dataset.

[0070] SMOTE (Synthetic Minority Oversampling Technique) is an oversampling method for class imbalance problems. It balances the class distribution of a dataset by generating synthetic samples among minority class samples. It first extracts all minority class samples from the dataset, sets a target balance ratio between majority and minority class samples, and determines the number of minority class samples to be generated. For each minority class sample, it calculates the sample's m nearest neighbors (which also belong to the minority class), randomly selects one of these neighbors, and synthesizes a new sample through interpolation. This process is repeated until the target number of samples is reached.

[0071] For a balanced training dataset, the Joern tool is used to generate an Abstract Syntax Tree (AST) for each method (function). Using the obtained AST, the start and end points of a Control Flow Graph (CFG) are added. Following the edge addition rules for Control Flow Graphs, Call Graphs (CG), Data Flow Graphs (DFG), and Program Dependency Graphs (PDG), edges of various types are added to the graph, constructing a heterogeneous graph containing multiple edge types. This graph connects all methods in a Java source code file of a Java software project, forming a code structure graph G = {V, E, R}, where V is the set of nodes, E is the set of edges, and R is the set of edge types. Nodes are AST nodes, each represented by a vector containing information such as source code and node type. Edges are the aforementioned types of edges, representing the relationships between nodes; each edge is represented by a vector containing information such as edge type and start and end nodes.

[0072] Joern is a powerful code parsing and analysis tool that supports multiple programming languages. It helps researchers and engineers conduct in-depth code analysis by converting source code into various graphical representations.

[0073] Step 3: Train the defect prediction model using the constructed code structure graph. The target project obtains the defect prediction result based on the trained defect prediction model. 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 the prediction model, which includes a graph convolutional network and a cross attention mechanism. The graph convolutional network (GCN) aggregates information of different types of edges in the code structure graph. 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 represented as: performing graph convolution separately for each edge type r∈R in the code structure graph:

[0076]

[0077] in, It is the weight matrix of edges of type r. It is the set of neighboring nodes of edge type r, c i,r It is the number of neighboring nodes of edge type r. σ is the representation vector of the neighboring nodes, σ is the activation function (here, the ReLU activation function is used), and l is the number of convolutional layers.

[0078] Aggregate information from different edge types:

[0079]

[0080] Where, β r It is an edge type weight calculated based on the cross-attention mechanism. H is the cross-attention score, where r′ is an edge of a different type than r. The representation of each node in the graph is updated using a two-layer GCN, H( l + 1 ) is a matrix containing representation vectors of multiple nodes.

[0081] Using the code structure graph resulting from 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 fixed-size feature vector through pooling operations. Here, global average pooling is used, averaging the features of all nodes for each dimension:

[0082]

[0083] Among them, v mean ∈R D It is the final feature vector of the graph, where N represents the number of nodes in the graph. It is the representation vector of the i-th node after convolution, where l = 2.

[0084] Using the obtained feature vectors, the defect probability value is calculated through a fully connected layer and then activated by a softmax 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 It is the output of the fully connected layer, W fc It is the weight matrix of the fully connected layer, b fc y is the bias term, and y is the final output.

[0088] The parameters in the defect prediction model are adjusted using the gradient backpropagation algorithm to continuously optimize the defect prediction results.

[0089] After the defect prediction model is trained, graph construction and defect prediction are performed using the data from the target project. The predicted defect probability value for each file in the target project is output, thus completing the cross-project defect prediction task.

[0090] This embodiment uses accuracy, precision, recall, and F1-score as evaluation metrics. It is trained on a labeled dataset and tested on an unlabeled dataset. The experimental comparison results are shown in Table 1.

[0091] Table 1 Comparison of Cross-Project Defect Prediction Methods

[0092] Model Accuracy Precision 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 Network 0.83 0.81 0.80 0.80 Graph Convolutional Network 0.85 0.84 0.81 0.82 The present embodiments 0.88 0.87 0.85 0.86

[0093] Based on the results in Table 1, it can be seen that the cross-project defect prediction method proposed in this embodiment outperforms other methods.

[0094] Example 2

[0095] The purpose of this embodiment is to provide a cross-project defect prediction system based on similarity matching and heterogeneous graphs, as provided by the present invention, including:

[0096] The calculation module is configured to: calculate the distribution difference and instance feature similarity between each source item and the target item, and obtain the distribution difference score and instance feature similarity score for each source item;

[0097] The module is configured to: calculate the weighted similarity score corresponding to each source item based on the distribution difference score and instance feature similarity score of each source item, and determine the source items to be used for training.

[0098] The training and prediction module is configured to: construct a code structure graph for the source project used for training; train the defect prediction model using the constructed code structure graph; and obtain the defect prediction result for the target project through the trained defect prediction model. The defect prediction model is constructed by a graph convolutional network and a cross-attention mechanism.

[0099] In further embodiments, the following is also provided:

[0100] An electronic device includes a memory and a processor, as well as computer instructions stored in the memory and running on the processor. When executed by the processor, the computer instructions perform the method described in Embodiment 1. For brevity, further details are omitted here.

[0101] It should be understood that in this embodiment, the processor can be a central processing unit (CPU), or it can be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.

[0102] Memory may include read-only memory and random access memory, and provides instructions and data to the processor. A portion of memory may also include non-volatile random access memory. For example, memory may also store information about the device type.

[0103] A computer-readable storage medium for storing computer instructions, which, when executed by a processor, perform the method described in Embodiment 1.

[0104] The method in Embodiment 1 can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor. The software modules can reside in readily available storage media in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory; the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method. To avoid repetition, a detailed description is not provided here.

[0105] A computer program product includes a computer program that, when executed by a processor, implements the method described in Embodiment 1.

[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 program modules, which execute in a device on a target real or virtual processor to perform the processes / methods 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 functionality of program modules can be combined or divided among program modules as needed. The machine-executable instructions for the program modules can execute within a local or distributed device. In a distributed device, the program modules can reside in both local and remote storage media.

[0107] The computer program code used to implement the methods of the present invention may be written in one or more programming languages. This computer program code may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the computer or other programmable data processing device, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a computer, partially on a computer, as a stand-alone software package, partially on a computer and partially on a remote computer, or entirely on a remote computer or server.

[0108] In the context of this invention, computer program code or related data may be carried by any suitable 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, and the like. Examples of signals may include electrical, optical, radio, sound, or other forms of propagation signals, such as carrier waves, infrared signals, etc.

[0109] Those skilled in the art will recognize that the units and algorithm steps described in conjunction with the embodiments herein can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0110] While the specific embodiments of the present invention have been described above in conjunction with the accompanying drawings, this 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 without creative effort based on the technical solutions of the present invention 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 item and the target item to obtain the distribution difference score and instance feature similarity score for each source item; Specifically: Based on the characteristic distribution probabilities of the source and target items, the distribution difference between the source and target items is calculated using the KL divergence method. The importance of features with the same features in the source and target projects is calculated using the maximum information coefficient and then normalized. Based on the normalized feature importance, the weighted similarity between the source project instance and the target project is calculated. The average of the weighted similarity of the features corresponding to each instance of the source project is calculated to obtain the instance feature similarity score corresponding to the source project. Calculate the weighted similarity score for each source item based on the distribution difference score and instance feature similarity score of each source item, and determine the source items to be used for training. A code structure graph is constructed for the source project used for training. The defect prediction model is trained using the constructed code structure graph. The target project obtains the defect prediction result through the trained defect prediction model. The defect prediction model is constructed by a graph convolutional network and a cross-attention mechanism. Specifically, the code structure diagram is constructed as follows: Use parsing tools 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; Based on the edge addition rules of control flow graph, call graph, data flow graph, and program dependency graph, add edges of various types to the graph, connect all methods in the file, and construct a code structure graph containing multiple types of edges; The defect prediction model processes the code structure diagram as follows: Graph convolution is performed separately for each edge type in the heterogeneous graph, and the graph convolution results of different edge types are obtained by aggregating edge type weights based on the cross-attention mechanism; The aggregated code structure graph is subjected to global pooling to generate feature vectors. The generated feature vectors are then processed through a fully connected layer and an activation function to obtain the defect probability value.

2. The cross-project defect prediction method based on similarity matching and heterogeneous graphs as described in claim 1, characterized in that, Based on the distribution difference score and instance feature similarity score of each source item, a weighted similarity score is calculated for each source item to determine the source items used for training, specifically: Assign corresponding weights to the distribution difference score and instance feature similarity score of each source item, and calculate the weighted similarity score for each source item. The source items are ranked according to the weighted similarity score, and the source item with the highest weighted similarity score is selected as the source item for training.

3. The cross-project defect prediction method based on similarity matching and heterogeneous graphs as described in claim 1, characterized in that, Before constructing the code structure graph for the source items used for training, the process includes: balancing the source items used for training using the SMOTE algorithm to obtain a balanced training dataset, and constructing a code structure graph for the balanced training dataset.

4. A cross-project defect prediction system based on similarity matching and heterogeneous graphs, characterized in that, include: The calculation module is configured to: calculate the distribution difference and instance feature similarity between each source item and the target item, obtaining the distribution difference score and instance feature similarity score for each source item; specifically: Based on the characteristic distribution probabilities of the source and target items, the distribution difference between the source and target items is calculated using the KL divergence method. The importance of features with the same features in the source and target projects is calculated using the maximum information coefficient and then normalized. Based on the normalized feature importance, the weighted similarity between the source project instance and the target project is calculated. The average of the weighted similarity of the features corresponding to each instance of the source project is calculated to obtain the instance feature similarity score corresponding to the source project. The module is configured to: calculate the weighted similarity score corresponding to each source item based on the distribution difference score and instance feature similarity score of each source item, and determine the source items to be used for training. The training and prediction module is configured to: construct a code structure graph for the source project used for training; train the defect prediction model using the constructed code structure graph; and obtain the defect prediction result for the target project through the trained defect prediction model. The defect prediction model is constructed by a graph convolutional network and a cross-attention mechanism. Specifically, the code structure diagram is constructed as follows: Use parsing tools 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; Based on the edge addition rules of control flow graph, call graph, data flow graph, and program dependency graph, add edges of various types to the graph, connect all methods in the file, and construct a code structure graph containing multiple types of edges; The defect prediction model processes the code structure diagram as follows: Graph convolution is performed separately for each edge type in the heterogeneous graph, and the graph convolution results of different edge types are obtained by aggregating edge type weights based on the cross-attention mechanism; The aggregated code structure graph is subjected to global pooling to generate feature vectors. The generated feature vectors are then processed through a fully connected layer and an activation function to obtain the defect probability value.

5. An electronic device, characterized in that, It includes a memory and a processor, as well as computer instructions stored in the memory and running on the processor, which, when executed by the processor, perform the method according to any one of claims 1-3.

6. A computer-readable storage medium, characterized in that, Used to store computer instructions, which, when executed by a processor, perform the method described in any one of claims 1-3.

7. A computer program product, characterized in that, Includes a computer program, which, when executed by a processor, implements the method described in any one of claims 1-3.

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