Fractal dimension-based Java software package defect tendency prediction method
By abstracting Java packages into undirected network graphs, calculating fractal dimension, and combining it with a logistic regression model, the problem of Java package defect prediction is solved, achieving efficient defect prediction and quality assessment.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-25
- Publication Date
- 2026-04-10
AI Technical Summary
There is a lack of effective methods in the existing technology to predict defects in software systems, especially at the Java package level, and the application of fractal dimension in software networks has not been proven.
The Java package is abstracted as an undirected network graph. The greedy coloring algorithm is used to calculate the minimum number of boxes covering the network. The fractal dimension is fitted by the gradient descent method. The defect is predicted by the logistic regression model. The prediction model is constructed using the fractal dimension and other metrics.
It achieves effective prediction of Java package defect tendencies, with high correlation between fractal dimension and software quality indicators, good model prediction performance, and is suitable for defect assessment of large software systems.
Smart Images

Figure CN121833460A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method for predicting defects in complex software networks, and more particularly to a method for predicting software system defects based on fractal dimension. Background Technology
[0002] Measuring software quality and predicting software defects are among the major problems in software engineering. Software failure data allows researchers to perform calculations at the software module, package, and system-wide levels, explicitly measuring software quality based on the failures affecting the software. However, since most failures only appear after system deployment, this method cannot be used in advance, and may only be identified and attributed to certain code segments after a long period of time, through in-depth analysis and some uncertainties. This is because software complexity is inherently an ambiguous property, especially at the system level.
[0003] In recent years, a series of software engineering studies have begun to analyze software systems using complex software graphs, which can typically be constructed from source code, binary files, or bytecode in Java systems. These existing studies support the method presented in this paper, using complex networks to analyze software systems. Furthermore, graph-based representations can define more reliable and effective metrics for software system complexity. Valverde and Sole provide a dynamically growing network model to explain the stationarity of network in-degree and out-degree distributions and why software networks can grow dynamically. Their research also shows that the topology of large software systems is generated through repetitive wiring mechanisms. To measure software complexity at different granularity levels, Ma and his collaborators propose a hierarchical metric for software coupling and cohesion based on the concept of software networks, demonstrating that this graphical metric can provide information about error-prone classes. Pan and his colleagues link the quality of software systems to their topology and introduce a new quality metric, Software Structure Quality (SQoS), to quantitatively measure the quality of object-oriented software networks by performing software defect propagation analysis at the class level; its distribution has been described by a mathematical model.
[0004] Among all the quality metrics proposed for complex software networks, fractal dimension appears to be a novel indicator that can serve as a global measure of the entire software network. Its unique advantage lies in its independence from other commonly used software metrics. The research of Kawasaki and Yakubo revealed the structural characteristics of complex networks: fractals and small-world structures cannot coexist within the same length range. Blagus et al., by studying density metrics in complex networks to seek fractal properties, analyzed over 50 real-world networks and found a power-law relationship between network density and size, independent of network type and origin. Their work confirms and extends the conclusion found by Laurentei et al. that self-organizing networks typically possess fractal scaling structures.
[0005] However, fractal dimension is not well defined for software networks. This is because not all networks have a structure where the number of boxes covering the network scales linearly according to a power law, i.e., the definition of a fractal in a network. However, current research has found fractal scaling in some software networks, making the application of fractal dimension possible. Currently, the method of using fractal dimension to describe software defect prediction in general object-oriented software systems has not been proven. This method belongs to the research on fractal dimension of general complex networks and the use of complex network analysis to characterize software quality. It has been shown that fractal dimension will be a useful network indicator in the field of software defect prediction. This work is of great significance for current research on measuring software quality problems and software defect prediction. Summary of the Invention
[0006] The purpose of this invention is to address the shortcomings of existing technologies by providing a Java software package defect tendency prediction method based on fractal dimension.
[0007] The above-mentioned technical problem of the present invention is mainly solved by the following technical solution: a Java software package defect tendency prediction method based on fractal dimension, the method comprising the following steps:
[0008] (1) Abstract the target Java software source code with a known number of defects into an undirected network graph, with each package corresponding to one network graph; the specific process is as follows:
[0009] (1.1) Extract the calling relationships between all methods in a package and transform these calling relationships into relationships between the classes that define the methods;
[0010] (1.2) Extract the generalization, implementation, and dependency relationships between classes within a package, and record them together with the relationships between classes in step (1.1) as the interaction relationships between classes;
[0011] (1.3) Construct an undirected network graph G = (N, D) with classes as nodes and interactions between classes as edges; where N is the set of network nodes in the undirected network graph, and each node represents a class in a package; D = {(C i C j )}(C i ∈N,C j ∈N) is a set of undirected edges, representing the interaction relationships between classes; C i C j These represent the i-th and j-th nodes, respectively.
[0012] (2) Based on the undirected network graph G obtained in step (1), the minimum number of boxes N covering the network of a single undirected network is calculated using the greedy coloring algorithm. B ; Set the box size l B Change from 1 to For a given size l = l B The box, where the color of node i in the box is in The maximum value of the box size, i.e., the network diameter, is defined as the maximum distance between all nodes in the network graph;
[0013] (3) Based on the N obtained in step (2) B and l B Gradient descent method is used for N B and l B Perform linear fitting, i.e. The slope of the line in its log-log plot is the fractal dimension d. B ;
[0014] (4) The fractal dimension d obtained in step (3) B And packages containing software defect data are substituted into a logistic regression model for software defect prediction.
[0015] Furthermore, in step (2), a greedy coloring algorithm is used to map the Box counting problem to the graph node coloring problem.
[0016] Furthermore, step (2) covers the minimum number of boxes N in the network. B The calculation specifically includes the following sub-steps:
[0017] (2.1) First, assign a unique ID from 1 to N to all network nodes, using f i This represents the i-th node, but it is not assigned any color.
[0018] (2.2) For all l B The value is assigned to the node f1 with color value 0 at i=1, i.e., c. 1l =0;
[0019] (2.3) Calculate from f i To all nodes f in the network that are less than i j distance l ij ;
[0020] (2.4) Setting l B =1;
[0021] (2.5) From all nodes f j The middle is l ij ≥l B Choose an unused color. That is, for a given l B Value, this is node f i color
[0022] (2.6) l B Increment by 1, then repeat step (2.6) until...
[0023] (2.7) Increment i by 1; repeat steps (2.3) to (2.7) until i = N.
[0024] Furthermore, step (3) uses gradient descent to analyze N. B and l B The process of performing linear fitting includes the following sub-steps:
[0025] (3.1) Assume the fitted line is y = ax + b, and each group N B and l B The value of is the true value of y and x in the fitted line; where a and b represent the slope and intercept, respectively, and the absolute value of the slope a is the final required fractal dimension d. B The specific formula is:
[0026] Define the cost function:
[0027]
[0028] in, For the observed value, y i is the true value, m is the total number of data points, and the independent variable i has values from 1 to m.
[0029] Taking the partial derivatives of the cost function with respect to a and b respectively, we get...
[0030] (3.2) Based on the gradient descent algorithm, the iterative formula is as follows:
[0031] for i in range(n):
[0032]
[0033]
[0034] In this iterative formula, n is the set number of iterations, and the value of i ranges from 0 to n; alpha is the step size, i.e., the learning rate; the values of a and b are updated in each iteration. When the optimal cost loss is obtained, a and b are also updated to their optimal values. At this point, the fitted line y = ax + b can be obtained, where the absolute value of the slope a is the fractal dimension d. B .
[0035] Further, step (4) uses the obtained feature values to substitute into the logistic regression model for software defect prediction. The calculation specifically includes the following sub-steps:
[0036] (4.1) Calculate several metrics CK for a class, including method weights (WMC), inheritance tree depth (DIT), number of subclasses (NOC), coupling between classes (CBO), response set size (RFC), and lack of method cohesion (LCOM).
[0037] (4.2) Organize the defect data in the software into data on whether each package contains defects. If any code block in a package contains a defect, the package is identified as a defect package and its category label is 1.
[0038] (4.3) Take the d obtained in step (3) B The defective package is used as a feature value in the original dataset. The original dataset is divided into training set and test set by 3 times of 10-fold cross-validation, resulting in data training set trainSet, label training set trainLabel, data test set testSet and label test set testLabel.
[0039] (4.4) Due to the special nature of the substituted feature values, the Sigmoid function is used to receive all input features for binary classification. The calculation formula is as follows:
[0040] Suppose there are n features, which can be obtained by adding a coefficient θ:
[0041] z = θ0 + θ1x1 + ... + θ n x n =θ T x
[0042] Where x1, x2, ..., x n There are n features, including fractal dimension and metric CK, θ0, θ1, ..., θ n Let θ be the coefficients of the n features, z be the sum of the products of each feature and its coefficient, and θ be the coefficients of the n features. TThe vector represents the feature coefficients, and x represents the feature vector;
[0043] By taking z as input to the Sigmoid function, we obtain:
[0044]
[0045] Substituting the above equation into the Logistic function to solve the binary classification problem of defect tendency in software package c, we get:
[0046] p(y=1|x,θ)=h θ (x)
[0047] p(y=0|x,θ)=1-p(y=1|x,θ)=1-h θ (x)
[0048] Here, the p function represents the probability that the category label y is 0 or 1 given x and θ, where 1 indicates that the target software package c has a defect (buggy); and 0 indicates that the target software package c meets the design expectations, that is, it has no defects (clean).
[0049] (4.5) The optimal regression coefficient θ is determined based on the improved stochastic gradient ascent algorithm. The algorithm iteration formula is as follows:
[0050] for i in range(m):
[0051]
[0052] In this iterative formula, m is the set number of iterations, and the value of i ranges from 0 to m; θ j The regression coefficients from the previous iteration are initialized to 1; α is the step size, the amount of movement in the direction of the fastest function growth, i.e., the learning rate; y is the corresponding class label in the training set trainLabel; x j The training set is trainSet; the result h is calculated using the Sigmoid function obtained in step (4.4). θ (x), adjust the regression coefficients according to the differences; repeat the iteration until an optimal regression coefficient value θ is obtained;
[0053] (4.6) Based on the optimal regression coefficient θ from step (4.5), read the data in the test set testSet, format it, and then call the classifier function (passing in the feature values of the testSet samples and the optimal regression coefficient θ) to predict the final result.
[0054] Compared with the prior art, the present invention has the following advantages and positive effects:
[0055] (1) Complex networks composed of large-scale, general-purpose software systems and software sub-projects generally have fractal properties, which makes it possible to apply fractal dimension to complex software networks. At the same time, when applied to actual software systems for measurement, it was found that the fluctuations in the fractal dimension of the software system are consistent with the fluctuations present in most subsystems.
[0056] (2) Because each sub-project of a large software project has different responsibilities and objectives, the source code may be written by different developers using different design approaches, making the source code of the sub-projects relatively independent. Therefore, in actual experiments, we simultaneously evaluated the correlation between the software defects of the sub-projects and the fractal dimension of the sub-projects within the same version. This is helpful for evaluating d B It serves as a supplementary quality indicator. The current evaluation is being conducted on a limited Java software system, but there is still a great deal of potential and feasibility to extend it to other large software systems composed of sub-projects.
[0057] (3) First, by correlating with some proven class-level software quality metrics, a very high correlation and confidence level can be found between fractal dimension and lines of code (loc), CBO, and RFC standards. Second, the number of software defects, a reliable indicator of software quality at any level, also shows a strong correlation with fractal dimension. Therefore, based on this strong correlation, fractal dimension can be used to improve defect prediction models based on complex networks. Practical experiments show that this indicator can achieve good predictive performance, strongly proving the effectiveness of fractal dimension d. B It can be used as a quality metric in Java package defect propensity prediction models. This work provides new ideas and solutions for measuring software quality and predicting software network defects. Attached Figure Description
[0058] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0059] Figure 1 This is the solution process of the method of the present invention.
[0060] Figure 2 This is an example of an undirected graph G constructed according to the present invention.
[0061] Figure 3 This is an example graph of function fitting constructed using examples of the present invention. Detailed Implementation
[0062] The specific embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.
[0063] The present invention proposes a Java software package defect tendency prediction method based on fractal dimension, the specific steps of which are as follows:
[0064] (1) The software written in Java is abstracted into an undirected network graph (one network graph per package) G = (N, D). For illustration, an undirected network G with three generations and each node having 1 child generation will be constructed in this example.
[0065] The following is a Python source code.
[0066]
[0067]
[0068]
[0069] According to the Python source code above, the runtime first calls the `dealwith_gml.cal_main()` method, which in turn calls the `dealwith_gml.cal_db(network)` method to calculate the fractal dimension of the network. All these methods are named in the format "class name.method name.parameter list," which are their fully qualified names. Based on the execution of the Python source code, we can obtain the following... Figure 2 The example network undirected graph G is shown, where the name of each node is the numerical ID of the method it corresponds to. Here, N is the set of network nodes in the undirected network graph, and each node represents a class in a package; D = {(C i C j )}(C i ∈N,C j (∈N) is a set of undirected edges, representing the interaction relationships between classes.
[0070] (2) Based on the network G obtained in step (1), call the fractal_dimension.box_cover.GC(G) function to calculate the minimum number of boxes N covering the network using the greedy coloring algorithm. B Set the box size to l B Change from 1 to The evaluation size is Two-dimensional matrix c il Its value c il This indicates that the given size is l = l B The color of node i of the box. According to Figure 1The method shown is an algorithm for calculating the number of boxes required to tile a network graph. Through a competition between accuracy, efficiency, and performance, and to ensure the reliability of the final result and make it as close as possible to the optimal minimum, a greedy coloring algorithm with high execution speed and relatively low dispersion is chosen. This method maps the box counting problem to the graph node coloring problem to solve the network coverage problem. From G( Figure 1 Starting with the top left image in the diagram, for a given box size (illustrated as l) B =3) A dual network G′ was constructed. Figure 1 (See the top right image in the diagram). If the distance between two nodes satisfies l ≥ l B Then connect the two nodes. Use a greedy algorithm to color the vertices in G′, and then use that color to determine the boxes covered in G.
[0071] The minimum number of boxes N in the overlay network B The calculation specifically includes the following sub-steps:
[0072] (2.1) First, assign a unique ID from 1 to N to all network nodes, using f i This represents the i-th node, but it is not assigned any color.
[0073] (2.2) For all l B The value is assigned to the node f1 with color value 0 at i=1, i.e., c. 1l =0;
[0074] (2.3) Calculate from f i To all nodes f in the network that are less than i j distance l ij ;
[0075] (2.4) Setting l B =1;
[0076] (2.5) From all nodes f j The middle is l ij ≥l B Choose an unused color. That is, for a given l B Value, this is node f i color
[0077] (2.6) l B Increment by 1, then repeat step (2.6) until...
[0078] (2.7) Increment i by 1; repeat steps (2.3) to (2.7) until i = N.
[0079] Based on the network input in this example, obtain the box size l. B The minimum number of boxes N in the overlay network B The correspondence is as follows:
[0080] l B =[1,2,3,4,5,6,7,8,9] N B =[19,13,7,4,4,3,3,2,1]
[0081] (3) Based on the N obtained in step (2) B and l B Gradient descent method is used for N B and l B Perform a linear fit; let x = l B y = N B Call the `fit_line_by_grad()` function to obtain the fitted line:
[0082] y = -1.27184698 × x + 1.40990823
[0083] Figure 3 To illustrate the fitting results, the points corresponding to LogXI and LogYI, along with the fitted line, are shown. The slope of the fitted line is calculated using numpy.poly1d(), and its absolute value, according to the definition of fractal dimension, is the fractal dimension d of the corresponding class network. B =1.2718469834813193.
[0084] (4) Based on the fractal dimension d obtained in step (3) B The relevant data obtained in this example are imported into SPSS software for correlation analysis to obtain d. B Correlation with the number of software defects. Software defects are a reliable indicator of software quality at any level (e.g., from an industry perspective, the average cost of bug fixing and system maintainability is associated with each bug). In practical applications, fractal dimension is closely related to the total number of system defects, exhibiting a high correlation and confidence level. Actual results also strongly suggest that fractal dimension can serve as a reliable indicator of system quality.
[0085] As shown in the table below, the fractal dimension d obtained in this example B It has a strong correlation with the number of software defects, and the correlation coefficient is generally maintained in the range of greater than 0.4, which indicates a close relationship.
[0086]
[0087] **. Significantly correlated at the .01 level (two-sided).
[0088]
[0089]
[0090] **The correlation is significant at a confidence level (two-sided).
[0091] (5) Based on the strong correlation conclusion in step (4), the d obtained in step (4) is... B Using software package defect data and other related data as feature values, the original dataset is generated and fed into a logistic regression model to predict software defect propensity. This process includes the following sub-steps:
[0092] (5.1) Calculate several metrics CK for a class, as shown in the table below:
[0093]
[0094] (5.2) Organize the defect data in the software into data on whether each package contains defects, that is: if any code block (method, class, etc.) in package A contains a defect, then the package is identified as a defective package and its category label is 1.
[0095] (5.3) d B The software package defect data (obtained in step 5.2) are used as feature values in the original dataset. The original dataset is divided into training set and test set by 3 times of 10-fold cross-validation, resulting in data training set trainSet, label training set trainLabel, data test set testSet and label test set testLabel.
[0096] (5.4) Due to the special nature of the substituted feature values, the Sigmoid function is used to receive all input features for binary classification. The calculation formula is as follows:
[0097] Assuming there are n features, we can obtain the following by adding a coefficient θ:
[0098] z = θ0 + θ1x1 + ... + θ n x n =θ T x
[0099] Where x1, x2, ..., x n There are n features, including the metric CK and the fractal dimension d. B , θ0,θ1,......,θ n Let x1, x2, ..., x6 be the coefficients of the n features, and z be the sum of the products of each feature and its coefficient. In this project, n = 7, x1, x2, ..., x6 are the six indicators in the CK metric set, and x7 is the fractal dimension d obtained in step (3).B .
[0100] By taking z as input to the Sigmoid function, we obtain:
[0101]
[0102] Substituting the above formula into the Logistic function to solve the binary classification problem of defect tendency for class c, we get:
[0103] p(y=1|x,θ)=h θ (x)
[0104] p(y=0|x,θ)=1-p(y=1|x,θ)=1-h θ (x)
[0105] Here, the p function represents the probability that the category label y is 0 or 1 given x and θ, where 1 indicates that the target software package c has a defect (buggy); and 0 indicates that the target software package c meets the design expectations, that is, it has no defects (clean).
[0106] (5.5) The optimal regression coefficient θ is determined based on the improved stochastic gradient ascent algorithm. The algorithm iteration formula is as follows:
[0107] for i in range(m):
[0108]
[0109] In this iterative formula, m is the set number of iterations, and the value of i ranges from 0 to m; θ j The regression coefficients from the previous iteration are initialized to 1; α is the step size, the amount of movement in the direction of the fastest function growth, i.e., the learning rate; y is the corresponding class label in the training set trainLabel; x j The training set is trainSet; the result h is calculated using the Sigmoid function obtained in step (5.4). θ (x), adjust the regression coefficients according to the differences; repeat the iteration until an optimal regression coefficient value θ is obtained;
[0110] (5.6) Based on the optimal regression coefficient θ from step (5.5), read the data in the test set testSet, perform formatting, and then call the classifier function (passing in the feature values of the testSet samples and the optimal regression coefficient θ) to predict the final result.
[0111] (6) Return the error rate (errorRate) used to determine if the model has defects, to verify the reliability of the propensity prediction method. This includes the following sub-steps:
[0112] (6.1) Calculate the predicted category based on the Sigmoid() function after inputting the true feature values. Based on the input data in this example, the calculation is as follows:
[0113]
[0114] Where m is the size of trainSet, index is the feature value number, and ones is a matrix with the same number of columns as trainSet and a value of 1.
[0115] (6.2) The optimal regression coefficient θ is determined based on the improved stochastic gradient ascent algorithm. According to the actual experimental results, the number of iterations is set to numIter = 200. Based on h from step (5.4)... θ Substituting the values into the calculation, the error between the actual and test results is calculated, and the regression coefficient is adjusted according to the direction of the error. The calculation is as follows:
[0116] for i in range(numIter):
[0117] error = trainLabel[index] - h θ
[0118] θ=ones(m)+alpha×error×trainSet[index]
[0119] Where alpha is the step size. Based on the input data in this example, the calculation results are as follows:
[0120]
[0121] (6.3) Based on the optimal regression coefficient θ from step (6.2), read the data from the test sample testSet, format it, and then call the classifier function (passing in the feature values of the testSet samples and the optimal regression coefficient θ) to predict the final features. Compare the final features with the actual features in testSet to calculate the number of errors. If the classifier's result does not match the actual result, then the error count errorCount = errorCount + 1. Iterate through all the test data, allTestCount = len(testSet), and calculate the error rate ERate using the error count errorCount.
[0122]
[0123] (6.4) Repeat steps (6.1) to (6.3) to calculate the average error rate, thus obtaining the final error rate for this example:
[0124]
[0125] The calculation results show that, through continuous model optimization, the difference between the predicted and actual values, as well as the number of incorrect predictions, are very small. Therefore, the average error rate of the software in this example for predicting defects is very low, meaning that the prediction results of this method are generally satisfactory.
[0126] The above embodiments are used to explain and illustrate the present invention, but not to limit the present invention. Any modifications and changes made to the present invention within the spirit and scope of the claims shall fall within the protection scope of the present invention.
Claims
1. A method for predicting the defect tendency of Java software packages based on fractal dimension, characterized in that, The method includes the following steps: (1) Abstract the target Java software source code with a known number of defects into an undirected network graph, with each package corresponding to one network graph; the specific process is as follows: (1.1) Extract the calling relationships between all methods in a package and transform these calling relationships into relationships between the classes that define the methods; (1.2) Extract the generalization, implementation, and dependency relationships between classes within a package, and record them together with the relationships between classes in step (1.1) as the interaction relationships between classes; (1.3) Construct an undirected network graph G = (N, D) with classes as nodes and interactions between classes as edges; where N is the set of network nodes in the undirected network graph, and each node represents a class in a package; D = {(C i C j )}(C i ∈N, C j ∈N) is a set of undirected edges, representing the interaction relationships between classes; C i C j These represent the i-th and j-th nodes, respectively. (2) Based on the undirected network graph G obtained in step (1), the minimum number of boxes N covering the network of a single undirected network is calculated using the greedy coloring algorithm. B ; Set the box size l B Change from 1 to For a given size The box, where the color of node i in the box is in The maximum value of the box size, i.e., the network diameter, is defined as the maximum distance between all nodes in the network graph; (3) Based on the N obtained in step (2) B and l B Gradient descent method is used for N B and l B Perform linear fitting, i.e. The slope of the line in its log-log plot is the fractal dimension in dB. (4) The fractal dimension d obtained in step (3) B And packages containing software defect data are substituted into a logistic regression model for software defect prediction.
2. The Java package defect tendency prediction method based on fractal dimension according to claim 1, characterized in that, In step (2), a greedy coloring algorithm is used to map the Box counting problem to the graph node coloring problem.
3. The Java software package defect tendency prediction method based on fractal dimension according to claim 1, characterized in that, Step (2) Minimum number of boxes N covering the network B The calculation specifically includes the following sub-steps: (2.1) First, assign a unique ID from 1 to N to all network nodes, using f i This represents the i-th node, but it is not assigned any color. (2.2) For all l B The value is assigned to the node f1 with color value O at i=1, i.e., c. 1l =0; (2.3) Calculate from f i To all nodes f in the network that are less than i j distance l ij ; (2.4) Setting l B =1; (2.5) From all nodes f j The middle is l ij ≥l B Choose an unused color. That is, for a given l B Value, this is node f i color (2.6) l B Increment by 1, then repeat step (2.6) until... (2.7) Increment i by 1; repeat steps (2.3) to (2.7) until i = N.
4. The Java software package defect tendency prediction method based on fractal dimension according to claim 1, characterized in that, Step (3) Use gradient descent to analyze N. B and l B The process of performing linear fitting includes the following sub-steps: (3.1) Assume the fitted line is y = ax + b, and each group N B and l B The value of is the true value of y and x in the fitted line; where a and b represent the slope and intercept, respectively, and the absolute value of the slope a is the final required fractal dimension d. B The specific formula is: Define the cost function: in, For the observed value, y i is the true value, m is the total number of data points, and the independent variable i has values from 1 to m. Taking the partial derivatives of the cost function with respect to a and b respectively, we get... (3.2) Based on the gradient descent algorithm, the iterative formula is as follows: for i in range(n): In this iterative formula, n is the set number of iterations, and the value of i ranges from 0 to n; alpha is the step size, i.e., the learning rate; the values of a and b are updated in each iteration. When the optimal cost loss is obtained, a and b are also updated to their optimal values. At this point, the fitted line y = ax + b can be obtained, where the absolute value of the slope a is the fractal dimension d. B .
5. The Java package defect tendency prediction method based on fractal dimension according to claim 1, characterized in that, Step (4) uses the obtained feature values to substitute into the logistic regression model to predict software defects. The calculation specifically includes the following sub-steps: (4.1) Calculate several metrics CK for a class, including method weights (WMC), inheritance tree depth (DIT), number of subclasses (NOC), coupling between classes (CBO), response set size (RFC), and lack of method cohesion (LCOM). (4.2) Organize the defect data in the software into data on whether each package contains defects. If any code block in a package contains a defect, the package is identified as a defect package and its category label is 1. (4.3) Take the d obtained in step (3) B The defective package is used as a feature value in the original dataset. The original dataset is divided into training set and test set by 3 times of 10-fold cross-validation, resulting in data training set trainSet, label training set trainLabel, data test set testSet and label test set testLabel. (4.4) Due to the special nature of the substituted feature values, the Sigmoid function is used to receive all input features for binary classification. The calculation formula is as follows: Suppose there are n features, which can be obtained by adding a coefficient θ: z=θ0+θ1x1+…+θ n x n =θ T x Where x1, x2, ..., x n There are n features, including fractal dimension and metric CK, θ0, θ1, ..., θ n Let θ be the coefficients of the n features, z be the sum of the products of each feature and its coefficient, and θ be the coefficients of the n features. T The vector represents the feature coefficients, and x represents the feature vector; By taking z as input to the Sigmoid function, we obtain: Substituting the above equation into the Logistic function to solve the binary classification problem of defect tendency in software package c, we get: p(y=1|x,θ)=h θ (x) p(y=0|x,θ)=1−p(y=1|x,θ)=1−h θ (x) Here, the p function represents the probability that the category label y is 0 or 1 given x and the target condition, where 1 indicates that the target software package c has a defect (buggy); and 0 indicates that the target software package c meets the design expectations, that is, it has no defects (clean). (4.5) The optimal regression coefficient θ is determined based on the improved stochastic gradient ascent algorithm. The algorithm iteration formula is as follows: for iin range(m): In this iterative formula, m is the set number of iterations, and the value of i ranges from 0 to m; θ j The regression coefficients from the previous iteration are initialized to 1; α is the step size, the amount of movement in the direction of the fastest function growth, i.e., the learning rate; y is the corresponding class label in the training set trainLabel; x j The training set is trainSet; the result h is calculated using the Sigmoid function obtained in step (4.4). θ (x), adjust the regression coefficients according to the differences; repeat the iteration until an optimal regression coefficient value θ is obtained; (4.6) Based on the optimal regression coefficient θ from step (4.5), read the data in the test set testSet, format it, and then call the classifier function (passing in the feature values of the testSet samples and the optimal regression coefficient θ) to predict the final result.