Method for predicting residual SOC (State of Charge) of rechargeable battery of electric vehicle based on improved Samat swarm algorithm
By improving the Sandmao Group algorithm, the CNN-LSTM hybrid neural network is optimized, combined with differential evolution strategy and self-attention mechanism, the accuracy and speed problems of residual SOC prediction of electric vehicle rechargeable batteries are solved, and efficient and accurate SOC prediction is achieved to adapt to dynamic changes in charging load.
Patent Information
- Application Number
- CN202510305407.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-14
- Publication Date
- 2025-07-01
AI Technical Summary
The existing residual SOC prediction method for electric vehicle rechargeable batteries has limited prediction accuracy when facing complex and changing actual situations, and the optimization algorithm is prone to falling into local optimal solutions in parameter settings, resulting in poor generalization capabilities.
The improved Sandmacao group optimization algorithm is used to optimize the CNN-LSTM hybrid neural network, combined with the differential evolution random to optimal type 1 variant strategy, a residual SOC prediction model for electric vehicle rechargeable batteries is constructed, feature correlation is enhanced through the self-attention mechanism, and model parameters are optimized to improve prediction accuracy and speed.
It realizes more accurate and faster residual SOC prediction of electric vehicle rechargeable batteries, can timely adapt to dynamic changes in charging load, improves the timeliness of prediction and model interpretability, and enhances the accuracy and generalization ability of prediction.
Smart Images

Figure CN120233233A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of clean energy load forecasting, and particularly relates to a method for predicting the remaining SOC of an electric vehicle charging battery based on an improved sand cat swarm algorithm. Background Art
[0002] In today's society, with the rapid development of new energy technology, electric vehicles are increasingly widely used. Accurately predicting the remaining amount of SOC of an electric vehicle battery is of crucial significance for vehicle owners' reasonable itinerary planning and battery management.
[0003] Traditional methods for predicting the remaining SOC of a charging battery, such as statistical methods, often rely on a large amount of historical data and relatively strict assumptions. In the face of complex and changing actual situations, the prediction accuracy is limited. For example, although the linear regression model is simple and easy to use, it cannot effectively capture the non-linear characteristics in the charging data.
[0004] In recent years, deep learning-based models, such as convolutional neural networks (CNNs) and long short-term memory networks (LSTMs), have been applied to the prediction of the remaining SOC of electric vehicle charging batteries with good compatibility due to their advantages in processing complex data and time series. CNNs can automatically extract spatial features from data, while LSTMs are good at dealing with long-term dependencies in time series. However, in practical applications, the parameter settings of the CNN-LSTM model are relatively complex, and different parameter combinations will have a significant impact on the prediction performance. If the parameters are not selected properly, the model is likely to fall into a local optimal solution, resulting in problems such as low prediction accuracy and poor generalization ability.
[0005] Intelligent optimization algorithms have good global search capabilities, but unadapted optimization algorithms also have deficiencies such as slow convergence speed and easy premature convergence in practical applications. Therefore, how to select an optimization algorithm suitable for predicting the remaining SOC of an electric vehicle charging battery and improve it so that it can more effectively optimize the parameters of the CNN-LSTM model, thereby improving the prediction accuracy, has become the focus of current research. Summary of the Invention
[0006] Object of the Invention: To solve the problems mentioned in the background art, the present invention provides a method for predicting the remaining SOC of an electric vehicle charging battery based on an improved sand cat swarm algorithm. By combining the advantages of CNN in processing spatial data and the advantages of LSTM in processing long time series data and data with long-term dependencies, the differential evolution random to optimal type 1 strategy is used to improve the sand cat swarm optimization algorithm to optimize and establish a prediction model for the remaining SOC of an electric vehicle charging battery, and obtain more accurate and faster prediction results.
[0007] Technical Solution:
[0008] The present invention discloses a method for predicting the remaining SOC of an electric vehicle charging battery based on an improved sand cat swarm algorithm, and the method includes the following steps:
[0009] S1 Collect the historical charging data of the electric vehicle, and perform null value filling and normalization preprocessing on the data;
[0010] S2 Construct a feature matrix based on the factors affecting the remaining SOC of the battery after charging: current, charging power, charging efficiency, time, and battery rated capacity, as the input of the remaining SOC prediction model of the charging battery;
[0011] S3 Build a remaining SOC prediction model of the charging battery based on a CNN-LSTM hybrid neural network;
[0012] S4 Use the sand cat swarm optimization algorithm improved by the differential evolution stochastic to optimal type-1 mutation strategy to optimize the prediction model;
[0013] S5 Input the feature matrix into the optimized prediction model to predict the remaining SOC of the charging battery.
[0014] Furthermore, the method for null value filling in S1 is as follows:
[0015]
[0016] where y k is the filled data at the missing moment; y k-1 is the SOC value at the same weekly date moment in the previous week; y k+1 is the SOC value at the same weekly date and the same moment in the next week;
[0017] Perform normalization processing on the current, charging power, charging efficiency, and battery rated capacity, and the normalization formula is:
[0018]
[0019] where: x is the sample data before normalization; x one is the value after normalization; x max and x min are the maximum and minimum values in the sample data before normalization, respectively.
[0020] Furthermore, the steps for constructing the feature matrix of the remaining SOC prediction model of the charging battery in S2 are as follows:
[0021] Obtain the input-output relationship of the model:
[0022]
[0023] where I (k-m)×1 , Q (k-m)×1 , η (k-m)×1,T (k-m)×1 ,C (k-m)×1 The input feature vector X represents current, charging power, charging efficiency, time, and battery rated capacity respectively; The model output Y is the remaining SOC of the battery after charging; k is the current sample point time, k + 1 is the time to be predicted; k - m is m + 1 times before the time to be predicted, including the k time;
[0024] The input feature matrix X of the model is:
[0025] X = [I (k+m)×1 ,Q (k+m)×1 ,η (k+m)×1 ,T (k+m)×1 ,C (k+m)×1
[0026] In the formula, I (m+1)×1 ,Q (m+1)×1 ,η (k+m)×1 ,T (k+m)×1 ,C (k+m)×1 are the column vectors of voltage, current, and charging power respectively.
[0027] In the formula, I (m+1)×1 ,Q (m+1)×1 ,η (k+m)×1 ,T (k+m)×1 ,C (k+m)×1 are the column vectors of current, charging power, charging efficiency, time, and battery rated capacity respectively. Among them, The function f calculation formula of
[0028]
[0029] Under the condition of the same charging efficiency, combining the above formula, its formula is as follows:
[0030]
[0031] Furthermore, the steps for building the remaining SOC prediction model of the charging battery based on the CNN-LSTM hybrid neural network in S3 are as follows:
[0032] S301 Data processing: Turn off the alarm, clear the workspace and the figure window, read the Excel data, calculate the total number of samples, divide the training set and the test set in a ratio of 5:1, extract and normalize the input features and output labels, and organize them into an input format suitable for the neural network;
[0033] S302 Network construction: Define the input layer, perform convolutional operations through the sequence folding layer, and sequentially add a convolutional layer with 16 filters and a stride of 1, a batch normalization layer, a ReLU activation layer, a max pooling layer with a pooling window of 2×2 and a stride of 2. After passing through the sequence unfolding layer and the smoothing layer, connect to an LSTM layer with the output being the last time step, a self-attention layer with a single head, 2 keys, and query channels, a Dropout layer with a dropout rate of 0.1, a fully connected layer with an output dimension of 1, and a regression layer;
[0034] S303 Training settings: Use the Adam optimizer for training;
[0035] S304 Training and prediction: Train the model and record the time, use the trained model for prediction, and denormalize the prediction results and convert them into a suitable data format.
[0036] Furthermore, the specific steps for optimizing the remaining SOC prediction model of rechargeable batteries using the improved sand cat swarm optimization algorithm described in S4 are as follows:
[0037] S401 Initialize the differential evolution strategy
[0038] Randomly generate the initial population where N is the population size, and each individual is a D-dimensional vector;
[0039] S402 For each individual (the current generation is t), generate a new mutant individual V i t+1 , randomly select three different individuals and and the current best individual Calculate the mutant vector:
[0040]
[0041] where F is the scaling factor, and its value is between (0, 2);
[0042] S403 Generate the trial vector For each dimension j (j = 1, 2,..., D), with a certain probability CR, decide whether to select a value from the mutant vector V i t+1 or the current individual :
[0043]
[0044] where j0 is a randomly selected dimension to ensure that at least one dimension comes from the mutant vector;
[0045] S404 Use the trial vector Compare with the current individual Select the individual with better fitness to enter the next generation. If then otherwise
[0046] The calculation process of the improved sand cat swarm optimization algorithm in S405 is as follows. After the calculation, the optimal fitness value and the best position are output:
[0047] R = 2×r G ×rand(0,1) - r G
[0048]
[0049] P(t + 1) = P b (t) - r·P rnd ·cos(θ)
[0050] r = r G ×rand(0,1)
[0051] P rnd = |rand(0,1)·P bc (t) - P c (t)|
[0052] P c (t + 1) = r·(P bc (t) - rand(0,1)·P c (t))
[0053] In the formula, R is the guiding parameter that controls the conversion between search and attack, rand(0,1) is a random number uniformly distributed within (0,1), r G is the conventional sensitivity range, S M is the auditory characteristic of the sand cat, t is the current iteration number of the population, T is the maximum iteration number of the population, θ is a random angle of the moving direction of the sand cat in the attack stage, r is the sensitivity range of each individual in the population, P rnd is the distance, P bc (t) is the global optimal solution, P c (t) is the current position, P c (t + 1) is the position of the population after update.
[0054] Furthermore, based on the improved sand cat swarm algorithm, the hyperparameters of the prediction model are optimized:
[0055] Input layer setting: Use a sequence folding layer to perform independent convolutional operations on the time steps of the image sequence. Add a convolutional layer with 16 filters, a stride of 1, and a first pooling layer with a pooling window of size 2x1 and a stride of 2. After the independent convolutional operations are completed, restore the sequence. Set the initial population size to 5 and the maximum number of generations to 10.
[0056] Among the lower bounds of the parameters, set the learning rate to 0.001, the number of neurons in the LSTM to 10, the key value of the attention mechanism to 2, and the regularization parameter to 0.0001. Among the upper bounds of the parameters, set the corresponding parameters to 0.01, 50, 50, and 0.001 respectively.
[0057] Furthermore, the prediction model selects the Adam algorithm with an adaptive learning rate adjustment as the optimization algorithm for the model gradient, and uses the early stopping method to prevent overfitting of the LSTM network.
[0058] The optimization process of the early stopping method is as follows:
[0059] Construct an early stopping model based on a dynamic prediction window, and its mathematical formula is as follows:
[0060] Let the time step of the training process be t (t increases by 1 for each iteration), the validation frequency be τ (validate once every τ iterations), and the validation times be recorded as t v = τ, 2τ, 3τ,.... At the t v th iteration, the validation loss is L v (t v ). Define the width of the dynamic prediction window as the patience value P, and predict the loss trend in the next P steps through the historical validation loss.
[0061] Use weighted exponential smoothing to predict the future loss:
[0062]
[0063] Among them, α ∈ (0, 1) is the smoothing factor, which controls the weight decay rate of the historical loss.
[0064] If the validation loss of consecutive P predictions is not better than the current optimal loss Then stop training:
[0065]
[0066] Among them, take 1 when the condition inside the parentheses is satisfied, otherwise take 0.
[0067] Introduce the update rule of the adaptive parameter α so that it changes with the training stage:
[0068]
[0069] where β is the attenuation coefficient and T max is the maximum number of training iterations. As the training progresses, the prediction depends more on the recent loss.
[0070] Furthermore, the remaining SOC prediction model of the rechargeable battery adds a self-attention mechanism through the selfAttentionLayer.
[0071] Beneficial effects:
[0072] 1. The present invention optimizes the CNN-LSTM-Attention model through an improved sand cat swarm algorithm, integrates the advantages of each network, comprehensively considers various parameters, and enables it to accurately adapt to the battery SOC prediction under different time and space, further reflecting the generality and forward-looking nature of the present invention.
[0073] 2. By improving the sand cat swarm algorithm, the present invention avoids local optima, quickly finds the optimal parameters of the model, shortens the training time, can timely adapt to the dynamic changes of the charging load, ensures the prediction timeliness, and is conducive to the timely charging allocation of electric vehicles.
[0074] 3. During the process of optimizing the model, the improved sand cat swarm algorithm enables the CNN-LSTM-Attention model to maintain high prediction accuracy while enhancing the interpretability by analyzing the optimization path of the model parameters, helping those skilled in the art more intuitively understand the action mechanism of each network layer in processing charging data, and providing clearer theoretical support for further optimizing the model and decision-making in practical applications. Brief description of the drawings
[0075] Figure 1 is the specific flowchart of the present invention;
[0076] Figure 2 is the trend chart of the change of the objective function value (mean square error MSE) during the iteration process of the hyperparameter optimization algorithm in the embodiment of the present invention;
[0077] Figure 3 is the scatter comparison chart of the two-dimensional features (MAE and R 2 ) of the original model and the optimized model in the embodiment of the present invention;
[0078] Figure 4 is the comparison chart of the true value and the test values of the optimized and non-optimized models in the embodiment of the present invention;
[0079] Figure 5 is the radar comparison chart of the comprehensive performance (MAE, MAPE, MSE, RMSE, R 2 after normalization) of the original model and the optimized model in the embodiment of the present invention;
[0080] Figure 6This is the polar coordinate comparison chart of each error index (MAE, MAPE, etc.) between the original model and the optimized model in the embodiments of the present invention;
[0081] Figure 7 This is the curve chart of the neural network training progress in the embodiments of the present invention;
[0082] Figure 8 This is the bar chart comparison of the neural network before and after optimization in terms of MAE, MAPE, and RMSE indicators in the embodiments of the present invention. Detailed implementation manners
[0083] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0084] As Figure 1 shown, this embodiment discloses a method for predicting the remaining SOC of an electric vehicle charging battery based on an improved sand cat swarm algorithm, and the steps are as follows:
[0085] Step 1: Data preprocessing
[0086] Obtain electric vehicle charging data from electric vehicle charging piles in Chinese cities, including current, charging power, charging efficiency, time, battery rated capacity, and battery SOC data. Perform preprocessing on these data, including null value filling and normalization.
[0087] The method for null value filling is as follows:
[0088]
[0089] In the formula, y k is the data filled at the missing moment; y k-1 is the SOC value at the same weekday moment in the previous week; y k+1 is the SOC value at the same weekday and the same moment in the next week.
[0090] To accelerate the convergence of the network loss function and improve the model training speed, it is necessary to perform normalization processing on the current, charging power, charging efficiency, time, and battery rated capacity. The normalization formula is:
[0091]
[0092] In the formula: x is the sample data before normalization; x one is the value after normalization; x max and x minThey are the maximum and minimum values in the sample data before normalization respectively.
[0093] Step 2: Analyze the charging information
[0094] Analyze the charging information. The main factors affecting the remaining SOC of the battery after charging are current, charging power, charging efficiency, time, and battery rated capacity. According to these factors, construct a feature matrix as the input of the prediction model. The relationship between the predicted SOC value and each influencing factor is as follows:
[0095]
[0096] In the formula, I (k-m)×1 , Q (k-m)×1 , η (k-m)×1 , T (k-m)×1 , C (k-m)×1 are the input feature vectors X, representing current, charging power, charging efficiency, time, and battery rated capacity respectively; is the model output Y, that is, the remaining SOC of the battery after charging; k is the current sample point time, k + 1 is the time to be predicted; k - m is m + 1 moments before the time to be predicted, including the k moment.
[0097] The input feature matrix X of the model is:
[0098]
[0099] I (m+1)×1 , Q (m+1)×1 , η (k+m)×1 , T (k+m)×1 , C (k+m)×1 are the column vectors of current, charging power, charging efficiency, time, and battery rated capacity respectively, as shown in the following formula:
[0100]
[0101] In the formula, I j , Q j , η j , T j , C j (j = 1, 2,..., m + 1) are the decimal values of current, charging power, charging efficiency, time, and battery rated capacity respectively, and the units are ampere (A), kilowatt-hour (kWh), none, second (s), and ampere-hour (Ah) respectively.
[0102] Among them The function f calculation formula of
[0103]
[0104] In addition, under the condition of the same charging efficiency, combining the above formula, the formula is as follows:
[0105]
[0106] Step 3: Build a prediction model for the remaining SOC of the electric vehicle charging battery based on the CNN-LSTM hybrid neural network
[0107] S1 Initialization and data preparation
[0108] S11 Turn off the alarm information, clear the workspace, and close all figure windows
[0109] Turn off the alarm information in MATLAB, clear the variables in the workspace, and close all the opened figure windows.
[0110] Add the file paths of all subdirectories and files in the current directory to the MATLAB search path.
[0111] S12 Read data
[0112] Read data from the Excel file.
[0113] Calculate the total number of samples num_samples.
[0114] S13 Divide the training set and the test set
[0115] Set the last column as the output outdim = 1.
[0116] Set the proportion of the training set in the data set as 5 / 6 num_size = 5 / 6.
[0117] Calculate the number of training set samples num_train_s = round(num_size * num_samples).
[0118] Calculate the dimension of the input features f_ = size(res, 2) - outdim.
[0119] Extract the input features P_train and the output labels T_train of the training set.
[0120] Extract the input features P_test and the output labels T_test of the test set.
[0121] S14 Data normalization
[0122] Use the mapminmax function to normalize the input features of the training set to the interval [0, 1], and save the normalization parameter ps_input.
[0123] Normalize the input features of the test set using the same normalization parameter.
[0124] Use the mapminmax function to normalize the output labels of the training set to the interval [0, 1], and save the normalization parameter ps_output.
[0125] Normalize the output labels of the test set using the same normalization parameter.
[0126] S15 Data tiling
[0127] Reorganize the input features of the training set and the test set into a format suitable for the input of the neural network, and the feature dimension of each sample is (numFeatures, 1, 1).
[0128] S2 Construct a CNN-LSTM-Attention hybrid neural network
[0129] S21 Define the input layer
[0130] The input layer sequenceInputLayer accepts sequence data with a shape of [numFeatures, 1, 1].
[0131] S22 Use the sequence folding layer
[0132] The sequence folding layer sequenceFoldingLayer folds the input sequence so that the subsequent convolutional layer can independently process the data of each time step.
[0133] S23 Add convolutional layers
[0134] The first convolutional layer convolution2dLayer uses 16 filters, the filter size is [1, 1], and the stride is 1. The second convolutional layer convolution2dLayer uses 32 filters, the filter size is [1, 1], and the stride is 1. The third convolutional layer convolution2dLayer uses 64 filters, the filter size is [1, 1], and the stride is 1. Formula:
[0135] y = W * x + b
[0136] Where W is the weight matrix, x is the input data, and b is the bias term.
[0137] S24 Add batch normalization layers
[0138] The batch normalization layer batchNormalizationLayer normalizes the output of the convolutional layer, accelerates the training process, and prevents gradient disappearance or explosion. Formula:
[0139]
[0140] where μ is the mean, σ is the standard deviation, γ and β are learnable scaling and offset parameters, and ε is a small constant to prevent division-by-zero errors.
[0141] S25 Add ReLU activation layer
[0142] The ReLU activation layer reluLayer performs a non-linear transformation on the output of the batch normalization layer. Formula:
[0143] y = max(0, x)
[0144] S26 Add max pooling layer
[0145] The max pooling layer maxPooling2dLayer uses a pooling window of size [2, 1] with a stride of 2 and same padding. Formula:
[0146] y = max(x i:i+k )
[0147] where k is the size of the pooling window.
[0148] S27 Use sequence unfolding layer
[0149] The sequence unfolding layer sequenceUnfoldingLayer restores the folded sequence for subsequent LSTM layer processing.
[0150] S28 Add flattening layer
[0151] The flattening layer flattenLayer flattens multi-dimensional data into a one-dimensional vector for subsequent fully connected layer processing.
[0152] S29 Add LSTM layer
[0153] The first LSTM layer lstmLayer uses 25 hidden units, the second LSTM layer lstmLayer uses 50 hidden units, and the third LSTM layer lstmLayer uses 75 hidden units. The output mode is the output of the last time step. Formula:
[0154] h t = tanh(W h · [h t-1 , x t + b h )
[0155] where h t is the hidden state, W h is the weight matrix, x t is the input data, and b h is the bias term.
[0156] Add a self-attention layer to S210
[0157] The self-attention layer selfAttentionLayer uses 1 head, 2 key and query channels to implement the self-attention mechanism. Formula:
[0158]
[0159] where Q is the query matrix, K is the key matrix, V is the value matrix, and d k is the dimension of the key.
[0160] Add a Dropout layer to S211
[0161] The Dropout layer dropoutLayer discards the input with a probability of 0.1 to prevent overfitting. Formula:
[0162]
[0163] where p is the dropout probability.
[0164] Add a fully connected layer to S212
[0165] The fully connected layer fullyConnectedLayer outputs a dimension of 1. Formula:
[0166] y = W * x + b
[0167] where W is the weight matrix, x is the input data, and b is the bias term.
[0168] Add a regression layer to S213
[0169] The regression layer regressionLayer is used for regression tasks and calculates the loss between the predicted value and the true value. Formula:
[0170]
[0171] where y is the true value, is the predicted value.
[0172] Set training options in S3
[0173] Set training options in S31
[0174] Use the Adam optimizer and set the maximum number of training times to 30 times.
[0175] Set the gradient threshold to 1, the initial learning rate to 0.02, and the L2 regularization parameter to 0.001.
[0176] Set the training environment to CPU.
[0177] Set the verification data and verification frequency, and stop training when the verification performance does not improve for 5 consecutive times.
[0178] S4 Train the model
[0179] S41 Start training
[0180] Use the trainNetwork function to train the model and record the training time.
[0181] Use the trained model for prediction and denormalize the prediction results.
[0182] Convert the prediction results into a suitable data format.
[0183] Step 4: Principle of hyperparameter optimization using the sand cat swarm optimization algorithm
[0184] S1 Initialize parameters
[0185] S11 Initial population size: Set the initial population size SearchAgents_no, which represents the number of solutions initially generated during the optimization process. These solutions are candidate values for hyperparameters. For example, SearchAgents_no = 5 means 5 sets of hyperparameter combinations are initially generated.
[0186] S12 Maximum number of generations: Set the maximum number of generations Max_iter, which represents the maximum number of iterations in the optimization process. Each iteration updates the solutions in the population. For example, Max_iter = 10 means the optimization process will perform at most 10 iterations.
[0187] S13 Objective function: Define the objective function fobj to evaluate the fitness of each solution. The objective function is usually a function that calculates a model performance metric, such as the mean squared error (MSE). In this example, the objective function fobj is an anonymous function that accepts a set of hyperparameters x and other necessary parameters and returns the performance metric of the model on the validation set.
[0188] S14 Lower and upper bounds of parameters: Set the lower bound lb and upper bound ub for each hyperparameter to ensure that the solutions generated during the optimization process are within a reasonable range. For example: the range of the learning rate is [0.001, 0.01]; the range of the number of neurons in the LSTM is [10, 50]; the range of the key values of the attention mechanism is [2, 50]; the range of the regularization parameter is [0.0001, 0.001].
[0189] S15 Parameter dimension: Calculate the dimension dim of the hyperparameters, that is, the number of hyperparameters to be optimized. For example, if four hyperparameters are optimized, then dim = 4.
[0190] S16 Index: Set the index to identify a specific parameter used in the optimization process. For example, index = 3 means the third parameter is used in the optimization process.
[0191] S2 Generate the initial population
[0192] Randomly generate the initial population. Each solution is a vector containing dim hyperparameters, and the value of each hyperparameter is randomly generated within the corresponding upper and lower bounds.
[0193] S3 Evaluate the initial population
[0194] Use the objective function fobj to evaluate the fitness of each solution. The fitness is usually a performance metric of the model on the validation set, such as the mean squared error (MSE).
[0195] S4 Evolution process
[0196] Iterative update: Within the maximum number of evolution generations Max_iter, repeat the following steps: position update, boundary handling, fitness evaluation, and update the global optimal solution.
[0197] S5 End condition
[0198] When the maximum number of evolution generations Max_iter is reached or other end conditions are met (such as the fitness does not improve significantly for several consecutive iterations), the optimization process ends.
[0199] Step Five: Select the Adam algorithm as the optimization algorithm for the model gradient, and use early stopping for the LSTM network to prevent overfitting. The specific method is as follows:
[0200] Select the Adam algorithm:
[0201] (1) Construct a hybrid neural network model.
[0202] (2) Select the Adam optimizer and set the learning rate to 0.02.
[0203] (3) Compile the model using the Adam optimizer, specifying the loss function (such as mean squared error) and evaluation metrics (such as mean absolute error).
[0204] (4) Load and preprocess the training data and validation data.
[0205] (5) Train the model with the training data.
[0206] (6) Evaluate the model performance with the test data, and calculate the loss and evaluation metrics.
[0207] Adopt early stopping:
[0208] The optimization process of early stopping is as follows:
[0209] Construct an early stopping model based on a dynamic prediction window, and its mathematical formula is as follows:
[0210] Let the time step of the training process be \(t\) ( \(t\) increases by 1 for each iteration), and the validation frequency be \(\tau\) (validate once every \(\tau\) iterations). The validation moments are denoted as \(t v =\tau, 2\tau, 3\tau,...\). The validation loss at the \(t v -th iteration is \(L v (t v ). Define the width of the dynamic prediction window as the patience value \(P\), and predict the loss trend in the next \(P\) steps through the historical validation losses.
[0211] Use weighted exponential smoothing to predict the future loss:
[0212]
[0213] where \(\alpha\in(0,1)\) is the smoothing factor, which controls the weight decay rate of the historical losses.
[0214] If the validation losses of \(P\) consecutive predictions are not better than the current best loss then stop training:
[0215]
[0216] where 1 is taken when the condition inside the parentheses is satisfied, otherwise 0 is taken.
[0217] Introduce an update rule for the adaptive parameter \(\alpha\) so that it changes with the training stage:
[0218]
[0219] where \(\beta\) is the decay coefficient and \(T max is the maximum number of training iterations. As the training progresses, the prediction depends more on the recent losses.
[0220] Hyperparameter configuration adjustment:
[0221] Change the Plots parameter from "none" to "training - progress". This adjustment belongs to the configuration change for visualizing the training process, making the training progress curve displayed during the training process. The main purpose is to ensure that the BPTT method is correctly applied, better monitor the performance changes during the training process, and observe the training progress of the model through visualization.
[0222] Step six: Incorporate the self - attention mechanism to strengthen the connection between features. The specific method is as follows:
[0223] The self-attention layer is used to enhance the model's attention to important features. Here, a single-head self-attention layer is created, with the number of channels for keys and queries being 2; the self-attention mechanism calculates the importance weights for each position in the input sequence, enabling the model to better focus on important features.
[0224] Step Seven: Conduct model evaluation
[0225] Using the prediction results of the trained model, the evaluation of the prediction results includes using the root mean square error (RMSE), mean absolute error (MAE), mean square error (MSE), and mean absolute percentage error (MAPE) as evaluation metrics. The specific calculation formulas are as follows:
[0226]
[0227] MSE is the expected value of the square of the difference between the predicted value and the true value. It punishes large errors severely, and a smaller value indicates a better prediction effect; MAPE is the percentage of the average relative error, which can intuitively reflect the degree of deviation, and a smaller value indicates a smaller relative error; MAE is the average absolute difference, with a linear penalty, and a smaller value indicates a smaller prediction error; RMSE is the square root of MSE, with the same dimension as the original data, and a smaller value indicates a smaller prediction error.
[0228] To verify the feasibility and superiority of the embodiments, the inventors set up cases for the above embodiments for verification. The verification cases are as follows:
[0229] The data is sourced from the electric vehicle charging pile data in Chinese cities and is predicted.
[0230] (1) Preprocess the collected data, perform normalization and null value filling, and then divide it into a training set and a test set after completion.
[0231] (2) Build an electric vehicle charging battery remaining SOC prediction model based on a CNN-LSTM hybrid neural network.
[0232] (3) Use the sand cat swarm optimization algorithm improved by the differential evolution stochastic to optimal type-1 mutation strategy to optimize the hybrid neural network model.
[0233] (4) Select the Adam algorithm as the optimization algorithm for the model gradient. Use early stopping for the LSTM network to prevent overfitting, and adjust the hyperparameter configuration to ensure the correct application of the BPTT method.
[0234] (5) Incorporate the self-attention mechanism to strengthen the connection between features.
[0235] (6) Input the feature matrix into the optimized prediction model to predict the remaining SOC of the electric vehicle charging battery. The evaluation of the prediction results includes root mean square error (RMSE), mean absolute error (MAE), mean square error (MSE), and mean absolute percentage error (MAPE).
[0236] By optimizing the CNN-LSTM-Attention hybrid neural network model through the above mutation-based sand cat swarm optimization algorithm, high-precision prediction of the remaining SOC of the electric vehicle battery after charging is achieved. Convolutional neural networks and long short-term memory neural networks can complementarily process different types of data and features. The former can maintain the spatial hierarchical structure of the input data, and the latter can capture dependencies over long time spans, thus not only being able to process complex multimodal data but also improving the prediction ability and generalization ability of the model, which has important academic value and practical application potential.
[0237] Among them, Figure 2 represents the evolution curve; the X-axis refers to the number of iterations of the hyperparameter optimization algorithm, and the Y-axis refers to the objective function value (mean square error MSE, the smaller the better). The figure shows the change trend of the best fitness during the optimization process. The MSE becomes smaller and smaller as the number of iterations increases. The first 3 generations are the rapid decline stage, where the algorithm quickly explores the region of better parameters; after the 4th generation is the convergence stage, and the improvement amplitude slows down, indicating that the algorithm is approaching the local optimum; the initial MSE is optimized from 0.038 to 0.026, and the performance is improved by 31.6%. The final MSE is stable, indicating that the optimization algorithm effectively improves the model performance.
[0238] Figure 3 is a two-dimensional feature scatter plot; the X-axis is MAE (mean absolute error), and the Y-axis is R 2 (coefficient of determination). The original model (blue squares) is located in the lower right corner, indicating that it has a systematic bias; the optimized model (red circles) is located in the upper left corner, indicating that it approaches the ideal region (low MAE, high R 2 ). The MAE is optimized from 0.84 to 0.58, and the performance is improved by 31%. There is a negative correlation between MAE and the coefficient of determination; the optimized model breaks away from the original clustering, proving that the hyperparameter adjustment is effective.
[0239] Figure 4 is the comparison between the true value and the test values before and after optimization; the red solid line is the true value, the purple dashed line is the predicted value of the original CNN-LSTM-Attention, and the green solid line is the predicted value of the optimized model. The optimized model basically synchronously captures the peak changes.
[0240] Figure 5 is a radar chart, and the five axes respectively correspond to MAE, MAPE, MSE, RMSE, and R 2(After normalization). The original model (blue area) has a significant expansion on the MAE / MAPE / RMSE axes, indicating large errors; the optimized model (red area) has a graph closer to the center, and the comprehensive performance is improved evenly.
[0241] Figure 6 It is a polar plot; each subplot corresponds to an error index: the longer the ray length, the greater the error; the blue one is the original, and the red one is the optimized. The MAE is optimized from about 0.8 to 0.6, and the performance is improved by about 25%. The MAPE is optimized from 0.038 to 0.028, and the performance is improved by 26.3%.
[0242] Figure 7 It is the neural network training progress curve;
[0243] Figure 8 It is the bar chart comparison of the neural network before and after optimization on MAE, MAPE, and RMSE.
[0244] The above description of the embodiments enables those skilled in the art to implement or use the present invention. Various modifications to the embodiments will be obvious to those skilled in the art. The general principles of the present invention can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention should not be limited to the embodiments shown herein, but should cover the widest scope consistent with the principles and novel features disclosed in the present invention.
Claims
1. A method for predicting the remaining SOC of an electric vehicle rechargeable battery based on an improved sand cat swarm algorithm, characterized in that: The method comprises the following steps: S1 collects historical charging data of electric vehicles and performs null value filling and normalization preprocessing on the data; S2 constructs a feature matrix based on the factors affecting the remaining SOC of the battery after charging: current, charging power, charging efficiency, time, and battery rated capacity, which serves as the input of the remaining SOC prediction model of the charging battery; S3 builds a rechargeable battery remaining SOC prediction model based on a CNN-LSTM hybrid neural network; S4 uses the sand cat swarm optimization algorithm improved by differential evolution random to optimal type 1 mutation strategy to optimize the prediction model; S5 inputs the characteristic matrix into the optimized prediction model to predict the remaining SOC of the rechargeable battery.
2. The method for predicting the remaining SOC of an electric vehicle rechargeable battery based on an improved sand cat swarm algorithm according to claim 1, characterized in that: The method of filling the empty values described in S1 is as follows: In the formula, y k Fill in data for missing moments; y k-1 is the SOC value of the same weekday and time in the previous week; k+1 The SOC value of the same day and time of the following week; The current, charging capacity, charging efficiency, and battery rated capacity are normalized, and the normalization formula is: Where: x is the sample data before normalization; x one is the normalized value; x max and x min are the maximum and minimum values of the sample data before normalization.
3. The method for predicting the remaining SOC of an electric vehicle rechargeable battery based on an improved sand cat swarm algorithm according to claim 1, characterized in that: The steps for constructing the characteristic matrix of the rechargeable battery remaining SOC prediction model in S2 are as follows: Get the model input and output relationship: Among them I (k-m)×1 ,Q (k-m)×1 , η (k-m)×1 ,T (k-m)×1 ,C (k-m)×1 is the input feature vector X, which represents current, charging capacity, charging efficiency, time, and battery rated capacity; is the model output Y, i.e. the remaining SOC of the battery after charging; k is the current sample time, k+1 is the time to be measured; km is the m+1 time before the time to be predicted, including the k time; The input feature matrix X of the model is: X=[I (k+m)×1 ,Q (k+m)×1 ,η (k+m)×1 ,T (k+m)×1 ,C (k+m)×1 ] In the formula, I (m+1)×1 , Q (m+1)×1 , η (k+m)×1 、T (k+m)×1 , C (k+m)×1 are column vectors of current, charging capacity, charging efficiency, time, and battery rated capacity. The calculation formula of function f is: In the case of the same charging efficiency, combined with the above formula, the formula is as follows:
4. The method for predicting the remaining SOC of an electric vehicle rechargeable battery based on an improved sand cat swarm algorithm according to claim 1, characterized in that: The steps for building a rechargeable battery remaining SOC prediction model based on the CNN-LSTM hybrid neural network described in S3 are as follows: S301 Data Processing: turn off the alarm, clear the workspace and graphics window, read Excel data, calculate the total number of samples, divide the training set and test set into 5:1, extract and normalize the input features and output labels, and organize them into an input format suitable for the neural network; S302 Network Construction: Define the input layer, perform convolution operation through the sequence folding layer, add a convolution layer with 16 filters and a step size of 1, a batch normalization layer, a ReLU activation layer, a maximum pooling layer with a pooling window of 2×2 and a step size of 2, and then pass through the sequence expansion layer and the smoothing layer. Then, connect to the LSTM layer whose output is the last time step, the self-attention layer of the single head 2 keys and the query channel, the Dropout layer with a discard rate of 0.1, the fully connected layer with an output dimension of 1, and the regression layer; S303 training settings: Adam optimizer is used for training; S304 Training and prediction: Train the model and record the time, use the trained model to predict, denormalize the prediction results and convert them into a suitable data format.
5. The method for predicting the remaining SOC of an electric vehicle rechargeable battery based on an improved sand cat swarm algorithm according to claim 4, characterized in that: The specific steps of optimizing the remaining SOC prediction model of the rechargeable battery by the improved sand cat group optimization algorithm described in S4 are as follows: S401 Initialize the differential evolution strategy Randomly generate the initial population Where N is the population size, each individual is a D-dimensional vector; S402 For each individual (The current generation is t), generate a new mutant individual Randomly select three different individuals and And the best individual Calculate the mutation vector: Where F is the scaling factor, which ranges from (0,2); S403 Generate test vector For each dimension j (j = 1, 2, ..., D), a certain probability CR is used to decide whether to select the mutation vector or current individual Select the value in: Where j0 is a randomly selected dimension, ensuring that at least one dimension comes from the mutation vector; S404 will test vector With the current individual Compare and select individuals with better fitness to enter the next generation. If but otherwise The calculation process of the improved sand cat swarm optimization algorithm S405 is as follows. After the calculation, the optimal fitness value and the optimal position are output: R=2×r G ×rand(0,1)-r G P(t+1)=P b (t)-r·P rnd ·cos(θ) r=r G ×rand(0,1) P rnd =|rand(0,1)·P bc (t)-P c (t)| P c (t+1)=r·(P bc (t)-rand(0,1)·P c (t)) Where R is the bootstrap parameter that controls the transition between search and attack, rand(0,1) is a random number uniformly distributed within (0,1), and r G is the normal sensitivity range, S M is the auditory characteristic of the sand cat, t is the current iteration number of the population, T is the maximum iteration number of the population, θ is a random angle of the direction in which the sand cat moves during the attack phase, r is the sensitivity range of each individual in the population, P rnd is the distance, P bc (t) is the global optimal solution, P c (t) is the current position, P c (t+1) is the updated position of the population.
6. The method for predicting the remaining SOC of a rechargeable battery of an electric vehicle based on an improved sand cat swarm algorithm according to claim 5, characterized in that: Based on the improved sand cat swarm algorithm, the hyperparameters of the prediction model are optimized: Input layer settings, use sequence folding layer to perform independent convolution operations on the time steps of the image sequence, add convolution layer, 16 filters, step size 1, the first pooling layer, including 2x1 pooling window, step size 2, after the independent convolution operation is completed, the sequence is restored, the initial population size is set to 5; the maximum evolutionary generation is set to 10; In the lower limit of the parameters, the learning rate is set to 0.001, the number of neurons of LSTM is set to 10, the key value of the attention mechanism is set to 2, and the regularization parameter is set to 0.0001; the corresponding parameters in the upper limit of the parameters are set to 0.01, 50, 50, and 0.001 respectively.
7. The method for predicting the remaining SOC of an electric vehicle rechargeable battery based on an improved sand cat swarm algorithm according to claim 6, characterized in that: The prediction model uses the Adam algorithm with adaptive learning rate adjustment as the optimization algorithm for the model gradient, and uses the early stopping method to prevent the LSTM network from overfitting; The early stopping optimization process is as follows: Construct an early stopping model based on a dynamic prediction window. The mathematical formula is as follows: Assume that the time step of the training process is t (t increases by 1 for each iteration), the verification frequency is τ (verification is performed once every τ iterations), and the verification time is recorded as t v =τ, 2τ, 3τ, .... At the tth v The validation loss at the iteration is L v (t v ). Define the width of the dynamic prediction window as the patience value P, and predict the loss trend of the next P steps through the historical verification loss. Use weighted exponential smoothing to predict future losses: Among them, α∈(0,1) is a smoothing factor that controls the weight decay speed of historical loss. If the validation loss of consecutive P predictions is not better than the current optimal loss Then stop training: The value inside the brackets is 1 if the condition is met, otherwise it is 0. The update rule of the adaptive parameter α is introduced to make it change with the training stage: Where β is the attenuation coefficient, T max is the maximum number of training iterations. As training progresses, predictions become more dependent on recent losses.
8. The method for predicting the remaining SOC of a rechargeable battery of an electric vehicle based on an improved sand cat swarm algorithm according to claim 7, characterized in that: The rechargeable battery remaining SOC prediction model adds a self-attention mechanism through selfAttentionLayer.
Citation Information
Cited By
Electric vehicle charging data generation method and device based on attention and conditional probability distribution, and storage medium
CN120611155A
Power battery health state monitoring method and system based on multi-source feature fusion and dynamic weight
CN120910537A
Power battery health state monitoring method and system based on multi-source feature fusion and dynamic weight
CN120910537B
Automobile factory energy consumption prediction method and management system
CN121279671A