Software defect prediction method based on dynamic path adaptive graph convolutional network

Through the dynamic path adaptive graph convolutional network, the problem of module dependency modeling in complex software systems in existing software defect prediction methods is solved, and the efficient capture of key dependencies and accurate identification of minority modules are achieved, which improves the generalization performance of the model in cross-version and cross-project scenarios.

CN120705051AActive Publication Date: 2025-09-26HENAN UNIVERSITY OF TECHNOLOGY

Patent Information

Application Number
CN202510830067.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-20
Publication Date
2025-09-26
Estimated Expiration
2045-06-20

AI Technical Summary

Technical Problem

Existing software defect prediction methods have difficulty capturing nonlinear dependencies between modules when dealing with complex software systems. Static graph structures are difficult to adapt to the dynamic evolution of dependencies during software iterations. Traditional graph convolution does not distinguish the importance of paths in multi-hop neighborhood aggregation. Class imbalance processing methods easily destroy the consistency of graph topology. Existing attention mechanisms lack real-time adjustment capabilities, resulting in a decrease in the generalization performance of the model in cross-version and cross-project scenarios.

Method used

A dynamic path adaptive graph convolutional network is adopted to aggregate the module dependencies of multi-hop paths through a dynamic path weighted convolutional layer. The multi-head attention mechanism is applied to optimize the adjacency matrix. The weighted loss function is constructed by combining SMOTE oversampling and focal loss functions. The graph topology structure is dynamically updated, the weights of key dependency edges are enhanced, and redundant connections are pruned to optimize the defect prediction of software modules.

Benefits of technology

It effectively suppresses long path noise, enhances the modeling capabilities of complex software module call chains, improves the accuracy of capturing key dependencies, reduces computational complexity, and is suitable for real-time defect prediction in large-scale software systems. It significantly improves the generalization performance of the model and the ability to identify minority modules.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120705051A_ABST
    Figure CN120705051A_ABST
Patent Text Reader

Abstract

The invention provides a software defect prediction method based on a dynamic path adaptive graph convolution network, and the method comprises the steps: constructing graph structure data of a software module, inputting the graph structure data into the graph convolution network to learn a dependency relationship between modules, carrying out the adaptive weight distribution of a multi-hop path through a dynamic path weighting convolution layer, and carrying out the prediction of a software defect. The long-path noise interference is suppressed based on the path length attenuation coefficient; optimizing an adjacent matrix in real time based on a multi-head attention mechanism, enhancing a key dependency edge and pruning redundant connection; and embedding a dynamic path score and an adaptive graph updating algorithm into a classification objective function, updating a training weight in combination with a balance strategy, and outputting a defect prediction result through the optimized model. According to the method, the problems of insufficient dependent modeling, noise accumulation and performance degradation in a class imbalance scene of a traditional graph convolutional network under a static graph hypothesis can be effectively solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of software defect prediction, and more specifically to a software defect prediction method based on a dynamic path adaptive graph convolutional network. Background Art

[0002] As software systems become increasingly complex, the impact of software defects on system reliability and security becomes increasingly severe. In high-risk areas such as financial transactions, medical equipment, and infrastructure control, defects can lead to catastrophic consequences such as system crashes and data leaks. Therefore, automated defect prediction technology that proactively identifies high-risk modules has become a key research direction in software quality assurance.

[0003] Over the past decade, traditional methods based on hand-crafted software metrics combined with statistical learning techniques have dominated defect prediction. However, these methods struggle to capture complex nonlinear dependencies between modules and rely on manual feature engineering, which limits their generalization capabilities. In recent years, deep learning methods have improved prediction performance through automatic feature extraction, but models based on sequential architectures struggle to model control flow semantics and long-range dependencies, and face bottlenecks in identifying complex defect patterns. Graph neural networks (GNNs) improve on traditional methods by explicitly modeling module dependencies, but existing research often assumes static graph structures, resulting in significantly reduced generalization performance in cross-version and cross-project scenarios. Furthermore, the extreme class imbalance problem, where defective modules typically account for less than 10%, severely impairs model performance. Traditional resampling techniques can disrupt graph topology consistency, exacerbating prediction bias.

[0004] Although current defect prediction methods based on graph convolutional networks (GCNs) have made progress, they still have the following key flaws: (1) The static graph assumption is difficult to adapt to the dynamic evolution of dependencies during software iterations, resulting in a decrease in cross-version prediction performance; (2) Traditional graph convolution does not distinguish the importance of paths in multi-hop neighborhood aggregation, and long path noise accumulates with the number of propagation layers; (3) Class imbalance processing methods easily destroy the consistency of graph topology and reduce the recognition accuracy of minority class modules; (4) The existing attention mechanism lacks the ability to adjust the graph structure in real time, making it difficult to dynamically prune redundant connections. Therefore, how to overcome the above technical problems and defects has become a key issue that needs to be addressed. Summary of the Invention

[0005] To overcome the above-mentioned problems in the prior art, this application provides a software defect prediction method based on a dynamic path adaptive graph convolutional network, which adopts the following technical solutions:

[0006] In a first aspect, the present application provides a software defect prediction method based on a dynamic path adaptive graph convolutional network, comprising:

[0007] Conduct modular analysis on software systems and construct graph structure data of software modules;

[0008] The graph structure data is input into the dynamic path adaptive graph convolutional network, and the module dependencies of the multi-hop path are aggregated through the dynamic path weighted convolutional layer. The long path noise is suppressed based on the path length attenuation coefficient, and the node feature representation and path weight information are output.

[0009] Based on node feature representation and path weight information, a multi-head attention mechanism is applied to optimize the adjacency matrix in real time, enhancing the weights of key dependency edges and pruning redundant connections. The optimized adjacency matrix is ​​output, which reflects the graph topology after the attention mechanism strengthens key edges and prunes redundant edges.

[0010] Based on the optimized adjacency matrix, a dynamic path scoring algorithm and an adaptive graph update strategy are used to further update the graph topology to retain key dependencies, and output the optimized graph structure data adjusted by dynamic scoring and update strategy.

[0011] Based on the optimized graph structure data, the topology-aware class balancing strategy is embedded in the classification objective function, and a weighted loss function is constructed by fusing SMOTE oversampling and focal loss functions.

[0012] Based on the weighted loss function, the dynamic path adaptive graph convolutional network is optimized and the training weights are updated to output the defect prediction results of the software module.

[0013] Furthermore, the modular analysis of the software system and the construction of graph structure data of the software modules include:

[0014] Extract software modules, including static code metrics such as code complexity, number of lines of code, and cyclomatic complexity, and dynamic analysis metrics such as code change frequency and execution coverage, and generate multidimensional feature vectors;

[0015] The similarity value between modules is obtained through cosine similarity, and the association strength between modules is determined based on the similarity value;

[0016] Based on the calculated similarity values, the K-nearest neighbor strategy is used to screen the Top-K similar neighbors for each module;

[0017] Based on similar neighbors, directed weighted edges are constructed for each module to generate graph structure data, where the graph structure data is a directed weighted graph G = (V, E), where the node set V represents the software module and the edge set E represents the similarity relationship between modules.

[0018] Furthermore, the module dependencies of multi-hop paths are aggregated through a dynamic path weighted convolutional layer, including:

[0019] Calculate the path weight w of each path p in the set P(v) of all multi-hop paths of node v p , the sum of path weights is normalized to 1;

[0020] Perform weighted aggregation on all path features of node v based on the path weight to obtain the updated node feature representation of node v, while limiting the maximum path length and the number of paths retained per node;

[0021] After multi-layer dynamic path weighted convolution, the updated node feature representation of node v tends to be stable, and key module dependency focusing and noise suppression are achieved by attenuating the weight of long paths and enhancing the weight of high-attention short paths.

[0022] Furthermore, a multi-head attention mechanism is applied to optimize the adjacency matrix in real time, enhancing the weights of key dependency edges and pruning redundant connections, including:

[0023] Through the multi-head attention mechanism, a preset number of independent attention heads are used to parallelly calculate the associated attention weights between the node feature matrix and the initial adjacency matrix;

[0024] Based on the associated attention weights, multi-view information is fused through splicing operations to obtain the fused attention weights;

[0025] Based on the fused attention weights, the adjacency matrix is ​​dynamically optimized: edges with weights higher than a preset threshold are retained, and redundant connections with weights lower than a preset threshold are pruned. Dynamic pruning and adjacency matrix updates are performed, and the weights of the retained edges are updated to the weighted sum of the weights of multiple attention heads.

[0026] Furthermore, based on the optimized adjacency matrix, a dynamic path scoring algorithm and an adaptive graph update strategy are used to further update the graph topology to retain key dependencies. The output of the optimized graph structure data after dynamic scoring and update strategy adjustment includes:

[0027] The dynamic path scoring algorithm calculates the importance score C of each path p based on the comprehensive evaluation of path feature similarity and path length attenuation. p ;

[0028] After the path scoring is completed, the adjacency matrix is ​​updated according to the preset threshold θ;

[0029] Through iterative updates, low-scoring paths are gradually pruned and the weights of high-scoring paths are strengthened, ultimately forming sparsely optimized graph structure data.

[0030] Furthermore, the dynamic path scoring algorithm calculates the importance score C of each path p based on the comprehensive evaluation of path feature similarity and path length attenuation. p , which can be expressed as:

[0031]

[0032] Among them, h i and h j is the node feature vector, L p is the path length, λ∈[1.0,3.0] is the length attenuation coefficient, which is used to suppress long path noise.

[0033] Furthermore, the adjacency matrix is ​​updated according to the preset threshold θ, which can be expressed as:

[0034]

[0035] Where Δ∈[0.1,0.5] is the weight adjustment step size, which controls the degree of edge weight enhancement or weakening, w ij is the initial edge weight from node i to node j in the original adjacency matrix, A` ij is the weight of the new edge from node i to node j in the optimized adjacency matrix after dynamic scoring and adaptive updating, and ò is the lower limit of the weight to prevent the effective dependency from being completely removed.

[0036] Furthermore, a weighted loss function is constructed by fusing SMOTE oversampling and focal loss function, including:

[0037] The SMOTE oversampling algorithm is used to generate synthetic samples to balance the category distribution. Specifically, the SMOTE algorithm calculates the feature space neighbors of the defective samples and generates synthetic samples on the line connecting the original samples and the random neighbors. The synthetic sample features are calculated by adding a random scaling coefficient and the feature difference to the original sample features. No new graph nodes or edges are added. The feature vectors of the synthetic samples are mapped to the existing graph structure, and the connection weights between the synthetic samples and the neighboring nodes are adaptively adjusted through a dynamic path scoring mechanism.

[0038] The focus loss function is used to improve the loss contribution of defective samples through the category weight coefficient, and the weight of easy-to-classify samples is reduced by adjusting the coefficient to focus on difficult-to-classify samples.

[0039] Furthermore, the nearest neighbor in the feature space is calculated for the defective sample, and a synthetic sample is generated on the line connecting the original sample and the random nearest neighbor, which can be expressed as:

[0040]

[0041] in, is a synthetic sample, x i is the original sample, x j To randomly select neighbor samples in the feature space, δ is a uniformly distributed random number.

[0042] In a second aspect, the present application also provides a software defect prediction method system based on a dynamic path adaptive graph convolutional network, comprising:

[0043] Graph structure data construction module, used to perform modular analysis on software systems and construct graph structure data of software modules;

[0044] The node feature representation and path weight acquisition module is used to input graph structure data into the dynamic path adaptive graph convolutional network, aggregate the module dependencies of multi-hop paths through the dynamic path weighted convolutional layer, suppress long path noise based on the path length attenuation coefficient, and output node feature representation and path weight information;

[0045] The optimized adjacency matrix acquisition module is used to optimize the adjacency matrix in real time based on node feature representation and path weight information using a multi-head attention mechanism. This mechanism enhances the weights of key dependency edges and prunes redundant connections, outputting an optimized adjacency matrix that reflects the graph topology after the attention mechanism strengthens key edges and prunes redundant edges.

[0046] The optimized graph structure data adjustment module is used to further update the graph topology structure to retain key dependencies based on the optimized adjacency matrix, using a dynamic path scoring algorithm and an adaptive graph update strategy, and output the optimized graph structure data after dynamic scoring and update strategy adjustment;

[0047] A weighted loss function construction module is used to embed a topology-aware class balancing strategy into the classification objective function based on optimized graph structure data. The weighted loss function is constructed by fusing SMOTE oversampling and focal loss functions.

[0048] The defect prediction result output module is used to optimize the dynamic path adaptive graph convolutional network based on the weighted loss function and update the training weights to output the defect prediction results of the software module.

[0049] In a third aspect, the present application provides an electronic device, comprising:

[0050] One or more processors; a memory; and one or more computer programs, wherein the one or more computer programs are stored in the memory, and the one or more computer programs include instructions that, when executed by the device, cause the device to perform the method as described in the first aspect.

[0051] In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer-readable storage medium is run on a computer, the computer executes the method described in the first aspect.

[0052] In a fifth aspect, the present application provides a computer program, which, when executed by a computer, is used to execute the method described in the first aspect.

[0053] In one possible design, the program in the fifth aspect may be stored in whole or in part on a storage medium packaged with the processor, or may be stored in whole or in part on a memory not packaged with the processor.

[0054] This application has the following beneficial effects:

[0055] 1. This application uses dynamic path weighted convolution layers and path attenuation factors to effectively suppress long-path noise interference in multi-hop propagation, prioritize short-path dependencies, reduce redundant information interference, enhance the modeling capabilities of complex software module call chains, and improve the capture accuracy of key dependencies.

[0056] 2. This application optimizes the adjacency matrix in real time based on the multi-head attention mechanism, dynamically prunes redundant connections and strengthens the weights of key dependency edges, so that the model can adapt to the evolution of dependency relationships in software iterations. At the same time, by limiting the path length and the number of retained paths, the computational complexity is significantly reduced, making it suitable for real-time defect prediction in large-scale software systems.

[0057] 3. This application integrates synthetic sample generation and weighted loss functions to maintain the integrity of the graph structure while balancing the category distribution, avoids topological destruction by dynamically adjusting the connection weights, and focuses on the classification of difficult samples to improve the recognition ability of minority class modules.

[0058] 4. This application combines dynamic path scoring with an adaptive graph update strategy to comprehensively evaluate path importance through feature similarity and path length, ensuring that key dependencies are stably retained across different version iterations and cross-project scenarios, significantly improving the generalization performance of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] Figure 1 is an exemplary system architecture diagram to which the embodiments of the present application can be applied;

[0060] Figure 2 This is a flow chart of a software defect prediction method based on a dynamic path adaptive graph convolutional network according to an embodiment of the present application;

[0061] Figure 3 A flow chart for generating graph structure data in an embodiment of the present application;

[0062] Figure 4 This is a flowchart of implementing multi-hop dependency modeling through a dynamic path weighted convolutional layer in an embodiment of the present application;

[0063] Figure 5 A flowchart for dynamically optimizing the adjacency matrix according to an embodiment of the present application;

[0064] Figure 6 This is a flowchart of graph structure data optimization in an embodiment of the present application;

[0065] Figure 7 This is a flowchart of topology-aware weighted training in an embodiment of the present application;

[0066] Figure 8 It is a schematic diagram of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION

[0067] Unless otherwise defined, all technical and scientific terms used herein have the same meanings as commonly understood by those skilled in the art to which this application belongs. The terms used in the specification of the application are for the purpose of describing specific embodiments only and are not intended to limit this application. The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of this application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.

[0068] References herein to "embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute an independent or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0069] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.

[0070] like Figure 1 As shown, system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. Network 104 is a medium for providing communication links between terminal devices 101, 102, 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links or fiber optic cables.

[0071] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, and 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0072] Terminal devices 101, 102, and 103 can be various electronic devices with display screens and support web browsing, including but not limited to smartphones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III, Moving Picture Experts Group Audio Layer 3), MP4 (Moving Picture Experts Group Audio Layer IV, Moving Picture Experts Group Audio Layer 4) players, laptop computers, desktop computers, etc.

[0073] The server 105 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal devices 101 , 102 , and 103 .

[0074] It should be noted that the software defect prediction method based on the dynamic path adaptive graph convolutional network provided in the embodiment of the present application is generally executed by a server / terminal device. Accordingly, the software defect prediction method system based on the dynamic path adaptive graph convolutional network is generally set in the server / terminal device.

[0075] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.

[0076] Reference Figure 2 , Figure 2 An optional flowchart of a software defect prediction method based on a dynamic path adaptive graph convolutional network provided in an embodiment of the present disclosure is provided. The software defect prediction method based on a dynamic path adaptive graph convolutional network can be executed by a terminal, can be executed by a server, or can be executed by a terminal and a server in cooperation. The software defect prediction method based on a dynamic path adaptive graph convolutional network includes but is not limited to the following steps S1 to S6.

[0077] Step S1: perform modular analysis on the software system and construct graph structure data of the software modules.

[0078] In the embodiment of the present application, when constructing the graph structure data of the software module, feature extraction, similarity calculation and adjacency optimization are implemented, please refer to Figure 3 , the specific steps include:

[0079] Step 31 : extracting software modules, wherein the software modules include static code metrics such as code complexity, number of code lines, and cyclomatic complexity, and dynamic analysis indicators such as code change frequency and execution coverage, and generating a multi-dimensional feature vector.

[0080] Step 32, obtain the similarity value between modules through cosine similarity, and determine the correlation strength between modules based on the similarity value, which can be expressed as:

[0081]

[0082] where x i and x j denote the feature vectors of module i and module j respectively, · denotes the vector dot product operation, ||x i || and ||x j || are the Euclidean norms of the eigenvectors, and N is the total number of modules in the software system.

[0083] In step 33, based on the calculated similarity value, the K nearest neighbor strategy is used to screen the top-K similar neighbors for each module, where the K value is determined by five-fold cross-validation optimization and ranges from 3 to 10 to ensure that the graph structure avoids excessive density while retaining key dependencies.

[0084] In step 34, directed weighted edges are constructed for each module based on similar neighbors. Edge weights can be initialized to the corresponding cosine similarity value or uniformly set to a constant of 1 to reflect the strength of the association between modules. The sparsity of the adjacency matrix is ​​controlled by dynamically adjusting the value of K to balance information richness and computational efficiency. In practice, for large-scale software systems, a smaller value of K is selected to reduce computational overhead; for systems with complex dependencies, a larger value of K is selected to capture more potential associations.

[0085] Step 35: Generate graph structure data, where the graph structure data is a directed weighted graph G = (V, E), where the node set V represents the software modules and the edge set E represents the similarity relationship between modules, providing an optimizable topological basis for subsequent dynamic path selection.

[0086] In step S2, the graph structure data is input into the dynamic path adaptive graph convolutional network, the module dependencies of the multi-hop paths are aggregated through the dynamic path weighted convolutional layer, and the long path noise is suppressed based on the path length attenuation coefficient, and the node feature representation and path weight information are output.

[0087] It should be noted that the output node feature representation contains the module dependency information after dynamic path weighted aggregation.

[0088] In the embodiment of the present application, the module dependencies of the multi-hop path are aggregated by the dynamic path weighted convolution layer. Please refer to Figure 4 , the specific steps include:

[0089] Step 41, dynamic path weight calculation: Calculate the path weight w of each path p in the set of all multi-hop paths P(v) of node v p , the total path weight is normalized to 1.

[0090] The path weight w of each path p in the set P(v) of all multi-hop paths of node v is calculated p , which can be expressed as: where α ij is the attention weight of edge (i, j), L p is the path length, β∈[0.5,2.0] is the path length attenuation coefficient, which is dynamically optimized by gradient descent to suppress long path noise. For example, when β=1.5, the weight decays by about 22% for every increase in path length, effectively reducing long-distance noise interference. The sum of path weights normalized to 1 can be expressed as:∑ p∈P(v) w p =1.

[0091] Step 42, weighted feature aggregation: perform weighted aggregation on all path features of node v based on the path weight to obtain an updated node feature representation of node v, while limiting the maximum path length and the number of retained paths per node.

[0092] Among them, all path features of node v are weighted and aggregated based on the path weight to obtain the updated node feature representation of node v, which can be expressed as:

[0093]

[0094] Where h′ v represents the updated feature representation of node v, P(v) represents the set of all possible paths of node v, and w p Represents the weight of path p, AGG is the aggregation function, which is specifically implemented as a sum (Sum) or mean (Mean) operation, used to fuse the features h of all nodes u on path p u ; σ is a nonlinear activation function, which uses ReLU or LeakyReLU function with a negative slope coefficient fixed to 0.2 to enhance the nonlinear expression ability of the model.

[0095] At the same time, limiting the maximum path length and the number of paths retained per node can be expressed as: By limiting the maximum path length L max ≤4 and the number of Top-K paths retained per node (K=3) to control computational complexity and ensure the high efficiency of the model on large-scale graph data.

[0096] Step 43, updated node features: After multi-layer dynamic path weighted convolution, the updated node feature representation of node v tends to be stable, and key module dependency focusing and noise suppression are achieved by attenuating the long path weight and enhancing the high-attention short path weight.

[0097] After multi-layer dynamic path weighted convolution, the updated node feature representation of node v tends to be stable and meets the limit condition: Where l represents the number of layers of path convolution, H (l) Represents the node feature matrix after l-layer path convolution, H (l+1) represents the node feature matrix after l+1 layer path convolution, ||·|| represents the norm of the matrix, lim l→∞ This property is achieved through the path length attenuation coefficient β and the path selection strategy, avoiding the over-smoothing problem caused by infinite iterations in traditional GCN.

[0098] In the embodiment of the present application, the path weight w p With the attention weight α ij And the path length is dynamically adjusted. For short paths with high attention weights, w p Significantly increases; for long paths with low attention weights, w p This is exponentially attenuated, focusing on key dependencies and suppressing the spread of redundant information. This application uses a dynamic path-weighted convolutional layer to adaptively optimize information propagation paths, improving the ability to model complex software dependencies while ensuring computational efficiency and model stability.

[0099] It should be noted that, in this application, for each multi-hop path of the current node, the path weight is determined by the product of the attention weights of all edges on the path divided by the power of the path length attenuation coefficient of the path length, and the path length attenuation coefficient is a trainable parameter; a summation or mean operation is performed on the node features on the path, the result is multiplied by the corresponding path weight, and the results of all paths are accumulated and processed through a ReLU or a LeakyReLU activation function with a fixed negative slope; the sum of the path weights is normalized to 1, and the maximum path length and the number of retained paths per node are limited; after multi-layer propagation, the node features tend to be stable, and the key module dependency focusing and noise suppression are achieved by attenuating the weights of long paths and enhancing the weights of high-attention short paths.

[0100] Step S3, based on the node feature representation and path weight information, applies the multi-head attention mechanism to optimize the adjacency matrix in real time, enhances the weights of key dependency edges and prunes redundant connections, and outputs the optimized adjacency matrix, where the optimized adjacency matrix reflects the graph topology after the attention mechanism strengthens the key edges and prunes the redundant edges. Please refer to Figure 5 , the specific steps include:

[0101] Step 51, performing multi-head attention calculation on the node feature matrix and the initial adjacency matrix, including: using a multi-head attention mechanism, using a preset number of independent attention heads to parallelly calculate the associated attention weights between the node feature matrix and the initial adjacency matrix, where each attention head calculates the attention weight of node i and neighbor j using the following formula:

[0102]

[0103] Where h represents the index of the current attention head, W represents the attention weight of node i to neighbor node j under the hth attention head; h represents the trainable weight matrix unique to the h-th attention head, which is used to perform linear transformation on node features; a h represents the trainable attention parameter vector corresponding to the h-th attention head; h i and h j denotes the input feature vectors of nodes i and j, respectively; || denotes a vector concatenation operation, and N(i) denotes the set of neighboring nodes of node i; LeakyReLU is an activation function with a fixed negative slope of 0.2, used to introduce nonlinearity; exp denotes an exponential function, and the summation operation in the denominator ensures that the sum of the attention weights of node i for all its neighbors k∈N(i) is 1. The preset number of independent attention heads in this application can be set to 4-8.

[0104] Step 52, multi-head attention weight fusion includes: each attention head independently captures the dependency pattern of different semantic spaces, and fuses the multi-view information through a splicing operation based on the associated attention weight to obtain the fused attention weight, which can be expressed as:

[0105] where h′ i Represents the output feature vector of node i after fusing multiple attention heads; Concat represents the vector concatenation operation, which concatenates the outputs of all attention heads into one vector; H represents the total number of attention heads; It represents the weighted feature representation of node i to neighbor j under the h-th attention head.

[0106] Step 53, dynamic pruning and adjacency matrix update, includes: based on the fused attention weights, dynamically optimizing the adjacency matrix: retaining edges with weights higher than a preset threshold, and pruning redundant connections with weights lower than a preset threshold, performing dynamic pruning and adjacency matrix update, and updating the weights of the retained edges to the weighted sum of the weights of multiple attention heads. Among them, γ hThe contribution coefficient of each attention head ensures that key dependencies are strengthened during topological evolution. This mechanism enables the model to adaptively capture diverse interaction patterns between modules while suppressing interference from noisy edges, improving the robustness of defect prediction.

[0107] This application independently processes node associations through multiple attention heads, and each head executes the following process: first, the node and neighbor features are transformed by a unique trainable matrix, then the transformed features are spliced, and the spliced ​​vector is multiplied by the trainable parameter vector again, and then processed by the LeakyReLU function with a fixed negative slope, and finally the calculated results of the neighbor set are Softmax normalized to obtain the attention weight; the features output by each attention head are spliced ​​to expand the dimension; based on the fusion weight, the edges with weights greater than the high threshold are retained, and the edges with weights less than the low threshold are deleted. The weights of the retained edges are fused with multi-head weights in a learnable proportion to strengthen key connections.

[0108] Step S4: Based on the optimized adjacency matrix, the dynamic path scoring algorithm and the adaptive graph update strategy are used to further update the graph topology to retain key dependencies and output the optimized graph structure data after dynamic scoring and update strategy adjustment. Please refer to Figure 6 , specifically including:

[0109] The dynamic path scoring algorithm calculates the importance score C of each path p based on the comprehensive evaluation of path feature similarity and path length attenuation. p , the preset formula is:

[0110]

[0111] Among them, h i and h j is the node feature vector, L p is the path length, and λ∈[1.0,3.0] is the length attenuation coefficient, which is used to suppress long path noise. For example, when λ = 1.5, the weight of a path of length 3 is attenuated by approximately 78% compared to a path of length 1, significantly reducing the interference of indirect dependencies. After the path scoring is completed, the adjacency matrix is ​​updated according to the preset threshold θ:

[0112]

[0113] Among them, Δ∈[0.1,0.5] is the weight adjustment step size, which controls the degree of edge weight enhancement or weakening, w ij is the initial edge weight from node i to node j in the original adjacency matrix, A` ijThe weight of the new edge from node i to node j in the adjacency matrix is ​​optimized after dynamic scoring and adaptive updates. ò is a lower bound on the weight to prevent effective dependencies from being completely removed. Through iterative updates, low-scoring paths are gradually pruned, while the weights of high-scoring paths are strengthened, ultimately forming a sparse, optimized graph structure. This process is performed dynamically during training, ensuring that the model adapts to the topology as the software evolves. Computational complexity is also controlled by limiting the maximum number of paths retained per node (e.g., the top-3 paths).

[0114] This application calculates the average value of the feature similarity of path node pairs as path similarity. The comprehensive path score is the exponential decay function value of the path similarity multiplied by the path length, and the decay coefficient is trainable. The edge weight is increased for high-scoring paths, the edge weight is reduced for paths with low scores but not lower than the protection value, and the edges are removed for paths with too low scores and lower than the protection value.

[0115] In step S5, based on the optimized graph structure data, the topology-aware class balancing strategy is embedded in the classification objective function. A weighted loss function is constructed by fusing the SMOTE oversampling and focal loss functions. The specific contents include:

[0116] In order to solve the problem of extremely low proportion of defect modules in software defect prediction, the SMOTE oversampling algorithm is used to generate synthetic samples to balance the category distribution. Specifically, the feature space neighbors of the defective samples are calculated, and synthetic samples are generated on the line connecting the original samples and the random neighbors. The features of the synthetic samples are obtained by adding the random proportional coefficient and the feature difference of the original sample features. No new graph nodes and edges are added, and the feature vectors of the synthetic samples are mapped to the existing graph structure. The connection weights of the synthetic samples and the neighbor nodes are adaptively adjusted through the dynamic path scoring mechanism, that is, first calculate the K nearest neighbors of the minority class samples, and randomly select the neighbor samples x in the feature space. j and with the original sample x i Linear interpolation generates new samples, and the preset formula is:

[0117]

[0118] Among them, δ is a uniformly distributed random number, is a synthetic sample, x i is the original sample, x j To randomly select neighboring samples in the feature space, we ensure that the synthetic samples are distributed in a continuous area between the original samples and their neighbors to avoid overfitting. To maintain the consistency of the graph topology, synthetic samples are generated only for a few class modules and no new graph nodes or edges are added. Instead, the feature vectors of the synthetic samples are mapped to the existing graph structure, and the connection weights with neighboring nodes are adaptively adjusted through a dynamic path scoring mechanism.

[0119] The focus loss function is used to improve the loss contribution of defective samples through the category weight coefficient, and the weight of easy-to-classify samples is reduced by adjusting the coefficient to focus on difficult-to-classify samples. That is, the focus loss function is further introduced as the classification loss function, and its preset formula is:

[0120] FL(p t )=-α t (1-p t ) γ log(p t )

[0121] Among them, FL is the focal loss function, α t is the category balance factor, γ is the difficult sample focus parameter, p t is the model’s predicted probability of the true category of the sample, log(p t ) is the basic cross entropy loss term.

[0122] This application calculates the feature space neighbors of defective samples and generates synthetic samples on the line connecting the original samples and random neighbors. The synthetic features are obtained by adding the original features and random proportional coefficients and feature differences. No new graph nodes and edges are added, and only the original node features are updated. The focus loss function is used to improve the loss contribution of defective samples through the category weight coefficient, and the weight of easy-to-classify samples is reduced by adjusting the coefficient to focus on difficult-to-classify samples.

[0123] Step S6: Optimize the dynamic path adaptive graph convolutional network based on the weighted loss function and update the training weights, and output the defect prediction results of the software module.

[0124] In the embodiment of the present application, the over-training optimization outputs the final prediction result, specifically including:

[0125] The model was trained using the AdamW optimizer and the validation set loss was monitored using an early stopping strategy. Training was terminated if the loss did not decrease after 50 consecutive rounds to prevent overfitting. Five-fold cross-validation was used to determine the optimal model weights, outputting the defect probability and classification label of each software module as defective or non-defective.

[0126] Although in the description of the above method flow, each step is introduced in the order shown in the flowchart, this does not mean that it must be completed in strict accordance with this order in actual execution. Unless the solution of this application has clear limitations on this, the execution order of each step can be adjusted accordingly according to actual needs. Certain steps can be executed in a serial manner, or they can be performed alternately or in parallel with other steps. In addition, some steps may contain multiple sub-steps or stages; these sub-steps or stages do not need to be completely synchronized and can be staggered if the overall process allows.

[0127] Those skilled in the art will appreciate that all or part of the processes in the above-described method embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes in the above-described method embodiments. The aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

[0128] It should be understood that although the steps in the flowcharts of the accompanying drawings are shown in sequence as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some of the steps in the flowcharts of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0129] To solve the above technical problems, the present application also provides a computer device. Figure 8 , Figure 8 This is a basic structural block diagram of the computer device in this embodiment.

[0130] The computer device 8 includes a memory 8a, a processor 8b, and a network interface 8c that are interconnected through a system bus. It should be noted that the figure only shows a computer device 8 having components 8a-8c, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to a microprocessor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a digital signal processor (DSP), an embedded device, etc.

[0131] The computer device may be a desktop computer, notebook computer, PDA, cloud server, etc. The computer device may interact with the user via a keyboard, mouse, remote control, touchpad, or voice control device.

[0132] The memory 8a includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 8a can be an internal storage unit of the computer device 8, such as the hard disk or memory of the computer device 8. In other embodiments, the memory 8a can also be an external storage device of the computer device 8, such as a plug-in hard disk equipped on the computer device 8, a smart memory card (SMC), a secure digital (SD) card, a flash card, etc. Of course, the memory 8a can also include both the internal storage unit of the computer device 8 and its external storage device. In this embodiment, the memory 8a is generally used to store the operating system and various application software installed on the computer device 8, such as the program code of the software defect prediction method based on the dynamic path adaptive graph convolutional network. In addition, the memory 8a can also be used to temporarily store various types of data that have been output or are to be output.

[0133] In some embodiments, the processor 8b may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 8b is generally used to control the overall operation of the computer device 8. In this embodiment, the processor 8b is used to execute program code stored in the memory 8a or process data, such as executing the program code of the software defect prediction method based on the dynamic path adaptive graph convolutional network.

[0134] The network interface 8c may include a wireless network interface or a wired network interface. The network interface 8c is generally used to establish a communication connection between the computer device 8 and other electronic devices.

[0135] The present application also provides another embodiment, namely, providing a non-volatile computer-readable storage medium, which stores a program of a software defect prediction method based on a dynamic path adaptive graph convolutional network. The software defect prediction method based on a dynamic path adaptive graph convolutional network can be executed by at least one processor to enable the at least one processor to perform the steps of the software defect prediction method based on a dynamic path adaptive graph convolutional network as described above.

[0136] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0137] Obviously, the embodiments described above are only some of the embodiments of the present application, rather than all of the embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application has been described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions described in the aforementioned specific embodiments, or to make equivalent replacements for some of the technical features therein. Any equivalent structure made using the contents of the present application specification and the accompanying drawings, directly or indirectly used in other related technical fields, is also within the scope of patent protection of the present application.

Claims

1. A software defect prediction method based on dynamic path adaptive graph convolutional network, characterized in that: include: Conduct modular analysis on software systems and construct graph structure data of software modules; The graph structure data is input into the dynamic path adaptive graph convolutional network, and the module dependencies of the multi-hop path are aggregated through the dynamic path weighted convolutional layer. The long path noise is suppressed based on the path length attenuation coefficient, and the node feature representation and path weight information are output. Based on node feature representation and path weight information, a multi-head attention mechanism is applied to optimize the adjacency matrix in real time, enhancing the weights of key dependency edges and pruning redundant connections. The optimized adjacency matrix is ​​output, which reflects the graph topology after the attention mechanism strengthens key edges and prunes redundant edges. Based on the optimized adjacency matrix, a dynamic path scoring algorithm and an adaptive graph update strategy are used to further update the graph topology to retain key dependencies, and output the optimized graph structure data adjusted by dynamic scoring and update strategy. Based on the optimized graph structure data, the topology-aware class balancing strategy is embedded in the classification objective function, and a weighted loss function is constructed by fusing SMOTE oversampling and focal loss functions. Based on the weighted loss function, the dynamic path adaptive graph convolutional network is optimized and the training weights are updated to output the defect prediction results of the software module.

2. The software defect prediction method based on dynamic path adaptive graph convolutional network according to claim 1 is characterized in that: The modular analysis of the software system and the construction of graph structure data of the software modules include: Extract software modules, including static code metrics such as code complexity, number of lines of code, and cyclomatic complexity, and dynamic analysis metrics such as code change frequency and execution coverage, and generate multidimensional feature vectors; The similarity value between modules is obtained through cosine similarity, and the association strength between modules is determined based on the similarity value; Based on the calculated similarity values, the K-nearest neighbor strategy is used to screen the Top-K similar neighbors for each module; Generate graph structure data, where the graph structure data is a directed weighted graph G=(V, E), where the node set V represents software modules and the edge set E represents similarity relationships between modules.

3. The software defect prediction method based on dynamic path adaptive graph convolutional network according to claim 1 is characterized in that: The module dependencies of multi-hop paths are aggregated through dynamic path weighted convolutional layers, including: Calculate the path weight w of each path p in the set P(v) of all multi-hop paths of node v p , the sum of path weights is normalized to 1; Perform weighted aggregation on all path features of node v based on the path weight to obtain the updated node feature representation of node v, while limiting the maximum path length and the number of paths retained per node; After multi-layer dynamic path weighted convolution, the updated node feature representation of node v tends to be stable, and key module dependency focusing and noise suppression are achieved by attenuating the weight of long paths and enhancing the weight of high-attention short paths.

4. The software defect prediction method based on dynamic path adaptive graph convolutional network according to claim 1 is characterized in that: Apply a multi-head attention mechanism to optimize the adjacency matrix in real time, enhance the weights of key dependency edges, and prune redundant connections, including: Through the multi-head attention mechanism, a preset number of independent attention heads are used to parallelly calculate the associated attention weights between the node feature matrix and the initial adjacency matrix; Based on the associated attention weights, multi-view information is fused through splicing operations to obtain the fused attention weights; Based on the fused attention weights, the adjacency matrix is ​​dynamically optimized: edges with weights higher than a preset threshold are retained, and redundant connections with weights lower than a preset threshold are pruned. Dynamic pruning and adjacency matrix updates are performed, and the weights of the retained edges are updated to the weighted sum of the weights of multiple attention heads.

5. The software defect prediction method based on dynamic path adaptive graph convolutional network according to claim 1 is characterized in that: Based on the optimized adjacency matrix, a dynamic path scoring algorithm and an adaptive graph update strategy are used to further update the graph topology to preserve key dependencies. The output is the optimized graph structure data adjusted by dynamic scoring and update strategy, including: The dynamic path scoring algorithm calculates the importance score C of each path p based on the comprehensive evaluation of path feature similarity and path length attenuation. p ; After the path scoring is completed, the adjacency matrix is ​​updated according to the preset threshold θ; Through iterative updates, low-scoring paths are gradually pruned and the weights of high-scoring paths are strengthened, ultimately forming sparsely optimized graph structure data.

6. The software defect prediction method based on dynamic path adaptive graph convolutional network according to claim 5 is characterized in that: The dynamic path scoring algorithm calculates the importance score C of each path p based on the comprehensive evaluation of path feature similarity and path length attenuation. p , which can be expressed as: Among them, h i and h j is the node feature vector, L p is the path length, λ∈[1.0,3.0] is the length attenuation coefficient, which is used to suppress long path noise.

7. The software defect prediction method based on dynamic path adaptive graph convolutional network according to claim 5 is characterized in that: The adjacency matrix is ​​updated according to the preset threshold θ, which can be expressed as: Where Δ∈[0.1,0.5] is the weight adjustment step size, which controls the degree of edge weight enhancement or weakening, w ij is the initial edge weight from node i to node j in the original adjacency matrix, A` ij To optimize the new edge weight from node i to node j in the adjacency matrix after dynamic scoring and adaptive update, It is the lower limit of weight, which prevents effective dependencies from being completely removed.

8. The software defect prediction method based on dynamic path adaptive graph convolutional network according to claim 1 is characterized in that: The weighted loss function is constructed by fusing SMOTE oversampling and focal loss functions, including: The SMOTE oversampling algorithm is used to generate synthetic samples to balance the category distribution. Specifically, the SMOTE algorithm calculates the feature space neighbors of the defective samples and generates synthetic samples on the line connecting the original samples and the random neighbors. The synthetic sample features are calculated by adding a random scaling coefficient and the feature difference to the original sample features. No new graph nodes or edges are added. The feature vectors of the synthetic samples are mapped to the existing graph structure, and the connection weights between the synthetic samples and the neighboring nodes are adaptively adjusted through a dynamic path scoring mechanism. The focus loss function is used to improve the loss contribution of defective samples through the category weight coefficient, and the weight of easy-to-classify samples is reduced by adjusting the coefficient to focus on difficult-to-classify samples.

9. The software defect prediction method based on dynamic path adaptive graph convolutional network according to claim 8 is characterized in that: Calculate the nearest neighbor in the feature space for the defective sample and generate a synthetic sample on the line connecting the original sample and the random nearest neighbor, which can be expressed as: in, is a synthetic sample, x i is the original sample, x j To randomly select neighbor samples in the feature space, δ is a uniformly distributed random number.

Citation Information

Patent Citations

  • Software defect prediction method based on complex network and graph neural network

    CN114896138A

  • Link prediction method based on global path perception graph neural network model

    CN116306834A

  • Software defect prediction method and system based on atomic association rule network

    CN117389879A

  • Software defect prediction method based on dual directed dependency graph reconstruction

    CN118245359A

  • Distributed system fault positioning diagnosis method and system based on log analysis

    CN119668990A

Cited By

  • Tire rubber mixing process control method and system based on spatial-temporal characteristics and physical information

    CN121091829A