Time-aware instant software defect prediction method and device and readable storage medium
By using conditional adversarial generation network and flexible action-evaluation algorithm in real-time software defect prediction technology, the time-aware characteristics and concept drift problems of software changes are solved, and the accuracy and practicality of software defect prediction are improved.
Patent Information
- Application Number
- CN202411763203.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2044-12-03
AI Technical Summary
Existing instant software defect prediction technology cannot effectively solve the time-aware characteristics and concept drift problems of software changes, resulting in limited prediction accuracy and practicality.
Simulated change samples are obtained by taking real change samples and inputting them into the generative model of the conditional adversarial generation network. Then, according to the change chronological order, the optimization strategy of the instant software defect prediction agent constructed based on the flexible action-evaluation algorithm is adjusted to obtain the final software defect prediction agent.
Through the combination of conditional adversarial generation network and flexible action-evaluation algorithm, the optimization strategy of real-time software defect prediction agents can be adjusted in a timely manner, solve concept drift problems, and improve the accuracy and practicality of software defect prediction.
Smart Images

Figure CN119862105A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of software defect prediction, and in particular relates to a time-aware real-time software defect prediction method, device and readable storage medium. Background Art
[0002] Traditional software defect prediction (SDP) technology mainly focuses on module-level prediction, that is, locating files, software packages or subsystems that may have defects. However, this technology has certain limitations in effectiveness. It cannot accurately locate defects, lacks a timely feedback mechanism, and cannot quickly identify defect repairers. In order to meet these challenges, researchers proposed the Just-in-Time Software Defect Prediction (JIT-SDP) technology.
[0003] The basic principle of JIT-SDP is to use the historical software changes to build the SDP model and predict whether the current software changes have defects. However, there are two main problems with this model: First, it ignores the fact that software changes have time-aware characteristics. When building and verifying the SDP model, the software changes are not sorted by time. In the actual prediction process, future defect change information may be used to predict historical changes, affecting the accuracy of the prediction. Second, software development organizations will continue to evolve. Over time, software developers, technologies, and processes may change. Therefore, the patterns and relationships of software changes will also change over time. The SDP model built based on historical changes will become outdated over time and have concept drift problems.
[0004] How to solve the concept drift problem is the key to improving the performance and practicality of JIT-SDP.
[0005] It should be noted that the above information disclosed in this background technology section is only used to understand the background technology of the present application concept, and therefore, the above description is not considered to constitute information of the prior art. Summary of the invention
[0006] The embodiments of the present disclosure at least provide a time-aware real-time software defect prediction method, device, and readable storage medium.
[0007] In a first aspect, an embodiment of the present disclosure provides a time-aware real-time software defect prediction method, comprising the following steps:
[0008] Get a sample of real changes;
[0009] Input the real change samples into the generative model based on the conditional adversarial generative network to obtain simulated change samples;
[0010] According to the time sequence of changes, the optimization strategy of the real-time software defect prediction agent built based on the flexible action-evaluation algorithm is adjusted through real change samples and simulated change samples to obtain the final software defect prediction agent;
[0011] Software defects are predicted through trained real-time software defect prediction agents.
[0012] In an optional implementation, the step of inputting the real change sample into the generative model based on the conditional adversarial generative network to obtain the simulated change sample includes:
[0013] Define the generator and discriminator of the generative model based on the conditional adversarial generative network;
[0014] Input the real change samples and change metrics into the generator to generate initial simulated change samples;
[0015] Calculate the data distribution P of the real change sample and the data distribution Q of the initial simulated change sample respectively;
[0016] Calculate the maximum mean difference MMD(P,Q) between data distribution P and data distribution Q;
[0017] Add MMD(P, Q) to the loss functions of the generator and discriminator respectively;
[0018] First update the parameters of the discriminator and minimize the loss function L(D) of the discriminator;
[0019] Then update the parameters of the generator and minimize the loss function L(G) of the generator;
[0020] Repeatedly update the parameters of the discriminator and the generator until the preset training round is reached or the loss function L(D) and the loss function (G) converge, completing the training of the generative model.
[0021] In an optional implementation, the formula of the loss function L(D) of the discriminator is as follows:
[0022] L(D)=-log(D(x))-log(1-D(G(z)))+λMMD(P,Q);
[0023] Where D represents the discriminator, x represents the real change sample, G represents the generator, z represents the predicted change, G(z) represents the change data generated by the generator, and λ represents the weight parameter of the maximum mean difference MMD(P, Q).
[0024] In an optional implementation, the formula of the generator's loss function L(G) is as follows:
[0025] L(G)=-log(D(G(z)))+λMMD(P,Q);
[0026] Where D represents the discriminator, G represents the generator, z represents the predicted change, G(z) represents the change data generated by the generator, and λ represents the weight parameter of the maximum mean difference MMD(P, Q).
[0027] In an optional implementation, the steps of constructing an instant software defect prediction agent based on a flexible action-evaluation algorithm are as follows:
[0028] Add the causal convolutional neural network (CCNN) to the policy network;
[0029] Treat the change sample as the environment and the change as the state;
[0030] Take the defect binary classification prediction as action a;
[0031] The weighted sum of the evaluation indicators accuracy and F1-score is used as the reward function to complete the construction of the real-time software defect prediction agent.
[0032] In an optional implementation, the step of adjusting the optimization strategy of the real-time software defect prediction agent constructed based on the flexible action-evaluation algorithm through the real change samples and the simulated change samples includes:
[0033] Initialize the real-time software defect prediction agent. The initialization parameters include: policy network parameters θ, Q function network parameters θ q ,CCNN network parametersθ c , target network parameters θ t ,priority experience replay cache D;
[0034] S1: initialization state s;
[0035] S2: Input the real change samples and simulated change samples into the software defect prediction agent in chronological order, use the policy network to select action a, execute action a, observe the new state s′, and obtain the immediate reward r;
[0036] S3: Add (s,a,r,s′,m) to the experience replay buffer D, where m is a flag indicating whether the software change is defective.
[0037] S4: When the number of samples in the experience replay buffer D reaches the preset number, calculate the target Q value y i =r i +γ*Q target (s′ i ,a′ i );
[0038] In the formula, y i represents the target Q value, γ represents the discount factor, Q target represents the Q target network;
[0039] Update the Q function network parameters θ q , and use the gradient descent method to minimize the loss function L(Q) of the Q function network;
[0040] S5: Update the policy network parameters θ according to the updated Q function network c , and use the gradient ascent method to maximize the objective function J(θ) of the policy network parameter θ,
[0041] S6: Based on θ c Calculate the causal probability p i =CCNN(s i ,θ c ), update the policy network parameters θ, and use the gradient descent method to minimize the loss function L(p) based on the flexible action-criteria algorithm;
[0042] S7: Update target network parameters θ t新 =(1-α)*θ t +α*θ and policy network parameters θ c新 =(1-α)*θ c +α*θ; where α represents the regularization coefficient;
[0043] Repeat steps S1-S7 until the number of iterations reaches M, completing the adjustment of the optimization strategy.
[0044] In an optional implementation, the step of inputting the real change samples and the simulated change samples into the software defect prediction agent in chronological order is:
[0045] Combine the simulated change samples and the real change samples into a new training set and sort them according to the chronological order of the changes;
[0046] The sorted training sets are input into the software defect prediction agent in sequence.
[0047] In a second aspect, the present disclosure also provides an in-depth perception real-time software defect prediction device, including:
[0048] A first acquisition module, adapted to acquire a real change sample;
[0049] A second acquisition module is adapted to input the real change sample into the generative model based on the conditional adversarial generative network to obtain the simulated change sample;
[0050] The training module is suitable for adjusting the optimization strategy of the real-time software defect prediction agent built based on the flexible action-evaluation algorithm through real change samples and simulated change samples according to the time sequence of changes, so as to obtain the final software defect prediction agent;
[0051] The prediction module is suitable for predicting software defects through the trained real-time software defect prediction agent.
[0052] In a third aspect, an embodiment of the present disclosure further provides a computer-readable storage medium, wherein the computer-readable storage medium stores at least one instruction, and when the instruction is executed by a processor, the time-aware real-time software defect prediction method as described above is implemented.
[0053] In a fourth aspect, an embodiment of the present disclosure further provides an electronic device, comprising a memory and a processor; the memory stores at least one instruction; the processor implements the time-aware real-time software defect prediction method as described above by loading and executing the at least one instruction.
[0054] The beneficial effect of the present invention is that the time-aware real-time software defect prediction method, device and readable storage medium obtain simulated software changes through the generative model of the conditional adversarial generative network, and according to the time sequence of the changes, through real change samples and simulated change samples, after each time step, through the reward results and current status, timely adjust the optimization strategy of the real-time software defect prediction intelligent agent, thereby solving the concept drift problem.
[0055] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0056] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0058] Figure 1 A flowchart of a time-aware real-time software defect prediction method provided in an embodiment of the present disclosure.
[0059] Figure 2 Box plots of the Accuracy indicators of the three methods provided in the embodiments of the present disclosure.
[0060] Figure 3 Box plots of the F1-score indicators of the three methods provided in the embodiments of the present disclosure.
[0061] Figure 4 A schematic diagram of the structure of a time-aware real-time software defect prediction device provided in an embodiment of the present disclosure.
[0062] Figure 5 It is a partial structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0064] To facilitate understanding of this embodiment, a model building method disclosed in the embodiment of the present disclosure is first introduced in detail. The execution subject of the time-aware real-time software defect prediction method provided in the embodiment of the present disclosure is generally a computer device with certain computing capabilities, and the computer device includes, for example: a terminal device or a server or other processing device, and the terminal device can be a user equipment (User Equipment, UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (Personal Digital Assistant, PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. In some possible implementations, the model building method can be implemented by a processor calling a computer-readable instruction stored in a memory.
[0065] Some embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0066] Example 1
[0067] See also Figure 1At least one embodiment provides a time-aware real-time software defect prediction method, which obtains simulated software changes through a generative model of a conditional adversarial generative network, and adjusts the optimization strategy of the real-time software defect prediction agent in a timely manner through reward results and current status after each time step through real change samples and simulated change samples in the chronological order of the changes, thereby solving the concept drift problem.
[0068] Specifically, the time-aware real-time software defect prediction method includes the following steps:
[0069] S110: Obtain a real change sample.
[0070] S120: Input the real change sample into the generative model based on the conditional adversarial generative network to obtain a simulated change sample.
[0071] Specifically, step S120 includes the following steps:
[0072] S121: Define a generator and a discriminator of a generative model based on a conditional adversarial generative network.
[0073] S122: Input the real change sample and the change metric into the generator to generate an initial simulated change sample.
[0074] S123: Calculate the data distribution P of the real changed samples and the data distribution Q of the initial simulated changed samples respectively.
[0075] S124: Calculate the maximum mean difference MMD(P, Q) between the data distribution P and the data distribution Q.
[0076] Specifically, in order to measure the difference between the simulated change samples and the real change data, the maximum mean difference (MMD) method is used to evaluate the similarity between the data distribution P and the data distribution Q, thereby improving the quality and authenticity of the simulated change samples.
[0077] S125: Add MMD(P, Q) to the loss functions of the generator and discriminator respectively.
[0078] S126: First update the parameters of the discriminator and minimize the loss function L(D) of the discriminator.
[0079] Specifically, the formula of the loss function L(D) of the discriminator is as follows:
[0080] L(D)=-log(D(x))-log(1-D(G(z)))+λMMD(P,Q);
[0081] Where D represents the discriminator, x represents the real change sample, G represents the generator, z represents the predicted change, G(z) represents the change data generated by the generator, and λ represents the weight parameter of the maximum mean difference MMD(P, Q).
[0082] The discriminator not only needs to correctly distinguish between real data and generated data by minimizing -D(x) and -D(G(z)), but also needs to minimize MMD(P, Q) to make the data distribution Q of the generated simulated change samples closer to the data distribution P of the real change samples.
[0083] S127: Update the parameters of the generator again and minimize the loss function L(G) of the generator.
[0084] Specifically, the formula of the generator's loss function L(G) is as follows:
[0085] L(G)=-log(D(G(z)))+λMMD(P,Q);
[0086] Where D represents the discriminator, G represents the generator, z represents the predicted change, G(z) represents the change data generated by the generator, and λ represents the weight parameter of the maximum mean difference MMD(P, Q).
[0087] The MMD(P, Q) term is added to the generator's loss function L(G). The generator not only needs to minimize -D(G(z)) to make the data of the generated simulated change samples closer to the data of the real change samples, but also needs to minimize MMD(P, Q) to further improve the quality and authenticity of the generated simulated change sample data.
[0088] S128: Repeatedly update the parameters of the discriminator and the generator until the preset training round is reached or the loss function L(D) and the loss function (G) converge, completing the training of the generative model.
[0089] S130: According to the time sequence of the changes, the optimization strategy of the real-time software defect prediction agent constructed based on the flexible action-evaluation algorithm is adjusted through real change samples and simulated change samples to obtain the final software defect prediction agent.
[0090] Specifically, the steps of constructing the real-time software defect prediction agent based on the flexible action-evaluation algorithm in step S130 are as follows:
[0091] S131: Add the causal convolutional neural network CCNN to the policy network.
[0092] Specifically, a causal convolutional neural network (CCNN) is added to the policy network to identify the causal relationship of defect changes.
[0093] S132: Treat the change sample as the environment and the change as the state;
[0094] S133: Defect binary classification prediction is taken as action a;
[0095] S134: The weighted sum of the evaluation indicators accuracy and F1-score is used as the reward function to complete the construction of the real-time software defect prediction agent.
[0096] The step of adjusting the optimization strategy of the real-time software defect prediction agent constructed based on the flexible action-evaluation algorithm by using the real change samples and the simulated change samples in step S130 includes:
[0097] Initialize the real-time software defect prediction agent. The initialization parameters include: policy network parameters θ, Q function network parameters θ q ,CCNN network parametersθ c , target network parameters θ t ,Priority experience replay cacheD.
[0098] S1: Initialization state s.
[0099] S2: Input the real change samples and simulated change samples into the software defect prediction agent in chronological order, use the policy network to select action a, execute action a, observe the new state s′, and obtain the immediate reward r.
[0100] Specifically, the step of inputting the real change samples and the simulated change samples into the software defect prediction intelligent agent in chronological order in step S2, namely: combining the simulated change samples and the real change samples into a new training set, and sorting them in chronological order of the changes; and inputting the sorted training set into the software defect prediction intelligent agent in sequence.
[0101] S3: Add (s, a, r, s′, m) to the experience replay buffer D, where m is a flag indicating whether the software change is defective.
[0102] S4: When the number of samples in the experience replay buffer D reaches the preset number, calculate the target Q value y i =r i +γ*Q target (s′ i ,a′ i );
[0103] In the formula, y i represents the target Q value, γ represents the discount factor, Q target represents the Q target network;
[0104] Update the Q function network parameters θ q, and use the gradient descent method to minimize the loss function L(Q) of the Q function network.
[0105] S5: Update the policy network parameters θ according to the updated Q function network c , and use the gradient ascent method to maximize the objective function J(θ) of the policy network parameters θ.
[0106] S6: Based on θ c Calculate the probability of causality p i =CCNN(s i ,θ c ), update the policy network parameters θ, and use gradient descent to minimize the loss function L(p) based on the flexible action-criteria algorithm.
[0107] S7: Update target network parameters θ t新 =(1-α)*θ t +α*θ and policy network parameters θ c新 =(1-α)*θ c +α*θ; where α represents the regularization coefficient.
[0108] Repeat steps S1-S7 until the number of iterations reaches M, completing the adjustment of the optimization strategy.
[0109] S140: Predict software defects through the trained real-time software defect prediction agent.
[0110] Example 2
[0111] The time-aware real-time software defect prediction method (hereinafter referred to as RCC) provided in Example 1 is verified, and the specific steps are as follows:
[0112] Sort the changes in chronological order according to the submission date, and put all changes submitted in the same month and year into the same group. Use the data of 6 consecutive months as the real change data to construct the real-time software defect prediction agent in Example 1, and optimize the strategy of the real-time software defect prediction agent according to the steps of Example 1 to obtain the final software defect prediction agent. At the same time, a corresponding software defect prediction model is constructed based on Random Forest (RF), and a corresponding software defect prediction model is constructed based on Long Short-Term Memory (LSTM). Input 6 months of data into the corresponding model, take the average of 10 runs as the final result, and the experimental results of the Accuracy index are shown in Table 1 below.
[0113] Table 1 Comparison of Accuracy indicators of RCC method, RF method and LSTM method
[0114] RF LSTM RCC QT 0.791 0.781 0.851 OPENSTACK 0.872 0.882 0.922
[0115] For the QT dataset, the RF method is better than the LSTM method, and the RCC method performs best. For the OPENSTACK dataset, the LSTM method is better than the RF method, and the RCC method also performs best. In order to compare the stability of the Accuracy index of the RCC method with the benchmark method, the maximum value, minimum value, median, upper quartile, and lower quartile are selected in the experimental results of each method in turn, and a box plot is drawn. Figure 2 shown.
[0116] according to Figure 2 As shown in the figure, on the two data sets, the performance of RF and LSTM methods on the Accuracy index is not consistent, but the RCC method is always the best.
[0117] The experimental results of the F1-score indicator of the RCC method, RF method, and LSTM method are shown in Table 2 below.
[0118] Table 2 Comparison of F1-score indicators of RCC method, RF method and LSTM method
[0119] RF LSTM RCC QT 0.623 0.611 0.823 OPENSTACK 0.583 0.683 0.856
[0120] As can be seen from the table above, for the QT dataset, the RF method is better than the LSTM method, and the RCC method performs best. For the OPENSTACK dataset, the LSTM method is better than the RF method, and the RCC method also performs best. In order to compare the stability of the F1-score indicator of the RCC method with that of the benchmark method, the maximum value, minimum value, median, upper quartile, and lower quartile are selected in the experimental results of each method in turn, and a box plot is drawn, as shown in the figure below: Figure 3 shown.
[0121] according to Figure 3 It can be seen that the performance of RF and LSTM methods on the F1-score indicator is not consistent, but the RCC method is always the best.
[0122] In order to evaluate the effectiveness of the data augmentation method, before the RF and LSTM methods are run, the same model as the RCC method is adopted: first use the data augmentation method to generate simulated changes, and then merge the simulated data with the original training set to form a new training set. The average of 10 runs is taken as the final result. The experimental results of the RF and LSTM methods Accuracy and F1-score indicators are shown in Table 3.
[0123] Table 3 Comparison of Accuracy and F1-score indicators between RF and LSTM methods
[0124]
[0125] According to the table above, after the training set data is enhanced, LSTM outperforms the RF method in both Accuracy and F1-score. Since LSTM is a deep learning method based on time series, after the training set is enhanced, the SDP model will learn the features more fully, and LSTM can capture long-term dependencies, so the prediction performance will be better.
[0126] Example 3
[0127] See also Figure 4 This embodiment also provides a time-aware real-time software defect prediction device, including the following modules:
[0128] The first acquisition module is adapted to acquire a real change sample and is used to execute step S110 in the first embodiment.
[0129] The second acquisition module is adapted to input the real change sample into the generative model based on the conditional adversarial generative network to acquire the simulated change sample, and is used to execute step S120 in embodiment 1.
[0130] The training module is adapted to adjust the optimization strategy of the real-time software defect prediction agent constructed based on the flexible action-evaluation algorithm according to the time sequence of the changes through real change samples and simulated change samples to obtain the final software defect prediction agent. It is used to execute step S130 in embodiment 1.
[0131] The prediction module is adapted to perform defect prediction on the software through the trained real-time software defect prediction agent, and is used to execute step S140 in the first embodiment.
[0132] Example 4
[0133] This embodiment provides a computer-readable storage medium, in which at least one instruction is stored. When the instruction is executed by a processor, the time-aware real-time software defect prediction method provided in Embodiment 1 is implemented.
[0134] Through the generative model of the conditional adversarial generative network, simulated software changes are obtained, and in the chronological order of the changes, real change samples and simulated change samples are used. After each time step, the optimization strategy of the real-time software defect prediction agent is adjusted in time through the reward results and current status, thereby solving the concept drift problem.
[0135] Example 5
[0136] See also Figure 5This embodiment provides an electronic device, including: a memory 502 and a processor 501; the memory 502 stores at least one program instruction; the processor 501 loads and executes the at least one program instruction to implement the time-aware real-time software defect prediction method provided in Example 1.
[0137] The memory 502 and the processor 501 are connected in a bus manner, and the bus may include any number of interconnected buses and bridges, and the bus connects various circuits of one or more processors 501 and the memory 502 together. The bus can also connect various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. The data processed by the processor 501 is transmitted on a wireless medium via an antenna, and further, the antenna also receives data and transmits the data to the processor 501.
[0138] The processor 501 is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management and other control functions. The memory 502 can be used to store data used by the processor 501 when performing operations.
[0139] In summary, the present invention provides a time-aware instant software defect prediction method, device and readable storage medium, wherein the time-aware instant software defect prediction method includes: obtaining real change samples; inputting the real change samples into a generative model based on a conditional adversarial generative network to obtain simulated change samples; adjusting the optimization strategy of the instant software defect prediction agent constructed based on the flexible action-evaluation algorithm through real change samples and simulated change samples according to the time sequence of the changes to obtain the final software defect prediction agent; and predicting defects for the software through the trained instant software defect prediction agent. Through the generative model of the conditional adversarial generative network, simulated software changes are obtained, and according to the time sequence of the changes, through real change samples and simulated change samples, after each time step, the optimization strategy of the instant software defect prediction agent is adjusted in time through the reward result and the current state, thereby solving the concept drift problem.
[0140] In addition, without departing from the scope of the present disclosure, the discrete or separate techniques, systems, subsystems, and methods described and illustrated in the various embodiments may be combined or integrated with other systems, modules, techniques, or methods. Other items shown or discussed as coupled may be directly connected, or may be indirectly coupled or communicated electrically, mechanically, or otherwise through some interface, device, or intermediate component. Other examples of changes, substitutions, and alterations may be determined by those skilled in the art without departing from the spirit and scope disclosed herein.
Claims
1. A time-aware real-time software defect prediction method, characterized in that: The following steps are involved: Get a sample of real changes; Input the real change samples into the generative model based on the conditional adversarial generative network to obtain simulated change samples; According to the time sequence of changes, the optimization strategy of the real-time software defect prediction agent built based on the flexible action-evaluation algorithm is adjusted through real change samples and simulated change samples to obtain the final software defect prediction agent; Software defects are predicted through trained real-time software defect prediction agents.
2. The time-aware real-time software defect prediction method according to claim 1, characterized in that: The step of inputting the real change sample into the generative model based on the conditional adversarial generative network to obtain the simulated change sample includes: Define the generator and discriminator of the generative model based on the conditional adversarial generative network; Input the real change samples and change metrics into the generator to generate initial simulated change samples; Calculate the data distribution P of the real change sample and the data distribution Q of the initial simulated change sample respectively; Calculate the maximum mean difference MMD(P,Q) between data distribution P and data distribution Q; Add MMD(P, Q) to the loss functions of the generator and discriminator respectively; First update the parameters of the discriminator and minimize the loss function L(D) of the discriminator; Then update the parameters of the generator and minimize the loss function L(G) of the generator; Repeatedly update the parameters of the discriminator and the generator until the preset training round is reached or the loss function L(D) and the loss function (G) converge, completing the training of the generative model.
3. The time-aware real-time software defect prediction method according to claim 2, characterized in that: The formula of the loss function L(D) of the discriminator is as follows: L(D)=-log(D(x))-log(1-D(G(z)))+λMMD(P,Q); Where D represents the discriminator, x represents the real change sample, G represents the generator, z represents the predicted change, G(z) represents the change data generated by the generator, and λ represents the weight parameter of the maximum mean difference MMD(P, Q).
4. The time-aware real-time software defect prediction method according to claim 2, characterized in that: The formula of the generator's loss function L(G) is as follows: L(G)=-log(D(G(z)))+λMMD(P,Q); Where D represents the discriminator, G represents the generator, z represents the predicted change, G(z) represents the change data generated by the generator, and λ represents the weight parameter of the maximum mean difference MMD(P, Q).
5. The time-aware real-time software defect prediction method according to claim 1, characterized in that: The steps of building an instant software defect prediction agent based on the flexible action-evaluation algorithm are as follows: Add the causal convolutional neural network (CCNN) to the policy network; Treat the change sample as the environment and the change as the state; Take the defect binary classification prediction as action a; The weighted sum of the evaluation indicators accuracy and F1-score is used as the reward function to complete the construction of the real-time software defect prediction agent.
6. The time-aware real-time software defect prediction method according to claim 5, characterized in that: The step of adjusting the optimization strategy of the real-time software defect prediction agent constructed based on the flexible action-evaluation algorithm through the real change samples and the simulated change samples includes: Initialize the real-time software defect prediction agent. The initialization parameters include: policy network parameters θ, Q function network parameters θ q ,CCNN network parameters θ c , target network parameter θ t ,priority experience replay cache D; S1: initialization state s; S2: Input the real change samples and simulated change samples into the software defect prediction agent in chronological order, use the policy network to select action a, execute action a, observe the new state s′, and obtain the immediate reward r; S3: Add (s,a,r,s′,m) to the experience replay buffer D, where m is a flag indicating whether the software change is defective. S4: When the number of samples in the experience replay buffer D reaches the preset number, calculate the target Q value y i =r i +γ*Q target (s′ i ,a′ i ); In the formula, y i represents the target Q value, γ represents the discount factor, Q target represents the Q target network; Update the Q function network parameters θ q , and use the gradient descent method to minimize the loss function L(Q) of the Q function network; S5: Update the policy network parameters θ according to the updated Q function network c , and use the gradient ascent method to maximize the objective function J(θ) of the policy network parameters θ; S6: Based on θ c Calculate the causal probability p i =CCNN(s i ,θ c ), update the policy network parameters θ, and use the gradient descent method to minimize the loss function L(p) based on the flexible action-criteria algorithm; S7: Update target network parameters θ t新 =(1-α)*θ t +α*θ and policy network parameters θ c新 =(1-α)*θ c +α*θ; where α represents the regularization coefficient; Repeat steps S1-S7 until the number of iterations reaches M, completing the adjustment of the optimization strategy.
7. The time-aware real-time software defect prediction method according to claim 6, characterized in that: The step of inputting the real change samples and the simulated change samples into the software defect prediction agent in chronological order is: Combine the simulated change samples and the real change samples into a new training set and sort them according to the chronological order of the changes; The sorted training sets are input into the software defect prediction agent in sequence.
8. An inter-aware real-time software defect prediction device, characterized in that: include: A first acquisition module, adapted to acquire a real change sample; A second acquisition module is adapted to input the real change sample into the generative model based on the conditional adversarial generative network to obtain the simulated change sample; The training module is suitable for adjusting the optimization strategy of the real-time software defect prediction agent built based on the flexible action-evaluation algorithm through real change samples and simulated change samples according to the time sequence of changes, so as to obtain the final software defect prediction agent; The prediction module is suitable for predicting software defects through the trained real-time software defect prediction agent.
9. A computer-readable storage medium, wherein at least one instruction is stored in the computer-readable storage medium, characterized in that: When the instructions are executed by a processor, the time-aware real-time software defect prediction method described in any one of claims 1 to 7 is implemented.
10. An electronic device, characterized in that: It comprises a memory and a processor; the memory stores at least one instruction; the processor implements the time-aware real-time software defect prediction method according to any one of claims 1 to 7 by loading and executing the at least one instruction.
Citation Information
Patent Citations
Software defect prediction method based on generative adversarial network and ensemble learning
CN114064459A
Online cross-project instant defect prediction method and system for mobile application program
CN117112426A
Workload perception instant defect prediction method based on evolution feature construction
CN117743803A