# GAN-Based Generation of Synthetic Data for Vehicle Driving Events
### Theoretical Background
#### 1.1.3 Time-Series GAN (TimeGAN)  
GANs were not created specifically for time series data; they are mainly used with images, and as such do not perform well regarding specific time series properties. The TimeGAN framework was introduced by [PERSON] et al. [11] in 2019. It seeks to overcome these limitations when generating synthetic data sequences based on a real dataset. The TimeGAN architecture combines an adversarial network (generator and discriminator networks) with an autoencoder (embedding network and retrieval network). An _autoencoder_ is a neural network that learns a representation of the data in an unsupervised manner and aims to learn an encoding of a dataset by training the network to ignore the noisy signal. Specifically, TimeGAN comprises two groups of networks: (1) encoding networks and (2) adversarial networks. In addition to these network groups, there is another component called the supervisor network. Each network is implemented through a _Gated Recurrent Unit_ (GRU) or LSTM-type RNN network, which receives a three-dimensional tensor as input. A _tensor_ is a type of data structure that can be understood as a multidimensional array [12]. Encoding networks encompass two networks: the _embedding network_, which acts as an encoder that converts the real data into a latent representation, and the _recovery network_, which converts the latent representation present in the latent space into reconstructed data. Adversarial networks also include two networks: a (_sequence_) _generator network_ and a (_sequence_) _discriminator network_. The generator network receives a noisy input and produces an output in the latent space (not the feature space); its objective is to learn a distribution \(\bar{p}(x_{1:T})\) that approximates the distribution used to generate the actual data \(p(x_{1:T})\), where \(x_{1:T}=x_{1},x_{2},\cdots,x_{T}\) is a multivariate sequence of length \(T\). On the other hand, the discriminator network receives an input from the latent space, then classifies the data as real or synthetic. Lastly, the _supervisor network_ generates a new sequence given a  
Figure 1: Architecture of an LSTM cell. previous series in the latent space \(H\), allowing the quality of the generated sequences to be controlled. TimeGAN simultaneously learns to encode features, generate representations, and iterate over time. The generator and discriminator networks operate in a _latent space_ provided by the embedding network. The latent and real data dynamics are synchronized through the supervised loss. The four networks comprising the TimeGAN framework and their respective losses are shown in Figure 2.  
TimeGAN considers the contribution of three loss functions: reconstruction, unsupervised, and supervised. These allow for learning of the distribution of the data both at the level of each feature and at the temporal level. The _reconstruction_ loss ensures that data are efficiently encoded and decoded in and from the latent space. The _unsupervised_ loss is produced between the generator and the discriminator network, which forces the generator to create realistic data sequences. The _supervised_ loss allows for generating the next time step in latent space. The generator is trained to ensure that the generator learns the temporal dynamics of the data series, forcing the generator to create realistic data sequences. The supervised loss is also applied to the embedding network in order to preserve the temporal variation used to encode the real sequences. The TimeGAN algorithm learns in three training phases. First, in the _embedding phase_, only the embedding and retrieval networks are trained. Next, in the _supervised phase_, the generator is trained only with supervised loss. Finally, in the _joint phase_, the algorithm learns to encode, iterate, and generate time series data. All phases are trained over the same number of iterations, as all phases have equal weighting in the original TimeGAN implementation.