State of Charge Estimation Method for Lithium-Ion Batteries in All-Electric Ships Based on LSTM Neural Network

Abstract All-electric ships (AES) are considered an effective solution for reducing greenhouse gas emissions as they are a platform to use clean energy sources such as lithium-ion batteries, fuel cells and solar cells instead of fossil fuel. Even though these batteries are a promising alternative, the accuracy of the battery state of charge (SOC) estimation is a critical factor for their safe and reliable operation. The SOC is a key indicator of battery residual capacity. Its estimation can effectively prevent battery over-discharge and over-charge. Next, this enables reliable estimation of the operation time of fully electric ferries, where little time is spent at the harbour, with limited time available for charging. Thus, battery management systems are essential. This paper presents a neural network model of battery SOC estimation, using a long short-term memory (LSTM) recurrent neural network (RNN) as a method for accurate estimation of the SOC in lithium-ion batteries. The current, voltage and surface temperature of the batteries are used as the inputs of the neural network. The influence of different numbers of neurons in the neural network’s hidden layer on the estimation error is analysed, and the estimation error of the neural network under different training times is compared. In addition, the hidden layer is varied from 1 to 3 layers of the LSTM nucleus and the SOC estimation error is analysed. The results show that the maximum absolute SOC estimation error of the LSTM RNN is 1.96% and the root mean square error is 0.986%, which validates the feasibility of the method.


INTRODUCTION
Shipping is generally the most energy-effective mode of global mass cargo transportation. Nevertheless, the air pollution from shipping is still growing, while land-based emission is gradually declining. This is becoming a driving factor for the development of innovative and ecofriendly technologies for shipping [1]. One of the solutions is the largescale introduction of energy storage technologies, particularly using Li-ion batteries with high energy storage capacity [2]. The use of batteries onboard vessels is growing rapidly, leading to the development of ships with hybrid power systems or fully all-electric ships (AES), which are charged when in harbour, or back zero-emission sources like fuel-cells, solar panels, thermo-electric generators, wind energy conversion systems etc. [3][4][5]. In the former, due to the limited time spent in dock, high-power wireless charging technologies are being developed [2,6]. The number of AES is increasing rapidly and they are becoming a promising tool for reducing greenhouse gas emissions and the dependency on fossil fuels [3,4]. An example of a scheme for future zero emission AES, incorporating a lithium-ion battery pack, fuel-cell stack, super-capacitor bank and a photovoltaic (PV) power system, is shown in Fig. 1 [7].
With the advantages of high energy density, long service life and low self-discharge rate, lithium-ion batteries are becoming an important part of the energy source capacity in the AES. There are two main factors, when dealing with such energy storage systems: optimal sizing [8] and SOC assessment. The SOC of lithium-ion batteries is the main basis for power management and control strategies. It plays a very important role in battery protection, working efficiency and service life extension as well as quality of service assessment, leading to an increase in the safety of the entire AES. Therefore, accurate estimation of the SOC of the batteries is essential for their efficient use and energy management throughout all ship services.

Fig. 1. Schematic diagram of a future zero-emission all-electric ship
Currently, methods of SOC estimation are divided into three categories. The first category directly predicts the SOC based on the voltage, current or internal resistance of the batteries. The main methods of this category include the ampere-time integration method, the open circuit voltage method and the estimation method based on the internal resistance of the batteries [9][10][11]. The second category is based on an algorithmic estimation of equivalent battery models, such as the sliding mode observer [12] and the Luenberger observer [13]. The third category is the machine learningbased prediction method developed nearly five years ago, mainly including the support vector machine [14,15], extreme learning machine [16], RBF kernel function neural network [17], recurrent neural network RNN [18], and other less popular solutions.
The ampere-time integration method achieves SOC estimation by measuring and integrating the current, but it cannot solve the cumulative error and the inaccurate SOC initial value problem [19]. The disadvantage of the open circuit voltage method is that SOC estimation requires the battery to stand for a long time and is not suitable for online measurement [20]. The internal resistance method is rarely used because of the difference in the number and consistency of battery types [21].
The equivalent battery models generally use the equivalent resistance and capacitance to simulate the dynamic response of the battery, but ignore the physical and chemical reactions inside the battery unit. When the battery is over-charged or over-discharged causing severe physical and chemical reactions, the equivalent model cannot then be used to represent the real battery model [20]. This method is computationally intensive, and requires additional parameters or different battery models to estimate the SOC in different environments in practical applications. In [21], the adaptive sigma-point Kalman filter for optimising the battery model is used to estimate the SOC, but it only partly reduces the disadvantages of the complexity of the battery model and requires computational effort. In addition, improved algorithms such as the Gray extended Kalman filter [22] and a square root unscented Kalman filter [23] have been proposed. Such Kalman filtering algorithms rely on high-precision battery models and result in increased computational complexity [24].
Researchers have also used a machine learning-based prediction method to perform SOC estimation, which relies on traditional machine learning techniques. In [25], SVM technology is used for SOC estimation. In [26], researchers use the extreme learning machine algorithm for SOC estimation. Traditional machine learning techniques have common defects, and the training speed is slow and easily falls into the local minimum point. In view of the shortcomings of the above three types of methods, this paper uses the long short-term memory (LSTM) cell based recurrent neural network (RNN) to reduce the absolute error of SOC estimation to less than 2% [27]. In an extension of [27], the paper investigates the impact of the LSTM RNN properties on the estimation accuracy. It uses more experiments and additional factors for performance evaluation.
In recent years, with the continuous development of deep learning technology, some deep learning models have been gradually applied to the study of time series data. The deep learning model is a deep learning neural network model with multiple non-linear implicit levels. It can abstract the input signal layer by layer and extract features to dig deeper potential laws [28]. In real life, deep learning is used in content filtering of search engines, social media personal preference analysis and natural language processing on various portable smart devices. The prediction methods used in these successful deep learning application cases can be attributed to a branch of the artificial neural network, which is called the recurrent neural network with long short-term memory (LSTM) cells. This paper will use the recurrent neural network with LSTM cells as a new machine learning technology, which can estimate the battery's SOC by learning the parameters such as network weight and offset. The SOC cannot be directly measured but there is non-linear correlation between the SOC and easily measurable signals like the voltage, current and surface temperature. The three parameters have no correlation in terms of the battery's physical characteristic. This technology can accurately map various items of information measured from the battery, such as the voltage, current and battery surface temperature, to the state of charge of the battery [27]. It avoids the cumbersome parameter estimation process such as the Kalman filter during the training process. Only information about the number of hidden layer neurons, the batch size, the number of iterations, and the number of LSTM nuclei during training is required to obtain the optimal model. An LSTM recurrent neural network can derive different network parameter models under different operating conditions, different input parameter variables and even different battery types. This process only needs to sample a different type of battery to obtain a certain amount of training data.

LSTM RECURRENT NEURAL NETWORKS MODEL
Recurrent neural networks are different from BP neural networks or other conventional machine learning neural networks, where the current input parameter to the neural network is to calculate the output of the current time. Recurrent neural works can transmit a series of information from the previous time to the current time. The RNN standard model and expansion model are shown in Fig. 2. When the input enters a sequence x=(x 1 , x 2 … x t ), a hidden layer sequence h=(h 1 , h 2 … h t ) can be calculated by Eq. (1). The input sequence and hidden layer sequence can calculate an output sequence y=(y 1 , y 2 … y t ) using Eq. (2). Eq. (1) and Eq. (2) have been described in [27,29]: where f(.) represents the activation function, subscript t denotes the time, W is the network weight coefficient and b is the offset vector [29].

. RNN standard model and expansion model
Although the RNN can effectively deal with non-linear time series over time, recurrent neural networks will generate a series of problems, such as gradient descent or gradient explosion, which will lead to the loss of effective information in the early stage or cause an error in the estimate by invalid information. Therefore, the LSTM recurrent neural networks are applied, and the RNN cell nuclei of the traditional recurrent neural networks are replaced with LSTM cell nuclei, which have long-term memory ability. This solves the problem of predicting and estimating long-term data with better success. The LSTM cell nuclei are shown in Fig. 3 [29].

Fig. 3. LSTM cell nuclei structure
In the LSTM cell nuclei, C t is the state unit of the LSTM, which runs through the entire cell. The LSTM cell is able to fill the state unit with effective information or remove invalid information. The structure used in the process is called the threshold. The threshold consists of a sigmoid function and matrix point multiplication. The sigmoid function outputs a number between 0 and 1, describing the extent to which each item of information passes the threshold, where 0 means that all information is prohibited and 1 means that all information passes. There are three thresholds in the entire LSTM cell, namely the forgetting gate f, the input gate i and the output o. The forward propagation of the LSTM neural networks can be expressed by the following formula [27,29]: where the initial state matrix of the hidden layer is set to an all-zero matrix, δ and tanh represent the sigmoid activation function and the double-tangent activation function, i t represents input at time t, f t represents forget at time t, o t represents output at time t and c t represents the state of the cell. W represents a matrix of weight coefficients between different layers (for example, W xi represents the weighting matrix of the input layer to the input threshold i), b represents the bias term of the different layers (for example, b i represents the bias term of the input threshold i). The training framework is based on an LSTM battery. The SOC model includes input layers, hidden layers and output layers, where the input layer characterises the input variables, the hidden layer can be one or more LSTM cell nuclei, and the output characterises the output variables. The fully connected layer realises the hidden layer's linear output h t according to the combination of the weight W and the offset b, and then the output value at time t can be obtained through the output layer.

Start
Step 1: Initialize the weights and offsets of the network, set the number of hidden layer neurons, learning rate, number of iterations, number of LSTM cells, time step and number of iterations Step 2: The network performs forward propagation to calculate the output of the network hidden layer and the output layer.
Step 3: The network performs backpropagation, calculates the error of the hidden layer and the output layer and finds the partial guide Step 4: Update the network weights and offsets using the partial derivative obtained by backpropagation As shown in Fig. 4, after the LSTM recurrent neural network performs forward propagation, the error function is used to calculate the error between the network output value and the true value by Eq. (4): where T represents the entire sequence length selected by the SOC estimation, and SOC t and SOC t * represent the estimated and true values of the battery SOC at time t respectively. In each training iteration, the LSTM recurrent neural network performs backpropagation, using the Adam [30] optimisation method to update the weights and offsets of the network as presented in Eq. (5): where L represents the error function, the attenuation coefficients β 1 and β 2 are usually set between 0.9 and 0.999, the learning rate α is generally set to 0.0001, the constant number θ is 10 -8 , and W ξ is the weight matrix. Finally, the number of training iterations reaches the preset maximum number, signifying the end of the trained model. This trained model, which now meets the performance requirements, is saved and later selected for future prediction.

EXPERIMENTAL TESTING AND DATA PREPROCESSING EXPERIMENTAL TESTING
In this paper, the battery unit used is similar to that of the Tesla Electric Vehicle. The NCR18650PF lithium-ion battery produced by Panasonic Corporation is investigated as the experimental object. The rated capacity of the battery is 2.9 A⋅h and the rated internal resistance is 35 mΩ. See Table 1 for further battery specifications. The established single-cell battery test bench is shown in Fig. 5. It consists mainly of a single-section Panasonic 18650 lithium-ion battery, a Chroma charger, a WT1600 power meter, and a temperature acquisition unit. The Chroma charger can charge the lithium-ion battery according to the set voltage and current. The WT1600 power meter can realise the battery voltage and current collection function. All experiments were performed at room temperature.
In order to obtain battery discharge data for training and verification of the LSTM recurrent neural network, the battery is charged using the 4.2 V/2.9 A charging mode. When the battery voltage reaches 4.2 V, the charging current reduces to 50 mA, indicating that the battery is fully charged. After the charging process is completed, the battery is allowed to stand at room temperature for 1 hour, and a constant value 0.5 Ω resistor is used to discharge the battery. The discharge of the battery is recorded. When the battery voltage drops to 2.5 V, the battery power is completely discharged. The battery is allowed to stand for another hour again, the charge and discharge test is repeated, and the data are recorded. The voltage, current and the surface temperature change of the battery in a single discharge phase are as shown in Fig. 6. At room temperature, the battery has been charged and discharged five times. Four sets of data are used to train the LSTM neural network. The remaining group is used as the test set of the LSTM neural network to test the trained neural network's accuracy. The SOC estimation result based on the LSTM recurrent neural network model is compared with the real value. The following formulae are used to evaluate the performance of the SOC prediction model based on the LSTM recurrent neural network: the root mean square error RMSE, the mean absolute error MAE, and the maximum absolute error MAX.
I esi represents the estimated value, I ai is the actual value, and N is the number of observations.

DATA PREPROCESSING
LSTM neural network training selects three important factors, including the voltage, current, and battery surface temperature. Through proper data preprocessing, the training data of the network will be more effective and robust. The arithmetic average filtering algorithm is used to smooth out each set of raw data, and then all the data are normalised to improve the convergence speed of the network model training. The input and output are normalised to a range between 0 and 1 using the following formula: where x max and x min are the maximum and minimum values of the LSTM neural network input vector.

RESULT AND ANALYSIS
As described in the previous chapter, the LSTM neural network input is X t and the output is SOC t . The SOC t is the measured value of the battery state of charge at time t, and X t represents the input of the neural network at time t, which is a vector X t =[V t , I t , T t ], including the battery voltage V t , battery current I t , and battery surface temperature T t . After the training process, the neural network can self-learn the entire network parameters for later actual estimation, as illustrated in Fig. 7. In this paper, 5 sets of battery discharge data were collected at room temperature, 4 groups were used as the training set to train the neural network, and 1 group was used as a verification set to verify the accuracy of the saved model. This means that 20% of the 5 groups of data is proposed as testing data. So, 20% of all the input data, measured by the unit of batch size, serves as a predictor of reliability, which seems sufficient for the purpose.
The LSTM neural network is set to a single-layer LSTM cell. After debugging, the number of hidden layer neurons is set to 320, the batch size is 200, and the maximum number of iterations is 200, which produced the best result in the practical project of lithium-ion battery SOC prediction. The neural network is trained with four sets of data for a total time of 117s. The obtained model is used for the verification set. The maximum absolute error, MAX, in the final prediction result is 1.96%, while the mean absolute error, MAE, and the root mean square error, RMSE, are 0.455% and 0.986%, respectively. It is noted that the predicted value deviates from the true value to a small extent. The performance of the SOC estimation model based on the LSTM neural network is shown in Fig. 8

INFLUENCE OF HYPER-PARAMETERS OF LSTM NEURAL NETWORK ON SOC PREDICTION RESULTS
The number of hidden layer neurons n and batch size B s are important hyper-parameters of the LSTM neural network, in which batch size B s is divided into several small batch data to be input into the neural network. These are the two main hyper-parameters, whose adjustments have an important influence on the accuracy of the LSTM neural network SOC prediction.
Firstly, the hidden layer is set to single-layer LSTM cell cores, the batch size is set to 512, the maximum number of iterations is set to 200, and the numbers of hidden layer neurons are set to 80, 260, and 440, respectively. Next, the total training time of the neural network, the maximum absolute error MAX, the mean absolute error MAE, and the root mean square error RMSE are selected to evaluate the prediction results, as shown in Fig. 9.
As the number of neurons n increases, the training time of the entire SOC prediction network model increases. The MAE and the RMSE show a moderately downward trend. Nevertheless, the increase in the number of neurons as a whole reduces the two errors. Fortunately, the MAX error drops significantly. When n=80, the MAX is greater than 6%. When n=440, the MAX is less than 4%. In order to achieve good accuracy and reliability of the SOC prediction model while also considering the model training time, the number of neurons in the hidden layer LSTM nuclear unit should be appropriately increased.
To further verify the effect of the batch size on the SOC prediction results, the hidden layer is set to a single-layer LSTM cells nucleus. The number of hidden layer neurons is set to 200, the maximum number of training iterations is set to 200, and the batch size is set to 200, 356, and 512, respectively. The results from the LSTM neural network prediction and the prediction errors trained for the different batch sizes are shown in Fig. 10.  Table 2 shows that, as the batch size increases, the total training time of the neural network decreases. At the same time, the increase of the batch size will increase the maximum absolute error, but the overall root mean square error and the average mean error will be reduced, which improves the overall accuracy of the model prediction. In order to reduce the model training time, the batch size should be increased, taking into account the maximum absolute error limit of SOC prediction. However, the batch size cannot be increased too much, or else the maximum absolute error of SOC prediction will exceed 5%, resulting in inaccurate SOC prediction.

INFLUENCE OF THE NUMBER OF LSTM NUCLEI ON SOC PREDICTION RESULTS
The LSTM neural network can be designed for multiple LSTM nuclei in the hidden layer. In order to reflect the influence of multiple LSTM nuclei on the SOC prediction results, the number of neurons in the hidden layer of a single LSTM cell is set to 320, the batch size is set to 400, and the maximum number of training iterations is set to 200, while the hidden layer is changed from 1, 2, and 3 LSTM nuclei, and the SOC prediction error is obtained for different numbers of LSTM nuclei in the hidden layer. The SOC prediction results are obtained for the hidden layers with different numbers of LSTM nuclei. The performance of the model is shown in Fig. 11. When the LSTM hidden layer is designed as one or two LSTM nuclei, the SOC prediction error can be guaranteed to be less than 4%. When the hidden layer is selected as three LSTM nuclei, the error of the trained SOC prediction model is large. After the SOC reaches 40%, the prediction error is larger than 5%, and accurate prediction of the SOC cannot be achieved. Therefore, the designed number of hidden layer LSTM nuclei should be less than 3, or else the trained prediction model will be over-fitted and a good prediction result cannot be attained.

CONCLUSION
The SOC prediction error of a lithium-ion battery and an SOC prediction method based on an LSTM neural network for the same has been investigated. This paper aims to solve three problems. Firstly, it solves the problem of the battery physics modelling used for SOC prediction in the past and uses the LSTM neural network to directly map battery-related measured values (such as voltage, current and temperature) to the SOC. Secondly, the solution can free researchers from manual calculation of the battery model parameters or estimation algorithms such as those in the Kalman filter algorithm. The LSTM neural network can use the data collected from the original training to train the neural network to self-learn all network parameters. The third contribution lies in the accuracy of the battery SOC prediction. Through experimental verification, the maximum absolute error of the established prediction model is less than 2%, which is lower than the actual application requirement of 5%, thus meeting the practical application requirements. In summary, the LSTM neural network has been experimentally validated and has achieved good performance. It has proven to be a powerful tool for estimation of the SOC of lithium-ion batteries and may be another diagnostic strategy for batteries for consideration in future work. Considering the amount of data generated by the energy storage system, it is natural to consider machine learning algorithms to perform state and parameter estimation. This paper shows how these algorithms self-learn the parameters of the prediction model, even if exposed to scarce data sets, in order to achieve competitive evaluation performance. As a result, the proposal can be a powerful tool supporting the management of power systems onboard the ever-increasing number of ships with energy storage facilities containing lithium-ion batteries. This is relevant to ships with hybrid power systems and fully electric ships, especially those utilising various charging technologies in dock. The necessary docking time can be optimised by improving ferry fleet management.