An Open-Source and Reproducible Implementation of LSTM and GRU Networks for Time Series Forecasting
Gissel Velarde, Pedro Brañez, Alejandro Bueno, Rodrigo Heredia, Mateo Lopez-Ledezma · 2025
Read An Open-Source and Reproducible Implementation of LSTM and GRU Networks for Time Series Forecasting by Gissel Velarde, Pedro Brañez, Alejandro Bueno, Rodrigo Heredia, Mateo Lopez-Ledezma (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2504-18185.txt.
Introduction
Gissel Velarde and four co-authors released in 2025 an open, reproducible implementation of two classic sequence-forecasting networks. The two designs, LSTM and GRU, are staples for predicting time series, yet published results often cannot be rerun because code and settings vanish. Their package fixes the pipeline in public.
Tests ran on Indian bank stock prices and on synthetic weekly activity patterns. Error and direction accuracy were reported for both nets. One well-chosen series could train the models when patterns repeat across a set, a thrifty finding for small teams with thin data.
Catalog record
| CREATOR | Gissel Velarde, Pedro Brañez, Alejandro Bueno, Rodrigo Heredia, Mateo Lopez-Ledezma |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 20 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2504-18185
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
An Open-Source and Reproducible Implementation of LSTM and GRU Networks for Time Series Forecasting Gissel Velarde, Pedro Brañez, Alejandro Bueno, Rodrigo Heredia, Mateo Lopez-Ledezma Abstract This paper introduces an open-source and reproducible implementation of Long Short-Term Memory (LSTM) and Gated Recurrent Unit (GRU) Networks for time series forecasting. We evaluated LSTM and GRU networks because of their performance reported in related work. We describe our method and its results on two datasets. The first dataset is the S&P BSE BANKEX, composed of stock time series (closing prices) of ten financial institutions. The second dataset, called Activities, comprises ten synthetic time series resembling weekly activities with five days of high activity and two days of low activity. We report Root Mean Squared Error (RMSE) between actual and predicted values, as well as Directional Accuracy (DA). We show that a single time series from a dataset can be used to adequately train the networks if the sequences in the dataset contain patterns that repeat, even with certain variation, and are properly processed. For 1-step ahead and 20-step ahead forecasts, LSTM and GRU networks significantly outperform a baseline on the Activities dataset. The baseline simply repeats the last available value. On the stock market dataset, the networks perform just like the baseline, possibly due to the nature of these series. We release the datasets used as well as the implementation with all experiments performed to enable future comparisons and to make our research reproducible. 1 Introduction Artificial Neural Networks (ANNs) and particularly Recurrent Neural Networks (RNNs) gained attention in time series forecasting due to their capacity to model dependencies over time [ 10 ] . With our proposed method, 1 1 1 The code and datasets are available at: https://github.com/Alebuenoaz/LSTM-and-GRU-Time-Series-Forecasting [ 12 ] . we show that RNNs can be successfully trained with a single time series to deliver forecasts for unseen time series in a dataset containing patterns that repeat, even with certain variation. Therefore, once a network is properly trained, it can be used to forecast other series in the dataset if adequately prepared. LSTM [ 7 ] and GRU [ 4 ] are two related deep learning architectures from the RNN family. LSTM consists of a memory cell that regulates its flow of information thanks to its non-linear gating units, known as the input, forget and output gates, and activation functions [ 6 ] . GRU architecture consists of reset and update gates, and activation functions. Both architectures are known to perform equally well on sequence modeling problems, yet GRU was found to train faster than LSTM on music and speech applications [ 5 ] . Empirical studies on financial time series data reported that LSTM outperformed Autoregressive Integrated Moving Average (ARIMA) [ 11 ] . ARIMA [ 3 ] is a traditional forecasting method that integrates autoregression with moving average processes. In [ 11 ] , LSTM and ARIMA were evaluated on RMSE between actual and predicted values on financial data. The authors suggested that the superiority of LSTM over ARIMA was thanks to gradient descent optimization [ 11 ] . A systematic study compared different ANNs architectures for stock market forecasting [ 2 ] . More specifically, the authors evaluated architectures of the types LSTM, GRU, Convolutional Neural Networks (CNN), and Extreme Learning Machines (ELM). In their experiments, two-layered LSTM and two-layered GRU networks delivered low RMSE. In this study, we evaluate LSTM and GRU architectures because of their performance reported in related work for time series forecasting [ 11 , 2 ] . Our method is described in section 2 . In sections 2.1 , 2.2 , and 2.3 , we review principles of Recurrent Neural Networks (RNN) of the type LSTM and GRU. In section 2.4 , we explain our data preparation, followed by the networks’ architecture, training (section 2.5 ), and evaluation (section 2.6 ). The evaluation is done on two datasets. In section 3.1 , we describe the S&P BSE-BANKEX or simply BANKEX dataset, which was originally described in [ 2 ] and consists of stock time series (closing prices). In section 3.2 , we describe the Activities dataset, a dataset composed of synthetic time series resembling weekly activities with five days of high activity and two days of low activity. The experiments are presented in section 3 . Finally, we state our conclusions in section 5 , and present possible directions for future work. We release the datasets used as well as the implementation with all experiments performed to enable future comparisons and make our research reproducible. 2 METHOD The general overview of the method is described as follows. The method inputs time series of values over time and outputs predictions. Every time series in the dataset is normalized. Then, the number of test samples is defined to create the training and testing sets. One time series from the train set is selected and prepared to train a LSTM and a GRU, independently. Once the networks are trained, the test set is used to evaluate RMSE and DA between actual and predicted values for each network. The series are transformed back to unnormalized values for visual inspection. We will describe every step in detail. Next, in sections 2.1 , 2.2 , and 2.3 , we review principles of RNNs of the type LSTM and GRU, following the presentation as in [ 5 ] . Figure 1: LSTM (left) and GRU (right). c represents the memory cell and \tilde{c} the new memory cell of the LSTM. h represents the activation and \tilde{h} the new activation of the GRU. Based on [ 5 ] . 2.1 Recurrent Neural Networks ANNs are trained to approximate a function and learn the networks’ parameters that best approximate that function. RNNs are a special type of ANNs developed to handle sequences. A RNN updates its recurrent hidden state h_{t} for a sequence x=(x_{1},x_{2},...,x_{T}) by: h_{t}=\left\{\begin{matrix}0,&t=0\\ \phi(h_{t-1},x_{t}),&otherwise,\end{matrix}\right. (1) where \phi is a nonlinear function. The output of a RNN maybe of variable length y=(y_{1},y_{2},...,y_{T}) . The update of h_{t} is computed by: h_{t}=g(Wx_{t}+Uh_{t-1}), (2) where W and U are weights’ matrices and g is a smooth and bounded activation function such as a logistic sigmoid, or simply called sigmoid function f(x)=\sigma=\frac{1}{1+e^{-x}} , or a hyperbolic tangent function f(x)=tanh(x)=\frac{e^{x}-e^{-x}}{e^{x}+e^{-x}} . Given a state h_{t} , a RNN outputs a probability distribution for the next element in a sequence. The sequence probability is represented as: p(x_{1},x_{2},...,x_{T})=p(x_{1})p(x_{2}\mid x_{1})...p(x_{T}\mid x_{1},x_{2},...,x_{T-1}). (3) The last element is a so called end-of-sequence value. The conditional probability distribution is given by: p(x_{t}\mid x_{1},x_{2},...x_{t-1})=g(h_{t}), (4) where h_{t} is the recurrent hidden state of the RNN as in expression ( 1 ). Updating the network’s weights involves several matrix computations, such that back-propagating errors lead to vanishing or exploding weights, making training unfeasible. LSTM was proposed in 1997 to solve this problem by enforcing constant error flow thanks to gating units [ 7 ] . GRU is a closely related network proposed in 2014 [ 4 ] . Next, we review LSTM and GRU networks. See Figure 1 for illustration. 2.2 Long Short-Term Memory The LSTM unit decides whether to keep content memory thanks to its gates. If a sequence feature is detected to be relevant, the LSTM unit keeps