forwardDiffuse method
Closed-form forward diffusion:
x_t = √α̅_t · x_0 + √(1 - α̅_t) · ε with ε ~ N(0, I).
Returns the noised sample and the noise it used (so training
code can regress ε̂ → ε). Pass eps to make the noise
deterministic; otherwise it is drawn using seed (defaults to
the system RNG).
Implementation
({Tensor xT, Tensor eps}) forwardDiffuse(
Tensor x0,
int t, {
int? seed,
Tensor? eps,
}) {
_checkT(t);
final n = x0.length;
final noise =
eps ?? _gaussianTensor(x0.shape, seed: seed, device: x0.device);
if (noise.length != n || !_shapesEqual(noise.shape, x0.shape)) {
throw ArgumentError(
'forwardDiffuse: eps shape ${noise.shape} does not match x0 ${x0.shape}',
);
}
final aScalar = sqrtAlphaBars[t];
final bScalar = sqrtOneMinusAlphaBars[t];
return (xT: x0 * aScalar + noise * bScalar, eps: noise);
}