Noise Modules#

The engression mechanism relies on pre-additive stochastic noise layers. These modules are common to both the Enformer and GEnformer architectures. They inject stochastic noise into the continuous representations of the sequence to enable learning the full conditional predictive distribution.

class genformer.noise.GaussianNoise(*args, **kwargs)[source]#

Bases: Module

Gaussian noise injection module for the engression paradigm.

This module injects additive Gaussian noise into the continuous representations of the sequence, acting as a pre-additive stochastic noise layer. According to the paper “Deep Generative Transformers for Probabilistic Time Series and Spatiotemporal Forecasting”, injecting this stochastic noise enables the Transformer architecture to learn the full conditional predictive distribution rather than point predictions.

Parameters:
  • std (float) – The standard deviation (\(\sigma\)) of the Gaussian noise.

  • seed (int | None) – An optional seed for reproducible noise generation.

Mathematical Definition:

The noise \(\epsilon^{(m)}\) is sampled from a Gaussian distribution:

\[\epsilon^{(m)} \sim \mathcal{N}(\mathbf{0}, \sigma^2 \mathbf{I})\]

The noise is then added to the input sequence:

\[\mathbf{X'}_{batch}^{(m)} = \mathbf{X}_{batch}^{(m)} + \epsilon^{(m)}\]
reset_seed(seed=None)[source]#

Reset the internal generator seed.

Parameters:

seed (int | None)

reset_std(std=None)[source]#

Update the standard deviation of the noise.

Parameters:

std (float | None)

forward(x)[source]#

Injects Gaussian noise into the input tensor.

Parameters:

x (torch.Tensor) – The input sequence representations.

Returns:

torch.Tensor – The noise-perturbed representations.

class genformer.noise.UniformNoise(*args, **kwargs)[source]#

Bases: Module

Uniform noise injection module for the engression paradigm.

This module injects additive Uniform noise into the continuous representations of the sequence.

Parameters:
  • std (float) – The scale parameter (\(\sigma\)) defining the noise boundaries.

  • seed (int | None) – An optional seed for reproducible noise generation.

Mathematical Definition:

The noise \(\epsilon^{(m)}\) is sampled from a Uniform distribution:

\[\epsilon^{(m)} \sim \mathcal{U}(-\sigma, \sigma)\]

The noise is then added to the input sequence:

\[\mathbf{X'}_{batch}^{(m)} = \mathbf{X}_{batch}^{(m)} + \epsilon^{(m)}\]
reset_seed(seed=None)[source]#

Reset the internal generator seed.

Parameters:

seed (int | None)

reset_std(std=None)[source]#

Update the standard deviation parameter.

Parameters:

std (float | None)

forward(x)[source]#

Injects Uniform noise into the input tensor.

Parameters:

x (torch.Tensor) – The input sequence representations.

Returns:

torch.Tensor – The noise-perturbed representations.