A software architecture recovery method based on hierarchical clustering combination

Through a method based on hierarchical clustering combination, combined with principal component analysis, the problem of architecture deterioration in software system architecture recovery is solved, and the accuracy and authenticity of software architecture recovery are improved.

CN114510257BActive Publication Date: 2024-10-01XIAN UNIV OF POSTS & TELECOMM
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111501663.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-09
Publication Date
2024-10-01
Estimated Expiration
2041-12-09

AI Technical Summary

Technical Problem

In the existing technology, when new requirements are added to a software system, the architecture may deteriorate and deviate from the original document, making it more difficult to restore the software architecture. It is difficult for existing clustering algorithms to select an appropriate method to restore the software architecture.

Method used

A method based on hierarchical clustering combination is adopted to obtain the function entities in the software source code and construct their relationships. Five similarity calculation methods and three hierarchical clustering algorithms of CL, WCA and LIMBO are used to cluster the function entities. Recovering software structure using principal component analysis.

Benefits of technology

It improves the accuracy of software architecture recovery, can better retain the basic information of each clustering algorithm, and enhances the matching between the software architecture restored based on clustering and the real architecture.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114510257B_ABST
    Figure CN114510257B_ABST
Patent Text Reader

Abstract

The present invention provides a software architecture recovery method based on hierarchical clustering combination, including: constructing the relationship between function entities in software source code; using five similarity calculation methods to respectively calculate the similarity between function entities; based on the similarity calculated by each similarity calculation algorithm, using three hierarchical clustering algorithms, CL, WCA, and LIMBO, to cluster the function entities respectively; representing each clustering result in the form of a description matrix; using the principal component analysis method to combine the description matrices representing each clustering result to obtain a multidimensional matrix; recovering the final hierarchical structure from the multidimensional matrix to achieve software structure recovery. The present invention uses principal component analysis to combine and reduce the dimensions of multiple matrices that can describe and consider various relationships between software entities, and the combined result retains the basic information of each clustering algorithm as much as possible, thereby improving the accuracy of the software architecture recovered based on clustering and the real architecture.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of software engineering, and in particular relates to a software architecture recovery method based on hierarchical clustering combination. Background Art

[0002] When new requirements are added to a software system, the size and complexity of the system increases, while the architecture may deteriorate and deviate from the original documentation. The main reasons include the lack of an architectural design phase in software development; the inability to obtain the design documents of the original developers; the files may not be updated; the source code is copied without understanding the code segments, etc. The importance of software architecture lies in the fact that it meets non-functional requirements, also known as quality requirements. These non-functional requirements determine the quality of an application at runtime, such as scalability and reliability, and also determine the quality of the development phase, including maintainability, testability, scalability, and deployability. A suitable architecture can increase these quality attributes of an application, and software architecture recovery is a hot issue in the field of software engineering.

[0003] In the prior art, clustering-based software architecture recovery methods are usually adopted, such as hierarchical and partition-based clustering algorithms. For hierarchical clustering, the process is: the algorithm starts with n singletons (each entity) and merges them until a single cluster is obtained. The two most similar clusters are merged in each step of the process. The hierarchical clustering algorithm provides a different perspective on software clustering and iteratively gives a detailed view of the software architecture, while the late clustering iterations give a high-level view. For the partition clustering algorithm, the process is: start with a cluster (containing all entities) and split it until a clustering result is obtained. For a given set of n entities, this method simply divides the entity set into non-overlapping clustering clusters so that each entity is in exactly one cluster.

[0004] The existing clustering algorithms must target similar groups of entities in the target system based on specific features. However, in software systems, it is difficult to select a suitable algorithm for a task. Therefore, a software architecture recovery method based on hierarchical clustering combination is urgently needed. Summary of the invention

[0005] In order to solve the above problems existing in the prior art, the present invention provides a software architecture recovery method based on hierarchical clustering combination. The technical problem to be solved by the present invention is achieved through the following technical solutions:

[0006] The present invention provides a software architecture recovery method based on hierarchical clustering combination, comprising:

[0007] Step 1: Get the function entity in the software source code;

[0008] Step 2: Construct the relationship between function entities;

[0009] Among them, the function entity relationship includes: global variables, local variables, user-defined types, data files referenced by the entity, mutual calls between entities, system calls, and macros referenced by the entity;

[0010] Step 3: Use five similarity calculation methods to calculate the similarity between function entities respectively, and obtain the similarity calculated by each similarity calculation algorithm;

[0011] Step 4: Based on the similarity calculated by each similarity calculation algorithm, three hierarchical clustering algorithms, CL, WCA, and LIMBO, are used to cluster the function entities respectively, and the clustering results according to each similarity are obtained;

[0012] Step 5: Represent each clustering result in the form of a description matrix;

[0013] Step 6: Use the principal component analysis method to combine the description matrices representing each clustering result to obtain a multidimensional matrix;

[0014] Step 7: Recover the final hierarchical structure from the multidimensional matrix to achieve software structure recovery.

[0015] Optionally, step 1 includes:

[0016] Through software code processing tools, entity information can be reversely obtained from software source code.

[0017] Optionally, step 2 includes:

[0018] Step 2-1: Obtain the feature vector of each function entity;

[0019] Each function entity is represented by a codeword. When the codeword is 1, it means that the position corresponding to the codeword has a feature, and when the codeword is 0, it means that there is no feature. The existing features are combined to obtain the feature vector of each function entity.

[0020] Step 2-2: Use the feature vector of each function entity to construct the relationship between function entities.

[0021] Optionally, step 3 includes:

[0022] Step 3-1: Use the Jaccard method to calculate the expression and calculate the first binary similarity between function entities;

[0023] The Jaccard method calculation expression is expressed as:

[0024]

[0025] Step 3-2: Using the JaccardNM method expression, calculate the second binary similarity between function entities;

[0026] The JaccardNM method expression is expressed as:

[0027]

[0028] Step 3-3: Using the Jaccam method expression, calculate the third binary similarity between function entities;

[0029] The Jaccam method expression is expressed as:

[0030]

[0031] Among them, E i , E j represents the two entities being calculated, a represents the number of features shared by the two entities, and b represents E i But E j The number of features that do not exist in E j But E i d represents the number of features missing in both entities;

[0032] Step 3-4: Use the Unbiased Ellenberg measure method expression to calculate the fourth non-binary similarity between function entities;

[0033] The expression of the Unbiased Ellenberg measure method is:

[0034]

[0035] Among them, Ma represents the sum of the features present in the two functional entities;

[0036] Step 3-5: Use the information loss expression to calculate the fifth similarity between function entities;

[0037] The information loss expression is expressed as:

[0038] δI(E i , E j )=p(E i )+p(E j )*Djs(f i , f j )

[0039] in, Dkl[f i ||f j ] is assumed to be distributed as f j The measure of redundancy in the encoding ofi When Djs is f i and f j With f ij The average Dkl distance.

[0040] Optionally, step 4 includes:

[0041] Step 4-1: According to the first binary similarity, the second binary similarity and the third binary similarity, all function entities are clustered using the CL method to obtain three clustering results;

[0042] Each clustering result is expressed as: Sim(E1, E 23 )=min(Sim(E1,E2),Sim(E1,E3))

[0043] Among them, Sim(a, b) represents the similarity between entities a and b, E 23 Indicates the clustering results of E2 and E3;

[0044] Step 4-2: Based on the fourth non-binary similarity, use the WCA method to cluster all function entities to obtain the fourth clustering result;

[0045] Step 4-3: According to the fifth similarity, use the LIMBO method to cluster all function entities and obtain the fifth clustering result.

[0046] Optionally, step 4-2 includes:

[0047] Step 4-21: According to the fourth non-binary similarity, merge the two most similar function entities to form a first new cluster;

[0048] Step 4-22: Using the eigenvector expression, calculate the first new cluster E ij The eigenvector f ij ;

[0049] The eigenvector expression is:

[0050]

[0051] Among them, E i and E j They are the function entities to be clustered, and their eigenvectors are f i and f j , n i Indicates E i The number of function entities in n j Indicates E j The number of function entities in ;

[0052] Step 4-23: Associating the feature vector of the first new cluster with the first new cluster to obtain a newly formed non-singleton cluster;

[0053] Step 4-24: Take the newly formed non-singleton cluster as a new functional entity, and recalculate the similarity between this new functional entity and all other functional entities until the specified number of clusters is reached or only one cluster remains, thereby obtaining the fourth clustering result.

[0054] Optionally, step 4-3 includes:

[0055] Step 4-31: The entity E with the least information loss i and E j Merge to obtain the merged second new cluster E ij ;

[0056] Step 4-32: Calculate E ij The eigenvector of

[0057] Among them, E ij The eigenvector f ij It is expressed as:

[0058]

[0059] Among them, n i and n j Respectively represent E i and E j The number of function entities contained in ;

[0060] Step 4-33: The merged second new cluster E ij As a new functional entity, the similarity between the new functional entity and other functional entities is recalculated until a cluster is finally formed to obtain the fifth clustering result.

[0061] Optionally, step 6 includes:

[0062] Step 6-1: Arrange the elements at the same position in each description matrix according to space to obtain a multidimensional matrix;

[0063] Wherein, the multidimensional matrix has multiple attributes at the same position when observed from the spatial position, and each attribute is at a corresponding dimension;

[0064] The multidimensional matrix is ​​represented as: ij ={X ij (1) , ..., X ij (L)} T

[0065] Step 6-2: Calculate the mean of all elements of the multidimensional matrix;

[0066] The mean is expressed as:

[0067]

[0068] Step 6-3: Calculate the covariance matrix of the multidimensional matrix according to the means of all elements;

[0069] The covariance matrix is ​​expressed as:

[0070]

[0071] Step 6-4: Calculate the eigenvalues ​​and eigenvectors of the covariance matrix, and determine the eigenvector with the maximum value;

[0072] Step 6-5: Project each element in the multidimensional matrix onto the eigenvector of the maximum value to obtain the target matrix after describing the matrix combination.

[0073] Optionally, step 7 includes:

[0074] Using the CL algorithm, a final hierarchy is created from the target matrix to recover the software architecture.

[0075] The present invention provides a software architecture recovery method based on hierarchical clustering combination, comprising: obtaining function entities in software source code; constructing relationships between function entities; using five similarity calculation methods to respectively calculate the similarities between function entities, and obtaining similarities calculated by each similarity calculation algorithm; based on the similarities calculated by each similarity calculation algorithm, using three hierarchical clustering algorithms, CL, WCA, and LIMBO, to respectively cluster the function entities, and obtain clustering results clustered according to each similarity; representing each clustering result in the form of a description matrix; using a principal component analysis method to combine the description matrices representing each clustering result to obtain a multidimensional matrix; and recovering the final hierarchical structure from the multidimensional matrix to achieve software structure recovery. The present invention uses principal component analysis to combine and reduce the dimensions of multiple matrices that can describe and consider various relationships between software entities, and the combined result retains the basic information of each clustering algorithm as much as possible, thereby improving the accuracy of the software architecture recovered based on clustering and the real architecture.

[0076] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0077] Figure 1 It is a flow chart of a service clustering method based on particle swarm fuzzy clustering provided by an embodiment of the present invention;

[0078] Figure 2 is a bar chart of the number of services in the experiment of the present invention;

[0079] Figure 3 is a comparison chart of accuracy indicators when clustering is performed using different clustering algorithms provided by an embodiment of the present invention;

[0080] Figure 4 is a comparison chart of recall rate indicators when clustering is performed using different clustering algorithms provided by an embodiment of the present invention;

[0081] Figure 5 It is a comparison chart of entropy indicators when clustering is performed using different clustering algorithms provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0082] The present invention is further described in detail below with reference to specific embodiments, but the embodiments of the present invention are not limited thereto.

[0083] Therefore, the clustering algorithms in the prior art generally have the following two limitations:

[0084] 1) Previously, when a single clustering algorithm was used, the selected similarity measure performed well on one evaluation criterion but poorly on another.

[0085] 2) The results restored by each algorithm are of reference significance, so an appropriate strategy should be selected to combine the advantages of each algorithm.

[0086] like Figure 1 As shown, the present invention provides a software architecture recovery method based on hierarchical clustering combination, comprising:

[0087] Step 1: Get the function entity in the software source code;

[0088] In this step, the entity information can be obtained from the software source code by using software code processing tools.

[0089] Step 2: Construct the relationship between function entities;

[0090] Among them, the function entity relationship includes: global variables, local variables, user-defined types, data files referenced by the entity, mutual calls between entities, system calls, and macros referenced by the entity;

[0091] It is worth mentioning that finding comprehensive and appropriate features in the software architecture recovery problem will obtain ideal clustering results. On this basis, the following feature selection principles are defined. The basis for selecting entities and feature relationships may be different for different systems, because most legacy systems are written in C language. Considering routines including functions and procedures, it is expected to be more reasonable as an entity. In order to improve the quality of clusters and enhance cohesion, more detailed information extracted from legacy systems is defined as meaningful features and associated with each entity or cluster. Therefore, the present invention selects functions as entities in the software code, and functions as smaller scales, and the 7 entity relationships shown in Table 1 can be obtained.

[0092] Table 1 Entity relationships and entity relationship descriptions

[0093]

[0094] In an optional embodiment of the present invention, step 2 includes:

[0095] Step 2-1: Obtain the feature vector of each function entity;

[0096] Each function entity is represented by a codeword. When the codeword is 1, it means that the position corresponding to the codeword has a feature, and when the codeword is 0, it means that there is no feature. The existing features are combined to obtain the feature vector of each function entity.

[0097] Step 2-2: Use the feature vector of each function entity to construct the relationship between function entities.

[0098] It is worth noting that each entity is represented by E = {E1, E2, ..., E i}, i is the number of selected entities, and the various relationships between the entities extracted are represented as the characteristic entities of each entity and represented by a feature vector: f i ={f i1 , f i2 , ..., f ip}. Similarities between entities are determined based on their features or characteristics. Features are usually binary, where "1" represents the presence of the feature and "0" represents the absence of the feature. After identifying entities and features, each entity in the system is represented as a feature vector. If the features are binary, the result is a binary feature vector.

[0099] Step 3: Use five similarity calculation methods to calculate the similarity between function entities respectively, and obtain the similarity calculated by each similarity calculation algorithm;

[0100] A similarity measure is selected to form an N*N similarity matrix, which represents the similarity between each pair of entities in the system. After calculating the similarity, the entities are merged using a hierarchical clustering algorithm based on the calculated similarity. As a result, the entities between the formed clusters are more similar than other clusters or unmerged entities, so the similarity within the cluster is greater than the similarity between clusters.

[0101] Similarity measure is a measure that comprehensively evaluates the similarity between two entities. The closer two entities are, the greater their similarity measure. Clustering algorithms usually use three types of similarity measures, namely distance measure, correlation coefficient and correlation coefficient. Distance measure describes how far apart entities are in a numerical way and is usually used when features are continuous. Correlation coefficient is usually used to associate continuous features, while correlation coefficient is usually used for binary features. The similarity method used in the present invention is shown in Table 2 and described as follows:

[0102] Table 2 Similarity calculation method and formula

[0103]

[0104] In an optional embodiment of the present invention, step 3 includes:

[0105] Step 3-1: Use the Jaccard method to calculate the expression and calculate the first binary similarity between function entities;

[0106] The Jaccard method calculation expression is expressed as:

[0107]

[0108] Step 3-2: Using the JaccardNM method expression, calculate the second binary similarity between function entities;

[0109] The JaccardNM method expression is expressed as:

[0110]

[0111] Step 3-3: Using the Jaccam method expression, calculate the third binary similarity between function entities;

[0112] The Jaccam method expression is expressed as:

[0113]

[0114] Among them, Ei and Ej represent two entities being calculated, a represents the number of features shared by the two entities; b represents the number of features that exist in Ei but not in Ej; c represents the number of features that exist in Ej but not in Ei; d represents the number of features that are missing in both entities;

[0115] Step 3-4: Use the Unbiased Ellenberg measure method expression to calculate the fourth non-binary similarity between function entities;

[0116] The Unbiased Ellenberg measure method expression is expressed as:

[0117]

[0118] Among them, Ma represents the sum of the features present in the two functional entities;

[0119] Step 3-5: Use the information loss expression to calculate the fifth similarity between function entities;

[0120] The information loss degree expression is expressed as:

[0121] δI(E i , E j )=p(E i )+p(E j )*Djs(f i , f j )

[0122] in, Dkl[f i ||f j ] is assumed to be distributed as f j The measure of redundancy in the encoding of i When Djs is f i and f j With f ij The average Dkl distance.

[0123] It is worth mentioning that:

[0124] (1) The Jaccard similarity coefficient is used to compare the similarities and differences between finite sample sets and calculate the distance between objects. The larger the Jaccard coefficient value, the higher the sample similarity.

[0125] (2) JaccardNM, which overcomes some of the shortcomings of binary similarity metrics. The problem arises in the original measurement because it does not take into account the ratio of common features to total features. It maintains the ratio of common features to total features through n = a + b + c + d in the denominator so that it does not depend entirely on a.

[0126] (3) Jaccam, which has the ability to create more clusters while reducing the arbitrary decisions made by AHC during the clustering process.

[0127] (4) Unbiased Ellenberg measure is a non-binary form of Jaccard measure, which is used to calculate the similarity of entities with non-binary features formed in the clustering process.

[0128] (5) Information Loss measure: Applying information theory techniques to software clustering, the Aggregate Information Bottleneck (AIB) algorithm does not follow the principle of high cohesion and low coupling. Instead, it retains important information about entities by reducing the information loss in each cluster.

[0129] Step 4: Based on the similarity calculated by each similarity calculation algorithm, three hierarchical clustering algorithms, CL, WCA, and LIMBO, are used to cluster the function entities respectively, and the clustering results according to each similarity are obtained;

[0130] In an optional embodiment of the present invention, step 4 includes:

[0131] Step 4-1: According to the first binary similarity, the second binary similarity and the third binary similarity, all function entities are clustered using the CL method to obtain three clustering results;

[0132] Each clustering result is expressed as: Sim(E1, E 23 )=min(Sim(E1,E2),Sim(E1,E3))

[0133] Among them, Sim(a, b) represents the similarity between entities a and b, E 23 Indicates the clustering results of E2 and E3;

[0134] Step 4-2: Based on the fourth non-binary similarity, use the WCA method to cluster all function entities to obtain the fourth clustering result;

[0135] Step 4-3: According to the fifth similarity, use the LIMBO method to cluster all function entities and obtain the fifth clustering result.

[0136] In an optional embodiment of the present invention, step 4-2 includes:

[0137] Step 4-21: According to the fourth non-binary similarity, merge the two most similar function entities to form a first new cluster;

[0138] Step 4-22: Using the eigenvector expression, calculate the first new cluster E ij The eigenvector f ij ;

[0139] The feature vector expression is:

[0140]

[0141] Among them, E i and E j They are the function entities to be clustered, and their eigenvectors are f i and f j , n i Indicates E i The number of function entities in n j Indicates E j The number of function entities in ;

[0142] Step 4-23: Associating the feature vector of the first new cluster with the first new cluster to obtain a newly formed non-singleton cluster;

[0143] Step 4-24: Take the newly formed non-singleton cluster as a new functional entity, and recalculate the similarity between this new functional entity and all other functional entities until the specified number of clusters is reached or only one cluster remains, thereby obtaining the fourth clustering result.

[0144] In an optional embodiment of the present invention, step 4-3 includes:

[0145] Step 4-31: The entity E with the least information loss i and E j Merge to obtain the merged second new cluster E ij ;

[0146] Step 4-32: Calculate E ij The eigenvector of

[0147] Among them, E ij The eigenvector f ij It is expressed as:

[0148]

[0149] Among them, n i and n j Respectively represent E i and E j The number of function entities contained in ;

[0150] Step 4-33: The merged second new cluster E ij As a new functional entity, the similarity between the new functional entity and other functional entities is recalculated until a cluster is finally formed to obtain the fifth clustering result.

[0151] It is worth noting that software architecture is ultimately reflected in the hierarchy and position of each entity. Therefore, using different hierarchical clustering methods, such as CL, WCA, and LIMBO, may produce very different results, and these methods have their own characteristics. The best indicator, CL, performs well in the internal evaluation of clustering results and can produce cohesive results for software clustering. Combined with similarity measures such as Jaccard, JaccardNM, and Jaccam, it performs well in the number of clusters, reduces arbitrary decisions, and can balance these two factors. WCA and Limbo reduce the number of arbitrary decisions in the second half of the clustering process. There is a high degree of consistency with the results of expert decomposition. The LIMBO algorithm uses an information loss metric to initially generate small internal clusters, and then merges them together while reducing any decisions in the later stages of clustering, thereby generating better (or more cohesive) clusters. If so, the software system contains useful functions that are common across multiple subsystems. The LIMBO algorithm will get better results. If the utility function is associated with a subsystem, WCA measured by the unbiased Ellenberg measure can give better results. Therefore, the above hierarchical clustering algorithm is selected as the basic clustering algorithm, and the steps of the WCA algorithm and the LIMBO algorithm are shown in Algorithm 1 and Algorithm 2 respectively.

[0152] Algorithm 1:

[0153]

[0154] Algorithm 2:

[0155]

[0156] Step 5: Represent each clustering result in the form of a description matrix;

[0157] It is worth mentioning that the results of hierarchical clustering are usually represented by dendrograms, which can be obtained intuitively, can show hierarchical features, and are easy to interpret. The framework based on the descriptor matrix is ​​used to preserve the common structure of the input clusters and generate completely consistent trees. The ultrametric information contained in the pairing matrix can be clearly mapped to the tree structure information. Therefore, for each dendrogram, there is an ultrametric matrix to uniquely characterize it, and it can be used to recover the dendrogram. The dendrogram descriptor can be regarded as a distance function that describes the relative position of a given pair of leaves in the dendrogram, which is used to characterize the corresponding dendrogram.

[0158] For all triplets of points i, j and l. Any dendrogram characterized by a unique ultrametric matrix can be recovered from its corresponding ultrametric matrix by hierarchical clustering. In other words, the hierarchical clustering and ultrametric description of the dendrogram are opposite. The description matrix can represent the corresponding positions of entity pairs in the dendrogram, and represent the entities in the dendrogram in a new form, so that aggregation can be performed. Many description matrices for dendrogram representation have been proposed. The present invention adopts Cophenetic Difference (CD) as the representation method of the dendrogram description matrix, which is the lowest height (i.e., the merged distance) of the internal nodes of two specific leaves connected together in the dendrogram. For example, Figure 2 The CD between midpoints v and x is 30.

[0159] Step 6: Use the principal component analysis method to combine the description matrices representing each clustering result to obtain a multidimensional matrix;

[0160] As an optional embodiment of the present invention, step 6 includes:

[0161] Step 6-1: Arrange the elements at the same position in each description matrix according to space to obtain a multidimensional matrix;

[0162] Wherein, the multidimensional matrix has multiple attributes at the same position when observed from the spatial position, and each attribute is at a corresponding dimension;

[0163] Step 6-2: Calculate the mean of all elements of the multidimensional matrix;

[0164] Step 6-3: Calculate the covariance matrix of the multidimensional matrix according to the means of all elements;

[0165] Step 6-4: Calculate the eigenvalues ​​and eigenvectors of the covariance matrix, and determine the eigenvector with the maximum value;

[0166] Step 6-5: Project each element in the multidimensional matrix onto the eigenvector of the maximum value to obtain the target matrix after describing the matrix combination.

[0167] The present invention uses basic clustering methods to combine different similarities, and each clustering method will produce a dendrogram with a different structure. The present invention uses principal component analysis to combine the description matrices represented by these different forms of dendrograms to obtain the final structure required by the present invention, which is called the HCC-PCA method. When combining the hierarchical clustering results represented by different descriptor matrices, the present invention should try to retain more information contained in each descriptor matrix and retain the most important information. Therefore, the present invention uses principal component analysis to achieve.

[0168] The present invention summarizes the reasons for selecting PCA as the combination of these clustering results from the two aspects of necessity and purpose. (1) Several basic clusters generated by several algorithms combined with different similarity calculation methods include the positional relationship between the extracted entities, and there is also a certain correlation between them. (2) The elements in the same position between the generated description matrices also have a certain overlap. PCA generates a multidimensional matrix for all the variable combinations initially proposed, and each position contains the elements in the same position of these matrices.

[0169] Delete duplicate closely related variables, create fewer new variables, and retain the original information as much as possible. (3) It creates some new features for the original data, which can represent the original data set. And the new features are built on the basis of the old features, reducing the complexity of problem analysis by reducing the number of predictor variables and providing a framework to explain the results. Since these basic clusters produce the results of architecture repair and have different forms, PCA is used to build the connection between these results, from which the new architecture can be summarized.

[0170] The following are the steps of the PCA-based hierarchical clustering combination method:

[0171] After the dendrogram obtained by base clustering is represented by a description matrix, L N*N matrices are obtained, denoted as Z = {z1, z2, z3…, z L}, each zL represents the descriptor matrix representation of each clustering result. The purpose of PCA is to combine these matrices into N^2 samples with L attributes and then reduce the dimension.

[0172] The multidimensional matrix is ​​represented as: ij ={X ij (1) , ..., X ij (L)} T , where X ij (1) To X ij (L) That is, each element in the same position of the matrix together constitutes X ij The sample means of the L attributes are then calculated, and the mean is expressed as:

[0173]

[0174] Where N is the number of objects, then the covariance matrix C is calculated using:

[0175] The covariance matrix is ​​expressed as:

[0176]

[0177] The present invention calculates eigenvalues ​​and eigenvectors and stores them in a vector λ, where λ contains L eigenvalues ​​and a matrix V represents the corresponding L eigenvectors. Finally, the eigenvector corresponding to the maximum eigenvalue is extracted and represented as Vmax. The vector Vmax contains L elements. In the last step, each object of the array X is projected onto the maximum value of the vector V, which is calculated by the following formula:

[0178]

[0179] From this, the final description matrix X can be extracted final , as described by PCA below.

[0180] PCA Algorithm:

[0181]

[0182] Step 7: Recover the final hierarchical structure from the multidimensional matrix to achieve software structure recovery.

[0183] In this step, the CL algorithm may be used to create a final hierarchical structure from the target matrix to achieve recovery of the software architecture.

[0184] The present invention provides a software architecture recovery method based on hierarchical clustering combination, comprising: obtaining function entities in software source code; constructing relationships between function entities; using five similarity calculation methods to respectively calculate the similarities between function entities, and obtaining similarities calculated by each similarity calculation algorithm; based on the similarities calculated by each similarity calculation algorithm, using three hierarchical clustering algorithms, CL, WCA, and LIMBO, to respectively cluster the function entities, and obtain clustering results clustered according to each similarity; representing each clustering result in the form of a description matrix; using a principal component analysis method to combine the description matrices representing each clustering result to obtain a multidimensional matrix; and recovering the final hierarchical structure from the multidimensional matrix to achieve software structure recovery. The present invention uses principal component analysis to combine and reduce the dimensions of multiple matrices that can describe and consider various relationships between software entities, and the combined result retains the basic information of each clustering algorithm as much as possible, thereby improving the accuracy of the software architecture recovered based on clustering and the real architecture.

[0185] The effect of the recovery method provided by the present invention is illustrated below through experimental data.

[0186] The data sets required for the experiment include CVS and Bash from Maqbool, O, etc. CVS is a commonly used code version control software. It is mainly used for open source software management. Bash is the Shell (command line environment) of Unix and Linux systems, and is the default Shell of most Linux distributions. The present invention selects functions as entities and uses their formal features.

[0187] In the experimental clustering strategy, the present invention uses CL, WCA and LIMBO, and uses similarity methods Jaccard, JaccardNM, Jaccam, Unbiased Ellenberg measure, and information loss to cluster the entities and feature data of the two data sets, and obtains different results. Then, the present invention uses a hierarchical clustering combination method to combine these results. In addition to the PCA-based hierarchical clustering combination method proposed by the present invention for software architecture recovery, the present invention also uses the two previously proposed methods Sum Operator and Weighted Average for comparison.

[0188] In the process of verifying the recovery method of the present invention, internal evaluation as well as external evaluation is required.

[0189] Internal Assessment:

[0190] Number of clusters,The more non-singleton clusters produced in the initial stage,represents a better clustering effect and the result is more cohesive.,The number of clusters is considered to be a good indicator that the,clustering method performs well and creates good clustering quality in terms of,authority.,During the clustering process, the more clusters a clustering method creates, the higher the clustering quality.

[0191] Arbitrary decisions, clustering algorithms group entities based on the similarity of their features. At a certain step, there may be more than two entities that are equally similar. In this case, the clustering algorithm will arbitrarily choose two entities to cluster. Therefore, arbitrary decisions are common in the clustering process. Therefore, during the clustering process, as the clustering proceeds, the number of arbitrary decisions should be minimized in order to obtain high-quality results.

[0192] External Assessment:

[0193] Comparison of Expert Decomposition Results,In order to evaluate the quality of the results obtained by various,clustering algorithms, the present invention compares the clustering results obtained by applying,these algorithms with the decompositions manually prepared by human,experts.

[0194] MoJo metric. The present invention uses MoJo metric for software clustering evaluation. MoJo calculates the number of move and join operations required to transform one decomposition into another decomposition. The move operation simply moves an entity from one cluster to another. The join operation merges two clusters, so the total number of clusters is reduced by 1. The smaller the MoJo value, the higher the similarity between the test cluster and the expert decomposition. MoJo metric, Wen, Z. et al. proposed the MoJo metric for software clustering evaluation. MoJo calculates the number of move and join operations required to transform one decomposition into another decomposition. The move operation simply moves an entity from one cluster to another. The join operation merges two clusters, so the total number of clusters is reduced by 1. A smaller MoJo value indicates a higher similarity between the test cluster and the expert decomposition.

[0195] MoJo(A,B)=min(mno(A,B),mno(B,A))

[0196] Wherein, mno(A, B) represents the minimum number of operations to convert partition A into partition B. Then the Clustering quality metric used in the evaluation of the present invention is defined as

[0197]

[0198] Where n is the number of objects to be clustered.

[0199] Number of clusters. A large number of non-singleton clusters are generated in the early stage, which means that the underlying entities are looking for close associations, merging at the bottom, and gathering multiple pairs of the most relevant and similar entities. Therefore, the number of clusters will increase. When a singleton cluster joins a non-singleton cluster, the number of clusters can remain unchanged. When two non-singleton clusters begin to merge, the number of clusters will decrease. Figure 3 As shown, on average, the method HCC-PCA of the present invention creates a large number of non-single clusters in the clusters compared with the single clustering algorithm and other combination strategies. The number of clusters generated in each step of the clustering process is an important indicator for evaluating the quality of clustering.

[0200] refer to Figure 4, since the LIMBO algorithm uses information loss metric, it can generate the maximum number of clusters in the early clustering process. However, due to the subsequent combination of singletons and non-singleton entities, the number of clusters starts to decrease and then continues to increase. Due to the arbitrary decision-making in the clustering process, singleton entities may be randomly assigned to different non-singleton clusters, which affects the quality of clustering. The excellent results of the CL algorithm show that the number of clusters generated in the early stage is the least, which is similar to the clustering results generated by WCA because the similarity metric they use is to judge similarity by the presence of "a" or features. The HCC-PCA algorithm can generate a large number of clusters in the early stage and maintain a steady increase during the clustering process, indicating that the clustering using the PCA combination method in the early stage will merge more non-singleton clusters and will combine a large number of non-singleton clusters. After the singleton clusters are merged, the non-singleton clusters and other singleton clusters are merged, and then the number of clusters decreases. In the two datasets of Bash and CVS, the effect of the single hierarchical clustering algorithm and other combination methods is significantly lower than that of the PCA-based combination method.

[0201] Arbitrary decisions. Arbitrary decisions may degrade the performance and affect the clustering quality, so the percentage of arbitrary decisions is used as a metric to estimate clustering. Figure 5 The percentage of arbitrary decisions made by various algorithms during an iteration is shown, where n represents the number of entities in the system. We divide the clustering process by 5% and calculate the number of arbitrary decisions made by each node. In the early stages of clustering, more arbitrary decisions are made because the entities have the same similarity. Any early decision will not have much impact on the quality of the clustering. This is because singleton entities are always merged in the early stages of clustering. Figure 5 As shown in Figure 2, all algorithms produce more than 20% arbitrary decisions. As the clustering algorithm executes, more non-single entities will be merged. At this time, arbitrary decisions can lead to huge changes in clustering results, and LIMBO shows more arbitrary decisions. This can be attributed to the clustering utility function in the first half of the clustering process. Since all the utility functions are similar, the number of arbitrary decisions in LIMBO is relatively high.

[0202] Therefore, while LIMBO produces better clustering performance with non-singleton cases in the early stages, it also produces more arbitrary decisions, while the combination method can show lower arbitrary decisions in the early stages, and the PCA-based hierarchical clustering combination method works best. Figure 5It can be seen that HCC-PCA can always maintain the lowest percentage of arbitrary decisions compared to other methods. This represents a relatively high execution quality because it merges clusters with a small number of arbitrary decisions in the second half of the clustering and also obtains the best clustering quality, so it is due to the PCA-based combination process in the first half of the iteration. This method can produce smaller and denser singleton entity mergers with the lowest percentage of arbitrary decisions. Therefore, the use of HCC-PCA is more suitable for software clustering.

[0203] Comparison with Expert Decomposition. By using external evaluation to compare clustering algorithms, the MoJo metric is used to compare manually prepared expert decompositions with test clusters automatically prepared by the clustering algorithm.

[0204] To evaluate the clustering quality of various clustering algorithms, the present invention uses the maximum Q(M) value obtained at the cutoff height. The maximum Q(M) value metric provides better insight into the clustering quality than the average Q(M) value. The average Q(M) value may be overly biased due to the low value at the beginning of the clustering process.

[0205] As can be seen from Table 4, for a single algorithm, the maximum Q(M) value of all systems is obtained by the (LIMBO) algorithm, followed by WCA and the CL algorithm combined with similarity. For the results of the combined algorithm, the PCA-based method obtained the best results, while the results of A and B are closer to the average effect of a single algorithm. In the results of Table 2, the results of the single algorithm still show that LIMBO and WCA have the best results, while the combined algorithm PCA performs best in all comparisons, and the results of the other two combined algorithms A and B are still average. Since the purpose of software architecture recovery is to recover the structure that is as close to the real architecture as possible, the PCA-based hierarchical clustering combination method is more suitable for software architecture recovery.

[0206] Table 4 Clustering algorithm

[0207] TABLE IV: Comparison of Q(M)Values ​​between different methods

[0208]

[0209] This paper discusses a hierarchical clustering combination method for software architecture recovery. This method uses several IAHCs with better indicators in software clustering and matches different similarity calculation methods. A dendrogram with different structural characteristics is generated, and then these dendrograms are expressed in the form of description matrices. The description matrix represents the location information of the entity in the dendrogram, and corresponds one to one. Then, these description matrices are combined using principal component analysis and dimensionality reduction technology. The input of the combination process is L description matrices input hierarchical clustering, and the output is the created dendrogram. Principal component analysis is used to convert N entities with L attributes into hierarchical clustering. 2 The dimension of each sample is reduced to 1.

[0210] The present invention evaluates the methods used in the experiment, uses two open source software systems, and compares the experimental results of several IAHCs, the PCA-based combination method and two other methods, and analyzes the advantages and disadvantages of the algorithms from the internal and external evaluation of the clustering results. The experiments show that for the test system used, the PCA-based combination method can produce better results in all indicators because it combines the performance of these IAHCs.

[0211] In the field of software clustering, more research is needed to improve the accuracy and authority of the architecture. In the combination strategy of the tree diagram, the present invention only uses the description matrix with position information. In the future, the present invention will explore more tree diagrams and multiple representation methods. The present invention will explore more types of cluster integration algorithms for architecture recovery and apply the recovery method to other open source software projects.

[0212] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.

[0213] The above contents are further detailed descriptions of the present invention in combination with specific preferred embodiments, and it cannot be determined that the specific implementation of the present invention is limited to these descriptions. For ordinary technicians in the technical field to which the present invention belongs, several simple deductions or substitutions can be made without departing from the concept of the present invention, which should be regarded as falling within the protection scope of the present invention.

Claims

1. A software architecture recovery method based on hierarchical clustering combination, characterized in that: include: Step 1: Get the function entity in the software source code; Step 2: Construct the relationship between the function entities; The function entity relationship includes: global variables, local variables, user-defined types, data files referenced by the entity, mutual calls between entities, system calls, and macros referenced by the entity; Step 3: Use five similarity calculation methods to calculate the similarity between function entities respectively, and obtain the similarity calculated by each similarity calculation algorithm; Step 4: Based on the similarity calculated by each similarity calculation algorithm, three hierarchical clustering algorithms, CL, WCA, and LIMBO, are used to cluster the function entities respectively, and the clustering results according to each similarity are obtained; Step 5: Represent each clustering result in the form of a description matrix; Step 6: Use the principal component analysis method to combine the description matrices representing each clustering result to obtain a multidimensional matrix; Step 7: Recover the final hierarchical structure from the multidimensional matrix to achieve software structure recovery; The step 3 comprises: Step 3-1: Use the Jaccard method to calculate the expression and calculate the first binary similarity between function entities; The Jaccard method calculation expression is expressed as: Step 3-2: Using the JaccardNM method expression, calculate the second binary similarity between function entities; The JaccardNM method expression is expressed as: Step 3-3: Using the Jaccam method expression, calculate the third binary similarity between function entities; The Jaccam method expression is expressed as: Among them, E i , E j represents the two entities being calculated, a represents the number of features shared by the two entities, and b represents E i But E j The number of features that do not exist in E j But E i d represents the number of features missing in both entities; Step 3-4: Use the Unbiased Ellenberg measure method expression to calculate the fourth non-binary similarity between function entities; The Unbiased Ellenberg measure method expression is expressed as: Among them, Ma represents the sum of the features present in the two functional entities; Step 3-5: Use the information loss expression to calculate the fifth similarity between function entities; The information loss degree expression is expressed as: δI(E i ,HAVE BEEN j )=p(E i )+p(E j )*Djs(f i ,f j ) in, Dkl[f i ||f j ] is assumed to be distributed as f j The measure of redundancy in the encoding of i When Djs is f i and f j With f ij The average Dkl distance.

2. The software architecture recovery method based on hierarchical clustering combination according to claim 1 is characterized in that: The step 1 comprises: Through software code processing tools, entity information can be reversely obtained from software source code.

3. The software architecture recovery method based on hierarchical clustering combination according to claim 1 is characterized in that: The step 2 comprises: Step 2-1: Obtain the feature vector of each function entity; Each function entity is represented by a codeword. When the codeword is 1, it means that the position corresponding to the codeword has a feature, and when the codeword is 0, it means that there is no feature. The existing features are combined to obtain the feature vector of each function entity. Step 2-2: Use the feature vector of each function entity to construct the relationship between function entities.

4. The software architecture recovery method based on hierarchical clustering combination according to claim 1 is characterized in that: The step 4 comprises: Step 4-1: According to the first binary similarity, the second binary similarity and the third binary similarity, all function entities are clustered using the CL method to obtain three clustering results; Each clustering result is expressed as: Sim(E1, E 23 )=min(Sim(E1,E2),Sim(E1,E3)) where Sim(a,b) represents the similarity between entities a and b, E 23 Indicates the clustering results of E2 and E3; Step 4-2: Based on the fourth non-binary similarity, use the WCA method to cluster all function entities to obtain the fourth clustering result; Step 4-3: According to the fifth similarity, use the LIMBO method to cluster all function entities and obtain the fifth clustering result.

5. The software architecture recovery method based on hierarchical clustering combination according to claim 4 is characterized in that: The step 4-2 comprises: Step 4-21: According to the fourth non-binary similarity, merge the two most similar function entities to form a first new cluster; Step 4-22: Using the eigenvector expression, calculate the first new cluster E ij The eigenvector f ij ; The feature vector expression is: Among them, E i and E j They are the function entities to be clustered, and their eigenvectors are f i and f j , n i Indicates E i The number of function entities in n j Indicates E j The number of function entities in ; Step 4-23: Associating the feature vector of the first new cluster with the first new cluster to obtain a newly formed non-singleton cluster; Step 4-24: Take the newly formed non-singleton cluster as a new functional entity, and recalculate the similarity between this new functional entity and all other functional entities until the specified number of clusters is reached or only one cluster remains, thereby obtaining the fourth clustering result.

6. The software architecture recovery method based on hierarchical clustering combination according to claim 4 is characterized in that: The step 4-3 comprises: Step 4-31: The entity E with the least information loss i and E j Merge to obtain the merged second new cluster E ij ; Step 4-32: Calculate E ij The eigenvector of Among them, E ij The eigenvector f ij It is expressed as: Among them, n i and n j Respectively represent E i and E j The number of function entities contained in ; Step 4-33: The merged second new cluster E ij As a new functional entity, the similarity between the new functional entity and other functional entities is recalculated until a cluster is finally formed to obtain the fifth clustering result.

7. The software architecture recovery method based on hierarchical clustering combination according to claim 1 is characterized in that: The step 6 comprises: Step 6-1: Arrange the elements at the same position in each description matrix according to space to obtain a multidimensional matrix; Wherein, the multidimensional matrix has multiple attributes at the same position when observed from the spatial position, and each attribute is at a corresponding dimension; The multidimensional matrix is ​​represented as: ij ={X ij (1) ,...,X ij (L) )} T Step 6-2: Calculate the mean of all elements of the multidimensional matrix; The mean is expressed as: Step 6-3: Calculate the covariance matrix of the multidimensional matrix according to the means of all elements; The covariance matrix is ​​expressed as: Step 6-4: Calculate the eigenvalues ​​and eigenvectors of the covariance matrix, and determine the eigenvector with the maximum value; Step 6-5: Project each element in the multidimensional matrix onto the eigenvector of the maximum value to obtain the target matrix after describing the matrix combination.

8. The software architecture recovery method based on hierarchical clustering combination according to claim 7 is characterized in that: The step 7 comprises: Using the CL algorithm, a final hierarchy is created from the target matrix to recover the software architecture.