Time-aware instant software defect prediction method, device and readable storage medium
By combining conditional adversarial generative networks and causal convolutional neural networks, simulated change samples are generated and time sequence optimization is performed, which solves the problems of time-aware characteristics and concept drift in real-time software defect prediction, and improves the accuracy and stability of prediction.
Patent Information
- Application Number
- CN202411763203.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2044-12-03
AI Technical Summary
Existing real-time software defect prediction technologies ignore the time-aware nature of software changes, leading to decreased prediction accuracy. Furthermore, changes in software development organizations over time cause models to become outdated, resulting in concept drift problems.
A conditional adversarial generative network is used to generate simulated change samples, and an instantaneous software defect prediction agent is constructed through a causal convolutional neural network. The optimization strategy is adjusted by using real change samples and simulated change samples in chronological order, which solves the problem of data distribution mismatch.
This technology enables real-time software defect prediction, solves the concept drift problem, and improves the prediction accuracy and stability of the model.
Smart Images

Figure CN119862105B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of software defect prediction technology, specifically relating to a time-aware real-time software defect prediction method, apparatus, and readable storage medium. Background Technology
[0002] Traditional Software Defect Prediction (SDP) technology primarily focuses on module-level prediction, i.e., locating potentially defective files, software packages, or subsystems. However, this technology has limitations in effectiveness, failing to pinpoint defects precisely, lacking timely feedback mechanisms, and unable to quickly identify personnel responsible for defect remediation. To address these challenges, researchers have proposed Just-in-Time Software Defect Prediction (JIT-SDP) technology.
[0003] The basic principle of JIT-SDP is to use historical software changes to build an SDP model and predict whether current software changes will have defects. However, this model has two main problems: First, it ignores the time-aware nature of software changes. When building and validating the SDP model, software changes are not ordered chronologically. In actual prediction, future defective change information may be used to predict historical changes, affecting the accuracy of the prediction. Second, software development organizations are constantly evolving. Over time, software developers, technologies, and processes may change. Therefore, the patterns and relationships of software changes also change over time. SDP models built based on historical changes become outdated over time, resulting in concept drift.
[0004] Solving the concept drift problem is key to improving the performance and usability of JIT-SDP.
[0005] It should be noted that the information disclosed in this background section is only for understanding the background technology of the present application concept, and therefore, the above description is not considered to constitute prior art information. Summary of the Invention
[0006] This disclosure provides at least one time-aware real-time software defect prediction method, apparatus, and readable storage medium.
[0007] In a first aspect, embodiments of this disclosure provide a time-aware real-time software defect prediction method, comprising the following steps:
[0008] Obtain real change samples;
[0009] Real change samples are input into a generative model based on a 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 constructed based on the flexible action-evaluation algorithm is adjusted by using real change samples and simulated change samples to obtain the final software defect prediction agent.
[0011] Predict software defects using a trained real-time software defect prediction agent.
[0012] In one optional implementation, the step of training the generative model based on the conditional adversarial generative network in the step of inputting real change samples into the generative model based on the conditional adversarial generative network to obtain simulated change samples includes:
[0013] Define the generator and discriminator for a generative model based on conditional adversarial generative networks;
[0014] Input the real change samples and change metrics into the generator to generate the initial simulated change samples;
[0015] Calculate the data distribution P of the actual 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 distributions P and Q;
[0017] Add MMD(P, Q) to the loss functions of the generator and discriminator, respectively;
[0018] First, update the discriminator's parameters and then minimize the discriminator's loss function L(D);
[0019] Then update the generator's parameters and minimize the generator's loss function L(G);
[0020] The parameters of the discriminator and the generator are repeatedly updated until the preset training rounds are reached or the loss function L(D) and loss function (G) converge, thus completing the training of the generative model.
[0021] In one alternative implementation, the loss function L(D) of the discriminator is formulated as follows:
[0022] L(D)=-log(D(x))-log(1-D(G(z)))+λMMD(P,Q);
[0023] In the formula, D represents the discriminator, x represents the actual 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 one alternative implementation, the loss function L(G) of the generator is formulated as follows:
[0025] L(G)=-log(D(G(z)))+λMMD(P,Q);
[0026] In the formula, 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 one alternative implementation, the steps of constructing an instantaneous software defect prediction agent based on a flexible action-evaluation algorithm are as follows:
[0028] Add a causal convolutional neural network (CCNN) to the policy network;
[0029] Treat the changed sample as the environment, and the change as the state;
[0030] Defect binary classification prediction is taken as action a;
[0031] The reward function is obtained by weighted summation of the evaluation metrics accuracy and F1-score, thus completing the construction of the instant software defect prediction agent.
[0032] In one 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 using real change samples and simulated change samples includes:
[0033] The instantaneous software defect prediction agent is initialized, and 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: Initialize state s;
[0035] S2: Input 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 an immediate reward r;
[0036] S3: Add (s,a,r,s′,m) to the experience replay cache D, where m represents 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, and γ represents the discount factor. target Represents the Q target network;
[0039] Update the network parameters θ of the Q function q And the gradient descent method is used to minimize the loss function L(Q) of the Q-function network;
[0040] S5: Update network parameters θ according to the updated Q-function network update strategy. c And the gradient ascent method is used to maximize the objective function J(θ) of the policy network parameters θ.
[0041] S6: Based on θ c Calculate the probability p of causal relationship 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-evaluation 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 one optional implementation, the step of inputting real change samples and simulated change samples into the software defect prediction agent in chronological order is as follows:
[0045] The simulated change samples and the real change samples are combined into a new training set and sorted according to the time sequence of the changes.
[0046] The sorted training set is then sequentially input into the software defect prediction agent.
[0047] Secondly, embodiments of this disclosure also provide an inter-sensory real-time software defect prediction device, comprising:
[0048] The first acquisition module is suitable for acquiring real change samples;
[0049] The second acquisition module is adapted to input real change samples into a generative model based on a conditional adversarial generative network to obtain simulated change samples;
[0050] The training module is suitable for adjusting the optimization strategy of the real-time software defect prediction agent built on the flexible action-evaluation algorithm according to the time sequence of changes, through real change samples and simulated change samples, to obtain the final software defect prediction agent.
[0051] The prediction module is suitable for predicting software defects using a trained real-time software defect prediction agent.
[0052] Thirdly, embodiments of this disclosure also provide a computer-readable storage medium storing at least one instruction that, when executed by a processor, implements the time-aware real-time software defect prediction method described above.
[0053] Fourthly, embodiments of this disclosure also provide an electronic device, including a memory and a processor; the memory stores at least one instruction; the processor loads and executes the at least one instruction to implement the time-aware real-time software defect prediction method as described above.
[0054] The beneficial effect of this 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 conditional adversarial generative network, and adjust the optimization strategy of the real-time software defect prediction agent in a timely manner after each time step by using real change samples and simulated change samples, based on the reward results and the current state, thereby solving the concept drift problem.
[0055] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.
[0056] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0057] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0058] Figure 1 A flowchart of a time-aware real-time software defect prediction method provided in an embodiment of this disclosure.
[0059] Figure 2 Box plots of the accuracy metrics for the three methods provided in the embodiments of this disclosure.
[0060] Figure 3 Box plots of the F1-score for the three methods provided in the embodiments of this disclosure.
[0061] Figure 4 A schematic diagram of the structure of the time-aware real-time software defect prediction device provided in an embodiment of this disclosure.
[0062] Figure 5 This is a partial structural schematic diagram of the electronic device provided in an embodiment of the present invention. Detailed Implementation
[0063] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0064] To facilitate understanding of this embodiment, a model building method disclosed in this disclosure will first be described in detail. The execution subject of the time-aware real-time software defect prediction method provided in this disclosure is generally a computer device with certain computing capabilities. This computer device may include, for example, a terminal device, a server, or other processing devices. The terminal device may be a user equipment (UE), mobile device, user terminal, terminal, cellular phone, cordless phone, personal digital assistant (PDA), handheld device, computing device, in-vehicle device, wearable device, etc. In some possible implementations, this model building method can be implemented by a processor calling computer-readable instructions stored in memory.
[0065] The following detailed description of some embodiments of the present invention is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0066] Example 1
[0067] Please see Figure 1At least one embodiment provides a time-aware instantaneous software defect prediction method. By using a generative model of a conditional adversarial generative network, simulated software changes are obtained. According to the time sequence of the changes, the optimization strategy of the instantaneous software defect prediction agent is adjusted in a timely manner after each time step by using real change samples and simulated change samples, based on the reward results and the current state, 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 the simulated change sample.
[0071] Specifically, step S120 includes the following steps:
[0072] S121: Define the generator and discriminator for a generative model based on conditional adversarial generative networks.
[0073] S122: Input the real change sample and change metric into the generator to generate the initial simulated change sample.
[0074] S123: Calculate the data distribution P of the actual change sample and the data distribution Q of the initial simulated change sample, respectively.
[0075] S124: Calculate the maximum mean difference MMD(P, Q) between data distributions P and Q.
[0076] Specifically, in order to measure the difference between simulated change samples and real change data, the maximum mean difference (MMD) method is used to evaluate the similarity between data distribution P and data distribution Q, thereby improving the quality and authenticity of 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 then minimize the discriminator's loss function L(D).
[0079] Specifically, the formula for 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] In the formula, D represents the discriminator, x represents the actual 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 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 sample closer to the data distribution P of the real change sample.
[0083] S127: Update the generator's parameters and minimize the generator's loss function L(G).
[0084] Specifically, the formula for the loss function L(G) of the generator is as follows:
[0085] L(G)=-log(D(G(z)))+λMMD(P,Q);
[0086] In the formula, 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 generator's loss function L(G) incorporates the MMD(P,Q) term. The generator not only needs to minimize -D(G(z)) to make the generated simulated change sample data closer to the real change sample data, 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 rounds are reached or the loss function L(D) and loss function (G) converge, thus completing the training of the generative model.
[0089] S130: According to the time sequence of 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 in step S130 for constructing the instantaneous software defect prediction agent based on the flexible action-evaluation algorithm 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 relationships of defect changes.
[0093] S132: Treat the changed sample as the environment and the change as the state;
[0094] S133: Treat the binary classification prediction of defects as action a;
[0095] S134: The weighted sum of the evaluation metrics accuracy and F1-score is used as the reward function to complete the construction of the instant software defect prediction agent.
[0096] The step S130, which involves adjusting the optimization strategy of the real-time software defect prediction agent constructed based on the flexible action-evaluation algorithm using real change samples and simulated change samples, includes:
[0097] The instantaneous software defect prediction agent is initialized, and 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.
[0098] S1: Initialization state s.
[0099] S2: Input 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 an immediate reward r.
[0100] Specifically, step S2, which involves inputting real change samples and simulated change samples into the software defect prediction agent in chronological order, means: combining simulated change samples and real change samples into a new training set and sorting them according to the chronological order of the changes; and then inputting the sorted training set into the software defect prediction agent in sequence.
[0101] S3: Add (s,a,r,s′,m) to the experience replay cache D, where m represents 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, and γ represents the discount factor. target Represents the Q target network;
[0104] Update the network parameters θ of the Q function qAnd the loss function L(Q) of the Q-function network is minimized using the gradient descent method.
[0105] S5: Update network parameters θ according to the updated Q-function network update strategy. c The gradient ascent method is used to maximize the objective function J(θ) of the policy network parameters θ.
[0106] S6: Based on θ c Calculate the probability p of causal relationship 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-evaluation 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 using a 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 was verified, and the specific steps are as follows:
[0112] Changes were sorted chronologically by submission date, and all changes submitted within the same month and year were grouped together. Data from six consecutive months was used as the actual change data to construct the real-time software defect prediction agent in Example 1. The agent was then optimized according to the steps in Example 1, resulting in the final software defect prediction agent. Simultaneously, corresponding software defect prediction models were constructed based on Random Forest (RF) and Long Short-Term Memory (LSTM) networks. The six months of data were input into the corresponding models, and the average of 10 runs was taken as the final result. The experimental results for the accuracy metric are shown in Table 1 below.
[0113] Table 1 Comparison of Accuracy Indices for RCC, RF, and LSTM Methods
[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 outperforms the LSTM method, while the RCC method performs best. For the OPENSTACK dataset, the LSTM method outperforms the RF method, and again, the RCC method performs best. To compare the accuracy of the RCC method with the stability of the benchmark methods, box plots were created by sequentially selecting the maximum, minimum, median, upper quartile, and lower quartile from the experimental results for each method. Figure 2 As shown.
[0116] according to Figure 2 As shown, the RF and LSTM methods do not perform consistently on the accuracy metric on the two datasets, but the RCC method is always the best.
[0117] The experimental results of the F1-score for the RCC method, RF method, and LSTM method are shown in Table 2 below.
[0118] Table 2. Comparison of F1-scores for RCC, RF, and LSTM methods.
[0119] RF LSTM RCC QT 0.623 0.611 0.823 OPENSTACK 0.583 0.683 0.856
[0120] As shown in the table above, for the QT dataset, the RF method outperforms the LSTM method, while the RCC method performs best. For the OPENSTACK dataset, the LSTM method outperforms the RF method, and again, the RCC method performs best. To compare the stability of the RCC method's F1-score with the benchmark methods, box plots were generated by selecting the maximum, minimum, median, upper quartile, and lower quartile from the experimental results for each method, as shown in the table. Figure 3 As shown.
[0121] according to Figure 3 It can be seen that the RF and LSTM methods do not perform consistently on the F1-score, but the RCC method is always the best.
[0122] To evaluate the effectiveness of the data augmentation method, the same approach as the RCC method was used before running the RF and LSTM methods: first, simulated changes were generated using the data augmentation method, and then the simulated data was combined with the original training set to form a new training set. The average of 10 runs was taken as the final result. The experimental results of the accuracy and F1-score of the RF and LSTM methods are shown in Table 3.
[0123] Table 3 Comparison of Accuracy and F1-score for RF and LSTM methods.
[0124]
[0125] The table above shows that after training set augmentation, LSTM outperforms the RF method in both accuracy and F1-score. Since LSTM is a time-series based deep learning method, after training set augmentation, the SDP model learns features more fully, and LSTM can capture long-term dependencies, thus resulting in better prediction performance.
[0126] Example 3
[0127] Please see 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 real change samples. It is used to perform step S110 in Embodiment 1.
[0129] The second acquisition module is adapted to input real change samples into a generative model based on a conditional adversarial generative network to acquire simulated change samples. It is used to execute step S120 in Example 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 changes, using real change samples and simulated change samples, to obtain the final software defect prediction agent. It is used to execute step S130 in Example 1.
[0131] The prediction module is adapted to predict software defects using a trained real-time software defect prediction agent. It is used to perform step S140 in Example 1.
[0132] Example 4
[0133] This embodiment provides a computer-readable storage medium storing at least one instruction that, when executed by a processor, implements the time-aware real-time software defect prediction method provided in Embodiment 1.
[0134] By using a generative model based on a conditional adversarial generative network, simulated software changes are obtained. Following the chronological order of the changes, and using real and simulated change samples, the optimization strategy of the instantaneous software defect prediction agent is adjusted in a timely manner after each time step based on the reward results and the current state, thereby solving the concept drift problem.
[0135] Example 5
[0136] Please see 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 as provided in Embodiment 1.
[0137] The memory 502 and processor 501 are connected via a bus, which may include any number of interconnecting buses and bridges. The bus connects various circuits of one or more processors 501 and memory 502 together. The bus may also connect various other circuits, such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and therefore will not be described further herein. A bus interface provides an interface between the bus and the transceiver. The transceiver may be a single element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices over a transmission medium. Data processed by processor 501 is transmitted over a wireless medium via an antenna, which further receives data and transmits it to processor 501.
[0138] 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. Memory 502 can be used to store data used by processor 501 during operation.
[0139] In summary, this invention provides a time-aware real-time software defect prediction method, apparatus, and readable storage medium. The time-aware real-time software defect prediction method includes: acquiring real change samples; inputting the real change samples into a generative model based on a conditional adversarial generative network to acquire simulated change samples; adjusting the optimization strategy of a real-time software defect prediction agent constructed based on a flexible action-evaluation algorithm according to the time sequence of changes, using the real change samples and simulated change samples, to obtain the final software defect prediction agent; and predicting software defects using the trained real-time software defect prediction agent. By acquiring simulated software changes through the generative model of the conditional adversarial generative network, and adjusting the optimization strategy of the real-time software defect prediction agent in a timely manner after each time step using the reward result and the current state, the method effectively solves the concept drift problem.
[0140] Furthermore, without departing from the scope of this disclosure, the discrete or individual technologies, systems, subsystems, and methods described and illustrated in the various embodiments may be combined or integrated with other systems, modules, technologies, or methods. Other items shown or discussed as coupled may be directly connected or indirectly coupled or communicated via some interface, device, or intermediate component in an electrical, mechanical, or other manner. Those skilled in the art can identify other examples of changes, substitutions, and modifications without departing from the spirit and scope of this disclosure.
Claims
1. A time-aware instant software defect prediction method, characterized in that, The method comprises the following steps: obtaining real change samples; inputting the real change samples into a generative model based on a conditional generative adversarial network to obtain simulated change samples; adjusting an optimization strategy of an intelligent agent for instant software defect prediction based on a flexible action-evaluation algorithm according to a time sequence of the changes by using the real change samples and the simulated change samples to obtain a final intelligent agent for instant software defect prediction; performing defect prediction on software by using the trained intelligent agent for instant software defect prediction; The intelligent agent for instant software defect prediction based on the flexible action-evaluation algorithm comprises the following steps: adding a causal convolutional neural network (CCNN) to a policy network; regarding the change samples as an environment and regarding the changes as states; regarding defect binary classification prediction as an action a; adding a weighted sum of an evaluation index accuracy and an F1-score as a reward function to complete the construction of the intelligent agent for instant software defect prediction; The step of adjusting the optimization strategy of the intelligent agent for instant software defect prediction based on the flexible action-evaluation algorithm comprises: Initialize the instant software defect prediction agent, the initialized parameters include: policy network parameters theta, Q function network parameters theta q , CCNN network parameters theta c , target network parameters theta t , priority experience replay buffer D; S1: initializing a state s; S2: inputting the real change samples and the simulated change samples into the intelligent agent for software defect prediction according to a time sequence, selecting an action a by using a policy network, executing the action a, observing a new state s', and obtaining an instant reward r; S3: adding (s, a, r, s', m) to an experience replay buffer D, wherein m represents a label indicating whether the software change has a defect; S4: when the number of samples in the experience replay buffer D reaches a preset number, calculate the target Q value y i = r i + γ * Q target ( s′ i , a′ i ); wherein y i denotes the target Q-value , γ denotes a discount factor, Q target denotes the Q-target network; updating the Q-function network parameters θ q and minimizing the loss function L(Q) of the Q-function network using a gradient descent method; S5: updating the CCNN network parameters θ according to the updated Q function network c and maximizing the objective function J(θ) of the strategy network parameters θ using the gradient ascent method. S6: update the policy network parameters θ according to θ = θ - α ∇L(θ) c Computing causal probabilities p i = CCNN(s i , θ c ) , update the policy network parameters θ, and minimize the loss function L(p) based on the flexible action-evaluation algorithm using gradient descent method; S7: update the target network parameter θ t新 = (1 - α) * θ t +α* θ and the CCNN network parameter θ c新 = (1 -α) * θ c +α* θ; wherein, α represents a regularization coefficient; repeating steps S1-S7 until the number of iterations reaches M to complete the adjustment of the optimization strategy.
2. The time-aware instant software defect prediction method according to claim 1, wherein the training step of the generative model based on the conditional generative adversarial network in the step of inputting the real change samples into the generative model based on the conditional generative adversarial network to obtain the simulated change samples comprises: defining a generator and a discriminator of the generative model based on the conditional generative adversarial network; inputting the real change samples and change metric elements into the generator to generate initial simulated change samples; calculating a data distribution P of the real change samples and a data distribution Q of the initial simulated change samples, respectively; calculating a maximum mean discrepancy MMD(P, Q) between the data distribution P and the data distribution Q; adding the MMD(P, Q) to loss functions of the generator and the discriminator, respectively; updating parameters of the discriminator first and minimizing the loss function L(D) of the discriminator; updating parameters of the generator second and minimizing the loss function L(G) of the generator; repeating the updating of the parameters of the discriminator and the parameters of the generator until a preset training round is reached or the loss function L(D) and the loss function L(G) converge, and completing the training of the generative model.
3. The time-aware instant software defect prediction method according to claim 2, wherein a formula of the loss function L(D) of the discriminator is as follows: ; In the formula, 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 instant software defect prediction method of claim 2, wherein, The loss function L(G) of the generator is as follows: ; In the formula, 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 instant software defect prediction method of claim 4, wherein, The step of inputting the real change sample and the simulated change sample to the software defect prediction agent in chronological order is: combining the simulated change sample and the real change sample into a new training set and sorting them in chronological order of changes; inputting the sorted training set into the software defect prediction agent in turn.
6. A time-aware instant software defect prediction apparatus for implementing the time-aware instant software defect prediction method of claim 1, wherein, It comprises: a first acquisition module adapted to acquire real change samples; a second acquisition module adapted to input the real change samples into a generative model based on a conditional generative adversarial network to obtain simulated change samples; a training module adapted to adjust the optimization strategy of an instant software defect prediction agent based on a flexible action-evaluation algorithm by using real change samples and simulated change samples in chronological order of changes to obtain a final software defect prediction agent; a prediction module adapted to predict software defects by using the trained instant software defect prediction agent.
7. A computer-readable storage medium having stored therein at least one instruction, wherein The instructions are executed by the processor to implement the time-aware instant software defect prediction method of any one of claims 1-5.
8. An electronic device, comprising: It comprises a memory and a processor; the memory stores at least one instruction; the processor loads and executes the at least one instruction to implement the time-aware instant software defect prediction method of any one of claims 1-5. It comprises a memory and a processor; the memory stores at least one instruction; the processor loads and executes the at least one instruction to implement the time-aware instant software defect prediction method of any one of claims 1-5.