braintools.input.OUProcess#
- class braintools.input.OUProcess(mean, sigma, tau, duration, n=1, t_start=None, t_end=None, seed=None)#
Generate Ornstein-Uhlenbeck process input.
The Ornstein-Uhlenbeck (OU) process is a stochastic process that models a particle undergoing Brownian motion with friction. It exhibits mean-reverting behavior, making it useful for modeling fluctuations around a steady state in neural systems.
The process follows the stochastic differential equation
\[dX_t = \frac{\mu - X_t}{\tau} dt + \sigma \sqrt{\frac{2}{\tau}}\, dW_t\]where μ is the mean, τ the correlation time, and σ the stationary standard deviation of \(X\). It is advanced with the exact update \(X_{t+dt} = \mu + (X_t - \mu) e^{-dt/\tau} + \sigma\sqrt{1 - e^{-2dt/\tau}}\,\xi_t\), so the stationary standard deviation is exactly σ for any
dtand the result does not depend on the time unit used.- Parameters:
mean (
float) – Mean value (drift target) of the OU process.sigma (
float) – Stationary standard deviation of the process.tau (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Correlation time constant. Larger values = slower fluctuations. Supports time units.duration (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Total duration of the input signal. Supports time units.n (
int) – Number of independent OU processes to generate. Default is 1.t_start (
Array|ndarray|bool|number|bool|int|float|complex|Quantity|None) – Start time of the process. Before this, output is 0. Default is 0.t_end (
Array|ndarray|bool|number|bool|int|float|complex|Quantity|None) – End time of the process. After this, output is 0. Default is duration.seed (
int|None) – Random seed for reproducibility. Default is None (uses global random state).
- Variables:
mean (float) – Mean value (drift target)
sigma (float) – Stationary standard deviation
tau (float or Quantity) – Correlation time constant
n (int) – Number of independent processes
t_start (float or Quantity) – Start time of the process
t_end (float or Quantity) – End time of the process
seed (int or None) – Random seed
Examples
>>> import brainunit as u >>> import brainstate >>> from braintools.input import OUProcess >>> brainstate.environ.set(dt=0.1 * u.ms)
Simple OU process:
>>> ou = OUProcess( ... mean=0.5, ... sigma=0.2, ... tau=10 * u.ms, ... duration=500 * u.ms ... ) >>> signal = ou()
Fast fluctuations around zero:
>>> fast_ou = OUProcess( ... mean=0.0, ... sigma=0.5, ... tau=2 * u.ms, # Fast time constant ... duration=200 * u.ms ... )
Slow fluctuations with drift:
>>> slow_ou = OUProcess( ... mean=1.0, ... sigma=0.3, ... tau=50 * u.ms, # Slow time constant ... duration=1000 * u.ms ... )
Multiple independent processes:
>>> multi_ou = OUProcess( ... mean=0.0, ... sigma=0.2, ... tau=5 * u.ms, ... duration=300 * u.ms, ... n=10 # 10 independent processes ... )
Windowed OU process:
>>> windowed_ou = OUProcess( ... mean=0.5, ... sigma=0.1, ... tau=20 * u.ms, ... duration=500 * u.ms, ... t_start=100 * u.ms, ... t_end=400 * u.ms ... )
Combine with other inputs:
>>> from braintools.input import Sinusoidal, Step >>> # OU process with time-varying mean >>> ou = OUProcess(mean=0.5, sigma=0.1, tau=20 * u.ms, duration=500 * u.ms) >>> sine_mean = Sinusoidal(0.3, 2 * u.Hz, 500 * u.ms) >>> modulated_ou = ou + sine_mean >>> # Gated OU process >>> gate = Step([0, 1.0], [0 * u.ms, 50 * u.ms], 500 * u.ms) >>> gated_ou = ou * gate
Create reproducible OU process:
>>> fixed_ou = OUProcess( ... mean=0.0, ... sigma=0.15, ... tau=15 * u.ms, ... duration=200 * u.ms, ... seed=123 # Fixed seed ... )
Notes
The process starts at
meanand reverts to it with time constant tauStationary variance: σ²
Autocorrelation decays as \(\exp(-|\text{lag}| / \tau)\)
For tau much shorter than dt, consecutive samples are nearly independent
Useful for modeling synaptic background activity
Can be combined with other Input classes using
+,-,*,/
See also
WienerProcessWiener process without mean reversion
PoissonPoisson spike train generator
ou_processFunctional API for OU process
- __init__(mean, sigma, tau, duration, n=1, t_start=None, t_end=None, seed=None)[source]#
Initialize the Input base class.
Methods
__init__(mean, sigma, tau, duration[, n, ...])Initialize the Input base class.
apply(func)Apply a custom function to the input.
clip([min_val, max_val])Clip the input values to a range.
generate()Generate the OU process using the functional API.
repeat(n_times)Repeat the input pattern n times.
scale(factor)Scale the input by a factor.
shift(time_shift)Shift the input in time.
smooth(tau)Apply exponential smoothing to the input.
Attributes
dtGet the time step from global environment.
n_stepsGet the number of time steps.
shapeGet the shape of the input array.