1. Introduction
Long short-term memory models got a significant upward trajectory of use after its pioneering paper [1]. The main goal of its design was to avoid the problems of simple recurrent neural networks and to obtain better results. It is widely preferred over GARCH models have been generalized and applied in wide areas to solve real-world problems at the level of time series that have high frequencies after the pioneering papers of [2] [3], through the great importance implied by these models and their ability to model variable fluctuations Over time and filling the gap in ARIMA models [4], but the problem of not taking the random evolution of fluctuations and relying only on deterministic evolution caused the incomplete validity of the predictions of these models
The problem also lies in these data as a result of the validity of their predictions for short-term periods and the inability to obtain all the information from the chain Temporal, and therefore from here comes the need to use deep learning models represented by LSTM model and its developments, which allows obtaining more information from the series, no matter how high the noise, and producing better predictions [5] [6] [7] [8].
The aim of designing and used LSTM networks is to reduce long-term dependency and its negative impact on the learning process. In addition to the four gates that the network depends on for its work, it helps the network to remember the most important information, which greatly improves the quality of the output. One area of use of the LSTM model is to predict stock values and returns in financial markets [9], it has also been used in traffic flow forecasts such as [10], LSTM models have been used in the field of forecasting ability of Solar Irradiance and Photovoltaic Power [11]. Moreover, Water quality analysis and forecasting, like [12].
The use of LSTM models has also developed in the environmental field, as a result of the large climate changes, it refers to long-term shifts in temperatures and weather patterns, Human activities have become the main cause of climate change, mainly due to the burning of fossil fuels, such as coal, oil and gas. Some of the effects of climate change are: higher temperatures - destructive storms - increased drought - loss of species - food shortages. The contribution of renewables to the economy is tested through the structure through the LSTM model [13], they have also been used to capture the precise spatio-temporal relationships of multiple meteorological features for temperature prediction [14]. [15] Use long short-term memory (LSTM) model to capture the dependence between historical climate data. [16] proposed a rainfall-runoff analysis system for the Kratie station on the Mekong River mainstream using the long short-term memory (LSTM) model, forecasting method is proposed based on meteorology data of next day for ideal weather condition, using long short term memory (LSTM) networks [17], [18]formulates the prediction problem as a structured output prediction problem jointly predicting multiple outputs simultaneously. The proposed prediction model is trained by using long short-term memory (LSTM) networks taking into account the dependence between consecutive hours of the same day. As utilized LSTM to obtain a data-driven forecasting model for an application of weather forecasting [19].
Despite the wide use of LSTM models, they contain a set of problems that may in some cases lead to the loss of part of the information and the failure to produce accurate predictions [20]. One of the problems is called the "sequence-to-sequence problem [21] [22] [23], which is called seq2seq for short. This problem can be described as the number of sequence elements at the time of input differs from the number at the time of output, which leads to the loss of important information. Encoder – Decoder LSTM models are widely used because of their superiority in the fields used to solve this problem [24]. Nevertheless, with a long sequence of inputs, as in the case of time series, the ED LSTM model encodes a fixed length input sequence [25]. This imposes limits on the length of input sequences that are in the learning phase and causes worse performance for long input sequences. Attention is used with the aim of freeing the decoder structure from its internal fixed-length representation [26].
Through this research, we aim to examine the future behaviors of climatic weather data like Max Temperature, Min Temperature, Relative Humidity (M), and Relative Humidity (E) And Bright Sun Shine Hours in the Narmadapuram district. Using Encoder-Decoder and Attention based on LSTM Model, This is done by comparing the predictive performance of the two models using a set of performance indicators for both the training and test data. This study attempts to elucidate whether imposing length restrictions on input sequences in the learning phase causes worse performance for long input sequences. The research includes four sections. This study also seeks to provide the National Informatics Center in the district with weather information in light of climate changes and the maximum and minimum of this information. This is in order to preserve the agricultural environment, being a major producer of wheat, and the diversity of livestock, and thus the possibility of planning to face challenges. The first section includes the introduction and previous studies. The second section explains the study methodology and the tools used. The third section includes a discussion of the results, and the fourth and final section contains the results of the research.
2. Materials and Methods
A. Data and study area
The data was taken from the climate monitoring stations in Narmadapuram. data.csv file contains 6 columns (Date, Max Temperature (°C), Min Temperature (°C), Relative Humidity M, Relative Humidity E, and Bright Sun Shine Hours) and 8155 rows for daily data. Functions for training and testing Datasets were constructed based on the original dataset and the number of previous time steps used as input variables to forecast the future time period (i.e., look back), which are the two major variables. Datasets were constructed with the default setting of creating datasets with the number of observations (X) and look-backs at each point in time (t + look back). During training, we utilized a look-back value of eight days. In order to create the LSTM model, the data has to be transformed. The final format included [samples, time steps, and features]. "Looking back to the previous day’s information, the samples were made up of information from that day’s data, and the time step was one day (the data was gathered daily). We divided the data into two sets: one for training and the other for testing. 80% of the observations were used for training, while the remaining 20% were used for testing. Afterward, we preserved the test set and randomly selected 80% of the training set as the new training set, while the rest (20%) was the validation set. You can download datasets and code from GitHub. (https://github.com/abotalebmostafa11/climate)
The Location of Narmada Puram are 22.75°N and 77.72°E. In central India, the region experiences high temperatures. There is a hot, dry summer with a high of 40–42 °C close to the Tropic of Cancer (April–June). After that, there will be a monsoon with lots of rain. The winters are moderate and dry (November to February). 331 meters (1,086 feet) above sea level is the average elevation, and 134 cm of rain falls there annually (53 inch). Figure. 1 show location map of study area
3. Methodology
Long Short Term Memory LSTM:
When solving the problem of vanishing gradients, long short-term memory (LSTM) was one of the earliest and most effective methods to be developed [27] [28]. In this context, "long-term" refers to simple recurrent neural networks storing information about their previous decisions as weights. A gradual shift in weights occurs throughout training when new information about the data is retrieved and used to calibrate the model. Short-lived activations hop from one node to another and are therefore referred to here. In the LSTM paradigm, a memory cell serves as intermediate storage. For the first time, multiplex nodes are incorporated into the construction of memory cells, making them a more complicated unit. Three gates (input, output, and forget) make up a generic LSTM unit [29]. With the input gate, LSTM may be programmed to either retain existing data or learn new information. The sigmoid layer and the tanh layer make up this gate's structure. The tanh layer generates a vector of potential new values to be added to LSTM [30], whereas the sigmoid layer specifies which values will be modified. To derive the final result from these layers, we use:
where 𝒊𝒕 is the updated value; 𝒖𝒕 is new candidate values; 𝝈 is the sigmoid layer (or nonlinear function); 𝒙𝒕 is a sequence of length t; 𝒃 is constant bias; 𝒉 is RNN memory at time step t; and 𝑾 and 𝑼 are weight matrices.
Forget gates, whose sigmoid functions are used to choose data for deletion from LSTM, are discussed in detail in [31]. The values of h and 𝒙𝒕 are used heavily in making this determination. This gate has an output f that may take on the values 0 and 1, where 0 signifies full erasure of the acquired value and 1 represents complete preservation of the value. This result is derived by:
where 𝒇𝒕 is updated value; 𝝈 is the sigmoid layer (or nonlinear function); 𝒙𝒕 represents a sequence of length t; 𝒃 is constant bias; 𝒉 represents RNN memory at time step t; and 𝑾 and 𝑼 are weight matrices.
The input gate uses a sigmoid layer to determine which sub-tree of the LSTM is responsible for the output. A nonlinear tanh function is then used to assign values between -1 and 1 after that. The output from the sigmoid layer is then multiplied by the final product. Following are some formulae that are used to determine output:
where 𝒐𝒕 is an output gate and 𝒉𝒕 is a value between [1, -1].
The LSTM is kept current by combining these two layers. The forget gate layer works by first doubling the previous value, 𝒄𝒕−𝟏, and then adding the candidate value, 𝒊𝒕𝒖𝒕, to forget the current value. Specifically, this process requires the following equation:
where 𝒄𝒕 represents a memory cell and 𝒇𝒕 represents a value between 0 and 1 produced by the forget gate. Specifically, a value of 0 denotes that the value is nullified, whereas a value of 1 indicates that it is retained [32]. Figure 8 depicts a potential configuration including these components.
Figure 2 explains us the mechanism work of LSTM model, the input information is passed to the forget layer, at which point the model decides to: (a) keep the information in the past and use it for prediction, or (b) forget the information and rely on the instantaneous state, then send this information to a tanh function to normalize the information and extract features and patterns and remove noise from them [33]
Encoder-Decoder LSTM:
Encoder – Decoder LSTM model were primarily designed to address the sequence-to-sequence problem, which is called seq2seq for short. This problem can be described as the number of sequence elements at the time of input differs from the number at the time of output, which leads to the loss of important information [34]. The modeling problem in this case is that the length of the input sequence may differ from the length of the output sequence due to the multiple lengths of the input and output steps. Accordingly, Encoder – Decoder LSTM is used, which is one of the methods that have proven effective to avoid the problem of seq2seq [35].
This architecture is comprised of two models: one for reading the input sequence and encoding it into a fixed-length vector, and a second for decoding the fixed-length vector and outputting the predicted sequence [36] [37]. Which can be merged of Encoder-Decoder LSTM designed specifically for seq2seq problems.
The main objective of the coding phase is to extract more features and information from the input time series data. The data of an asymmetric sequence of length 𝑋= {𝑥1, 𝑥2, . . 𝑥𝑡} is used as input and the encoder encodes the sequence into a fixed-length state vector𝒄, which is used as input to the decoder [38]. In the decoder stage, the decoder decodes the state vector 𝒄 and predicts the next time sequence 𝒀 by integrating the input data for the current time.
Figure 3 show us the mechanism work of Encoder – Decoder LSTM model, the hidden layer state h is evolved each time the input data is read. When reading the end of the sequence X, the hidden layer variable 𝒄, can be thought of as a summary of the input sequence. Which means that the features and information in the sequence have been extracted and mapped in 𝒄.
Attention LSTM:
Encoder – Decoder LSTM models are widely used because of their superiority in the fields used. However, with a long sequence of inputs, as in the case of time series, the ED LSTM model encodes a fixed length input sequence [25]. This imposes limits on the length of input sequences that are in the learning phase and causes worse performance for long input sequences [39] [40].
Attention is used with the aim of freeing the decoder structure from its internal fixed-length representation. The attention mechanism allows obtaining different information of first-order and lower-order importance and not just the first-order important information. It is described as mapping a query and a set of key-value pairs to an output, where the query, keys, values, and output are all vectors [41]. The output is computed as a weighted sum of the values, where the weight assigned to each value is computed by the query's compatibility function with the corresponding key [42]. There are also the same technique using in machine learning models .
Figure 4 show us how attention LSTM work, it include The first step, we map 𝑥𝑡 to ℎ𝑡:
Where 𝑓 is nonlinear activation function, ℎ𝑡 𝑅𝑡 𝑠 is hidden state at time t, s is size of hidden state, in the second step, an attention mechanism is built through a stochastic attention model. For a particular feature sequence𝑥𝑘= (𝑥1 𝑘). From the previous hidden state ℎ𝑡−1 and cell state 𝒄𝒕−𝟏in the LSTM unit, it is determined [43]:
where𝑉: is vector, 𝑊1 and 𝑊2 are matrices and both learnable parameters by model. 𝑎𝑡 𝑘: is vector has length m and its ℎ𝑡−𝑖 measures the importance of ℎ𝑘−𝑖 input features sequence at time t. and normalized by softmax. 𝛽𝑡 𝑘: is an attention weight, which contains a score of how much attention should be put on ℎ𝑘−𝑖 feature sequences.
From Figure 5, the different information in the sequence length is sent to the Softmax function to calibrate to uniform weights. Accordingly, the output of the attention model at time t of weighted input feature 𝑢𝑡is as follows:
Thus, the x in equation 1 is replaced by the weights 𝑢𝑡in the current equation to develop the attention model. It is possible to obtain attention-based time series with better features than input sequence elements.
Performance indicators:
We use indicators to evaluate the performance of the models used to determine their ability to explain the features and information contained in the data. This is done by examining the extent to which the estimated values using the model correspond to the actual values, taking into account the avoidance of an under fitting problem that may appear from the training data, and an over fitting problem that appears through the test data. The following performance indicators include:
^ the forecast is value; 𝒚𝒕 is the actual value; and 𝒏 is the number of fitted observed. The smaller the values of these indicators, the better the performance of the model.
Where 𝒚𝒕
4. Results
Daily data collected for Narmadapuram district between November 1, 1977 and April 30, 2022 was divided into two parts: training (80%) and testing (20%).
From November 1, 1977 to April 30, 2022, the MAX Temperature in Narmadapuram district has increased during the period from (8 °C) to (45.6 °C). Average MAX Temperature in Narmadapuram district was (26.19 °C). Kurtosis value was (-0.26) and the value of skewness was (0.37) which is close to 0.5 indicating the distributions is mesokurtic. The MIN Temperature in Narmadapuram district has increased during the period from (-3.5 °C) to (30.5 °C). Average MIN Temperature in Narmadapuram district was (9.53 °C). Kurtosis value was (-0.30) and the value of skewness was (0.45) which is close to 0.5 indicating the distributions is mesokurtic. The Relative Humidity (M) in Narmadapuram district has increased during the period from (11%) to (100%). Average Relative Humidity (M) in Narmadapuram district was (85.47%). Kurtosis value was (2.47) indicating that the distribution is flat and has thin tails (Platykurtic distributions) and the value of skewness was (-1.58), the negative skew refers to a longer or fatter tail on the left side of the distribution. The Relative Humidity (E) in Narmadapuram district has increased during the period from (4%) to (100%). Average Relative Humidity (E) in Narmadapuram district was (41.47%). Kurtosis value was (0.37) indicating the distributions is mesokurtic. the value of skewness was (0.83), indicating there is an opportunity of rising in Relative Humidity (E) in Narmadapuram district. The Bright Sun Shine Hours in Narmadapuram district has increased during the period from (0 h) to (74.80 h). Average Bright Sun Shine Hours in Narmadapuram district was (7.23 h). Kurtosis value was (34.75) indicating the data follows a Leptokurtic distribution which shows heavy tails on either side, which means there are outliers in the data. the value of skewness was (0.53), indicating there is an opportunity of rising in Bright Sun Shine Hours in Narmadapuram district. (Table, 1).
The comparison between best-fitted models (between (Encoder-decoder) LSTM and Attention LSTM on training dataset) based on, lowest values of MAE, RMSE, RRMSE, MSE and the highest value of R-Squared are shown in (Table, 2). It can be seen from (Table, 2) that (Encoder-decoder) LSTM is outperforming the Attention LSTM in most time series forecasting in training dataset in this study; the (Encoder-decoder) LSTM is the best model for forecasting MAX Temperature, Relative Humidity (M), Relative Humidity (E) and Bright Sun Shine Hours. The encoder-decoder network is useful to deal with the challenging sequence-to sequence prediction problems lately [44]. Time series forecasting tasks usually include the framework: a sequence of one or multiple input time steps transformed to a sequence of one output time step. The encoder LSTM encodes the input sequence into a fixed length vector, and the decoder LSTM decodes the fixed length vector and outputs the predicted. Since the encoder-decoder network fails to work well in predicting long sequences, AM is introduced to generate a vector based on a weighted sum of all the encoded information [45]. The only exception is in case of MIN Temperature forecasting, whereas the Attention LSTM is the best model. attention LSTM not only considers past and future data information but also highlights the effective temporal features in time series. The principal idea of Attention LSTM is to allocate corresponding attention according to the importance of information, which significantly improves the reception sensitivity and processing speed of information in the concentration area. AM is commonly used to optimize the sequence processing model by allocating correlative attention weight to the features extracted from the input sequence [46].
The performance comparison of actual and predicted values of MAX Temperature, MIN Temperature, Relative Humidity (M), Relative Humidity (E) and Bright Sun Shine Hours using the Encoder-Decoder LSTM and Attention LSTM models is shown in Figures 6 to 25. These figures have the same x-axis range (0-8155) and represent the number of values from the time series included in the plot. It should be noted that the figures provided give a visual representation of the performance of the Encoder-Decoder LSTM and Attention LSTM models in forecasting different weather parameters.
The upper graph in each figure includes all data points in the dataset, while the lower graph includes only the past observations in the testing dataset (the past 1631 observations in the testing dataset). The blue lines represent the actual values, while the orange lines indicate the forecasted values. By comparing the forecasted and actual values, we can evaluate the performance of the two forecasting methods and gain insights on which one is more accurate. Overall, it can be seen that the forecast trends of the two models are similar to the real trend. However, for a few outliers, the forecast accuracy of each model is small. For some peak values of actual MAX Temperature, Relative Humidity (M), Relative Humidity (E) and Bright Sun Shine Hours, it can be seen that the prediction value of the Encoder-Decoder LSTM model is the closest to the actual values in the testing dataset. Encoder-Decoder LSTM is particularly useful in this study as it is able to store information for long periods of time, and can automatically feed the previous target value as an input to predict the next step in the LSTM decoder part. (Encoder-decoder) LSTM is also one type of (Encoder-decoder) RNN that is useful in dealing with challenging sequence-to-sequence prediction problems. It works by encoding the input sequence into a fixed length vector, which is then decoded by the LSTM decoder to produce the predicted output [47]. Attention Mechanism (AM) is introduced to overcome the limitation of Encoder-Decoder LSTM in predicting long sequences. AM generates a vector based on a weighted sum of all the encoded information.
On the other hand, Attention LSTM not only considers past and future data information, but it also highlights the effective temporal features in time series. It allocates corresponding attention weight to the features extracted from the input sequence, which improves the sensitivity and processing speed of information. Additionally, the Attention LSTM model can underline the important time series characteristics and reduce the influence of some outliers on the prediction effect. This is evident in the case of MIN Temperature forecasting, where the Attention LSTM model (Figures 12 and 13) performs better than the Encoder-Decoder LSTM model (Figures 10 and 11). In conclusion, the Encoder-Decoder LSTM model was found to be the best model for forecasting MAX Temperature, Relative Humidity (M), Relative Humidity (E) and Bright Sun Shine Hours, while the Attention LSTM model was the best for forecasting MIN Temperature. Both models have their own strengths and can be used in time series forecasting tasks to improve performance. This study highlights the significance of using advanced deep learning models in time series forecasting tasks, particularly in the field of weather prediction. Accurate weather forecasting is crucial in various industries, such as agriculture, transportation, and energy, as well as for public safety and disaster management. With the use of machine learning models like Encoder-Decoder LSTM and Attention LSTM, more accurate weather predictions can be made, leading to better decision-making and improved outcomes in the relevant industries and fields.
5. Conclusions
The study highlights the effectiveness of using AI and ML techniques, including Encoder-Decoder LSTM and Attention LSTM models, in analyzing and predicting weather patterns in the Narmadapuram district. The results demonstrate the superiority of Encoder-Decoder LSTM in forecasting maximum temperature, morning relative humidity, evening relative humidity, and bright sunshine hours, while Attention LSTM outperforms in forecasting minimum temperature. These findings validate the potential of machine learning in addressing the challenges of urban development in smart cities, specifically in the area of weather forecasting. The results highlight the importance of identifying and utilizing the right machine learning model for a specific forecasting task, and can inform the development of more precise and accurate weather forecasting models in the future.
Funding: “This research received no external funding”
Conflicts of Interest: “The authors declare no conflict of interest.”