Grid-Search-Optimized LSTM with Attention for State-of-Charge Estimation in Sodium-Ion Energy Storage Batteries

State of charge (SOC) is the central state variable in energy battery storage. It defines how much usable charge remains, shapes power-limiting decisions, and underpins lifetime and safety management. In sodium-ion batteries, SOC estimation is complicated by flat voltage regions, pronounced nonlinearity, and sensitivity to current rate. Because SOC cannot be measured directly, it must be inferred from external signals such as voltage, current, and temperature.

Conventional approaches each carry a specific weakness. Coulomb counting integrates current but accumulates error and depends on an accurate initial SOC. Open-circuit-voltage methods require sufficiently relaxed cells and are difficult to apply under load. Equivalent-circuit and electrochemical models can represent internal dynamics, but their parameters must be identified and may shift with temperature, aging, and operating history. Data-driven sequence models avoid an explicit circuit description by learning the mapping from measured signals to SOC.

The GS-LSTM-Attention architecture combines three elements: a long short-term memory (LSTM) network for temporal dependence, an attention layer for weighting informative hidden states, and grid search for tuning key hyperparameters. The design targets two common weaknesses of data-driven SOC estimation: limited generalization under changing operating conditions and reliance on manual hyperparameter selection.

Energy storage battery modules
Energy battery storage systems depend on accurate SOC estimation for dispatch, power limiting, and lifetime management.

Temporal Modeling with LSTM

An LSTM unit controls information flow through forget, input, and output gates. For an input vector \(x_t\), previous hidden state \(h_{t-1}\), and previous cell state \(c_{t-1}\), the gate equations are:

$$f_t=\sigma(W_f x_t+U_f h_{t-1}+b_f)$$

$$i_t=\sigma(W_i x_t+U_i h_{t-1}+b_i)$$

$$\tilde{c}_t=\tanh(W_c x_t+U_c h_{t-1}+b_c)$$

$$c_t=f_t\odot c_{t-1}+i_t\odot\tilde{c}_t$$

$$o_t=\sigma(W_o x_t+U_o h_{t-1}+b_o)$$

$$h_t=o_t\odot\tanh(c_t)$$

Here, \(\sigma\) is the sigmoid function, \(\odot\) denotes element-wise multiplication, and \(W\), \(U\), and \(b\) are learned weights and biases. The forget gate removes outdated information, the input gate admits new candidate information, and the output gate exposes the hidden state used by subsequent layers. For SOC estimation, the input sequence consists of voltage and current samples; the hidden state sequence carries the temporal signature of charge and discharge.

Attention Weighting of Hidden States

The attention layer receives the LSTM hidden states \(h_1,\ldots,h_T\). A score function assigns an importance value to each time step, and a softmax normalization converts those scores into weights:

$$e_t=s(h_t),\quad \alpha_t=\frac{\exp(e_t)}{\sum_{k=1}^{T}\exp(e_k)},\quad z=\sum_{t=1}^{T}\alpha_t h_t$$

The resulting context vector \(z\) emphasizes the hidden states most relevant to the current SOC prediction. A fully connected layer then maps \(z\) to the estimated SOC:

$$\hat{y}=W_y z+b_y$$

This division of labor is important. The LSTM encodes temporal dependence across the voltage and current sequence, while attention reweights the encoded states instead of treating all time steps equally. Under dynamic current, the informative parts of the sequence may not be uniformly distributed; attention provides a learned mechanism for concentrating on the most predictive segments.

Grid Search for Hyperparameter Selection

Grid search evaluates a finite set of hyperparameter combinations and selects the combination with the best validation performance. The search space in this model contains three parameters: the number of hidden-layer neurons \(n_h\), the learning rate \(\eta\), and the number of training epochs \(N_e\). Thus, a candidate configuration is

$$\theta=(n_h,\eta,N_e)$$

and the selected configuration minimizes validation mean squared error:

$$\theta^*=\arg\min_{\theta\in\Theta}\operatorname{MSE}\left(M(\theta),D_{\mathrm{val}}\right)$$

where \(M(\theta)\) is the model trained with configuration \(\theta\), and \(D_{\mathrm{val}}\) is the validation set. The three parameters control different failure modes. Too few hidden neurons can underfit the nonlinear SOC trajectory; too many can overfit. A learning rate that is too small slows convergence, while an excessively large rate can produce unstable updates. The number of epochs has a similar bias-variance trade-off. Because grid search is exhaustive, restricting the search to three parameters keeps the procedure tractable while still addressing the settings most likely to affect accuracy.

SOC Estimation Workflow

The estimation procedure follows five stages:

  1. Normalize current, voltage, and SOC with min-max scaling to reduce scale differences and accelerate convergence.
  2. Construct the LSTM-Attention network with input, LSTM, attention, fully connected, and output layers.
  3. Define the grid-search space for hidden-layer size, learning rate, and training epochs.
  4. Select the configuration with the lowest validation MSE.
  5. Train the final model with the selected configuration and output the estimated SOC.

The min-max transformation is

$$x’=\frac{x-x_{\min}}{x_{\max}-x_{\min}}$$

where \(x’\) is the scaled value, \(x\) is the original value, and \(x_{\min}\) and \(x_{\max}\) are the minimum and maximum of that variable. Normalization is applied to the input signals and the SOC target; the reported MSE is calculated on the normalized SOC rather than being inverse-transformed to capacity units.

Experimental Data and Evaluation Metrics

The model was evaluated on data from a commercial 18650 sodium-ion cell with a nominal capacity of 1.0 Ah. The cell was unaged at the start of testing. Each cycle included charge and discharge stages, and data were sampled at 1 s intervals. Testing was performed at 25 °C with constant currents of 2, 5, and 6 A, corresponding to approximately 2C, 5C, and 6C for a 1.0 Ah cell. Voltage, current, and capacity were recorded; voltage and current served as model inputs, and SOC was the target.

Each current condition was modeled separately. This is a within-condition evaluation: the model learns the voltage-current-SOC relationship for a given current level rather than transferring across current levels. Temperature was fixed at 25 °C and was not used as an input feature.

Three metrics were used: mean squared error (MSE), mean absolute error (MAE), and the coefficient of determination \(R^2\):

$$\mathrm{MSE}=\frac{1}{n}\sum_{i=1}^{n}(y_i-\hat{y}_i)^2$$

$$\mathrm{MAE}=\frac{1}{n}\sum_{i=1}^{n}\left|y_i-\hat{y}_i\right|$$

$$R^2=1-\frac{\sum_{i=1}^{n}(y_i-\hat{y}_i)^2}{\sum_{i=1}^{n}(y_i-\bar{y})^2}$$

Here, \(y_i\) is the measured SOC, \(\hat{y}_i\) is the estimated SOC, \(\bar{y}\) is the mean measured SOC, and \(n\) is the number of samples. Lower MSE and MAE indicate better accuracy; \(R^2\) closer to 1 indicates a better fit. In the results, MSE and MAE are expressed on a percentage scale, with MSE computed from normalized SOC. \(R^2\) is calculated globally over the samples of each condition. The reported values are single-training-run results.

Accuracy Across Current Levels

The GS-LSTM-Attention model was compared with a plain LSTM and an LSTM-Attention model using the same voltage and current inputs. Table 1 summarizes the results.

SOC estimation accuracy of LSTM, LSTM-Attention, and GS-LSTM-Attention at 25 °C.
Model 2 A 5 A 6 A
MSE (%) MAE (%) \(R^2\) MSE (%) MAE (%) \(R^2\) MSE (%) MAE (%) \(R^2\)
LSTM 0.10 2.35 0.856 8 0.06 1.88 0.859 0 0.18 3.57 0.831 8
LSTM-Attention 0.07 2.03 0.900 8 0.04 1.48 0.903 2 0.07 1.99 0.938 8
GS-LSTM-Attention 0.02 0.87 0.977 1 0.03 1.34 0.914 0 0.05 1.88 0.952 7

At 2 A, GS-LSTM-Attention reached \(R^2=0.977\ 1\), compared with 0.856 8 for LSTM and 0.900 8 for LSTM-Attention. The corresponding increases were 0.120 3 and 0.076 3. MSE fell to 0.02% from 0.10% and 0.07%, while MAE fell to 0.87% from 2.35% and 2.03%.

At 5 A, the model obtained \(R^2=0.914\ 0\), MSE = 0.03%, and MAE = 1.34%. The LSTM and LSTM-Attention baselines reached \(R^2=0.859\ 0\) and 0.903 2, respectively. At 6 A, GS-LSTM-Attention achieved \(R^2=0.952\ 7\), MSE = 0.05%, and MAE = 1.88%, compared with \(R^2=0.831\ 8\) for LSTM and 0.938 8 for LSTM-Attention. All GS-LSTM-Attention results exceeded \(R^2=0.91\).

Relative to LSTM, the absolute MSE reductions at 2, 5, and 6 A were 0.08, 0.03, and 0.13 percentage points; the corresponding MAE reductions were 1.48, 0.54, and 1.69 percentage points. Relative to LSTM-Attention, the MSE reductions were 0.05, 0.01, and 0.02 percentage points, and the MAE reductions were 1.16, 0.14, and 0.11 percentage points. The ordering LSTM → LSTM-Attention → GS-LSTM-Attention is consistent across all three current levels and all three metrics.

The two added components do not contribute equally at every operating point. At 2 A, attention raises \(R^2\) by 0.044 0 over the plain LSTM, and grid search adds a further 0.076 3. At 6 A, attention accounts for most of the gain over LSTM, raising \(R^2\) by 0.107 0, while grid search adds 0.013 9. This pattern indicates that the relative value of architectural attention and hyperparameter tuning depends on the current regime. The largest \(R^2\) gain in absolute terms occurred at 2 A, while the largest MAE reduction occurred at 6 A.

Interpretation and Scope

The results support a specific conclusion: within the tested 25 °C, 2–6 A envelope, combining LSTM temporal encoding, attention weighting, and grid-search tuning improves SOC estimation relative to the two baselines. The attention layer changes how the hidden-state sequence is aggregated, while grid search adjusts model capacity and optimization behavior. The monotonic improvement across the three models is consistent with both mechanisms contributing, but it does not isolate their effects beyond the tested configurations.

Several boundaries matter for practical use. Each current level was modeled separately, so the reported accuracy represents within-condition estimation, not cross-current transfer. The evaluation covers one cell type, one temperature, and three current levels. Aging, cell-to-cell variability, temperature transients, and mixed charge-discharge profiles are outside this test matrix. The metrics are single-run values, and MSE is reported on normalized SOC without inverse transformation. These conditions do not diminish the observed accuracy, but they define the range in which it has been demonstrated.

Conclusion

GS-LSTM-Attention provides a structured approach to SOC estimation for sodium-ion energy storage batteries. The LSTM captures temporal dependence in voltage and current, attention assigns dynamic importance to hidden states, and grid search selects hidden-layer size, learning rate, and training epochs by validation MSE. In tests on a 1.0 Ah 18650 sodium-ion cell at 25 °C, the model achieved \(R^2>0.91\) at 2, 5, and 6 A, with the best result of \(R^2=0.977\ 1\) at 2 A. At 6 A, it reduced MSE and MAE relative to both LSTM and LSTM-Attention baselines.

The practical value of the method lies in its combination of sequence modeling and systematic tuning rather than in a single architectural change. Its demonstrated scope, however, remains a single temperature and a set of separately modeled current levels. Extending the validation to temperature variation, aging, cell-to-cell differences, and cross-condition transfer is the next requirement for assessing readiness in field-deployed energy battery storage.

Scroll to Top