# Simulating Intraday Electricity Consumption with ForGAN
## 2 GANs and ForGAN: Idea, Structure and Algorithms
### ForGAN Architecture
#### 2.5.1 The Generator  
The generator's objective is to generate a forecast \(x_{t+1}\) based on the condition \(c=(x_{1},\ldots,x_{t})\), the historical time series data. To achieve this, the generator incorporates two main components:  
* **Condition-to-Latent Layer (LSTM or GRU)--Data preprocessing**: This component makes the time series data ready for the use of a GAN. Assume a time series \(x_{1},x_{2},\ldots,x_{T}\) is given. A GRU network is selected for learning the dependence structure of the time series. For a chosen fixed length \(k\), all time windows \(c=(x_{1+j},\ldots x_{k+j})\) are considered with the goal of learning a lower-dimensional representation (the _latent representation_) \(g(x_{1+j},\ldots,x_{k+j})\in\mathbb{R}^{d}\), where the size of \(d\) is also a chosen positive integer. This results in a training set of size \(T-k-1\) for GRU to come up with a functional relationship between the condition window and its representation. In this implementation, a condition size of \(k=96\), i.e., one full day of data and \(d=32\), is used. Alternatively, the LSTM could have been selected for this data preparation step. Both the LSTM and GRU layers are effective at modeling sequential data by maintaining hidden states that capture long-range dependencies in time series. Also, there exist publicly available implementations of both the LSTM and GRU (see, e.g., Chapter 10 of [22]).
* **Model (Sequential Neural Network)**: Given the latent representation of the input sequence, the generator combines this with random noise and passes the information through a series of fully connected layers to predict the next value in the series. More precisely, for each condition window \(x_{1+j},\ldots x_{k+j}\), the corresponding GRU-representation \(g(x_{1+j},\ldots x_{k+j})\) is taken and a standard normally distributed random variable \(z_{k+1+j}\) of dimension \(N\) (with \(N=32\) in this implementation) to come up with a generated next time series point \(y_{k+1+j}\) via \[y_{k+1+j}=H_{\theta_{G}}\Big{(}g(x_{1+j},\ldots,x_{k+j}),z_{k+1+j}\Big{)}.\] (6) Here, the function \(H_{\theta_{G}}\) is a neural network with an input parameter of size \(N+d=64\), which is a dense hidden layer of the same size that is then fully connected to the output layer of size 1. A ReLU function is used as an activation function. The network  
Figure 3: ForGAN architecture showing the condition vector \(c\) as input to the generator (\(G\)) and the discriminator (\(D\)), along with the feedback loop.  
parameters \(\theta_{G}\) of the generator network are then calibrated with the discriminator as normal in a standard GAN.
* **Generation of a future path of the time series:** Once the GAN is successfully trained, it can be used to generate a future path of the time series via \[y_{S}=H_{\theta_{G}}(g(x_{S-k-1},\ldots,x_{S-1}),z_{S})\] (7) for some sequence of future values \(y_{S}\), \(S=T+1,T+2,\ldots\) Here, the data history \(x_{S-k-1},\ldots,x_{S-1}\) consists of elements from the real dataset as long as the indices are lower than or equal to \(T\), while all data with an index higher than \(T\) are produced by the generator.