Skip to content
Oakfield Operator Calculus Function Reference Site

Noise Operators

sim_add_stochastic_noise_operator(ctx, field, opts)

Add coloured stochastic noise with configurable spectral characteristics and stochastic calculus law. Implements Ornstein-Uhlenbeck processes with fractional noise extensions for modeling physical fluctuations, turbulence, and thermal noise.

sim_add_stochastic_noise_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

Ornstein-Uhlenbeck Process:

dξ=ξτdt+σdWtd\xi = -\frac{\xi}{\tau} dt + \sigma \cdot dW_t

where:

  • ξ\xi is the noise state
  • τ\tau is the autocorrelation time
  • σ\sigma is the noise intensity
  • dWtdW_t is a Wiener increment

Spectral Characteristics:

The noise has power spectral density:

S(f)11+(2πfτ)2fαS(f) \propto \frac{1}{1 + (2\pi f \tau)^2} \cdot |f|^{-\alpha}

where α\alpha controls the spectral color:

  • α=0\alpha = 0: White noise (flat spectrum)
  • α=1\alpha = 1: Pink/flicker noise (1/f1/f)
  • α=2\alpha = 2: Brownian/red noise (1/f21/f^2)

Stochastic Calculus Laws:

  • Itô: Standard interpretation; dWdW independent of current state
  • Stratonovich: Midpoint rule; preserves chain rule; often preferred for physical systems
ParameterTypeDefaultRangeDescription
sigmadouble ≥0Noise intensity (standard deviation) (required)
taudouble 0.0≥0Autocorrelation decay time (0 = white noise)
alphadouble 0.0[0, 2.5]Spectral exponent controlling color
seedinteger 0≥0RNG seed (0 = auto from system)
lawenum "ito"ito, stratonovichStochastic calculus convention
  • Operates elementwise; no boundary handling required
  • Internal state initialized to zero; transient period ≈ 3τ3\tau
  • For reproducible results, set explicit seed
  • White noise (τ=0\tau = 0): Uncorrelated samples; scales with Δt\sqrt{\Delta t}
  • Colored noise (τ>0\tau > 0): Requires Δtτ\Delta t \ll \tau for accurate dynamics
  • Large α\alpha values produce slowly-varying (low-frequency dominated) noise
  • Stratonovich interpretation avoids spurious drift in multiplicative noise contexts
  • One random number generation per element per timestep
  • Colored noise maintains per-element state (O(N) memory)
  • Seed affects entire field; use different operators for independent noise sources
-- Simple white noise
ooc.sim_add_stochastic_noise_operator(ctx, field, {
sigma = 0.1
})
-- Colored noise with Stratonovich interpretation
ooc.sim_add_stochastic_noise_operator(ctx, field, {
sigma = 0.15,
law = "stratonovich"
})
-- Ornstein-Uhlenbeck process
ooc.sim_add_stochastic_noise_operator(ctx, field, {
sigma = 0.05,
tau = 0.1
})
-- Pink noise (1/f spectrum)
ooc.sim_add_stochastic_noise_operator(ctx, field, {
sigma = 0.05,
tau = 0.1,
alpha = 1.0,
seed = 42
})
-- Brownian noise (1/f² spectrum)
ooc.sim_add_stochastic_noise_operator(ctx, field, {
sigma = 0.02,
tau = 0.5,
alpha = 2.0
})
-- Reproducible noise for testing
ooc.sim_add_stochastic_noise_operator(ctx, field, {
sigma = 0.1,
seed = 12345
})

sim_add_stimulus_operator(ctx, field, opts)

Generate spatially-correlated random fields using random Fourier features. Creates band-limited noise patterns with controllable spectral content, useful for initial conditions, driving forces, and procedural textures.

sim_add_stimulus_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

Note: Requires type = "stimulus_random_fourier".

The field is constructed as a superposition of random sinusoids:

u(x,t)=An=1Nwncos(knx+ϕn+ωt)u(\mathbf{x}, t) = A \sum_{n=1}^{N} w_n \cos(\mathbf{k}_n \cdot \mathbf{x} + \phi_n + \omega t)

where:

  • AA is the amplitude
  • NN is feature_count
  • kn\mathbf{k}_n are random wavenumbers in [kmin,kmax][k_{\min}, k_{\max}]
  • ϕn\phi_n are random phases in [0,2π][0, 2\pi]
  • wnw_n are weights from the spectral slope: wnknβ/2w_n \propto |k_n|^{-\beta/2}
  • ω\omega is the temporal frequency (optional)

Spectral Slope:

When spectral_slope (β\beta) is specified, the power spectral density follows:

S(k)kβS(k) \propto |k|^{-\beta}

Core Parameters:

ParameterTypeDefaultRangeDescription
typestring Must be "stimulus_random_fourier"
amplitudedouble unboundedOverall scale of features (required)
feature_countinteger 16≥1Number of random basis functions
seedinteger 1≥1RNG seed for reproducibility

Spectral Parameters:

ParameterTypeDefaultRangeDescription
k_mindouble 0.1≥0Minimum wavenumber (rad/unit)
k_maxdouble 1.0>k_minMaximum wavenumber (rad/unit)
spectral_slopedouble 0.0unboundedSpectral decay exponent β\beta

Temporal Parameters:

ParameterTypeDefaultRangeDescription
omegadouble 0.0unboundedTemporal angular frequency (rad/s)
time_offsetdouble 0.0unboundedAdditional time shift
nominal_dtdouble 0.0≥0Lock time to fixed timestep
fixed_clockboolean falseUse nominal_dt for time evolution

Coordinate Mapping:

ParameterTypeDefaultDescription
coord_modeenum "axis"Coordinate mode: axis, angle, radial, separable
coord_axisenum "x"Axis for 1D mapping
coord_combineenum "multiply"Combine rule for separable: multiply, add
coord_angledouble 0.0Angle for angle-mode (radians)
origin_x, origin_ydouble 0.0Coordinate origin
spacing_x, spacing_ydouble 1.0Grid spacing
coord_center_x, coord_center_ydouble 0.0Center for radial mode
coord_velocity_x, coord_velocity_ydouble 0.0Moving center velocity

Output Parameters:

ParameterTypeDefaultDescription
scale_by_dtboolean trueScale writes by dt
  • Generates field values based on coordinates; no explicit boundaries
  • Periodic by nature due to sinusoidal basis
  • Same seed produces identical patterns
  • Output is bounded by ANA \cdot N (sum of all features)
  • spectral_slope > 0 produces smoother fields (low-frequency dominated)
  • spectral_slope < 0 produces rougher fields (high-frequency dominated)
  • More features improve statistical convergence at cost of computation
  • Computational cost: O(N × feature_count) per timestep
  • Features are precomputed once at creation; only phases advance
  • Use fixed_clock for deterministic, frame-rate-independent animation
-- Basic random Fourier field
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_random_fourier",
amplitude = 0.5,
k_min = 0.1,
k_max = 2.0,
feature_count = 32,
seed = 99
})
-- Red noise spectrum (smooth variations)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_random_fourier",
amplitude = 0.2,
spectral_slope = 2.0, -- 1/k² falloff
feature_count = 64
})
-- Pink noise spectrum (1/f)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_random_fourier",
amplitude = 0.3,
spectral_slope = 1.0,
k_min = 0.05,
k_max = 5.0,
feature_count = 48
})
-- Time-varying random field
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_random_fourier",
amplitude = 0.4,
omega = 0.5, -- slow temporal variation
feature_count = 24
})
-- Narrow-band noise (limited wavenumber range)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_random_fourier",
amplitude = 0.3,
k_min = 0.8,
k_max = 1.2, -- centered around k=1
feature_count = 16
})
-- Radial coordinate mapping
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_random_fourier",
amplitude = 0.5,
coord_mode = "radial",
coord_center_x = 128,
coord_center_y = 128,
k_min = 0.1,
k_max = 1.0
})

sim_add_stimulus_operator(ctx, field, opts)

Generate Gaussian white noise with configurable mean and variance. Fundamental building block for stochastic simulations, Monte Carlo methods, and noise injection.

sim_add_stimulus_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

Note: Requires type = "stimulus_white_noise".

Each sample is drawn independently from a Gaussian distribution:

ξiN(μ,σ2)\xi_i \sim \mathcal{N}(\mu, \sigma^2)

When scale_by_dt = true, the noise is scaled for proper stochastic integration:

ξiN(μ,σ2Δt)Δt=N(μΔt,σ2Δt)\xi_i \sim \mathcal{N}\left(\mu, \frac{\sigma^2}{\Delta t}\right) \cdot \Delta t = \mathcal{N}(\mu \cdot \Delta t, \sigma^2 \cdot \Delta t)

This ensures that the integrated noise has variance proportional to time (Wiener process behavior).

ParameterTypeDefaultRangeDescription
typestring Must be "stimulus_white_noise"
sigmadouble ≥0Standard deviation (required)
meandouble 0.0unboundedMean offset
seedinteger 1≥1RNG seed for reproducibility
scale_by_dtboolean trueScale by sqrt(dt) for stochastic integration
nominal_dtdouble 0.0≥0Lock scaling to fixed timestep
fixed_clockboolean falseUse nominal_dt for scaling
  • Operates elementwise; no boundary handling required
  • Each call generates fresh noise; no temporal correlation
  • Same seed produces identical noise sequence
  • Uncorrelated in space and time (delta-correlated)
  • Proper scaling (scale_by_dt = true) essential for SDE integration
  • Mean shifts the distribution; does not affect variance
  • For non-Gaussian noise, consider combining with nonlinear transformations
  • Uses Box-Muller or similar transform for Gaussian generation
  • One random number per element per timestep
  • Very fast; typically memory-bandwidth limited
-- Basic white noise
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_white_noise",
sigma = 0.05,
seed = 12345
})
-- White noise with nonzero mean
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_white_noise",
sigma = 0.2,
mean = 0.1
})
-- Unscaled noise (for non-SDE applications)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_white_noise",
sigma = 0.1,
scale_by_dt = false
})
-- Fixed timestep scaling (for variable dt simulations)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_white_noise",
sigma = 0.1,
nominal_dt = 0.01,
fixed_clock = true
})
-- High-intensity noise for testing
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_white_noise",
sigma = 1.0,
seed = 42
})

sim_add_stimulus_operator(ctx, field, opts)

Generate fractional Brownian motion (fBm) noise with configurable roughness and multi-octave structure. Creates natural-looking textures and spatially-correlated noise with long-range dependence.

sim_add_stimulus_operator(ctx, field, [options]) -> operator

Returns: Operator handle (userdata)

Note: Requires type = "stimulus_fbm".

Fractional Brownian motion is constructed by summing multiple octaves of noise:

fBm(x)=i=0O1AλiHnoise(λix)\text{fBm}(\mathbf{x}) = \sum_{i=0}^{O-1} A \cdot \lambda^{-iH} \cdot \text{noise}(\lambda^i \mathbf{x})

where:

  • OO is the number of octaves
  • AA is the base amplitude
  • λ\lambda is the lacunarity (frequency multiplier)
  • HH is the Hurst exponent

Hurst Exponent:

The Hurst exponent H(0,1)H \in (0, 1) controls the roughness:

  • H=0.5H = 0.5: Standard Brownian motion (random walk)
  • H>0.5H > 0.5: Persistent (smoother, trending)
  • H<0.5H < 0.5: Anti-persistent (rougher, mean-reverting)

Spectral Properties:

The power spectral density follows:

S(f)f(2H+1)S(f) \propto f^{-(2H+1)}
ParameterTypeDefaultRangeDescription
typestring Must be "stimulus_fbm"
amplitudedouble unboundedScale of coarsest octave (required)
hurstdouble 0.5(0, 1)Hurst exponent controlling roughness
lacunaritydouble 2.0>1Octave frequency multiplier
octavesinteger 4[1, 16]Number of octaves
seedinteger 1≥1RNG seed for reproducibility
scale_by_dtboolean trueScale writes by dt
  • Generates based on coordinates; no explicit boundaries
  • Underlying noise is typically periodic or uses value noise
  • Same seed produces identical patterns
  • Output bounded approximately by Ai=0O1λiHA \cdot \sum_{i=0}^{O-1} \lambda^{-iH}
  • Higher octaves adds fine detail but increases computation
  • lacunarity = 2 is standard; other values change frequency spacing
  • hurst > 0.5 produces visually smoother terrain; hurst < 0.5 produces rougher textures
  • Cost: O(N × octaves) per timestep
  • Each octave requires noise evaluation at different frequency
  • Higher octaves contribute diminishing detail; often 4-8 octaves sufficient
  • Consider caching for static fBm fields
-- Standard fBm (Hurst = 0.5)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_fbm",
amplitude = 0.5,
octaves = 6,
seed = 123
})
-- Smooth terrain (persistent fBm)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_fbm",
amplitude = 0.5,
hurst = 0.7, -- smoother
octaves = 6,
lacunarity = 2.0,
seed = 123
})
-- Rough texture (anti-persistent)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_fbm",
amplitude = 0.25,
hurst = 0.3, -- rougher
octaves = 8
})
-- Low-octave (broad features only)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_fbm",
amplitude = 1.0,
hurst = 0.5,
octaves = 2
})
-- High-octave detail
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_fbm",
amplitude = 0.3,
hurst = 0.5,
octaves = 12,
lacunarity = 2.0
})
-- Custom lacunarity (non-power-of-2 spacing)
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_fbm",
amplitude = 0.4,
hurst = 0.6,
octaves = 5,
lacunarity = 1.87 -- golden ratio-ish
})
-- Low amplitude for subtle texture
ooc.sim_add_stimulus_operator(ctx, field, {
type = "stimulus_fbm",
amplitude = 0.1,
hurst = 0.5,
octaves = 4
})