Noise Operators
🎲 Stochastic Noise
Section titled “🎲 Stochastic Noise”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.
Method Signature
Section titled “Method Signature”sim_add_stochastic_noise_operator(ctx, field, [options]) -> operatorReturns: Operator handle (userdata)
Mathematical Formulation
Section titled “Mathematical Formulation”Ornstein-Uhlenbeck Process:
where:
- is the noise state
- is the autocorrelation time
- is the noise intensity
- is a Wiener increment
Spectral Characteristics:
The noise has power spectral density:
where controls the spectral color:
- : White noise (flat spectrum)
- : Pink/flicker noise ()
- : Brownian/red noise ()
Stochastic Calculus Laws:
- Itô: Standard interpretation; independent of current state
- Stratonovich: Midpoint rule; preserves chain rule; often preferred for physical systems
Parameters
Section titled “Parameters”| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
sigma | double | ≥0 | Noise intensity (standard deviation) (required) | |
tau | double | 0.0 | ≥0 | Autocorrelation decay time (0 = white noise) |
alpha | double | 0.0 | [0, 2.5] | Spectral exponent controlling color |
seed | integer | 0 | ≥0 | RNG seed (0 = auto from system) |
law | enum | "ito" | ito, stratonovich | Stochastic calculus convention |
Boundary & Initial Conditions
Section titled “Boundary & Initial Conditions”- Operates elementwise; no boundary handling required
- Internal state initialized to zero; transient period ≈
- For reproducible results, set explicit
seed
Stability & Convergence
Section titled “Stability & Convergence”- White noise (): Uncorrelated samples; scales with
- Colored noise (): Requires for accurate dynamics
- Large values produce slowly-varying (low-frequency dominated) noise
- Stratonovich interpretation avoids spurious drift in multiplicative noise contexts
Performance Notes
Section titled “Performance Notes”- 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
Examples
Section titled “Examples”-- Simple white noiseooc.sim_add_stochastic_noise_operator(ctx, field, { sigma = 0.1})
-- Colored noise with Stratonovich interpretationooc.sim_add_stochastic_noise_operator(ctx, field, { sigma = 0.15, law = "stratonovich"})
-- Ornstein-Uhlenbeck processooc.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 testingooc.sim_add_stochastic_noise_operator(ctx, field, { sigma = 0.1, seed = 12345})🎵 Random Fourier
Section titled “🎵 Random Fourier”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.
Method Signature
Section titled “Method Signature”sim_add_stimulus_operator(ctx, field, [options]) -> operatorReturns: Operator handle (userdata)
Note: Requires type = "stimulus_random_fourier".
Mathematical Formulation
Section titled “Mathematical Formulation”The field is constructed as a superposition of random sinusoids:
where:
- is the
amplitude - is
feature_count - are random wavenumbers in
- are random phases in
- are weights from the spectral slope:
- is the temporal frequency (optional)
Spectral Slope:
When spectral_slope () is specified, the power spectral density follows:
Parameters
Section titled “Parameters”Core Parameters:
| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
type | string | — | — | Must be "stimulus_random_fourier" |
amplitude | double | unbounded | Overall scale of features (required) | |
feature_count | integer | 16 | ≥1 | Number of random basis functions |
seed | integer | 1 | ≥1 | RNG seed for reproducibility |
Spectral Parameters:
| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
k_min | double | 0.1 | ≥0 | Minimum wavenumber (rad/unit) |
k_max | double | 1.0 | >k_min | Maximum wavenumber (rad/unit) |
spectral_slope | double | 0.0 | unbounded | Spectral decay exponent |
Temporal Parameters:
| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
omega | double | 0.0 | unbounded | Temporal angular frequency (rad/s) |
time_offset | double | 0.0 | unbounded | Additional time shift |
nominal_dt | double | 0.0 | ≥0 | Lock time to fixed timestep |
fixed_clock | boolean | false | — | Use nominal_dt for time evolution |
Coordinate Mapping:
| Parameter | Type | Default | Description |
|---|---|---|---|
coord_mode | enum | "axis" | Coordinate mode: axis, angle, radial, separable |
coord_axis | enum | "x" | Axis for 1D mapping |
coord_combine | enum | "multiply" | Combine rule for separable: multiply, add |
coord_angle | double | 0.0 | Angle for angle-mode (radians) |
origin_x, origin_y | double | 0.0 | Coordinate origin |
spacing_x, spacing_y | double | 1.0 | Grid spacing |
coord_center_x, coord_center_y | double | 0.0 | Center for radial mode |
coord_velocity_x, coord_velocity_y | double | 0.0 | Moving center velocity |
Output Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
scale_by_dt | boolean | true | Scale writes by dt |
Boundary & Initial Conditions
Section titled “Boundary & Initial Conditions”- Generates field values based on coordinates; no explicit boundaries
- Periodic by nature due to sinusoidal basis
- Same seed produces identical patterns
Stability & Convergence
Section titled “Stability & Convergence”- Output is bounded by (sum of all features)
spectral_slope > 0produces smoother fields (low-frequency dominated)spectral_slope < 0produces rougher fields (high-frequency dominated)- More features improve statistical convergence at cost of computation
Performance Notes
Section titled “Performance Notes”- Computational cost: O(N × feature_count) per timestep
- Features are precomputed once at creation; only phases advance
- Use
fixed_clockfor deterministic, frame-rate-independent animation
Examples
Section titled “Examples”-- Basic random Fourier fieldooc.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 fieldooc.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 mappingooc.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})❄️ White Noise
Section titled “❄️ White Noise”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.
Method Signature
Section titled “Method Signature”sim_add_stimulus_operator(ctx, field, [options]) -> operatorReturns: Operator handle (userdata)
Note: Requires type = "stimulus_white_noise".
Mathematical Formulation
Section titled “Mathematical Formulation”Each sample is drawn independently from a Gaussian distribution:
When scale_by_dt = true, the noise is scaled for proper stochastic integration:
This ensures that the integrated noise has variance proportional to time (Wiener process behavior).
Parameters
Section titled “Parameters”| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
type | string | — | — | Must be "stimulus_white_noise" |
sigma | double | ≥0 | Standard deviation (required) | |
mean | double | 0.0 | unbounded | Mean offset |
seed | integer | 1 | ≥1 | RNG seed for reproducibility |
scale_by_dt | boolean | true | — | Scale by sqrt(dt) for stochastic integration |
nominal_dt | double | 0.0 | ≥0 | Lock scaling to fixed timestep |
fixed_clock | boolean | false | — | Use nominal_dt for scaling |
Boundary & Initial Conditions
Section titled “Boundary & Initial Conditions”- Operates elementwise; no boundary handling required
- Each call generates fresh noise; no temporal correlation
- Same seed produces identical noise sequence
Stability & Convergence
Section titled “Stability & Convergence”- 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
Performance Notes
Section titled “Performance Notes”- Uses Box-Muller or similar transform for Gaussian generation
- One random number per element per timestep
- Very fast; typically memory-bandwidth limited
Examples
Section titled “Examples”-- Basic white noiseooc.sim_add_stimulus_operator(ctx, field, { type = "stimulus_white_noise", sigma = 0.05, seed = 12345})
-- White noise with nonzero meanooc.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 testingooc.sim_add_stimulus_operator(ctx, field, { type = "stimulus_white_noise", sigma = 1.0, seed = 42})🌫️ Fractional Brownian Motion
Section titled “🌫️ Fractional Brownian Motion”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.
Method Signature
Section titled “Method Signature”sim_add_stimulus_operator(ctx, field, [options]) -> operatorReturns: Operator handle (userdata)
Note: Requires type = "stimulus_fbm".
Mathematical Formulation
Section titled “Mathematical Formulation”Fractional Brownian motion is constructed by summing multiple octaves of noise:
where:
- is the number of octaves
- is the base amplitude
- is the lacunarity (frequency multiplier)
- is the Hurst exponent
Hurst Exponent:
The Hurst exponent controls the roughness:
- : Standard Brownian motion (random walk)
- : Persistent (smoother, trending)
- : Anti-persistent (rougher, mean-reverting)
Spectral Properties:
The power spectral density follows:
Parameters
Section titled “Parameters”| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
type | string | — | — | Must be "stimulus_fbm" |
amplitude | double | unbounded | Scale of coarsest octave (required) | |
hurst | double | 0.5 | (0, 1) | Hurst exponent controlling roughness |
lacunarity | double | 2.0 | >1 | Octave frequency multiplier |
octaves | integer | 4 | [1, 16] | Number of octaves |
seed | integer | 1 | ≥1 | RNG seed for reproducibility |
scale_by_dt | boolean | true | — | Scale writes by dt |
Boundary & Initial Conditions
Section titled “Boundary & Initial Conditions”- Generates based on coordinates; no explicit boundaries
- Underlying noise is typically periodic or uses value noise
- Same seed produces identical patterns
Stability & Convergence
Section titled “Stability & Convergence”- Output bounded approximately by
- Higher
octavesadds fine detail but increases computation lacunarity = 2is standard; other values change frequency spacinghurst > 0.5produces visually smoother terrain;hurst < 0.5produces rougher textures
Performance Notes
Section titled “Performance Notes”- 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
Examples
Section titled “Examples”-- 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 detailooc.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 textureooc.sim_add_stimulus_operator(ctx, field, { type = "stimulus_fbm", amplitude = 0.1, hurst = 0.5, octaves = 4})