Key class identification method based on graph neural network
By integrating multiple metric statistical methods and graph neural network-based models, the instability and objectivity problems of key class recognition in software systems are solved, and more accurate and robust key class recognition is achieved, which promotes rapid understanding of the software system.
Patent Information
- Application Number
- CN202411787284.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-03-28
AI Technical Summary
The prior art is difficult to accurately identify key categories in software systems, and the traditional methods lack robustness and objective evaluation, resulting in unstable identification results and difficulty in extending to more software systems.
Through integrated learning technology, a variety of metric statistics-based methods are integrated to generate candidate sets of key classes and determine the final result through voting methods. In addition, a key class recognition model based on graph neural network is constructed to capture the intrinsic features of the class-dependent network, learn appropriate graph representations, and accurately predict key classes.
A comprehensive data set for objectively evaluating key classes is constructed, which improves the robustness and accuracy of key class identification, simplifies the identification process, and provides a faster and more comprehensive way to understand the software system architecture.
Smart Images

Figure CN119719900A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a software key class identification method, in particular to a key class identification method based on a graph neural network for identifying key classes in a software project. Background Art
[0002] In today's fast-paced society, in order to meet user needs and maintain product competitiveness, software systems also need to undergo rapid iterations. For a mature software system, the most time-consuming factor in iterative upgrades is bug fixing and operation maintenance, which requires a comprehensive understanding of the entire software system. However, achieving this goal is extremely challenging for two main reasons: one is that there is a large turnover of personnel, and it is difficult to have developers who have a comprehensive understanding of the code; the other reason is that the amount of code is huge, and the continuous iteration of the software system leads to code expansion, which generates a lot of technical debt. It is difficult for developers to know where to start and gain an in-depth understanding of the system in a relatively short period of time. As a result, this situation makes it impossible to accurately solve program errors or quickly develop new features. At present, most software systems are built using object-oriented programming languages and consist of numerous classes, which are the basic building blocks of software systems. In order to capture the core business modules of the software system, it is necessary to identify key classes with core functions as a starting point for understanding the software system. However, in almost all software systems, there is no clear labeling of which classes are key classes, and even programmers often find it difficult to accurately determine them.
[0003] Traditional methods usually model different dependencies between classes in a software system as complex networks. Based on complex networks, a method is proposed to calculate specific indicators of classes, and then the experimental results are used as the basis for key class identification. Among them, specific indicators include class degree and in-degree, betweenness centrality, coreness, hits, etc. However, objective evaluation is hindered by the lack of software systems that clearly mark key categories.
[0004] Existing key class identification methods often evaluate a few software systems with key class identification by calculating a specific indicator for each class. The final identification results vary greatly on different software systems, and the key classes identified in the same system are also different. In addition, these software systems are often outdated, so the effectiveness of extending the results of very few data sets to more software systems is challenged, which reduces the overall confidence in its applicability. Summary of the invention
[0005] The problem to be solved by the present invention is to construct a data set for objectively evaluating key classes, and to use a method different from the traditional metric-based statistics to identify key classes. In order to solve the above problems, the present invention first draws inspiration from ensemble learning technology, integrates a variety of existing metric-based statistics methods to generate candidate sets of key classes, and then determines the final result by voting. The performance of this voting method has been verified by several real-world software systems, thereby constructing a comprehensive data set for objectively evaluating key classes. In addition, the present invention constructs a key class identification model based on graph neural networks to capture the intrinsic characteristics of class dependency networks and learn appropriate graph representations to accurately predict key classes, providing valuable insights for program understanding.
[0006] The specific technical solution for achieving the purpose of the present invention is:
[0007] A key class identification method based on graph neural network is more robust and accurate than the traditional method based on a certain indicator. It includes the following steps:
[0008] S100, construction of a comprehensive dataset for key class identification, including the following sub-steps;
[0009] Step S101, software system selection, manually selecting 256 software systems covering 64 categories from the Java repository Maven to ensure the system's broad representation in the software field;
[0010] Step S102, feature extraction, using a software measurement tool based on the ASM library to perform program network extraction on the collected Java software system, and obtaining the dependency relationships between classes in the system by parsing the bytecode, including the following dependencies: inheritance dependency, interface implementation dependency, member variable dependency, method parameter dependency, method return type dependency, local variable dependency, method call dependency, static method call dependency, and generic dependency; as long as the nine dependency relationships exist between the classes of the system, there are corresponding edges and weights between the nodes corresponding to the directed weighted dependency network diagram; the dependency network between the classes finally extracted is stored in a file in the form of Gml format;
[0011] Step S103, voting for key class labels of the data set, using multiple key class identification methods to first obtain a fixed percentage (top 15%) of key class ranking sets as candidate classes for further evaluation, and then propose a voting method to determine the key class, by iterating the candidate classes of the candidate set, to determine whether the candidate class exists in the key class ranking sets of at least half of the key class identification methods, if so, then add it to the key class set of the corresponding software system in the data set;
[0012] Step S104, key class verification, this step is a supplementary step to the construction of the key class comprehensive data set. In order to prove the effectiveness of the voting method, several software systems with key classes marked were selected for experiments, and the performance of the voting method and the key class identification method selected in step S103 were compared on them, thereby proving that the results of the voting method are more robust and superior;
[0013] S200, the construction of the key class identification model GT4KCI based on graph neural network includes the following sub-steps:
[0014] Step S201, node and edge feature extraction. The software class dependency network extracted in step S102 contains various graph features, from which the node in-degree, out-degree, total degree, degree centrality, closeness centrality and betweenness centrality are extracted as node features, and the edge features only consider the weight of the dependency relationship; after extracting the node and edge features, the graph structure of the class dependency network is combined and used as the input data of the graph neural network;
[0015] Step S202, graph representation learning, graph data is input into multiple hidden layers in the model, and the Graph Transformer in the hidden layer adopts an attention mechanism and uses multiple attention heads to learn node embedding; through iterative processes and optimization, an appropriate graph representation for the key class recognition task is achieved;
[0016] Graph neural networks use node information and connection information in the adjacency matrix to perform message passing operations. The idea of message passing operations is to aggregate node embeddings from neighboring nodes to update the node embedding of the current node, which serves as the basis for various downstream applications. When the Graph Transformer in the hidden layer of the GT4KCI model performs message passing to update node embeddings, it first needs to calculate the attention coefficient between the current node and the adjacent nodes. For the attention head c of the lth layer, the attention coefficient between node i and node j is calculated as follows:
[0017]
[0018] in q, k, and e are e c,ij is the abbreviated form of , T represents the transposition operation, d is the hidden dimension of the attention head, and exp is the natural exponential function; in the above formula, represents the attention coefficient of node i and node j at layer l for attention head c, and They represent the node embeddings of node i and node j after the weight matrix W and bias b are calculated. Similarly, e c,ij represents the processing result of the edge feature between nodes i and j after calculation, and N(i) represents the direct neighbor node of node i. In order to make the attention coefficients between different nodes easy to compare, the above formula calculates the attention coefficient between node i and all its neighbors and performs a softmax operation to obtain the normalized attention coefficient between nodes i and j.
[0019] Graph Transformer uses multi-head attention, which means that each attention head learns different node relationships, produces a different set of attention coefficients, and then aggregates and updates the node embeddings:
[0020]
[0021] in represents the node embedding of node i in layer l, represents the node embedding of each neighbor node j of node i at layer l, and || represents the connection operation; for each attention head c, after combining the node embedding of each neighbor node j of node i with the edge features of the two nodes, the attention coefficient between nodes i and j is used to assign weights to the combined embedding; for other attention heads, the same operation is performed to obtain a set of node embeddings corresponding to the number of attention heads; then, these node embeddings are connected to obtain a new node embedding at layer l+1
[0022] The Graph Transformer layer in the hidden layer is followed by a linear layer, a batch normalization layer, and a Relu activation function. Each iteration of the training process needs to be processed through multiple hidden layers to continuously optimize the performance of key class recognition.
[0023] Step S203, node ranking, each iteration of the model, inputs the learned node embedding into several linear layers for dimension conversion; sorts the scalar value y corresponding to each node in the output layer to determine whether it is a key class, and the selection ratio is 20%, and the training results are optimized based on the comparison with the key class labels in the existing data set to obtain the key class recognition result;
[0024] S300, verify the performance of the trained model and apply it to systems that require key class identification.
[0025] Furthermore, the step S102 of using the software measurement tool based on the ASM library to perform program network extraction on the collected Java software system also includes the following processing:
[0026] 1) Eliminate software systems with parsing anomalies or no connection information between classes;
[0027] 2) Eliminate software systems with very few classes. The threshold is set to 80 classes.
[0028] 3) Use filters to exclude classes from third-party libraries used in a system to ensure that only "business" classes are considered.
[0029] Furthermore, the multiple key class identification methods described in step S103 include MinClass, PageRank, HITS, Betweenness, Cores, Weighted K-Core, Degree, In-Degree and Out-Degree.
[0030] Furthermore, the selected software systems with key classes marked in step S104 include: Ant 1.6.1, Jmeter2.0.1, Jedit 5.1.0, Jhotdraw 60b1, Wro4J 1.6.3, Log4J 2.10.0 and Jgap 3.6.3.
[0031] Further, the step S300 specifically includes:
[0032] Step S301, perform a comprehensive performance comparison. After the GT4KCI model is iteratively trained on the training set and the validation set, it is compared with other baseline methods on the test set. The indicators include accuracy, precision, recall and F1. The experiment proves the overall superiority of GT4KCI.
[0033] Step S302, performing a Friedman test to verify whether the performance of the k methods for the key class recognition problem on the test data set has statistically significant differences through the average ranking of the Friedman test;
[0034] Step S303, further performing a Bonferroni-Dunn test. After determining that there are differences in the performance of the k algorithms, further testing is required to determine which specific algorithms have performances that are statistically different from each other. Therefore, the Bonferroni-Dunn test is used to compare GT4KCI with the remaining k-1 algorithms.
[0035] The technical effect of the present invention is to solve the problem that many metric-based methods lack robustness and objective evaluation in identifying key classes. First, a comprehensive data set is constructed to objectively evaluate key class identification, in which various key class identification methods are integrated by voting to solve the key class labeling problem in data set construction. In addition, the present invention constructs a model based on graph neural network to simplify the key class identification process. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 is a flow chart of the method of an embodiment;
[0037] Figure 2 Overall flow chart constructed for the comprehensive dataset;
[0038] Figure 3 This is a diagram of the dependencies between classes extracted from a program example;
[0039] Figure 4 A schematic diagram of a file in Gml format that is stored after the software parses and extracts features;
[0040] Figure 5 Flowchart of voting method to identify key classes in the construction of comprehensive dataset;
[0041] Figure 6 This is a performance comparison table of the voting method and nine other key class identification methods on seven software systems;
[0042] Figure 7 This is a diagram of the internal architecture of GT4KCI for key class identification;
[0043] Figure 8 The result diagram is a comprehensive comparison of the key class recognition performance of the model and the baseline method on the test set;
[0044] Fig. 9 Table of mean ranks calculated for Friedman and Bonferroni-Dunn tests. DETAILED DESCRIPTION
[0045] The working principle of the present invention is described in detail below in conjunction with the accompanying drawings:
[0046] Example
[0047] This embodiment selects a total of 256 Java systems belonging to 64 different software categories collected from Maven as the basis for constructing a data set. By applying a voting method that aggregates multiple key class identification methods and conducting experiments on several systems with labeled key class information to verify its effectiveness, an objective and comprehensive data set for the key class identification problem is constructed to overcome the problems of software systems that lack clearly marked key classes and system obsolescence.
[0048] The voting method is a combination of multiple key class identification methods. This process is relatively laborious, so this process is simplified by building a model based on graph neural network. The above key class identification dataset is divided into three parts: training set, validation set and test set. The training set and validation set are used in the training process. The performance evaluation on the validation set is used to determine whether to stop training early. The test set is used to evaluate the performance of the trained model. By comparing it with other baseline methods on the test set, its superiority is verified.
[0049] See also Figure 1 , Figure 1 The method flow chart of this embodiment includes the following steps:
[0050] Step S100: construct a comprehensive dataset for key class identification. For the construction process, see Figure 2 , including the following steps:
[0051] Step S101, software system selection, select software systems from different categories to ensure the diversity of the data set. This embodiment selects the Java software system as the analysis object, selects a total of 256 software systems covering 64 categories from the Java repository Maven, and ensures that each software system is widely used in its respective category, thereby ensuring the usage rate, relevance and applicability of the data set.
[0052] Step S102, feature extraction, extracting class features from the dependency network corresponding to the software system. The bytecode file corresponding to each software system is parsed by a software measurement tool based on the ASM library to extract the dependency network between classes in the system. Figure 3 A simple example shows the nine dependencies between classes in different packages. Figure 3 P1, P2, and P3 in the upper middle part represent three packages. Each package contains several classes. P1 contains classes A, B, and G, P2 contains classes C and D, and P3 contains classes E and F. R1-R9 represent nine different types of dependency relationships. Figure 3 The lower part shows the program dependency network that can be extracted from the above code snippet, which is represented here as a directed weighted graph. Finally, the extracted dependency network is saved in a Gml format file, such as Figure 4 As shown, node represents the description of the node, [] contains the node id and the corresponding name, edge represents the resolved dependency relationship, which corresponds to the directed edge between nodes in the directed weighted graph, source represents the source node, target represents the target node, and weight represents the weight of this directed edge.
[0053] During the parsing process, the following elimination and filtering operations were performed for some special cases:
[0054] 1. Eliminated software systems with parsing anomalies or no connection information between classes.
[0055] 2. Eliminate software systems with few classes. Obviously, software systems with few classes are easy to analyze and can be started directly. The threshold is set to 80 classes.
[0056] 3. Use filters to exclude classes concerning third-party libraries to ensure that “business” classes are considered.
[0057] Step S103, key class label voting, using multiple key class identification methods to obtain the top 15% key class ranking list of each method as candidate classes for further evaluation. The representative key class identification methods selected include: MinClass, PageRank, HITS, Betweenness, Cores, Weighted K-Core, Degree, In-Degree and Out-Degree. On this basis, the voting method is applied to obtain the final key class set, and the algorithm flow of the voting method to determine the key class is as follows Figure 5 As shown in the figure, the main idea is to combine the candidate classes of each of the above methods into a candidate set, and then traverse the key classes in the candidate set. If the occurrence rate of a class is greater than or equal to half of the total number of key class identification methods, it is identified as a key class. Finally, the key class processed by the voting method is output.
[0058] Step S104, key class verification, experiments are conducted on several software systems that have been marked with key classes to verify the effectiveness of key class identification. In order to prove the effectiveness of the voting method, seven software systems with marked key classes, including Ant 1.6.1, Jmeter 2.0.1, Jedit5.1.0, Jhotdraw 60b1, Wro4J 1.6.3, Log4J 2.10.0 and Jgap 3.6.3, are selected for quantitative analysis. The experimental results are shown in Figure 1. Figure 6As shown in the figure, the average recall rate of the voting method and the key class identification method selected in step S103 is compared. The number in the bracket under the system represents the number of key classes identified in the system, and the bold number represents the method with the best recognition performance for a certain system. According to the data in the table, the Out-Degree method, which has a huge gap with the results of other methods, is excluded, and the remaining eight methods are used as inputs for executing the voting method. The experimental results show that the voting method always performs well in these systems, indicating its stability and effectiveness, while other methods are unstable. This proves that the voting method can obtain a higher proportion of key categories, thereby gaining a more comprehensive understanding of the system.
[0059] Step S200, construct a key class identification model based on graph neural network - GT4KCI, use the node index calculated from the directed weighted dependency network as the initial feature of the node, obtain the hidden representation of each node after processing in several hidden layers, these representations capture the high-level abstract features and structural information of the data, and finally convert the node embedding into a scalar after processing in several linear layers in the output layer, so as to rank the importance of the nodes. It includes the following sub-steps:
[0060] Step S201, feature extraction, the embodiment of the present invention uses the Networkx toolkit to collect node and edge features, node features include in-degree, out-degree, total degree, degree centrality, closeness centrality and betweenness centrality. Among them, degree centrality calculates the proportion of nodes connected to a node:
[0061]
[0062] The closeness centrality of node u is calculated as the inverse of the average shortest path distance from all n-1 reachable nodes to node u. The formula for the normalized closeness centrality is:
[0063]
[0064] Where d(v,u) is the shortest path distance between node v and node u, and n-1 is the number of nodes reachable from u. The betweenness centrality of a node is the sum of the scores of all shortest path pairs passing through the node:
[0065]
[0066] Where s and t are any two nodes in the graph, and V is a node set. σ(s, t) is the total number of shortest paths from node s to node t, and σ(s, t|v) is the number of paths in the shortest path from node s to node t that pass through a node v other than nodes s and t. As for edge features, this embodiment only considers weights corresponding to dependency relationships.
[0067] Step S202, graph representation learning, build several hidden layers in GT4KCI, take the directed weighted dependency graph corresponding to each software system in the data set combined with the node and edge features extracted in step S201 as input, and perform model training. The graph neural network uses the node information and connection information encoded in the adjacency matrix to perform message passing operations. The main idea of the message passing operation is to aggregate the node embeddings from neighboring nodes to update the node embeddings of the current node, which serves as the basis for various downstream applications. This process is expressed as follows:
[0068]
[0069] in represents the hidden node embedding of the target node v in the kth layer of the model, represents the set of neighbor nodes of the target node v, Represents the node embedding of the neighbor node u of the target node v at the kth layer. AGGR is an aggregation function that summarizes the node embeddings of neighboring nodes, and UPD is an update function that merges the aggregated information into the current node. Indicates that the node embedding of the target node v at the k+1th layer is the aggregate node embedding of its neighbor nodes at the kth layer and the node embedding of node v at the kth layer. Combine the updated results.
[0070] Commonly used AGGR aggregation functions include mean, sum, maximum, weighted sum, etc. In the hidden layer of GT4KCI, Figure 7 As shown in the figure, the Graph Transformer layer plays an important role in learning node hidden embedding. It first needs to calculate the attention coefficient between the node and the adjacent nodes. For the attention head c of the lth layer, the attention coefficient between node i and node j is calculated as follows:
[0071]
[0072] in q, k, and e are e c,ij is the abbreviated form of , T represents the transposition operation, d is the hidden dimension of the attention head, and exp is the natural exponential function. In the above formula, represents the attention coefficient of node i and node j at layer l for attention head c, and They represent the node embeddings of node i and node j after the trainable parameter weight matrix W and bias b are calculated. Similarly, e c,ij The edge feature between nodes i and j is processed after the above encoding and added to As additional information. In order to make the attention coefficients between different nodes easy to compare, the above formula calculates the attention coefficient between node i and all its neighbors and performs a softmax operation to obtain the normalized attention coefficient between nodes i and j. Through this adaptive attention mechanism, Graph Transformer dynamically adjusts the weights according to the correlation between nodes and flexibly selects which neighbors of the node are more important.
[0073] Graph Transformer uses multi-head attention, each attention head learns different node relationships, generates a set of different attention coefficients, and then performs aggregation and update operations:
[0074]
[0075] in represents the node embedding of node i in layer l, represents the node embedding of each neighbor node j of node i at layer l, and || represents the connection operation. For each attention head c, after combining the node embeddings of the neighbor nodes of node i with the edge features, the calculated attention coefficient is used to assign weights to the combined embeddings. For other attention heads, the same operation is performed to obtain a set of node embeddings corresponding to the number of attention heads. Then, these node embeddings are connected to obtain a new node embedding at layer l+1.
[0076] The number of hidden layers in the model is a learnable parameter. After the Graph Transformer in the hidden layer, it must be processed by the linear layer, batch normalization layer and Relu activation function. The linear layer maps the output of the Graph Transformer to the target dimension and fuses the information of different attention heads through linear transformation. The batch normalization layer is used to improve training stability and accelerate convergence. The Relu activation function introduces nonlinearity to improve the network's expressiveness and training efficiency.
[0077] Step S203, node ranking, after multiple iterations of GT4KCI, the learned node embedding is input into multiple linear layers of the output layer for dimension conversion. After the conversion, the scalar value y corresponding to each node is used to determine whether the node represents a key class. This embodiment extracts the nodes with the top 20% y values in the graph as key classes, while other nodes are regarded as non-key classes. The training process is optimized by comparison with existing labels, in which the loss function combining the Sigmoid activation function and the binary cross entropy is selected:
[0078] Loss(x,y)=-[ylog(σ(x))+(1-y)log(1-σ(x))]
[0079] Where x is the original output of the model, y is the true label, σ(x) is the probability of x after Sigmoid activation, and the goal of training is to ensure that the loss value of the loss function is minimized. During the optimization process, after each iteration, the performance of the model is tested on the validation set to evaluate the accuracy of the model for key class recognition. When several evaluations still fail to improve the recognition performance, the training process ends and the performance of the model is evaluated on the test data set.
[0080] Step S300, finally, the performance of the trained model is verified, including the following steps:
[0081] Step S301, a comprehensive performance comparison of key class identification is performed, and the GT4KCI model is compared with other baseline methods on the test set. The verification results are as follows Figure 8 As shown in the figure, the indicators include several conventional indicators such as Accuracy, Precision, Recall and F1. In addition, MSE represents the sum of square deviations of the predicted proportions of each item, and Top1 / Top3 represent the frequencies of the recognition performance ranking first and entering the top 3 respectively. Among them, for each indicator, the indicator of the best performing method is bold, and the second best is underlined. It is easy to see from the figure that GT4KCI performs better than the baseline method in all indicators.
[0082] Step S302 , performing a Friedman test, and verifying whether the performance of the k methods for the key class recognition problem on the test data set has statistically significant differences through the average ranking of the Friedman test. Fig. 9 shows the calculated average rank of the Friedman test, based on which the Friedman statistic is calculated
[0083]
[0084] Among them, r1, r2, ..., rn represent the average ranking of these algorithms, and N and k represent the number of data sets and the number of algorithms, respectively. The Friedman statistic calculated by the above formula is much larger than the critical value of p-value of 0.05 and k-1 degrees of freedom, that is, the corresponding p-value is much smaller than the significance level of 0.05, which indicates that the performance of k key class identification methods is statistically significantly different.
[0085] Step S303, further perform the Bonferroni-Dunn test. After determining that the performance of the k algorithms is different, further testing is required to determine which specific algorithms are statistically different from each other. Therefore, the Bonferroni-Dunn test is used to compare GT4KCI with the remaining k-1 algorithms. The Bonferroni-Dunn test compares the difference in the average ranking of each algorithm with a certain domain value (CD). If it is greater than the domain value, it means that the algorithm with a higher average ranking is statistically better than the algorithm with a lower average ranking. The calculation method of CD is as follows:
[0086]
[0087] k represents the number of algorithms being compared, N is the number of datasets, and q _ This can be seen by looking at the corresponding Bonferroni-Dunn test table. This embodiment selects the top three methods except GT4KCI, and the CD value calculated is 0.785. The ranking difference between GT4KCI and the second highest ranking Degree is 0.89, which proves the statistical superiority of GT4KCI.
[0088] The present invention provides a new and complete comprehensive dataset for the key class identification problem, and designs a graph neural network-based model GT4KCI to provide more accurate results for key class identification, so as to achieve the purpose of understanding the existing system architecture more quickly and comprehensively.
Claims
1. A key class identification method based on graph neural network, characterized in that: The steps include: S100, construction of a comprehensive dataset for key class identification, including the following sub-steps; Step S101, software system selection, manually selecting 256 software systems covering 64 categories from the Java repository Maven; Step S102, feature extraction, using a software measurement tool based on the ASM library to perform program network extraction on the collected Java software system, and obtaining the dependency relationships between classes in the system by parsing the bytecode, including the following dependencies: inheritance dependency, interface implementation dependency, member variable dependency, method parameter dependency, method return type dependency, local variable dependency, method call dependency, static method call dependency, and generic dependency; as long as the nine dependency relationships exist between the classes of the system, there are corresponding edges and weights between the nodes corresponding to the directed weighted dependency network diagram; the dependency network between the classes finally extracted is stored in a file in the form of Gml format; Step S103, voting for key class labels of the data set, using multiple key class identification methods to first obtain the top 15% of the key class ranking sets of each fixed percentage as candidate classes for further evaluation, and then propose a voting method to determine the key class, by iterating the candidate classes of the candidate set, to determine whether the candidate class exists in the key class ranking sets of at least half of the key class identification methods, if so, then add it to the key class set of the corresponding software system in the data set; S200, the construction of the key class identification model GT4KCI based on graph neural network, specifically including: Step S201, node and edge feature extraction. The software class dependency network extracted in step S102 contains various graph features, from which the node's in-degree, out-degree, total degree, degree centrality, closeness centrality and betweenness centrality are extracted as node features, and the edge features only consider the weight of the dependency relationship; after extracting the node and edge features, the graph structure of the class dependency network is combined and used as the input data of the graph neural network; Step S202, graph representation learning, graph data is input into multiple hidden layers in the model, and the GraphTransformer in the hidden layer adopts an attention mechanism and uses multiple attention heads to learn node embedding; through iterative processes and optimization, an appropriate graph representation for the key class recognition task is achieved; Graph neural networks use node information and connection information in the adjacency matrix to perform message passing operations. The idea of message passing operations is to aggregate node embeddings from neighboring nodes to update the node embedding of the current node, which serves as the basis for various downstream applications. When the Graph Transformer in the hidden layer of the GT4KCI model performs message passing to update node embeddings, it first calculates the attention coefficient between the current node and the adjacent nodes. For the attention head c of the lth layer, the attention coefficient between node i and node j is calculated as follows: in q, k, and e are e , is the abbreviated form of , T represents the transposition operation, d is the hidden dimension of the attention head, and exp is the natural exponential function. In the above formula, represents the attention coefficient of node i and node j at layer l for attention head c, and They represent the node embeddings of node i and node j after the weight matrix W and bias b are calculated. Similarly, e , represents the processing result of the edge feature between nodes i and j after calculation, and N(i) represents the direct neighbor node of node i. In order to make the attention coefficients between different nodes easy to compare, the above formula calculates the attention coefficient between node i and all its neighbors and performs a softmax operation to obtain the normalized attention coefficient between nodes i and j. Graph Transformer uses multi-head attention, which means that each attention head learns different node relationships, produces a different set of attention coefficients, and then aggregates and updates the node embeddings: in represents the node embedding of node i in layer l, represents the node embedding of each neighbor node j of node i at layer l, and || represents the connection operation; for each attention head c, after combining the node embedding of each neighbor node j of node i with the edge features of the two nodes, the attention coefficient between nodes i and j is used to assign weights to the combined embedding; for other attention heads, the same operation is performed to obtain a set of node embeddings corresponding to the number of attention heads; then, these node embeddings are connected to obtain a new node embedding at layer l+1 The Graph Transformer layer in the hidden layer is followed by a linear layer, a batch normalization layer, and a Relu activation function; Each iteration of the training process is processed through multiple hidden layers to continuously optimize the performance of key class recognition; Step S203, node ranking, each iteration of the model, the learned node embedding is input into several linear layers for dimensional conversion; the scalar value y corresponding to each node in the output layer is sorted to determine whether it is a key class, and the selection ratio is 20%. The training results are optimized based on the comparison with the key class labels in the existing data set to obtain the key class recognition results.
2. The key class identification method according to claim 1, characterized in that: The step S102 uses the software measurement tool based on the ASM library to perform program network extraction on the collected Java software system, and also includes the following processing: 1) Eliminate software systems with parsing anomalies or no connection information between classes; 2) Eliminate software systems with few classes. The threshold is set to 80 classes. 3) Use filters to exclude classes from third-party libraries used in a system to ensure that only "business" classes are considered.
3. The key class identification method according to claim 1, characterized in that: The multiple key class identification methods described in step S103 include MinClass, PageRank, HITS, Betweenness, Cores, Weighted K-Core, Degree, In-Degree and Out-Degree.