## 2 Materials and Methods
### Day-Ahead Load Forecasting  
Many techniques have been used and methodologies proposed for day-ahead load forecasting, which is the most significant forecasting method for the day-to-day operation of electricity systems and electricity markets. DALF is a challenging task, as electricity load time series are highly non-linear, non-stationary, random, and they present multiple seasonal patterns. In this novel methodology, we use a long short-term memory neural network to forecast the day-ahead electricity load time series of a region. LSTM NN is a recurrent neural network able to deal with long-term dependencies and retain extended information. LSTM NN selectively remembers or forgets information over time, allowing the neural networks (NNs) to recall relevant context and dependencies over long sequences. The LSTM NN's basic architecture is shown in Figure 2 and consists of (a) the cell that stores the state of a sequence and is able to keep or forget information; (b) the input gate that determines the information to be stored in the cell; (c) the output gate that decides the next hidden state; and (d) the forget gate that decides the information that should be kept or discarded. These kinds of NNs allow information to be kept for long periods and sequences with time intervals between events to be processed more efficiently. Let \(h_{t}\) and \(c_{t}\) be the hidden and the cell state, respectively, of the LSTM NN at a time step \(t\), and let \(x_{t}\) be the input vector. The LSTM NN obtains the input vector and the previous state. The forget gate \(f_{t}\) decides which information to discard from the cell state based on \(c_{t-1}\). On the other hand, the input gate \(i_{t}\) decides which information to store in the cell gate. Next, using the previous information, the old cell state is updated to the new cell state \(c_{t}\). Finally, the output gate \(o_{t}\) decides the output based on the cell state. The LSTM operation is given by  
\[ \begin{array}{ll}f_{t}&=\sigma\;\Big{(}\;W_{f}\;x_{t}+U_{f}\;h_{t-1}+b_{f} \Big{)},\\ i_{t}&=\;\sigma\;\Big{(}\;W_{t}\;x_{t}+U_{i}\;h_{t-1}+b_{i}\Big{)},\\ o_{t}&=\;\sigma\;\big{(}\;W_{o}\;x_{t}+U_{o}\;h_{t-1}+b_{o}\big{)},\\ c_{t}&=f_{t}\;c_{t-1}+i_{t}\;\tanh\big{(}W_{c}\;x_{t}+U_{c}\;h_{t-1}+b_{c} \big{)}\;,\\ h_{t}&=\;o_{t}\tanh(c_{t}).\end{array}  \tag{6}\]  
where \(\sigma\) is the Sigmoid function; \(W_{g}\) is the respective weight for the gate \(g\); \(U_{g}\) is the recurrent connection between the previous hidden layer and the current layer for the gate \(g\); \(b_{g}\) is the respective bias of the gate \(g\); and \(t\) corresponds to the time step. The main advantages of LSTM NN are the ability to learn long-term dependencies and the capacity to handle sequential data with time steps of different lengths. Figure 2: Basic architecture of a long short-term memory neural network. Thus, for DALF purposes, the LSTM NN is trained with electrical load data and representative meteorological data time series for each season, as shown in Figure 3.  
In time-series forecasting tasks, particularly with LSTM neural networks, incorporating time-related features, such as hours, days, or months, is essential. However, these features are cyclical, i.e., hours repeat every 24 h, and months repeat every 12 months. Encoding them as raw integers can mislead the network because it implies a linear relationship between successive values. Indeed, after 23 h, the value cycles back to 0. Cyclical encoding transforms these features into a pair of sine and cosine values to preserve their cyclical nature, allowing the LSTM to better capture temporal patterns and dependencies. This method enhances the neural network's ability to recognize recurring trends, improving the model's learning process and overall predictive performance. By encoding time-related data cyclically, we ensure that the LSTM captures seasonal and temporal dependencies more effectively, leading to more precise demand prediction forecasting. Integrating K-means clustering with an LSTM NN leverages the strengths of both methods.