DiffusionNoiseHelper<T>
Helpers & Utilities · AiDotNet.Helpers
Helper class for noise sampling operations in diffusion models.
For Beginners
Diffusion models work by adding and removing noise from data. This helper provides the mathematical operations needed for that process:
- Sampling Gaussian (bell-curve) noise
- Computing noise schedules
- Scaling noise for different timesteps
How It Works
This static helper provides common noise sampling operations used throughout diffusion models, ensuring consistent implementations and avoiding code duplication.
Methods
| Method | Summary |
|---|---|
T ComputeSNR(T alphaCumprod) |
Computes the signal-to-noise ratio (SNR) for a given timestep. |
Tensor<T> AddNoise(Tensor<T> signal, Tensor<T> noise, T sqrtAlphaCumprod, T sqrtOneMinusAlphaCumprod) |
Adds noise to a signal at a specified timestep using the scheduler’s noise schedule. |
Tensor<T> ComputeTimestepEmbeddings(int[] timesteps, int embeddingDim) |
Computes sinusoidal timestep embeddings (like in Transformers). |
Tensor<T> LerpNoise(Tensor<T> noise1, Tensor<T> noise2, double t) |
Linearly interpolates between two noise tensors. |
Tensor<T> SampleGaussian(int[] shape, Random rng) |
Samples Gaussian noise using a provided random number generator. |
Tensor<T> SampleGaussian(int[] shape, int? seed) |
Samples Gaussian noise using a provided random number generator. |
Tensor<T> ScaleNoise(Tensor<T> noise, double scale) |
Scales noise by a given factor. |
Tensor<T> SlerpNoise(Tensor<T> noise1, Tensor<T> noise2, double t) |
Spherical linear interpolation between two noise tensors. |
Vector<T> ComputeTimestepEmbedding(int timestep, int embeddingDim) |
Computes sinusoidal embedding for a single timestep. |
Vector<T> SampleGaussianVector(int length, Random rng) |
Samples Gaussian noise as a Vector using a provided random number generator. |
Vector<T> SampleGaussianVector(int length, int? seed) |
Samples Gaussian noise as a Vector using a provided random number generator. |