

























The Density Functions p(x)p(x):
∫Xp(x)dx=1\int_{X} p(x)dx = 1
With Generative Models, all possible images compete for probability mass. Model can “reject” unreasonable inputs by giving them small probability mass.
The Bayes’ Theorem:
P(x∣y)=P(y∣x)P(x)P(y)P(x|y) = \frac{P(y|x) P(x)}{P(y)}
This means with two of the three models, we can get the third one.
Maximum Likelihood Estimation (MLE) The core objective is to find the best parameters (WW) for our function f(x,W)f(x, W) so that it accurately models the true distribution p(x)p(x) of our data.
To train the model using a dataset x(1),x(2),…,x(N)x^{(1)}, x^{(2)}, \dots, x^{(N)}, we solve for the optimal weights W∗W^* through these steps:
We start by trying to maximize the joint probability of all training data points. This is represented as the product of individual probabilities: argmaxW∏ip(x(i))\arg \max_{W} \prod_{i} p(x^{(i)}) .
Since multiplying many small probabilities can lead to numerical instability (underflow), we apply a logarithm. Because the log is a monotonic function, maximizing the log-likelihood is equivalent to maximizing the likelihood, but it allows us to swap the product for a sum: argmaxW∑ilogp(x(i))\arg \max_{W} \sum_{i} \log p(x^{(i)}) .
By substituting our model function f(x,W)f(x, W) for p(x)p(x), we arrive at our final objective: argmaxW∑ilogf(x(i),W)\arg \max_{W} \sum_{i} \log f(x^{(i)}, W) .
Autoregressive models assume that the data xx is not a single static point, but a sequence of components:
x=(x1,x2,...,xT)x = (x_1, x_2, ..., x_T)
An autoregressive model predicts the “next” part of the data based on what has already been generated.
It iterates through the elements, determining the probability of the next element given all previous elements.
To calculate the probability of the entire sequence p(x)p(x), these models decompose the joint probability using the chain rule. Instead of looking at the whole sequence at once, the model breaks it down into a series of conditional probabilities:
p(x)=∏t=1Tp(xt∣x1,...,xt−1)p(x) = \prod_{t=1}^{T} p(x_t | x_1, ..., x_{t-1})
Variational Autoencoders (VAE) define an intractable density that we cannot explicitly compute or optimize. We can determine its lower bound.
The autoencoder is an unsupervised method for learning to extract features zz from inputs xx, without labels.
It trains an encoder and a decoder, which gets the intermediate representation of the input and then reconstructs the input data back. The intermediate representation zz has lower dimensionality.
The loss function is the L2 distance between input and reconstructed data.
After training, we can use encoder for downstream tasks.
For generative tasks, we can force all zz to come from a known distribution so that we can sample zz to get generate outputs.
We assume the latent factor zz conforms to Gaussian distribution. We train the model with maximum likelihood.
pθ(x)=pθ(x∣z)pθ(z)pθ(z∣x)p_\theta(x) = \frac{p_\theta(x|z)p_\theta(z)}{p_\theta(z|x)}
We apply Bayes’ Rules. Since we cannot get the posterior pθ(z∣x)p_\theta(z|x) , we can train another network that learns qϕ(z∣x)≈pθ(z∣x)q_\phi(z|x) \approx p_\theta(z|x) .
For VAE, we train two networks.
The Encoder Network (qϕ(z∣x)q_\phi(z|x)): takes input data xx and maps it to a distribution over latent codes zz. Instead of a single point, it outputs the parameters—mean (μz∣x\mu_{z|x}) and variance (Σz∣x\Sigma_{z|x})—of a distribution (typically Gaussian).
The Decoder Network (pθ(x∣z)p_\theta(x|z)): takes a latent code zz and reconstructs the data xx. It outputs a distribution over the data, defined by its own mean (μx∣z\mu_{x|z}) and variance (σ2\sigma^2).
The fundamental challenge in VAEs is that the true posterior pθ(z∣x)p_\theta(z|x) is intractable. To solve this, VAEs use Variational Inference:
pθ(x)≈pθ(x∣z)p(z)qϕ(z∣x)p_\theta(x) \approx \frac{p_\theta(x|z)p(z)}{q_\phi(z|x)}
Building on the previous concepts, this derivation explains how we can optimize the log-likelihood of our data, logpθ(x)\log p_\theta(x), even when the true posterior is unknown.
logpθ(x)=logpθ(x∣z)p(z)pθ(z∣x)=logpθ(x∣z)p(z)qϕ(z∣x)pθ(z∣x)qϕ(z∣x)\log p_\theta(x) = \log \frac{p_\theta(x | z)p(z)}{p_\theta(z | x)} = \log \frac{p_\theta(x | z)p(z)q_\phi(z | x)}{p_\theta(z | x)q_\phi(z | x)}
=EZ∼qϕ(z∣x)[logpθ(x∣z)]−DKL(qϕ(z∣x),p(z))+DKL(qϕ(z∣x),pθ(z∣x))= E_{Z \sim q_\phi(z|x)}[\log p_\theta(x|z)] - D_{KL}(q_\phi(z|x), p(z)) + D_{KL}(q_\phi(z|x), p_\theta(z|x))
The derivation uses the properties of logarithms and expectations to decompose the log-likelihood into three distinct terms:
The Reconstruction Term (EZ∼qϕ(z∣x)[logpθ(x∣z)]E_{Z \sim q_\phi(z|x)}[\log p_\theta(x|z)]):
The Prior Regularization Term (DKL(qϕ(z∣x),p(z))D_{KL}(q_\phi(z|x), p(z))):
The Approximation Error (DKL(qϕ(z∣x),pθ(z∣x))D_{KL}(q_\phi(z|x), p_\theta(z|x))):
Since we cannot calculate the true posterior (the third term), we ignore it and maximize the first two terms—the Evidence Lower Bound (ELBO). By maximizing the ELBO, we simultaneously improve the quality of our data generation and the efficiency of our latent representation.
This is the lower bound of our maximal likelihood.
To train this, we first run input data through encoder to get distribution over zz, which should match the unit Gaussian. We sample zz from the output distribution and run it through decoder to get predicted data mean. Predicted mean should match x in L2.
Reconstruction loss wants Σz∣x=0\Sigma_{z|x} = 0 and μz∣x\mu_{z|x} to be unique for each x, so decoder can deterministically reconstruct x.
Prior loss wants Σz∣x=I\Sigma_{z|x} = \mathbf{I} and μz∣x=0\mu_{z|x} = 0 so encoder output is always a unit Gaussian.
We don’t model p(x)p(x) any more. We only draw samples from it.
Generative Adversarial Networks: Have data xix_i drawn from distribution pdata(x)p_{data}(x). Want to sample from pdatap_{data}
We introduce a latent variable z with simple prior p(z)p(z) (e.g. unit Gaussian). Sample z∼p(z)z \sim p(z) and pass to a Generator Network x=G(z)x = G(z). Then x is a sample from the Generator distribution pGp_G.
Train Generator Network G to convert z into fake data x sampled from pGp_G , fooling the discriminator D.
Train Discriminator Network D to classify data as real or fake
We jointly train G and D with a minimax game, hoping pGp_G to converge to pdatap_{data} .
minGmaxD(Ex∼pdata[logD(x)]+Ez∼p(z)[log(1−D(G(z)))])\min_G \max_D \left( E_{x \sim p_{data}} [\log D(x)] + E_{z \sim p(z)} [\log(1 - D(G(z)))] \right)
Generator wants D(G(z))=1D(G(z)) = 1. Train generator to minimize −log(D(G(z)))-\log(D(G(z))) and discriminator to maximize log(1−D(G(z)))\log(1-D(G(z))) so generator gets strong gradients at start.
Examples of GAN include DC-GAN and StyleGAN.
Latent space is smooth. Given latent vectors z0 and z1, we can interpolate between them and have the resulting image interpolating smoothly between samples.
However, the training of GAN is unstable.
We model the transformation between a simple noise distribution and the complex data distribution.
Flow Matching: Have data xx drawn from distribution pdatap_{data} and noise zz drawn from a simple prior pnoisep_{noise} (e.g. unit Gaussian). We define a path that interpolates between them over time t∈[0,1]t \in [0, 1].
On each training iteration, we sample x∼pdatax \sim p_{data}, z∼pnoisez \sim p_{noise}, and a time step t∼Uniform[0,1]t \sim \text{Uniform}[0, 1]. We construct a noisy sample xtx_t and a target velocity vv:
xt=(1−t)x+tz,v=z−xx_t = (1 - t)x + tz, \quad v = z - x
Train a Velocity Network fθ(xt,t)f_\theta(x_t, t) to predict the vector vv that points from the data toward the noise. This is optimized using a regression loss:
L=∥fθ(xt,t)−v∥22L = \| f_\theta(x_t, t) - v \|_2^2
During Inference (Sampling), we start with pure noise x1∼pnoisex_1 \sim p_{noise} and move backward toward the data distribution. We choose a number of steps TT (often T=50T=50):
For tt in [1,1−1T,1−2T,…,0][1, 1 - \frac{1}{T}, 1 - \frac{2}{T}, \dots, 0]:
This approach, known as Optimal Transport Flow Matching, results in straight trajectories between noise and data.
Classifier-Free Guidance (CFG): To control the generation process, we introduce a condition yy (e.g., a text prompt). During training, we occasionally drop yy so the model learns both conditional and unconditional distributions.
During sampling, we compute two separate velocities for a noisy sample xtx_t:
We combine these using a guidance weight ww to shift the direction more strongly toward the condition:
vcfg=(1+w)vy−wv∅v^{cfg} = (1 + w)v^y - w v^\emptyset
Increasing ww improves how well the image matches the prompt but can reduce sample diversity.
Noise Schedules: We may use a non-uniform noise schedule. The common choice is logit-normal sampling. For high-res data, we often shift to higher noise to account for pixel correlations.
Diffusion Distillation: We use distillation algorithms reduce the number of steps (sometimes all the way to 1).
Examples of these models include Stable Diffusion (which uses a similar diffusion objective) and Flux.
Unlike GANs, these models are much more stable to train and scale better to high-resolution data. However, sampling is typically slower because it requires multiple evaluations of the network.
Latent Diffusion Models are basically VAE + GAN + Diffusion.
We train encoder + decoder to convert images to latents. Then train diffusion model to remove noise from latents. We run decoder to get image from denoised latents.
The encoder + decoder is a VAE. For the decoder, we use GAN to prevent the outputs from being blurry.
This framework provides a unified view of generative modeling, where models like DDPM, DDIM, and Flow Matching are seen as specific configurations of a general training objective.
Core Concept: We define a forward process that transitions from clean data xx to noise zz over a continuous or discrete time tt, and train a network to reverse or predict aspects of this transition.
For every training step, we sample the components of the transition:
xt=a(t)x+b(t)zx_t = a(t)x + b(t)z
ygt=c(t)x+d(t)zy_{gt} = c(t)x + d(t)z
The neural network fθf_\theta takes the noisy sample and the time step to predict the target. We minimize the Mean Squared Error:
L=∥fθ(xt,t)−ygt∥22L = \| f_\theta(x_t, t) - y_{gt} \|_2^2
By varying the coefficients a,b,c,a, b, c, and dd, this single loss function covers different popular models:
To steer these models during sampling (e.g., using a text prompt yy), we compute a weighted average of the conditional and unconditional predictions:
vcfg=(1+w)fθ(xt,y,t)−wfθ(xt,y∅,t)v^{cfg} = (1 + w)f_\theta(x_t, y, t) - w f_\theta(x_t, y_\emptyset, t)
Summary: While GANs rely on a competitive game (minimax), Generalized Diffusion relies on direct regression. This makes training significantly more stable and allows for high-quality, diverse image and signal synthesis across various domains like photogrammetry and 3D reconstruction.
Diffusion models are multifaceted and can be understood through several mathematical and conceptual frameworks. Rather than just a single algorithm, they represent a class of models that bridge the gap between simple noise and complex data distributions.
In this view, diffusion is treated similarly to a Variational Autoencoder (VAE) but with a fixed encoder and a learned decoder.
Instead of modeling the probability density p(x)p(x) directly, we can model its gradient with respect to the input.
For a more continuous mathematical treatment, the noising process can be described as an SDE.
dx=f(x,t)dt+g(t)dwdx = f(x, t)dt + g(t)dw
Beyond the frameworks above, diffusion models can also be viewed as:
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。