GaussianDiffusion<T>
Models & Types · AiDotNet.NeuralNetworks.SyntheticData
Implements the Gaussian diffusion process for continuous/numerical features in TabDDPM.
For Beginners
This handles the “numbers” part of the diffusion process.
Forward (adding noise to numbers):
- Start with a real number (e.g., salary = $50,000)
- At each step, mix in a little bit of random Gaussian noise
- After 1000 steps, the number is pure noise (could be anything)
Reverse (removing noise from numbers):
- Start with a random number
- The model predicts what noise was added
- Remove that noise to get slightly cleaner number
- After 1000 removals, you have a realistic salary value
The math ensures that each step is a small, reversible change.
How It Works
The Gaussian diffusion process operates on continuous features:
- Forward process (add noise): q(x_t | x_0) = N(sqrt(alpha_bar_t) * x_0, (1 - alpha_bar_t) * I)
- Training: The model learns to predict the noise epsilon that was added at timestep t
- Loss: MSE between predicted and actual noise
- Reverse process (denoise): x_{t-1} = (1/sqrt(alpha_t)) * (x_t - (beta_t / sqrt(1-alpha_bar_t)) * predicted_noise) + sigma_t * z
with sigma_t^2 = beta_t by default, as in the TabDDPM reference code (see ReverseDiffusionVariance).
Constructors
| Constructor | Summary |
|---|---|
GaussianDiffusion(int numTimesteps, double betaStart, double betaEnd, BetaSchedule schedule, ReverseDiffusionVariance varianceType, Random random) |
Initializes a new Gaussian diffusion process. |
GaussianDiffusion(int numTimesteps, double betaStart, double betaEnd, string schedule, Random random) |
Initializes a new Gaussian diffusion process. |
Properties
| Property | Summary |
|---|---|
ReverseDiffusionVariance VarianceType { get; } |
Gets the reverse-step variance in use. |
int NumTimesteps { get; } |
Gets the number of diffusion timesteps. |
Methods
| Method | Summary |
|---|---|
T ComputeLoss(Vector<T> predictedNoise, Vector<T> actualNoise) |
Computes the MSE loss between predicted and actual noise. |
ValueTuple<Vector<T>, Vector<T>> AddNoise(Vector<T> x0, int t, Vector<T> noise) |
Adds noise to clean data at a given timestep (forward process). |
Vector<T> ComputeLossGradient(Vector<T> predictedNoise, Vector<T> actualNoise) |
Computes the gradient of the MSE loss with respect to predicted noise. |
Vector<T> DenoisingStep(Vector<T> xt, Vector<T> predictedNoise, int t) |
Performs one reverse diffusion step (denoising): x_{t-1} from x_t. |
int SampleTimestep() |
Samples a random timestep uniformly from [0, numTimesteps). |