# Generative Modeling for Imbalanced Credit Card Fraud Transaction Detection
## 3 Generative Models
### Generative Adversarial Network (GANs)  
Generative Adversarial Networks are a class of unsupervised generative models that consist of two competing neural networks: a generator and a discriminator [40]. The generator's primary role is to produce new data samples (fake data) that closely mimic real data distribution, aiming to deceive the discriminator. Meanwhile, the discriminator's task is distinguishing between genuine and generated samples, providing feedback to improve the generator's output. Figure 4 describes the main steps of a GAN. This adversarial training process continues until the generator produces data that are nearly indistinguishable from the real dataset, enhancing the model's ability to capture complex data distributions. The competition between these networks drives both to improve iteratively, leading to the generation of high-quality synthetic data. GANs have shown remarkable success across various domains, including image synthesis, data augmentation, and anomaly detection. The basic architecture of a GAN, often referred to as a vanilla GAN, involves the following components:  
1. **Generator**: The generator network takes a random noise vector as input and generates fake data. Its goal is to produce data that are as close as possible to real data samples. The generator does not have direct access to the real data; it learns to create realistic data by interacting with the discriminator [41]. 2. **Discriminator**: The discriminator network receives both real data and the data generated by the generator. It classifies these inputs as real or fake using a sigmoid activation function and binary cross-entropy loss. The discriminator is trained to distinguish between the real and generated data, providing feedback to the generator on how well it is performing [42]. ```
0:\(fraud\_samples\), Number of epochs epochs, Latent dimension latent_dim
0: Trained VAE, encoder, and decoder models
1:\(input\_dim\leftarrow\) Number of columns in \(fraud\_samples\)
2:Define Encoder Model:
3: Input layer with shape (30,)
4: Dense layer with 64 units and activation function'relu'
5: BatchNormalization
6: Dropout with rate 0.2
7: Dense layer with 32 units and activation function'relu'
8: BatchNormalization
9: Dropout with rate 0.3
10: Dense layer with 8 units for mean (\(\mu\))
11: Dense layer with 8 units for log-variance (log(\(\sigma^{2}\)))
12: Sampling layer using \(z=\mu+\sigma\cdot\epsilon\), where \(\epsilon\sim\mathcal{N}(0,1)\)
13:Define Decoder Model:
14: Input layer with shape (8,)
15: Dense layer with 32 units and activation function'relu'
16: BatchNormalization
17: Dropout with rate 0.3
18: Dense layer with 64 units and activation function'relu'
19: BatchNormalization
20: Dropout with rate 0.2
21: Dense layer with 30 units and activation function'sigmoid'
22: Define VAE Model:
23: Connect encoder and decoder
24: Define VAE loss as reconstruction loss (binary cross-entropy) plus KL divergence:
25:\(\mathcal{L}(x)=\mathbb{E}_{q(z|x)}[\log p(x|z)]-D_{KL}(q(z|x)||p(z))\)
26: Compile with optimizer Adam(learning rate = 0.001)
27:textDiffit the VAE:
28: Train with \(fraud\_samples\) for 100 epochs and batch size 32, shuffle=True
29:return Encoder, Decoder
```  
**Algorithm 2** Variational Autoencoder (VAE) Training  
The generator and discriminator are trained together in a competitive process known as a minimax game, where the generator tries to maximize the probability that the discriminator mistakes fake data for real data, while the discriminator tries to minimize this probability. This can be expressed mathematically as  
Figure 4: GAN architecture. \[\min_{G}\max_{D}V(D,G)=\mathbb{E}_{x\sim p_{\text{data}}(x)}[\log D(x)]+\mathbb{E}_ {z\sim p_{z}(z)}[\log(1-D(G(z)))] \tag{6}\]  
where \(\mathbb{E}\) denotes the expected value, \(p_{\text{data}}(x)\) represents the distribution of real data, and \(p_{z}(z)\) represents the distribution of the noise input to the generator.