pub fn ou_step(x: f32, mu: f32, theta: f32, sigma: f32, dt: f32, w: f32) -> f32Expand description
Ornstein-Uhlenbeck step with caller-supplied noise.
The O-U process is the canonical mean-reverting stochastic process. It is used in Idle Hero for economy curves (resource prices, rival activity) that should wander but always return to a set point.
§Math
dx = θ(μ - x) dt + σ √dt · w
x' = x + θ(μ - x) dt + σ √dt · wwhere w is a sample from a standard normal distribution N(0, 1).
§Arguments
x— current valuemu— long-run mean (equilibrium point)theta— mean-reversion speed (> 0; typical 0.1–1.0)sigma— volatility / noise scale (> 0)dt— time stepw— standard normal noise sample N(0, 1)
§Returns
Next value x'.
§Edge cases
dt = 0→ returnsxunchangedtheta = 0→ no mean reversion; pure random walkx + σ√dt·wsigma = 0→ deterministic decay tomu:x + θ(μ−x)dt
§Example
use prime_diffusion::ou_step;
// No noise — converges toward mu=0 from x=1.0
let x1 = ou_step(1.0, 0.0, 0.5, 0.0, 0.1, 0.0);
assert!((x1 - 0.95).abs() < 1e-5);