Weighted loss function updating method based on reward and punishment mechanism and action strategy

Through the weighted cross-entropy loss function update method based on reward and punishment mechanism and action strategy, the weighted cross-entropy loss function weight in neural network training is dynamically adjusted, which solves the performance degradation and local optimal solution caused by improper weight setting in the existing technology. problem, improving the adaptability and generalization ability of the model.

CN118114148BActive Publication Date: 2024-09-13GUANGDONG UNIV OF TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410280289.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-12
Publication Date
2024-09-13
Estimated Expiration
2044-03-12

AI Technical Summary

Technical Problem

When the existing weighted cross-entropy loss function is used in problems where class imbalance and misclassification costs are different, improper setting of weights will lead to reduced or invalid classification performance, and the weights are fixed before training and cannot be dynamically adjusted, and it is easy to fall into the local optimal solution. .

Method used

A weighted cross-entropy loss function update method based on reward and punishment mechanism and action strategy is adopted. Through the design of action pool, action cumulative reward pool and action probability pool, the weight of the weighted cross-entropy loss function is dynamically adjusted, and the weight is updated in real time according to the training effect of the model. value to avoid local optimal solutions.

Benefits of technology

It realizes the dynamic adjustment of the class weight of the loss function during the training process, improves the applicability and generalization ability of the model, can better adapt to complex classification problems, and avoids performance degradation and local optimal solutions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118114148B
    Figure CN118114148B
Patent Text Reader

Abstract

The present invention discloses a weighted loss function updating method based on a reward and punishment mechanism and an action strategy. The present invention comprises the following steps: defining a weighted cross entropy loss function and a common cross entropy loss function; initializing an action pool, an action cumulative reward pool, and an action probability pool; designing a reward and punishment mechanism and an action selection strategy; adjusting the weight of the weighted cross entropy loss function to realize the dynamic update of the weighted cross entropy loss function in neural network training. The present invention can dynamically update the weight of the weighted cross entropy loss function according to the training results of each cycle of the neural network model, in combination with the reward and punishment mechanism and the action selection strategy, perform back propagation, flexibly update the weights of different categories, adjust the sensitivity of the model to misclassification of different categories, and can help the model better adapt to the characteristics of the data set, thereby improving the generalization ability and performance of the model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of deep learning technology, and specifically relates to a weighted loss function updating method based on a reward and punishment mechanism and an action strategy. Background Art

[0002] The cross entropy loss function, as an indicator for measuring the difference between two probability distributions, is usually used to measure the difference between the predicted distribution of the model and the true distribution. It is an important topic in the field of machine learning and deep learning. In deep learning, the cross entropy loss function is often used for training neural networks. By minimizing the cross entropy loss, the output of the neural network can be made closer to the true label distribution, thereby improving the classification performance of the model. Compared with other loss functions, the cross entropy loss function has many incomparable advantages, such as sensitivity to probability distribution, good mathematical properties in gradient calculation methods, no gradient vanishing problem in the back propagation process, and wide application. However, with the rapid commercialization of deep learning, the cross entropy loss function has shortcomings in analyzing unbalanced categories. For example, when trying to detect and identify an abnormal fault with only a 1% occurrence rate, an accurate recognition rate cannot be achieved. Since specific classification scenarios have specific requirements, there are unavoidable problems such as category imbalance and different misclassification costs in classification scenarios.

[0003] At present, the mainstream method to solve problems such as class imbalance and different misclassification costs is the weighted cross entropy loss function, which assigns different weights to different categories or samples when calculating the loss. Compared with the ordinary cross entropy loss function, the weighted cross entropy loss function can make the model pay more attention to the minority category, thereby improving the performance of the model on the minority category. By adjusting the weights, the loss can be more finely controlled according to the importance of the category, which can help the model better adapt to the distribution characteristics of the data set, thereby improving the generalization ability and performance of the model. However, the ordinary weighted cross entropy loss function method still has the following problems: First, the weight setting method of the weighted cross entropy loss function depends on the specific problem and requirements. If the setting is not good, the classification performance will be greatly reduced or invalid. General weight setting methods such as manual setting, based on category frequency, based on misclassification cost, and based on model output probability are not the optimal weight setting methods, and it is difficult to meet complex classification problems. Second, the weights of the weighted cross entropy loss function are set before the neural network training and cannot be changed. In practical applications, it is usually necessary to adjust the weights of the weighted cross entropy loss function according to the performance of the model during the training process to achieve the best performance and effect. 3. Ordinary dynamic weight adjustment methods all make fine adjustments based on the preset weight direction and make adaptive adjustments based on the network training effect, which can easily fall into the local optimal solution. Summary of the invention

[0004] The purpose of the present invention is to overcome the problems existing in the prior art and provide a weighted loss function updating method based on a reward and punishment mechanism and an action strategy. Specifically, it is a weighted cross entropy loss function updating method based on a reward and punishment mechanism and an action selection strategy that is dynamically updated according to the performance of the model and can meet complex classification problems.

[0005] The invention defines a weighted cross entropy loss function and a common cross entropy loss function, initializes an action pool, an action cumulative reward pool, and an action probability pool, and then designs a reward and punishment mechanism and an action selection strategy. Based on the reward and punishment mechanism and the action selection strategy, the weight of the weighted cross entropy loss function is adjusted to realize the dynamic update of the weighted cross entropy loss function in neural network training.

[0006] The specific technical solution of the present invention is achieved through the following steps:

[0007] Step 1: Define the weighted cross entropy loss function and the ordinary cross entropy loss function;

[0008] The weighted cross entropy loss function Jw is defined as the objective function of the optimization algorithm, which is used for back propagation during training and is also the objective function for dynamically adjusting weights in this method. The ordinary cross entropy loss function J is defined only to measure the model fitting effect, and the loss value of the model is used as a measurement indicator.

[0009] The weighted cross entropy loss function is defined as follows:

[0010]

[0011] Where M is the number of training examples, w is the class weight, and y m is the target label of training example m, x m is the input of training example m, h θ is the model of the neural network weights θ.

[0012] The general cross entropy loss function is defined as follows:

[0013]

[0014] Where M is the number of training examples, y m is the target label of training example m, x m is the input of training example m, h θ is the model of the neural network weights θ.

[0015] Step 2: Initialize the action pool, action cumulative reward pool, and action probability pool;

[0016] Design the action pool M: define the direction of change of the weighted cross entropy loss function class weight w, including decreasing, keeping stable or increasing.

[0017] The design and initialization methods are as follows:

[0018] M=[M 1 ,M 2 ,M 3 ,M 4 ,M 5 ]=[w decreases when it is large, w decreases when it is small, w remains unchanged, w increases when it is small, w increases when it is large]

[0019] =[-1, -0.1, +0, +0.1, +1]

[0020] Design action cumulative reward pool R Ms : Record the current cumulative reward value of each action. The design and initialization method are as follows:

[0021] R Ms =[R 1 ,R 2 ,…,R i ,…,R n ];

[0022] Among them, R Ms The initial value of R = 0, i It's action M i The cumulative reward value.

[0023] Design action probability pool P ro : Determine the probability of each action being selected. The design and initialization method are as follows:

[0024] P ro =[p 1 ,p 2 ,…,p i ,…,p n ]

[0025] Among them, p i It's action M i The probability of being selected, ∑p i =1.

[0026] Step 3: Train the model: Train the neural network model and record the training effect of the model. The specific training method is as follows:

[0027] (3-1) Input data into the neural network model to start training;

[0028] (3-2) Perform forward propagation and use the ordinary cross entropy loss function J in step 1 to calculate the average verification loss value, and at the same time calculate the precision Precision and recall Recall to obtain the average F1 score F1Score.

[0029] (3-3) Use the weighted cross entropy loss function J in step 1w Backpropagation as the objective function of the optimization algorithm;

[0030] (3-4) Repeat the above steps (3-1)-(3-3) for multiple trainings, with min_epoch training times as one training cycle;

[0031] (3-5) Calculate the average validation loss and average F1 score for a training cycle;

[0032] The above is a process of training a neural network model. The current weighted cross entropy loss function Jw is obtained as the objective function of the optimization algorithm for back propagation training effect indicators. The neural network model of this method uses the Adam optimizer to update the network model parameters.

[0033] Step 4: Design reward and punishment mechanism and action selection strategy;

[0034] According to the average F1 score and average verification loss value of each round of training of the neural network model, the double reward value R is calculated based on the reward mechanism, and the action cumulative reward pool and action probability pool are updated based on the action selection strategy according to the double reward value R.

[0035] The specific implementation of the reward and punishment mechanism is as follows:

[0036] The method to calculate precision is as follows:

[0037] Among them, TP is the number of true positives and FP is the number of false positives. The precision ranges from 0 to 1, and the higher the value, the more accurate the model is in predicting the positive class.

[0038] The method to calculate recall is as follows:

[0039] Among them, FN is the number of false negative examples. The recall rate also ranges from 0 to 1. The higher the value, the stronger the model's ability to identify positive categories.

[0040] The method to calculate the average F1 score is as follows:

[0041] The average F1 score is the harmonic mean of precision and recall, which takes into account the performance of both. The average F1 score ranges from 0 to 1. The higher the value, the better the balance between precision and recall.

[0042] Get reward R based on the average F1 score F1 =NextF1Score-CurF1Score;

[0043] Among them, NextF1core is the average F1 score of the current training cycle, CurF1Score is the average F1 score of the previous training cycle, and the reward R F1 The value range is -1 to 1.

[0044] Based on the average validation loss value of the common cross entropy loss function J, the reward R is calculated Los =(sigmoid(CurJ-NextJ)-0.5)*2;

[0045] Among them, CurJ represents the average validation loss value of the previous training cycle, and NextJ represents the average validation loss value of the current training cycle. The difference between the average validation loss values ​​is normalized using the sigmoid activation function: Reward R Los The value range is -1 to 1.

[0046] Calculate the dual reward R based on the average F1 score and the average validation loss value: R = w 1 *R F1 +w 2 *R Los ;

[0047] Among them, w 1 and w 2 They are the proportions of the two rewards and punishments, and their initial values ​​are both set to 0.5.

[0048] The network training effect is judged by a dual reward based on the average F1 score and the average validation loss value, making the evaluation criteria more comprehensive.

[0049] The specific method of action selection strategy is as follows:

[0050] Update the cumulative reward pool R of the action in step 2 Ms :The cumulative rewards of other actions remain unchanged, and the current training cycle corresponds to action M i The cumulative reward of the action plus the reward and punishment value of this round, that is, the double reward R of the reward and punishment mechanism, is obtained to obtain the updated action cumulative reward pool R' Ms =[R 1 ,…,R i +R,…,R n ].

[0051] In particular, in order to prevent a certain action from having a particularly large cumulative reward, which causes the action to be drawn all the time, the cumulative reward R' of the action after the update i Make judgment and process: If R' i >Sum(R' Ms )-R' i , then R′ i =Sum(R′ Ms)-R′ i ;

[0052] Based on the updated cumulative reward pool R' in step 2 Ms , use the Softmax distribution function to update the probability of the action, according to the cumulative reward R' of each action i The influence of the action probability pool P' is used to update its frequency distribution and obtain the new action probability pool P' ro .

[0053]

[0054] p′ ro =[p′ 1 ,p′ 2 ,…,p′ n ]

[0055] Among them, p' i is the updated action M i The probability of R' i It's action M i The cumulative reward of , β is the parameter that controls the distribution and is used to adjust the impact of rewards and punishments on probability.

[0056] The Softmax distribution function is defined as follows: for k=1,2,…,K;

[0057] Among them, softmax(z) k Represents the kth element of the output vector of the softmax function, e is a natural constant, the denominator is the sum of the exponential functions of all input values, and the numerator is the exponential function of the corresponding input value.

[0058] The above are the specific methods of reward and punishment mechanism and action selection strategy.

[0059] The reward R based on the average validation loss Los The sigmoid activation function is used in the calculation process to normalize the difference in the average verification loss value so that its value range is between -1 and 1. A reward greater than 0 is a positive reward, and a reward less than 0 is a negative reward. F1 The value range of the two reward signals is the same, which improves comparability and consistency and simplifies the processing logic of the double reward R.

[0060] The Softmax distribution function is used to update the probability of the action in updating the action probability, converting the original score into a probability distribution, where the probability value of each category is between 0 and 1, and the sum of the probabilities of all categories is 1, making the probability distribution of the action smoother. In addition, the influence of rewards and punishments on the probability can be adjusted by setting the parameter β of the control distribution.

[0061] Step 5: Adjust the class weights of the weighted cross entropy loss function;

[0062] Based on the updated action probability pool P' ro The probability of randomly selecting the action M of the next training cycle i , adjust the class weights of the weighted cross entropy loss function w = w + M i , to achieve dynamic update of weighted cross entropy loss function in neural network training.

[0063] After adjusting the class weight w of the weighted cross entropy loss function, return to step 3 to start the next cycle of model training according to the updated weighted cross entropy loss function, calculate the average verification loss value and average F1 score of the new cycle, calculate the double reward value of the corresponding action, and continue to update the class weight w of the weighted cross entropy loss function. Dynamically update the class weight w of the weighted cross entropy loss function according to the training results of each cycle of the neural network model, perform back propagation, update the weights of different categories in real time, and adjust the model's sensitivity to misclassification of different categories, which can help the model better adapt to the characteristics of the data set, thereby improving the generalization ability and performance of the model.

[0064] Compared with the prior art, the present invention has the following advantages and beneficial effects:

[0065] 1. Compared with the static setting method in traditional methods that may cause performance degradation or failure, the present invention can adjust the class weights in real time according to the model performance by dynamically adjusting the class weights of the loss function during the training process to achieve the best classification performance and effect, thereby improving the applicability and practicality of the weighted cross entropy loss function.

[0066] 2. Compared with the static and fixed weight setting method in traditional methods, the present invention allows dynamic adjustment of the class weights of the weighted cross entropy loss function during the neural network training process. This flexibility can better cope with the changing situations in practical applications and improve the adaptability and generalization ability of the model.

[0067] 3. Compared with the traditional method of fine-tuning according to the preset weight direction and adaptive adjustment according to the network training effect, the class weight update method is based on the reward and punishment mechanism and action selection strategy. The weight update direction is selected according to the probability of the action pool. Any update action has the possibility of being selected at any time, but the probability is different. It is not easy to fall into the local optimal solution. The update method is more flexible and exploratory. BRIEF DESCRIPTION OF THE DRAWINGS

[0068] Figure 1 It is a flow chart of a weighted cross entropy loss function updating method based on a reward and punishment mechanism and an action selection strategy proposed by the present invention.

[0069] Figure 2Schematic diagram of the GRU neural network structure in the embodiment. DETAILED DESCRIPTION

[0070] The present invention is further described in detail below in conjunction with embodiments and drawings, but the embodiments of the present invention are not limited thereto.

[0071] Example

[0072] like Figure 1 As shown in FIG. 1 , the weighted loss function updating method based on the reward and punishment mechanism and the action strategy includes the following steps:

[0073] Step 1: Define the weighted cross entropy loss function and the ordinary cross entropy loss function;

[0074] The database used in this embodiment is the PTB Diagnostic ECG Database. The database contains 549 12-lead ECG information of 294 subjects. After preprocessing the data according to the task requirements, this embodiment segmented and extracted 39,571 12-lead heartbeat segment sequences, of which 32,529 were labeled Myocardial infarction (recorded as Class A), accounting for 82.2%, and 7,042 were labeled Healthy controls (recorded as Class B), accounting for 17.8%. The present invention sets the ratio of training set to test set to 4:1.

[0075] The goal of this embodiment is to identify and classify 12-lead ECG signals, and the GRU neural network model is used as the classification model. This embodiment uses the deep learning framework PyTorch in Python to build the GRU neural network model. The schematic diagram of the GRU neural network structure is shown in the figure. Figure 2 As shown, the specific implementation method is as follows:

[0076] (1) Define the GRU model class;

[0077] Create a class that inherits from 'torch.nn.Module' and define the structure of the GRU model in it.

[0078] (2) instantiate the model;

[0079] The GRU model is instantiated according to the required parameters. For example, in this embodiment, the input size is set to 12, the hidden layer size is set to 128, the number of GRU layers is set to 2, and the number of classifications is set to 2.

[0080] (3) Define the loss function and optimizer;

[0081] Use the "torch.nn.CrossEntropyLoss()" function to define the normal cross entropy loss function, and use the "torch.nn.CrossEntropyLoss(weight=class_weights)" function to define the weighted cross entropy loss function, where the class weights are initialized to [4+w,1]. , initialized according to the ratio of the number of samples in class A to class B, and w is the weight change value.

[0082] Step 2: Initialize the action pool, action cumulative reward pool, and action probability pool;

[0083] This embodiment defines an action pool M:

[0084] M=[M 1 ,M 2 ,M 3 ,M 4 ,M 5 ]=[w decreases when it is large, w decreases when it is small, w remains unchanged, w increases when it is small, w increases when it is large]

[0085] =[-1, -0.1, +0, +0.1, +1]

[0086] This embodiment defines the action cumulative reward pool R Ms :

[0087] R Ms =[R 1 ,R 2 ,R 3 ,R 4 ,R 5 ] = [0,0,0,0,0]; (initial value = 0)

[0088] Assume that the action probability pool P is defined in this embodiment ro :

[0089] P ro =[p 1 ,p 2 ,p 3 ,p 4 ,p 5 ]=[0.2,0.2,0.2,0.2,0.2](∑p i =1)

[0090] In this embodiment, the weight action of the first round of training is set to w unchanged.

[0091] Step 3: Training model;

[0092] This embodiment trains the neural network model and records the training effect of the model. The specific training method is as follows:

[0093] (1) Input data into the neural network model to start training;

[0094] In this embodiment, 12-lead ECG data, i.e., a 12-dimensional time series signal sequence, is input into the network model for training using a data loader, and the batch_size of the number of samples transmitted in a single time is set to 32.

[0095] (2) Perform forward propagation and use the common cross entropy loss function J in step 1 to calculate the average verification loss value, calculate the precision Precision and recall Recall, and thus obtain the average F1 score F1Score;

[0096] In this embodiment, the network is first initialized, and then the network is put into the GPU for training. The learning rate of the optimizer is set using the cosine annealing method, and the learning rate is gradually reduced during the training process to improve the training performance. The model training process includes two modules, training and verification. Both the training and verification modules require forward propagation. In the verification module, the ordinary cross entropy loss function J in step 1 is used to calculate the average verification loss value, and the verification precision Precision and recall Recall are calculated to obtain the average F1 score F1Score.

[0097] (3) The weighted cross entropy loss function J in step 1 is also used w Backpropagation as the objective function of the optimization algorithm;

[0098] In the training module, the weighted cross entropy loss function J in step 1 is used. w Backpropagation is performed as the objective function of the optimization algorithm, while the verification module does not need to perform backpropagation.

[0099] (4) The neural network model of this method uses the Adam optimizer to update the network model parameters;

[0100] This embodiment uses the "torch.optim.Adam" function as the optimizer of the neural network model to optimize and update the parameters of the network model.

[0101] (5) Repeat the above steps for multiple trainings, with training min_epoch times as one training cycle;

[0102] This embodiment is only a simple experiment, the total number of training times is set to 100, and min_epoch=5 is set as the number of times of a training cycle.

[0103] (6) Calculate the average validation loss and F1 score for a training cycle;

[0104] After one training cycle in this embodiment, the recorded validation loss value and F1 score are averaged to obtain the average validation loss value and average F1 score of one training cycle, which are subsequently used to update the weights of the weighted cross entropy loss function.

[0105] The above is a process of training a neural network model, and the training effect of the original weighted cross entropy loss function is obtained.

[0106] Step 4: Design reward and punishment mechanism and action selection strategy;

[0107] like Figure 2 As shown, the specific method of the reward and punishment mechanism of this embodiment is as follows:

[0108] The method to calculate precision is as follows:

[0109] Among them, TP is the number of true positives and FP is the number of false positives. The precision ranges from 0 to 1, and the higher the value, the more accurate the model is in predicting the positive class.

[0110] The method to calculate recall is as follows:

[0111] Among them, FN is the number of false negative examples. The recall rate also ranges from 0 to 1. The higher the value, the stronger the model's ability to identify positive categories.

[0112] Then the method to calculate the F1 score is as follows:

[0113] Among them, the F1 score is the harmonic mean of precision and recall, which takes into account the performance of both. The F1 score ranges from 0 to 1. The higher the value, the better the balance between precision and recall.

[0114] Finally, the reward R is obtained based on the average F1 score in step 3. F1 =NextF1Score-CurF1Score;

[0115] Among them, NextF1Score is the average F1 score of the current training cycle, CurF1Score is the average F1 score of the previous training cycle, and the reward R F1 The value range is -1 to 1.

[0116] (1) Based on the average verification loss value J in step 3, calculate the reward R Los =(sigmoid(CurJ-NextJ)-0.5)*2;

[0117] Among them, the sigmoid activation function is used to normalize the loss value difference: Reward R Los The value range is -1 to 1.

[0118] (2) Calculate the dual reward R based on the F1 score and the loss value: R = w 1 *R F1 +w 2 *R Los

[0119] Among them, w 1 and w 2 They are the proportions of the two rewards and punishments, and their initial values ​​are both set to 0.5.

[0120] The specific method of the action selection strategy in this embodiment is as follows: Update the action cumulative reward pool R in step 2 Ms :The cumulative rewards of other actions remain unchanged, and the current training cycle corresponds to action M i The cumulative reward of the action plus the reward and punishment value of this round, that is, the double reward R of the reward and punishment mechanism, is obtained to obtain the updated action cumulative reward pool R' Ms =[R 1 ,…,R i +R,…,R n ].

[0121] In particular, in order to prevent a certain action from having a particularly large cumulative reward, which causes the action to be drawn all the time, the cumulative reward R' of the action after the update i Make judgment and process: If R' i >Sum(R' Ms )-R' i , then R′ i =Sum(R′ Ms )-R′ i ;

[0122] Based on the updated cumulative reward pool R' in step 2 Ms , use the Softmax distribution function to update the probability of the action, according to the cumulative reward R' of each action i The influence of the action probability pool P' is used to update its frequency distribution and obtain the new action probability pool P' ro .

[0123]

[0124] P′ ro =[p′ 1 ,p′ 2 ,…,p′ n ]

[0125] Among them, p' i is the updated action M i The probability of R' i It's action Mi The cumulative reward of , β is the parameter that controls the distribution and is used to adjust the impact of rewards and punishments on probability.

[0126] The Softmax distribution function is defined as follows: for k=1,2,…,K;

[0127] Among them, softmax(z) k Represents the kth element of the output vector of the softmax function, e is a natural constant, the denominator is the sum of the exponential functions of all input values, and the numerator is the exponential function of the corresponding input value.

[0128] In this embodiment, the reward R based on the loss value Los The sigmoid activation function is used in the calculation process to normalize the loss value difference so that its value range is between -1 and 1. A value greater than 0 is a positive reward, and a value less than 0 is a negative reward. F1 The value range of the two reward signals is the same, which improves comparability and consistency and simplifies the processing logic of the double reward R.

[0129] This embodiment uses the Softmax distribution function to update the probability of the action in updating the action probability, converting the original score into a probability distribution, where the probability value of each category is between 0 and 1, and the sum of the probabilities of all categories is 1, making the probability distribution of the action smoother. In addition, the influence of rewards and punishments on the probability can be adjusted by setting the parameter β of the control distribution.

[0130] Step 5: Adjust the weights of the weighted cross entropy loss function;

[0131] Based on the updated action probability pool P' ro The probability of randomly selecting the action M of the next training cycle i , adjust the class weights of the weighted cross entropy loss function w = w + M i , to achieve dynamic update of weighted cross entropy loss function in neural network training.

[0132] In this example, the class weights of the weighted cross entropy loss function "torch.nn.CrossEntropyLoss(weight=class_weights)" defined in step 1 are updated from [4+w,1] to [4+w+M i ,1].

[0133] After adjusting the weights of the weighted cross entropy loss function, return to step 3 to start model training for the next cycle according to the updated weighted cross entropy loss function, calculate the average verification loss value and F1 score of the new cycle, calculate the reward value of the corresponding action, and continue to update the weights of the weighted cross entropy loss function.

[0134] The weight update method in this embodiment is based on the reward and punishment mechanism and the action selection strategy. The weight update direction is selected according to the probability of the action pool. Any update action has the possibility of being selected at any time, but the probability is different. It is not easy to fall into the local optimal solution. The update method is more flexible and more exploratory. In addition, the action type of the action pool of the present invention, the proportion of the two rewards and punishments, and the parameters controlling the softmax distribution can be set according to the specific task, and the versatility is wider.

[0135] Dynamically updating the weights of the weighted cross entropy loss function according to the training results of each cycle of the neural network model, performing back propagation, updating the weights of different categories in real time, and adjusting the model's sensitivity to misclassification of different categories can help the model better adapt to the characteristics of the data set, thereby improving the model's generalization ability and performance.

[0136] In this embodiment, the stopping condition of the network model training is one of the following two conditions:

[0137] (1) The total number of training times reaches the preset target, which is set to 100 in this embodiment;

[0138] (2) When the model performance does not improve over several consecutive epochs (number of training rounds), stop training to achieve early stopping;

[0139] End the training and use the model parameters with the best performance on the validation set as the final model parameters.

[0140] In this embodiment, a 12-lead ECG signal recognition and classification task is performed. Compared with the traditional method, as shown in Table 1, when processing the unbalanced class sample data of Class A and Class B, the method of the present invention obviously achieves better recognition and classification effects, with a classification accuracy rate of up to 90.34%, which improves the adaptability and generalization ability of the model to adapt to changes in problems and needs.

[0141] Table 1 Classification results of category A and category B

[0142]

[0143] The above embodiments are preferred implementation modes of the present invention, but the implementation modes of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present invention should be equivalent replacement methods and are included in the protection scope of the present invention.

Claims

1. A weighted loss function updating method based on reward and punishment mechanism and action strategy, characterized in that: After preprocessing the data according to the task requirements, the 12-lead heartbeat segment sequence is segmented and extracted, and the preprocessed extracted data is divided into a training set and a test set; the goal of this method is to identify and classify the 12-lead ECG signal, using the GRU neural network model as the classification model, and using the deep learning framework PyTorch in Python to build the GRU neural network model; it includes the following steps: Step 1: Define the weighted cross entropy loss function and the ordinary cross entropy loss function; Define the weighted cross entropy loss function J w As the objective function of the optimization algorithm, back propagation is performed during training to dynamically adjust the objective function of the class weights; the ordinary cross entropy loss function J is defined only to measure the model fitting effect, and the loss value of the model is calculated as a measurement indicator; Step 2: Initialize the action pool, action cumulative reward pool, and action probability pool; Design action pool M: define the direction of change of weight w of weighted cross entropy loss function; Design action cumulative reward pool P Ms : Record the current cumulative reward value of each action; Design action probability pool P ro : Determine the probability of each action being selected; Step 3: Training model; Train the neural network model. Use the ordinary cross entropy loss function to calculate the loss value and F1 score for forward propagation. Use the loss value of the weighted cross entropy loss function for back propagation. Repeat the training min_epoch times as a cycle, and calculate the average validation loss value and average F1 score of the cycle. Step 4: Design reward and punishment mechanism and action selection strategy; According to the average F1 score and average verification loss value of each round of training of the neural network model, the double reward value R is calculated based on the reward mechanism, and the action cumulative reward pool and action probability pool are updated based on the action selection strategy according to the double reward value R; Step 5: Adjust the class weights of the weighted cross entropy loss function; The action of the next training cycle is randomly extracted based on the probability of the updated action probability pool, and the class weight of the weighted cross entropy loss function is adjusted to realize the dynamic update of the weighted cross entropy loss function in neural network training; Step 2 is implemented as follows: The design and initialization of the action pool M are implemented as follows: M=[M1,M2,M3,M4,M5]=[w decreases when it is large, w decreases when it is small, w remains unchanged, w increases when it is small, w increases when it is large] =[-1、-0.1、+0、+0.1、+1] The design and initialization of the action cumulative reward pool R Ms As follows: R Ms =[R1, R2, ..., R i , …, R n ]; Among them, R Ms The initial value of R = 0, £ It's action M i The cumulative reward value of The design and initialization of the action probability pool P ro :P ro =[p1, p2, …, p i ,…,p n ]; Among them, p i It's action M i The probability of being selected, ∑p i =1; The action selection strategy described in step 4 is as follows: 4-1. Update the action cumulative reward pool R Ms :The cumulative rewards of other actions remain unchanged, and the current training cycle corresponds to action M i The cumulative reward of the action plus the reward and punishment value of this round, that is, the double reward R of the reward and punishment mechanism, is obtained to obtain the updated action cumulative reward pool R′ Ms =[R1,…,R £ +R,…,R n ]; the cumulative reward R′ for the action after update i Make judgment and process: If R′ i >Sum(R′ Ms )-R′ i , then R′ i =Sum(R′ Ms )-R′ i ; 4-2. Based on the updated cumulative reward pool R′ Ms , use the softmax distribution function to update the probability of the action, according to the cumulative reward R′ of each action i The influence of the action probability pool P′ is used to update its frequency distribution and obtain the new action probability pool P′. ro ; P′ ro =[p′1,p′2,…,p′ n ] Among them, p′ i is the updated action M i The probability of i It's action M i The cumulative reward of , β is the parameter that controls the distribution and is used to adjust the impact of rewards and punishments on probability.

2. The weighted loss function updating method based on reward and punishment mechanism and action strategy according to claim 1 is characterized in that: In step 1, the weighted cross entropy loss function is defined as: Where M is the number of training examples, w is the class weight, and y m is the target label of training example m, x m is the input of training example m, h θ is the model of the neural network weights θ; In step 1, the common cross entropy loss function is defined as: Where M is the number of training examples, y m is the target label of training example m, x m is the input of the training sample m, hθ is the model of the neural network weight θ; the ordinary cross entropy loss function J is only used to measure the model fitting effect, and the average validation loss value of the model is used as a measurement indicator.

3. The weighted loss function updating method based on reward and punishment mechanism and action strategy according to claim 1 is characterized in that: In step three, the method of training the model is as follows: (3-1) Input data into the neural network model to start training; (3-2) Perform forward propagation and use the ordinary cross entropy loss function J in step 1 to calculate the average verification loss value, and at the same time calculate the precision Precision and recall Recall to obtain the average F1 score F1Score; (3-3) Use the weighted cross entropy loss function J in step 1 w Backpropagation as the objective function of the optimization algorithm; (3-4) Repeat the above steps (3-1)-(3-3) for multiple trainings, with min_epoch training times as one training cycle; (3-5) Calculate the average validation loss value and average F1 score for one training cycle.

4. The weighted loss function updating method based on reward and punishment mechanism and action strategy according to claim 1 is characterized in that: The reward and punishment mechanism described in step 4 is as follows: (4-1) Calculate F1 score Among them, the F1 score is the harmonic mean of precision Precision and recall Recall, and the value range of the F1 score is also 0 to 1; (4-2) Reward R based on F1 score F1 =NextF1Score-CurF1Score; Among them, NextF1Score is the average F1 score of the current training cycle, CurF1Score is the average F1 score of the previous training cycle, and the reward R F1 The value range is -1 to 1; (4-3) Use the ordinary cross entropy loss function to calculate the average validation loss value of each training cycle, and then calculate the reward R based on the average validation loss value Los =(sigmoid(CurJ-NextJ)-0.5)*2; Among them, the sigmoid activation function is used to normalize the difference in the average verification loss value, and the reward R Los The value range is -1 to 1; (4-4) Calculate the dual reward R = W1*R based on the average F1 score and loss value F1 +W2*R Los ; Among them, w1 and w2 are the proportions of the two rewards and punishments, and their initial values ​​are both set to 0.

5.

5. The weighted loss function updating method based on reward and punishment mechanism and action strategy according to claim 1 is characterized in that: In step 5, the class weights of the weighted cross entropy loss function are adjusted as follows: Based on the updated action probability pool P' ro The probability of randomly selecting the action M of the next training cycle i , adjust the class weights of the weighted cross entropy loss function w = w + M i , to achieve dynamic update of weighted cross entropy loss function in neural network training.

6. The weighted loss function updating method based on reward and punishment mechanism and action strategy according to claim 1 is characterized in that: In step 5, after adjusting the class weights of the weighted cross entropy loss function, return to step 3 to start model training for the next cycle according to the updated weighted cross entropy loss function, calculate the average verification loss value and F1 score of the new cycle, calculate the reward value of the corresponding action, and continue to update the weights of the weighted cross entropy loss function.

Citation Information

Patent Citations

  • Zero-sample image classification model based on repeated attention network and method thereof

    CN110826638A

  • Weather image intelligent identification method and system based on multi-depth convolutional neural network fusion

    CN111476713A

  • Air refueling machine control strategy method based on deep reinforcement learning

    CN116661493A

  • Training reinforcement learning agents to learn expert exploration behaviors from demonstrators

    US20210397959A1