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 dW_t\]

where: - μ is the mean (drift target) - τ is the time constant - σ is the noise amplitude - W_t is a Wiener process

Parameters:
  • mean (float) – Mean value (drift target) of the OU process.

  • sigma (float) – Standard deviation of the noise.

  • 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).

mean#

Mean value (drift target)

Type:

float

sigma#

Noise amplitude

Type:

float

tau#

Time constant

Type:

float or Quantity

n#

Number of independent processes

Type:

int

t_start#

Start time of the process

Type:

float or Quantity

t_end#

End time of the process

Type:

float or Quantity

seed#

Random seed

Type:

int or None

Examples

>>> import brainunit as u
>>> import brainstate
>>> 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 has mean-reverting behavior controlled by tau

  • Steady-state variance: σ²/(2/τ)

  • Autocorrelation decays exponentially with time constant tau

  • For tau → ∞, approaches a Wiener process

  • For tau → 0, approaches white noise

  • Useful for modeling synaptic background activity

  • Can be combined with other Input classes using +, -, *, /

See also

WienerProcess

Wiener process without mean reversion

Poisson

Poisson spike train generator

ou_process

Functional 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.

Parameters:

duration (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – The total duration of the input.

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

dt

Get the time step from global environment.

n_steps

Get the number of time steps.

shape

Get the shape of the input array.