Battery capacity prediction method and system based on LSTM and attention mechanism
By introducing a battery capacity prediction method with LSTM and attention mechanism in battery capacity prediction, the problem of low battery life prediction accuracy in the prior art is solved, and a more accurate and robust battery capacity prediction is achieved.
Patent Information
- Application Number
- CN202510222668.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-27
- Publication Date
- 2025-04-29
AI Technical Summary
In the prior art, in battery life prediction, it is difficult to accurately capture the time dependence in battery discharge capacity data, resulting in low prediction accuracy.
Using a battery capacity prediction method based on LSTM and attention mechanism, a long and short-term memory neural network model is constructed to introduce attention mechanisms, the weights of each time step are dynamically calculated, and context vectors are generated, thereby improving prediction accuracy.
The prediction accuracy of battery discharge capacity is improved, the robustness of the model is enhanced, the stable prediction performance can be maintained under different usage conditions, and the modeling process is simplified through automatic feature extraction.
Smart Images

Figure CN119902088A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of battery health prediction, and in particular to a battery capacity prediction method and system based on LSTM and attention mechanism. Background Art
[0002] With the rapid development of electric vehicles and renewable energy systems, the performance and life of batteries, as the core components of these systems, have received widespread attention. Traditional battery life estimation methods usually rely on simple statistical models and empirical formulas, mainly based on the relationship between discharge capacity and cycle number. These methods often fail to provide accurate predictions when faced with complex battery performance changes.
[0003] The battery life prediction technology based on the model method is relatively mature. However, since the circuit parameter estimation results are affected by factors such as temperature and SOC, the parameter estimation accuracy is not high, resulting in low capacity prediction accuracy based on this type of method.
[0004] In recent years, the development of deep learning technology has provided new possibilities for battery performance prediction. In particular, the long short-term memory network (LSTM) has been widely used in various prediction tasks due to its advantages in processing time series data. However, although the LSTM model can process long sequence data, it still has certain shortcomings in dealing with the importance of the impact of different time steps on the output. The introduction of the attention mechanism can help the model better focus on important time points, thereby improving the prediction performance. Summary of the invention
[0005] The present invention proposes a battery capacity prediction method and system based on LSTM and attention mechanism to solve the deficiencies in the above-mentioned prior art and improve the prediction accuracy of battery discharge capacity.
[0006] On the one hand, to achieve the above object, the present invention provides a battery capacity prediction method based on LSTM and attention mechanism, comprising:
[0007] Obtaining capacity attenuation data of the battery to be tested;
[0008] Build a battery capacity prediction model;
[0009] Inputting the capacity decay curve of the battery to be tested into the battery capacity prediction model for prediction to obtain a prediction result;
[0010] Among them, the battery capacity prediction model is a long short-term memory neural network that introduces an attention mechanism.
[0011] Preferably, constructing the battery capacity prediction model includes:
[0012] Reading battery capacity decay data, and normalizing the battery capacity decay data to process the battery capacity decay data into a predetermined range, wherein the battery capacity decay data is time series data;
[0013] Generate sequence data based on the normalized data, and divide the sequence data into a training set and a test set, wherein the sequence data includes an input sequence and an output sequence, and each sequence in the sequence data has a specific length;
[0014] Construct a deep neural network model containing several LSTM layers, apply an attention mechanism on the output sequence of the LSTM layers, dynamically calculate the weight of each time step, and generate a context vector;
[0015] Combining the context vector with the hidden state of the current time step, and outputting the battery capacity prediction value through a fully connected layer;
[0016] The mean square error is used as the loss function, and the model parameters are optimized through the back propagation algorithm to obtain the battery capacity prediction model.
[0017] Preferably, the battery capacity attenuation data is data of several charge and discharge processes obtained from a battery test cycle, and the dimensions of the input sequence and the output sequence are (N, 1), where N≥10.
[0018] Preferably, applying an attention mechanism on the output sequence of the LSTM layer comprises:
[0019] Calculate the correlation score of each time step in the input sequence with the current time step;
[0020] Normalize the relevance scores into weights using the Softmax function, ensuring that the sum of all weights is 1;
[0021] The LSTM output sequence is weighted summed based on the weights to generate the context vector.
[0022] Preferably, the LSTM layer includes:
[0023] Forget gate: used to control the abandonment or retention of information in the memory unit;
[0024] Input gate: used to update the information of the memory unit;
[0025] Output gate: used to read the updated neural network state and output the memory unit;
[0026] Among them, the output of the forget gate is:
[0027] f t =sigmoid(W if .xt +b if +W hf .h t-1 +b hf );
[0028] In the formula, f t is the output of the forget gate, W if , W hf are parameter matrices, x t is the input data, b if , b hf are all bias terms, sigmoid is the activation function, h t-1 is the hidden state at the previous moment.
[0029] Preferably, the indicators for evaluating the battery capacity prediction model include the goodness of fit R 2 , specifically:
[0030]
[0031] In the formula, y i ,y i ′ are the actual value and the machine learning predicted value, is the mean value of all samples, and n is the sample size.
[0032] On the other hand, to achieve the above purpose, the present invention also provides a battery capacity prediction system based on LSTM and attention mechanism, including:
[0033] Data acquisition unit: used to obtain capacity decay data of the battery to be tested;
[0034] Model building unit: used to build a battery capacity prediction model;
[0035] A processing prediction unit: used for inputting the capacity decay curve of the battery to be detected into the battery capacity prediction model for prediction to obtain a prediction result; wherein the battery capacity prediction model is a long short-term memory neural network with an added attention mechanism;
[0036] The user interaction unit is used to support users in adjusting model parameters and input data range, and provide real-time feedback on prediction results.
[0037] Preferably, the model building unit comprises:
[0038] Data input module, used to collect battery discharge capacity data in real time and perform preprocessing;
[0039] A sequence generation module, used to divide the normalized data into input sequences and output sequences according to a preset length;
[0040] A deep learning model generation module, comprising a plurality of LSTM layers and an attention mechanism layer, for predicting the battery capacity based on the input sequence;
[0041] The visualization output module is used to display the comparison curve between the predicted results and the actual values, and provide an error analysis report.
[0042] Preferably, the visualization output module displays the battery capacity decay curve and prediction results through dynamic charts, and marks the attention weight distribution of key time steps.
[0043] Preferably, the user interaction unit supports adjusting the number of neurons, number of iterations and sliding window length of the LSTM layer through a graphical interface, and updates the model training results in real time.
[0044] Compared with the prior art, the present invention has the following advantages and technical effects:
[0045] (1) By combining the long short-term memory network (LSTM) and the attention mechanism, the present invention can more accurately capture the time dependency in the battery discharge capacity data, thereby improving the accuracy of battery life prediction. At the same time, the attention mechanism enables the model to dynamically adjust its focus on key time steps, maintain stable prediction performance under different usage conditions, and enhance the robustness of the model;
[0046] (2) The present invention achieves automatic feature extraction through deep learning, reduces the reliance on a large amount of prior data, simplifies the modeling process, and improves the training speed. This method is not only applicable to battery management of electric vehicles, but can also be extended to portable devices and renewable energy systems to provide accurate assessment for battery health monitoring. The present invention has significant advantages in the accuracy, robustness and application range of battery life prediction. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0048] Figure 1 is a capacity decay curve of a lithium-ion battery under constant power according to an embodiment of the present invention;
[0049] Figure 2 A schematic diagram of a prediction result of a capacity decay curve of a lithium-ion battery according to an embodiment of the present invention;
[0050] Figure 3 This is a flow chart of a battery capacity prediction method based on LSTM and attention mechanism according to an embodiment of the present invention. DETAILED DESCRIPTION
[0051] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0052] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0053] The present invention proposes a battery capacity prediction method based on LSTM and attention mechanism, such as Figure 3 ,include:
[0054] Obtaining capacity attenuation data of the battery to be tested;
[0055] Build a battery capacity prediction model;
[0056] Inputting the capacity decay curve of the battery to be tested into the battery capacity prediction model for prediction to obtain a prediction result;
[0057] Among them, the battery capacity prediction model is a long short-term memory neural network that introduces the attention mechanism.
[0058] The attention mechanism in this embodiment enables the model to dynamically adjust its focus on key time steps, maintain stable prediction performance under different usage conditions, and enhance the robustness of the model. In addition, automatic feature extraction is achieved through deep learning, which reduces the reliance on a large amount of prior data, simplifies the modeling process, and improves the training speed.
[0059] Furthermore, building a battery capacity prediction model includes:
[0060] Reading battery capacity attenuation data, and normalizing the battery capacity attenuation data to process the battery capacity attenuation data into a predetermined range, wherein the battery capacity attenuation data is time series data;
[0061] Generate sequence data based on the normalized data, and divide the sequence data into a training set and a test set, wherein the sequence data includes an input sequence and an output sequence, and each sequence in the sequence data has a specific length;
[0062] Build a deep neural network model with several LSTM layers, apply the attention mechanism on the output sequence of the LSTM layer, dynamically calculate the weight of each time step, and generate a context vector;
[0063] Combine the context vector with the hidden state of the current time step and output the battery capacity prediction value through the fully connected layer;
[0064] The mean square error is used as the loss function, the model parameters are optimized through the back propagation algorithm, and the generalization ability of the model is evaluated based on the training set and the test set to obtain the battery capacity prediction model.
[0065] Furthermore, the battery capacity attenuation data is the data of several charge and discharge processes obtained from the battery test cycle. The battery capacity sequence is processed by normalization technology to reduce data deviation and improve the model convergence speed, specifically:
[0066]
[0067] Where x′ is the normalized value, x is the original data value, min(X) is the minimum value in the data set, and max(X) is the maximum value in the data set.
[0068] Specifically, a serialization method is used to generate input sequences and output sequences, so that the model can learn the dynamic characteristics of the battery discharge process. In this embodiment, the length of the input sequence and the output sequence are both 10, and the dimension is (10, 1).
[0069] Furthermore, by constructing a deep network consisting of multiple LSTM units, it is possible to capture the long-term and short-term dependencies in the battery discharge capacity data. The LSTM layer includes:
[0070] The Forget Gate is used to control whether information in a memory unit is discarded (forgotten) or retained.
[0071] Assume input data x t If the number of features is p, then dim = (p, 1), the dimension of h(t-1) is dim = (q, 1), and the parameter matrix W if The dimension is dim=(p,q), and the bias is b if :dim=(q,1),W hf :dim=(q,q), bias b hf :dim=(q,1).
[0072] The final output f t for:
[0073] f t =sigmoid(W if .x t +b if +W hf .h t-1 +b hf );
[0074] In the formula, f t is the output of the forget gate, W if , W hf are parameter matrices, xt is the input data, b if , b hf are all bias terms, sigmoid is the activation function, h t-1 is the hidden state at the previous moment.
[0075] The input gate determines the information to update the memory cell, including the Sigmoid and Tanh parts, both of which contain the current input x t With the previous hidden state h t-1 The parameters of the Sigmoid part are W ii , b ii , W hi , b hi , dim are (q,p), (q,1), (q,q), (q,1) respectively; the parameter W of the Tanh part ig , b ig , W hg , b hg , dim are (q,p), (q,1), (q,q), (q,1) respectively.
[0076] Get the two outputs i of the input gate t , g t Then, the f obtained by the forget gate t With the state c at the previous moment t-1 By calculating, we can get the updated state c t , specifically:
[0077] i t =sigmoid(W ii .x t +b ii +W hi .h t-1 +b hi );
[0078] g t =tanh(W ig .x t +b ig +W hg .h t-1 +b hg );
[0079] c t =f t *c t-1 +i*g t .
[0080] The function of the output gate is to read the neural network state that has just been updated and output the memory unit. The specific information that can be output is controlled by the output gate.
[0081] The parameters of the output layer are W io 、h io , W ho , b ho . Through the output we get o t , and finally by o t With c t Get the output h at this moment t , and can also be passed on to the next neuron, specifically:
[0082] o t =sigmoid(W io .x t +b io +W ho .h t-1 +b ho );
[0083] h t =o t *tanhc t .
[0084] Specifically, by building a deep network consisting of multiple LSTM units, it is possible to capture the long-term and short-term dependencies in the battery discharge capacity data. This structure enables the model to better understand the changes in battery performance during different charge and discharge cycles.
[0085] Furthermore, applying the attention mechanism on the output sequence of the LSTM layer includes:
[0086] Calculate the correlation score between each time step in the input sequence and the current time step. Use the fully connected layer to map the hidden state of the current time step (Query) and the hidden state of all time steps (Key) to the same space, and then calculate the score through vector projection. The calculation formula is as follows:
[0087] s t =v T *tanh(W q q+W k *k t + b);
[0088] Among them, q(Query) represents the target information that needs to be paid attention to at present (such as the hidden state of the decoder at the current time step), k t (Key) represents the feature of the tth time step in the input sequence (such as the encoder hidden state), W q ,W kare the query projection matrix and the key projection matrix, respectively, which map the query vector and the key vector to the latent space. b is the bias term, which adjusts the fused feature distribution. v T (·) Compress the latent space vector into a scalar score, reflecting the matching degree between the query and the key. q , W k , b, and v are all trainable parameters for machine learning.
[0089] Scores t It reflects the importance relationship between time steps. Next, the scores are normalized into weights using the Softmax function, ensuring that the sum of all weights is 1, making it probabilistic.
[0090] Based on the calculated weights, a context vector is generated, which takes into account the information of all time steps, but emphasizes the time step that is most relevant to the current prediction. Finally, this context vector is combined with the hidden state of the current time step to obtain the final output.
[0091] In this way, the model can dynamically adjust the level of attention paid to important information in the input sequence, thereby significantly improving the predictive ability of battery discharge capacity time series data.
[0092] This embodiment adds an attention mechanism based on the LSTM model to improve the model's attention to key time steps. By weighting the LSTM outputs of different time steps, the model can dynamically adjust its response to important information in the input sequence, significantly enhancing the model's expressiveness.
[0093] Furthermore, the indicators for evaluating the battery capacity prediction model in this embodiment include the goodness of fit R 2 , specifically:
[0094]
[0095] In the formula, y i ,y i ′ are the actual value and the machine learning predicted value, is the mean value of all samples, and n is the sample size.
[0096] This embodiment also provides a battery capacity prediction system based on LSTM and attention mechanism, including:
[0097] Data acquisition unit: used to obtain capacity decay data of the battery to be tested;
[0098] Model building unit: used to build a battery capacity prediction model;
[0099] A processing prediction unit: used for inputting the capacity decay curve of the battery to be detected into the battery capacity prediction model for prediction to obtain a prediction result; wherein the battery capacity prediction model is a long short-term memory neural network with an added attention mechanism;
[0100] The user interaction unit is used to support users in adjusting model parameters and input data range, and provide real-time feedback on prediction results.
[0101] Furthermore, the model building unit includes:
[0102] Data input module, used to collect battery discharge capacity data in real time and perform preprocessing;
[0103] A sequence generation module, used to divide the normalized data into input sequences and output sequences according to a preset length;
[0104] A deep learning model generation module, comprising a plurality of LSTM layers and an attention mechanism layer, for predicting the battery capacity based on the input sequence;
[0105] The visualization output module is used to display the comparison curve between the predicted results and the actual values, and provide an error analysis report.
[0106] Furthermore, the visualization output module displays the battery capacity decay curve and prediction results through dynamic charts, and marks the attention weight distribution of key time steps.
[0107] The user interaction unit supports adjusting the number of neurons, number of iterations, and sliding window length of the LSTM layer through a graphical interface, and updates the model training results in real time.
[0108] In order to more clearly express the technical solution of the present invention, the following specific embodiments are provided to introduce the solution:
[0109] Taking NCM811 lithium-ion battery as the research object, the capacity decay curve (such as Figure 1 );
[0110] The battery capacity sequence is processed by normalization technology, and the input sequence and output sequence are generated by serialization method, so that the model can learn the dynamic characteristics of the battery discharge process;
[0111] A long short-term memory neural network (LSTM) was constructed, with the number of hidden layers set to 32, 16 neurons in each hidden layer, 1000 iterations, and 10 sliding windows to predict the life of sodium-ion batteries.
[0112] Add attention mechanism to improve the model's focus on key time steps.
[0113] Model training and evaluation. In this embodiment, 40% of the data is selected as the training set, and the rest is used as the test set for error evaluation. The error evaluation indicator selected is the goodness of fit R 2 , the calculation formula is:
[0114]
[0115] In the formula, y i ,y i ′ are the actual value and the machine learning predicted value respectively.
[0116] from Figure 2 It can be seen that the LSTM plus attention mechanism method adopted in this embodiment can achieve accurate prediction of the life of sodium ion batteries, and the calculated goodness of fit R 2 Greater than 97%.
[0117] The above are only preferred specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A battery capacity prediction method based on LSTM and attention mechanism, characterized in that: include: Obtaining capacity attenuation data of the battery to be tested; Build a battery capacity prediction model; Inputting the capacity decay curve of the battery to be tested into the battery capacity prediction model for prediction to obtain a prediction result; Among them, the battery capacity prediction model is a long short-term memory neural network that introduces an attention mechanism.
2. The battery capacity prediction method based on LSTM and attention mechanism according to claim 1, characterized in that: Constructing the battery capacity prediction model includes: Reading battery capacity attenuation data, and normalizing the battery capacity attenuation data to process the battery capacity attenuation data into a predetermined range, wherein the battery capacity attenuation data is time series data; Generate sequence data based on the normalized data, and divide the sequence data into a training set and a test set, wherein the sequence data includes an input sequence and an output sequence, and each sequence in the sequence data has a specific length; Construct a deep neural network model containing several LSTM layers, apply an attention mechanism on the output sequence of the LSTM layers, dynamically calculate the weight of each time step, and generate a context vector; Combining the context vector with the hidden state of the current time step, and outputting the battery capacity prediction value through a fully connected layer; The mean square error is used as the loss function, and the model parameters are optimized through the back propagation algorithm to obtain the battery capacity prediction model.
3. The battery capacity prediction method based on LSTM and attention mechanism according to claim 2, characterized in that: The battery capacity attenuation data is data of several charge and discharge processes obtained from a battery test cycle, and the dimensions of the input sequence and the output sequence are (N, 1), where N≥10.
4. The battery capacity prediction method based on LSTM and attention mechanism according to claim 2, characterized in that: Applying the attention mechanism on the output sequence of the LSTM layer includes: Calculate the correlation score of each time step in the input sequence with the current time step; Normalize the relevance scores into weights using the Softmax function, ensuring that the sum of all weights is 1; The LSTM output sequence is weighted summed based on the weights to generate the context vector.
5. The battery capacity prediction method based on LSTM and attention mechanism according to claim 2, characterized in that: The LSTM layer includes: Forget gate: used to control the abandonment or retention of information in the memory unit; Input gate: used to update the information of the memory unit; Output gate: used to read the updated neural network state and output the memory unit; Among them, the output of the forget gate is: f t =sigmoid(W if .x t +b if +W hf .h t-1 +b hf ); In the formula, f t is the output of the forget gate, W if , W hf are parameter matrices, x t is the input data, b if , b hf are all bias terms, sigmoid is the activation function, h t-1 is the hidden state at the previous moment.
6. The battery capacity prediction method based on LSTM and attention mechanism according to claim 4, characterized in that: The indicators for evaluating the battery capacity prediction model include goodness of fit R 2 , specifically: In the formula, y i ,y i ′ are the actual value and the machine learning predicted value, is the mean value of all samples, and n is the sample size.
7. The battery capacity prediction system based on LSTM and attention mechanism is characterized by: include: Data acquisition unit: used to obtain capacity decay data of the battery to be tested; Model building unit: used to build a battery capacity prediction model; A processing prediction unit: used for inputting the capacity decay curve of the battery to be detected into the battery capacity prediction model for prediction to obtain a prediction result; wherein the battery capacity prediction model is a long short-term memory neural network with an added attention mechanism; The user interaction unit is used to support users in adjusting model parameters and input data range, and provide real-time feedback on prediction results.
8. The battery capacity prediction system based on LSTM and attention mechanism according to claim 7, characterized in that: The model building unit comprises: Data input module, used to collect battery discharge capacity data in real time and perform preprocessing; A sequence generation module, used to divide the normalized data into input sequences and output sequences according to a preset length; A deep learning model generation module, comprising a plurality of LSTM layers and an attention mechanism layer, for predicting the battery capacity based on the input sequence; The visualization output module is used to display the comparison curve between the predicted results and the actual values, and provide an error analysis report.
9. The battery capacity prediction system based on LSTM and attention mechanism according to claim 8, characterized in that: The visualization output module displays the battery capacity decay curve and prediction results through dynamic charts, and marks the attention weight distribution of key time steps.
10. The battery capacity prediction system based on LSTM and attention mechanism according to claim 7, characterized in that: The user interaction unit supports adjusting the number of neurons, number of iterations and sliding window length of the LSTM layer through a graphical interface, and updates the model training results in real time.