braintools.input.ou_process#
- braintools.input.ou_process(mean, sigma, tau, duration, n=1, t_start=None, t_end=None, seed=None)#
Generate Ornstein-Uhlenbeck process input.
Creates a stochastic input following the Ornstein-Uhlenbeck process, which models a particle undergoing Brownian motion with friction. The process tends to revert to a mean value over time.
The dynamics follow:
\[dX = \frac{\mu - X}{\tau} dt + \sigma dW\]- Parameters:
mean (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Mean value (drift) of the OU process. Supports current units.sigma (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Standard deviation of the noise. Supports current units.tau (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Time constant of the process. 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).
- Returns:
current – The OU process input. Shape is (n_timesteps,) if n=1, or (n_timesteps, n) if n>1.
- Return type:
ndarray or Quantity
Examples
>>> import brainunit as u >>> import brainstate >>> brainstate.environ.set(dt=0.1 * u.ms)
Simple OU process
>>> current = ou_process( ... mean=0.5 * u.nA, ... sigma=0.2 * u.nA, ... tau=10 * u.ms, ... duration=500 * u.ms ... )
Fast fluctuations around zero
>>> current = ou_process( ... mean=0 * u.pA, ... sigma=5 * u.pA, ... tau=2 * u.ms, # Fast time constant ... duration=200 * u.ms ... )
Slow fluctuations with drift
>>> current = ou_process( ... mean=1.0 * u.nA, ... sigma=0.3 * u.nA, ... tau=50 * u.ms, # Slow time constant ... duration=1000 * u.ms ... )
Multiple independent processes
>>> currents = ou_process( ... mean=0 * u.pA, ... sigma=2 * u.pA, ... tau=5 * u.ms, ... duration=300 * u.ms, ... n=10 # 10 independent processes ... )
Windowed OU process
>>> current = ou_process( ... mean=0.5 * u.nA, ... sigma=0.1 * u.nA, ... tau=20 * u.ms, ... duration=500 * u.ms, ... t_start=100 * u.ms, ... t_end=400 * u.ms ... )
Notes
The process has mean-reverting behavior controlled by tau
Variance at steady state: σ²/(2/τ)
Autocorrelation decays exponentially with time constant tau
Useful for modeling synaptic background activity