Lecture 8 · Machine Learning for ICE · University of Klagenfurt, 2023
Lecture 8 of 8
From Machine Learning for ICE at the University of Klagenfurt, first taught in 2022: this is the 2023 edition, so some of it may be a little dated. In particular, diffusion models, today the leading generative models for images, are not covered here. All lectures.
01
A generative model estimates
The estimate can be explicit, with a parametric expression for the density, or implicit, with no expression at all, only a way to sample from it.
In practice, generative models are used to generate new data from the estimated distribution.
02
Variational autoencoders (Kingma and Welling, 2013) are based on variational Bayesian methods. An autoencoder architecture, read in probabilistic terms:
Input data x\sim p(x) Encoder Latent variable z\sim q_x(z)\approx p(z\mid x) Decoder Generated data \hat x\sim p(x\mid z)
To generate new data: sample a latent variable from the prior p(z), and pass it through the decoder to get \hat x.
Approximate the posterior with a Gaussian, p(z\mid x)\approx q_x(z)=\mathcal{N}\big(g(x),h(x)\big), with g and h to be found, and the likelihood with another Gaussian, p(x\mid z)=\mathcal{N}\big(f(z),c\mathbf{I}\big)\propto e^{-\frac{1}{2c}\lVert x-f(z)\rVert^2}. The prior p(z) is a standard normal.
The best approximation minimizes the KL divergence to the true posterior. With Bayes, p(z\mid x)=p(x\mid z)\,p(z)/p(x), and \log p(x) does not depend on g,h,f:
\begin{aligned} (g^*,h^*,f^*)&=\arg\min_{g,h,f}D_{\mathrm{KL}}\big(q_x(z)\,\|\,p(z\mid x)\big)=\arg\min_{g,h,f}\mathbb{E}_{z\sim q_x(z)}\Big[\log\frac{q_x(z)}{p(z\mid x)}\Big]\\ &=\arg\min_{g,h,f}\mathbb{E}_{z\sim q_x(z)}\Big[\log\frac{q_x(z)}{p(z)}\Big]-\mathbb{E}_{z\sim q_x(z)}\big[\log p(x\mid z)\big]\\ &=\arg\min_{g,h,f}\underbrace{\frac{1}{2c}\,\mathbb{E}_{z\sim q_x(z)}\big[\lVert x-f(z)\rVert^2\big]}_{\text{reconstruction (decoder) loss}}+\underbrace{D_{\mathrm{KL}}\big(q_x(z)\,\|\,p(z)\big)}_{\text{regularization}} \end{aligned}
A trade-off: reconstruct the input well, while keeping the codes close to the prior, so that sampling from the prior produces sensible data. The constant c sets the balance.
03
Generative adversarial networks (Goodfellow et al., 2014) are two networks in competition:
The generator wins when the discriminator can no longer tell its output from the real data.
Noise z\sim p_z(z) Generator G G(z) Discriminator D real data x also comes in real or fake? D(\cdot)\in(0,1)
Generator and discriminator play the min-max game
\min_G\max_D V(D,G)=\mathbb{E}_{x\sim p_{\text{data}}(x)}\big[\log D(x)\big]+\mathbb{E}_{z\sim p_z(z)}\big[\log\big(1-D(G(z))\big)\big]
The discriminator wants D(x) close to 1 on real data and close to 0 on generated data. The generator wants to fool it.
Along the way, the generator implicitly builds a distribution p_{\text{gen}}(x), which should get closer and closer to the real p_{\text{data}}(x).
Start from the inner maximization. For a fixed generator G, which D maximizes V(D,G)? Taking the derivative with respect to D(x), point by point:
D^*(x)=\frac{p_{\text{data}}(x)}{p_{\text{data}}(x)+p_{\text{gen}}(x)}
Now the generator, against the optimal discriminator:
\min_GV(D^*,G)=\mathbb{E}_{x\sim p_{\text{data}}(x)}\big[\log D^*(x)\big]+\mathbb{E}_{z\sim p_z(z)}\big[\log\big(1-D^*(G(z))\big)\big]
The generator controls p_{\text{gen}}(x). One can show that the minimum is reached when p_{\text{gen}}(x)=p_{\text{data}}(x), and that the value of the game is then -\log4. So at convergence
D^*(x)=\frac12
the discriminator is guessing at random between real and generated data.
At the start the discriminator separates the two distributions easily. Each generator step moves p_{\text{gen}} where D says “real”, until the two coincide and D^*(x)=\frac12 everywhere.
In communications, GANs are an excellent tool to model the medium.
For example, a generator can learn the noise measured on power line cables, which is far from Gaussian and changes with the mains cycle.
Consider a 4-QAM scheme, with symbols x_k in the constellation. Simulate a transmission over an AWGN channel and generate the “real” received samples y_k=x_k+n_k.
x = Input(shape=(2,)) # the symbol, the condition
z = Input(shape=(2,)) # the randomness
y = self.generator(Concatenate()([x, z])) # 100 relu, 100 sigmoid, 2
self.discriminator.trainable = False
self.combined = Model([x, z], self.discriminator(y))
for epoch in range(epochs):
data_tx = 2*np.random.randint(2, size=(batch_size, 2)) - 1
z_prior = np.random.uniform(-1, 1, size=(batch_size, 2))
data_rx = data_tx + 0.1*np.random.normal(0, 1, (batch_size, 2))
fake_rx = self.generator.predict(np.concatenate([data_tx, z_prior], axis=1))
# D learns real from fake, then G learns to fool it
self.discriminator.train_on_batch(data_rx, valid)
self.discriminator.train_on_batch(fake_rx, fake)
self.combined.train_on_batch([data_tx, z_prior], valid)the real samples the GAN must imitate
The condition x_k picks which cloud to draw, the noise z where in it. Once trained, the generator is a differentiable channel for the autoencoder of lecture 7.
After H. Ye, G. Y. Li, B.-H. F. Juang, K. Sivanesan, Channel agnostic end-to-end learning based communication systems with conditional GAN, 2018.
This was the last lecture. All lectures.
letizia.tech · Machine Learning for ICE · University of Klagenfurt