braintools.input.ou_process

Contents

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 \sqrt{\frac{2}{\tau}}\, dW,\]

so sigma is the stationary standard deviation of \(X\). The process is advanced with the exact update

\[X_{t+dt} = \mu + (X_t - \mu) e^{-dt/\tau} + \sigma \sqrt{1 - e^{-2 dt/\tau}}\, \xi_t, \qquad \xi_t \sim \mathcal{N}(0, 1),\]

which keeps the stationary standard deviation exactly sigma for any dt. Only the ratio dt / tau enters, so the result does not depend on the time unit used for dt and tau.

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) – Stationary standard deviation of the process. Supports current units.

  • tau (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Correlation 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
>>> from braintools.input import ou_process
>>> 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 starts at mean and reverts to it with time constant tau

  • Stationary variance: σ²

  • Autocorrelation decays as \(\exp(-|\text{lag}| / \tau)\)

  • Useful for modeling synaptic background activity