State of Charge Estimation for Energy Storage Cell Using GS-LSTM-Attention Model

In the rapidly evolving landscape of energy storage systems, the accurate estimation of the state of charge (SOC) of energy storage cell remains a critical challenge. SOC directly reflects the residual energy within a battery, serving as a fundamental parameter for energy management, performance optimization, and lifecycle prediction. Sodium-based energy storage cells have attracted significant attention due to their low cost and abundant raw materials, making them promising candidates for large-scale grid storage and electric vehicle applications. However, the SOC of an energy storage cell cannot be measured directly; it must be inferred from external characteristics such as voltage, current, and temperature. This estimation problem is further complicated by the inherent nonlinearity, time-varying behavior, and dynamic operating conditions of energy storage cells. Traditional methods, such as ampere-hour counting and open-circuit voltage measurement, suffer from error accumulation, sensitivity to initial conditions, and limited robustness under varying loads. Therefore, developing a reliable, accurate, and adaptive SOC estimation method is essential for the safe and efficient operation of energy storage cell systems.

In recent years, data-driven approaches based on deep learning have emerged as powerful tools for SOC estimation. Among them, long short-term memory (LSTM) networks have shown exceptional capability in modeling temporal dependencies due to their gated architecture. However, standard LSTM models often struggle with capturing the most salient features of complex sequential data, especially when the operating conditions vary widely. Furthermore, the performance of LSTM models heavily depends on the choice of hyperparameters, such as the number of hidden units, learning rate, and training epochs. Manual tuning is time-consuming and often leads to suboptimal results. To address these limitations, we propose a novel hybrid model that integrates grid search (GS) optimization with an attention-enhanced LSTM network, termed GS-LSTM-Attention. This model leverages the attention mechanism to dynamically focus on the most informative time steps of the sequence, while GS systematically explores the hyperparameter space to maximize estimation accuracy. We validate our approach using experimental data from a commercial 18650 cylindrical sodium energy storage cell under constant current discharge at 2 A, 5 A, and 6 A. The results demonstrate that the proposed GS-LSTM-Attention model significantly outperforms both the vanilla LSTM and LSTM-Attention models across all operating conditions, achieving a coefficient of determination (R²) as high as 0.9771.

The remainder of this article is organized as follows. First, we present a comprehensive review of related work in SOC estimation, highlighting the strengths and weaknesses of existing methods. Next, we detail the theoretical foundations of LSTM networks, the attention mechanism, and grid search optimization, and explain how they are integrated into our framework. Then, we describe the experimental setup, including the data acquisition process, preprocessing, and evaluation metrics. Subsequently, we report and analyze the estimation results, comparing our model with baseline approaches through extensive tables and visualizations. Finally, we conclude with a summary of contributions and future research directions.

Related Work

Accurate SOC estimation for energy storage cell has been a research focus for decades. Conventional methods include ampere-hour counting, open-circuit voltage (OCV) lookup, and model-based approaches such as equivalent circuit models (ECMs) and Kalman filters. Ampere-hour counting integrates current over time but is prone to drift due to sensor noise and initial state uncertainty. OCV methods rely on the relationship between OCV and SOC, which is influenced by temperature and aging. ECM-based approaches, such as the second-order RC model, can capture dynamic behavior but require careful parameter identification and are sensitive to model mismatches. Extended Kalman filters (EKF) and unscented Kalman filters (UKF) have been employed to improve estimation robustness, yet they still depend on accurate battery models and may diverge under extreme conditions.

With the rise of deep learning, data-driven methods have gained popularity. Neural networks, particularly LSTM and gated recurrent units (GRU), can learn complex nonlinear mappings directly from historical data. Huang et al. (2023) used a sparrow search algorithm to optimize LSTM hyperparameters for SOC estimation. Li et al. (2024) combined LSTM with temporal convolutional networks (TCN) to capture multi-scale features. Sun et al. (2022) integrated an attention mechanism with GRU to emphasize relevant temporal patterns. However, most existing work either optimizes hyperparameters manually or uses heuristic algorithms without systematic exploration. Moreover, the combination of attention mechanism and grid search optimization has not been thoroughly investigated for energy storage cell SOC estimation. Our work fills this gap by proposing a principled hyperparameter tuning framework that enhances the attention-based LSTM model, leading to superior estimation performance under different operating currents.

Methodology

Long Short-Term Memory Networks

LSTM networks are a variant of recurrent neural networks (RNNs) designed to overcome the vanishing gradient problem. By introducing three gating units – forget gate, input gate, and output gate – LSTM can selectively retain or discard information over long sequences. The mathematical formulation of an LSTM cell is given by the following equations:

$$
f_t = \sigma \left( W_f x_t + U_f h_{t-1} + V_f c_{t-1} + b_f \right)
$$
$$
i_t = \sigma \left( W_i x_t + U_i h_{t-1} + V_i c_{t-1} + b_i \right)
$$
$$
\tilde{c}_t = \tanh \left( W_c x_t + U_c h_{t-1} + b_c \right)
$$
$$
c_t = f_t \odot c_{t-1} + i_t \odot \tilde{c}_t
$$
$$
o_t = \sigma \left( W_o x_t + U_o h_{t-1} + V_o c_t + b_o \right)
$$
$$
h_t = o_t \odot \tanh(c_t)
$$
where $x_t$ is the input vector at time step $t$, $h_{t-1}$ and $c_{t-1}$ are the hidden state and cell state from the previous step, $f_t$, $i_t$, $o_t$ are the activations of the forget, input, and output gates, respectively, $\tilde{c}_t$ is the candidate cell state, and $\odot$ denotes element-wise multiplication. $\sigma$ is the sigmoid function and $\tanh$ is the hyperbolic tangent function. The weight matrices $W$, $U$, $V$ and bias vectors $b$ are learnable parameters. The LSTM layer outputs a sequence of hidden states $H = [h_1, h_2, …, h_T]$, which captures the temporal dependencies of the input sequence consisting of voltage and current measurements of the energy storage cell.

Attention Mechanism

The attention mechanism allows the model to dynamically assign importance weights to different time steps of the hidden state sequence. Instead of treating all historical information equally, the attention layer computes a context vector that is a weighted sum of the hidden states, where the weights are learned based on the relevance of each time step to the current prediction task. The attention scores are computed using a scoring function, typically a dot product or a small neural network, followed by a softmax normalization. Formally, for a sequence of hidden states $h_1, h_2, …, h_T$, the attention weight $\alpha_t$ for the $t$-th time step is:

$$
e_t = v^\top \tanh(W_a h_t + b_a)
$$
$$
\alpha_t = \frac{\exp(e_t)}{\sum_{k=1}^T \exp(e_k)}
$$
$$
c = \sum_{t=1}^T \alpha_t h_t
$$
where $W_a$ and $b_a$ are learnable parameters, $v$ is a weight vector, and $c$ is the context vector. This vector is then concatenated with the last hidden state or fed into a fully connected layer to produce the final SOC estimate. By focusing on key discharge segments (e.g., sudden voltage drops or plateau regions), the attention mechanism significantly enhances the predictive capability of the model for energy storage cell SOC estimation.

Grid Search Optimization

Hyperparameter selection is critical for achieving optimal performance in deep learning models. Manual tuning is inefficient and often yields suboptimal configurations. Grid search (GS) is a systematic enumeration technique that evaluates all possible combinations of predefined hyperparameter values. For each combination, the model is trained and validated on a hold-out set, and the combination that minimizes the validation mean squared error (MSE) is selected. In our approach, we define a search space $\Theta = \{\theta_1, \theta_2, \dots, \theta_n\}$ where each $\theta_i$ is a hyperparameter candidate set. For the LSTM-Attention model, we tune three key hyperparameters: the number of hidden units in the LSTM layer, the learning rate, and the number of training epochs. The candidate values are:

  • Hidden units: [32, 64, 128, 256]
  • Learning rate: [0.001, 0.005, 0.01, 0.05]
  • Training epochs: [50, 100, 200, 300]

The objective function of grid search is:

$$
\theta^* = \arg\min_{\theta \in \Theta} \text{MSE}\left(M(\theta), D_{\text{val}}\right)
$$
where $M(\theta)$ denotes the model trained with hyperparameters $\theta$, and $D_{\text{val}}$ is the validation dataset. The best combination found for our energy storage cell data under 2 A discharge was: hidden units = 128, learning rate = 0.005, epochs = 200. This systematic optimization leads to a 0.05% reduction in MSE compared to the default LSTM-Attention model.

Experimental Setup

Data Description

We collected experimental data from a commercial 18650 cylindrical sodium energy storage cell with a nominal capacity of 1.0 Ah. The cell was subjected to constant current discharge at three different rates: 2 A, 5 A, and 6 A, at a controlled temperature of 25 °C. Each cycle consisted of charging and discharging phases, and data were recorded at a sampling frequency of 1 Hz. The recorded variables include voltage (V), current (A), and capacity (Ah). The SOC is calculated as the ratio of remaining capacity to nominal capacity. To build independent models for each operating condition, we split the data into training and testing sets. For each discharge current, we used the first 70% of the sequential data for training and the remaining 30% for testing. Before feeding the data into the neural network, we applied min-max normalization to scale all features to the range [0, 1]:

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

This step accelerates convergence and ensures that variables with different units (volts and amps) are treated equally. The input to the model is a sequence of past voltage and current measurements over a time window of 10 time steps (10 seconds), and the target is the SOC at the next time step. This sliding window scheme captures local temporal dynamics of the energy storage cell.

Evaluation Metrics

We employ three standard metrics to quantify the estimation performance:

  • Mean Squared Error (MSE) – measures the average squared difference between predicted and true SOC values.
  • Mean Absolute Error (MAE) – measures the average absolute deviation.
  • Coefficient of Determination (R²) – indicates the proportion of variance explained by the model, with values close to 1 indicating a good fit.

Formally,

$$
\text{MSE} = \frac{1}{n} \sum_{i=1}^{n} (y_i – \hat{y}_i)^2
$$
$$
\text{MAE} = \frac{1}{n} \sum_{i=1}^{n} |y_i – \hat{y}_i|
$$
$$
R^2 = 1 – \frac{\sum_{i=1}^{n} (y_i – \hat{y}_i)^2}{\sum_{i=1}^{n} (y_i – \bar{y})^2}
$$
where $n$ is the number of test samples, $y_i$ is the true SOC, $\hat{y}_i$ is the predicted SOC, and $\bar{y}$ is the mean of true SOC values. All metrics are computed on the test set after un-normalization of the predicted SOC values.

Results and Discussion

Model Comparison

We compare the proposed GS-LSTM-Attention model against two baselines: (1) a standard LSTM network with the same architecture but no attention mechanism, and (2) an LSTM-Attention model where the attention layer is added but hyperparameters are set to default values (128 hidden units, learning rate 0.01, epochs 100). All models are trained and tested under identical data splits. Table 1 summarizes the estimation results for the three discharge currents.

Table 1: SOC Estimation Results for Different Models under Three Discharge Currents
Model 2 A 5 A 6 A
MSE (%) MAE (%) MSE (%) MAE (%) MSE (%) MAE (%)
LSTM 0.10 2.35 0.8568 0.06 1.88 0.8590 0.18 3.57 0.8318
LSTM-Attention 0.07 2.03 0.9008 0.04 1.48 0.9032 0.07 1.99 0.9388
GS-LSTM-Attention 0.02 0.87 0.9771 0.03 1.34 0.9140 0.05 1.88 0.9527

As shown in Table 1, the GS-LSTM-Attention model consistently achieves the lowest MSE and MAE and the highest R² across all three discharge rates. For the 2 A condition, the R² reaches 0.9771, which is 0.1203 higher than the LSTM model and 0.0763 higher than the LSTM-Attention model. This demonstrates that the attention mechanism and grid search jointly contribute to a substantial improvement in estimation accuracy. Under 5 A and 6 A, the improvements are also significant, with R² values of 0.9140 and 0.9527, respectively. Notably, the 5 A case shows a smaller relative improvement because the dataset for this condition has lower variability, but our model still outperforms the baselines. The MAE reductions are particularly pronounced: at 2 A, MAE drops from 2.35% (LSTM) to 0.87% (GS-LSTM-Attention), a reduction of 63%. At 6 A, MAE reduces from 3.57% to 1.88%, cutting the error nearly in half. These results confirm that the combination of attention and hyperparameter optimization yields a robust and accurate SOC estimator for energy storage cells under various constant-current discharge scenarios.

Visualization of Estimation Curves

To visually assess the tracking performance, we plot the predicted SOC versus the true SOC over the test sequences. Below we insert the relevant figure that illustrates the quality of our model’s predictions across different operating currents.

The predictive curves (not shown here due to text format) indicate that the GS-LSTM-Attention model’s SOC estimates align closely with the true trajectory across the entire discharge process, whereas the LSTM and LSTM-Attention models exhibit larger deviations, especially near the end of discharge where the SOC drops steeply. The attention mechanism enables the model to focus on critical phases such as the voltage plateau and the knee point, thereby reducing the maximum error. Grid search further refines the model capacity, preventing overfitting and ensuring stable convergence.

Discussion

The superior performance of the proposed model can be attributed to two factors. First, the attention layer dynamically selects the most relevant temporal contexts. For an energy storage cell, the rate of change of voltage and current differs during different SOC regions. For example, near the end of discharge, cell voltage drops rapidly, and the attention mechanism assigns higher weights to those time steps, enabling more accurate predictions. Second, grid search eliminates the guesswork in hyperparameter tuning. Without optimization, the LSTM-Attention model might use a suboptimal learning rate that leads to slow convergence or oscillation; grid search finds the setting that balances training speed and accuracy. The 2 A case benefits the most because the discharge lasts longer (about 30 minutes) and provides more temporal patterns for the model to learn. The 6 A case is more challenging due to the faster discharge (only about 10 minutes), but our model still achieves an R² of 0.9527, indicating strong generalization.

We also note that the MSE values reported in Table 1 are computed before un-normalization, so they reflect the normalized scale. However, the relative comparisons remain valid. For practical applications, an MAE below 2% is generally acceptable for energy management systems. Our GS-LSTM-Attention model achieves MAE ≤ 1.88% across all three conditions, meeting this benchmark.

Conclusion

In this work, we proposed a novel GS-LSTM-Attention model for accurate SOC estimation of sodium energy storage cell. By integrating the attention mechanism into the LSTM architecture, our model captures the most informative parts of the input sequence, enhancing its ability to track nonlinear SOC dynamics. The grid search algorithm systematically optimizes the critical hyperparameters, namely the number of hidden units, learning rate, and training epochs, leading to a significant boost in estimation performance. Experimental results on a 18650 sodium cell under constant current discharges at 2 A, 5 A, and 6 A demonstrate that the proposed model outperforms both the standard LSTM and the LSTM-Attention models in terms of MSE, MAE, and R². Notably, under 2 A discharge, the R² reaches 0.9771, with an MAE of only 0.87%. The improvements are consistent across all tested operating conditions, confirming the robustness and effectiveness of our approach. The proposed methodology provides a reliable tool for real-time SOC monitoring in energy storage cell systems, contributing to safer and more efficient battery operation. Future work will focus on extending the model to handle dynamic load profiles (e.g., pulsed discharge and charge cycles) and incorporating temperature and aging effects to enhance its practical applicability.

Scroll to Top