tanh_rate_ipn#
- class brainpy.state.tanh_rate_ipn(in_size, tau=Quantity(10., 'ms'), lambda_=1.0, sigma=1.0, mu=0.0, g=1.0, theta=0.0, mult_coupling=False, linear_summation=True, rectify_rate=0.0, rectify_output=False, rate_initializer=Constant(value=0.0), noise_initializer=Constant(value=0.0), name=None)#
NEST-compatible
tanh_rate_ipnnonlinear rate neuron with input noise.Stochastic rate model with hyperbolic-tangent nonlinearity applied to network inputs, matching NEST’s
rate_neuron_ipntemplate instantiated withtanh_rategain function.1. Model equations
The state \(X(t)\) evolves according to the Langevin equation
\[\tau\,dX(t)= \left[-\lambda X(t)+\mu+\phi(\cdot)\right]dt +\left[\sqrt{\tau}\,\sigma\right]dW(t),\]where the input nonlinearity is
\[\phi(h)=\tanh(g(h-\theta)).\]Here \(W(t)\) is a standard Brownian motion, \(\lambda\) is the passive decay rate, \(\mu\) is a constant drive, \(g\) is the gain, and \(\theta\) is the horizontal shift of the tanh function.
2. Numerical integration and noise implementation
For \(\lambda > 0\), integration uses the stochastic exponential Euler (exact for the Ornstein-Uhlenbeck process):
\[\begin{split}P_1 &= \exp(-\lambda h / \tau), \\ P_2 &= \frac{1 - P_1}{\lambda}, \\ X_{n+1} &= P_1 X_n + P_2 \left[\mu + \phi(\cdot)\right] + \sqrt{\frac{1-P_1^2}{2\lambda}} \sigma \xi_n,\end{split}\]with \(\xi_n \sim \mathcal{N}(0,1)\). For \(\lambda = 0\), it reduces to Euler-Maruyama:
\[X_{n+1} = X_n + \frac{h}{\tau} \left[\mu + \phi(\cdot)\right] + \sqrt{\frac{h}{\tau}} \sigma \xi_n.\]3. Update ordering (matching NEST ``rate_neuron_ipn`` with tanh)
Each simulation step proceeds as follows:
Store outgoing delayed value as current
rate.Draw
noise = sigma * xifrom the standard normal distribution.Propagate intrinsic dynamics with stochastic exponential Euler (Euler-Maruyama for
lambda=0).Read delayed and instantaneous input buffers.
Apply input contributions:
linear_summation=True: apply tanh to summed branch inputs.linear_summation=False: apply tanh per event before summation.
Apply rectification when
rectify_output=True(clamp to>= rectify_rate).Store outgoing instantaneous value as updated
rate.
4. Timing semantics, assumptions, and constraints
Noise term is white (independent at each step, variance scales with \(dt\)).
For \(\lambda > 0\), integration exactly preserves stationary variance of the OU process.
For \(\lambda = 0\), the process is non-stationary (variance grows linearly with time).
Multiplicative coupling factors are fixed to 1 for tanh_rate models (
mult_couplinghas no effect; kept for NEST API compatibility).
5. Computational implications
Per
update()call:Random number generation: \(O(\prod \mathrm{varshape})\).
Exponential operations for \(P_1, P_2\) when \(\lambda > 0\).
Event processing is linear in number of events per step.
Broadcasting parameters and inputs over
self.varshape.
- Parameters:
in_size (
Size) – Population shape specification consumed bybrainstate.nn.Dynamics. Determines output rate array shape.tau (
ArrayLike, optional) – Time constant \(\tau\) of rate dynamics. Must be positive. Accepts scalar or array broadcast toself.varshape. Unitful values are converted to ms; unitless are interpreted as ms. Default10.0 * u.ms.lambda (
ArrayLike, optional) – Passive decay rate \(\lambda\) (dimensionless). Must be non-negative. For \(\lambda > 0\), uses stochastic exponential Euler; for \(\lambda = 0\), uses Euler-Maruyama. Default1.0.sigma (
ArrayLike, optional) – Input noise scale (dimensionless). Must be non-negative. Scales the Wiener increment. Broadcast toself.varshape. Default1.0.mu (
ArrayLike, optional) – Mean drive \(\mu\) (dimensionless). Constant additive input. Broadcast toself.varshape. Default0.0.g (
ArrayLike, optional) – Gain of tanh nonlinearity (dimensionless). Controls steepness of tanh. Broadcast toself.varshape. Default1.0.theta (
ArrayLike, optional) – Threshold (horizontal shift) of tanh nonlinearity (dimensionless). Shifts the input \(h\) before applying tanh. Broadcast toself.varshape. Default0.0.mult_coupling (
bool, optional) – Kept for NEST compatibility. Fortanh_ratemodels, multiplicative coupling factors are identically 1, so this switch has no effect. DefaultFalse.linear_summation (
bool, optional) – Controls nonlinearity application order. IfTrue, sum inputs then apply tanh. IfFalse, apply tanh per event then sum weighted results. DefaultTrue.rectify_rate (
ArrayLike, optional) – Lower bound for output rate whenrectify_output=True(dimensionless). Must be non-negative. Broadcast toself.varshape. Default0.0.rectify_output (
bool, optional) – IfTrue, clamp updated rate to>= rectify_rateafter all dynamics. DefaultFalse.rate_initializer (
Callable, optional) – Initializer for state variablerate. Called asrate_initializer(self.varshape, batch_size)ininit_state(). Defaultbraintools.init.Constant(0.0).noise_initializer (
Callable, optional) – Initializer for state variablenoise(recording). Defaultbraintools.init.Constant(0.0).name (
strorNone, optional) – Module name passed tobrainstate.nn.Dynamics.
Parameter Mapping
Table 19 Parameter mapping to model symbols# Parameter
Default
Math symbol
Semantics
tau10.0 * u.ms\(\tau\)
Time constant of rate dynamics (ms).
lambda_1.0\(\lambda\)
Passive decay rate (dimensionless, >= 0).
sigma1.0\(\sigma\)
Input noise scale (dimensionless, >= 0).
mu0.0\(\mu\)
Constant mean drive (dimensionless).
g1.0\(g\)
Gain of tanh nonlinearity (dimensionless).
theta0.0\(\theta\)
Horizontal shift of tanh nonlinearity (dimensionless).
rectify_rate0.0\(r_{\min}\)
Lower clamp bound when
rectify_output=True.- Raises:
ValueError – If
tau <= 0,lambda_ < 0,sigma < 0, orrectify_rate < 0.ValueError – If
instant_rate_eventsspecify non-zerodelay_steps, or ifdelayed_rate_eventsspecify negativedelay_steps.
See also
tanh_rate_opnOutput-noise variant of tanh_rate.
sigmoid_rate_ipnSigmoid nonlinearity with input noise.
lin_rate_ipnLinear (identity) nonlinearity with input noise.
gauss_rate_ipnGaussian nonlinearity with input noise.
Notes
Runtime events:
instant_rate_events: applied in the current step (delay_steps=0).delayed_rate_events: scheduled with integerdelay_steps >= 0.
Event format supports dict or tuple:
Dict:
{'rate': value, 'weight': w, 'delay_steps': d, 'multiplicity': m}Tuple:
(rate, weight),(rate, weight, delay_steps), or(rate, weight, delay_steps, multiplicity)
References
Examples
>>> import brainpy >>> import brainstate >>> import saiunit as u >>> import jax.numpy as jnp >>> with brainstate.environ.context(dt=0.1 * u.ms): ... net = brainpy.state.tanh_rate_ipn( ... in_size=10, ... tau=10.0 * u.ms, ... lambda_=1.0, ... sigma=0.5, ... mu=0.0, ... g=1.0, ... theta=0.0, ... rectify_output=True, ... rectify_rate=0.0, ... ) ... net.init_all_states() ... rate = net.update(x=0.1) ... _ = rate.shape # (10,)
- init_state(**kwargs)[source]#
Initialize state variables and internal buffers.
Create
rate,noise,instant_rate,delayed_rate, and step counter states. Initialize delay queues.- Parameters:
**kwargs – Unused compatibility parameters accepted by the base-state API.
Notes
State variables are initialized from
rate_initializerandnoise_initializer. Bothinstant_rateanddelayed_rateare initialized as copies ofrate.
- property receptor_types#
Mapping of receptor type names to indices.
- Returns:
{'RATE': 0}for rate-based connections.- Return type:
- property recordables#
List of recordable state variables.
- update(x=0.0, instant_rate_events=None, delayed_rate_events=None, noise=None)[source]#
Advance rate dynamics by one simulation step.
Execute stochastic exponential Euler integration with input noise, process delayed and instant events, apply tanh nonlinearity, and optionally rectify output.
- Parameters:
x (
ArrayLike, optional) – External current input (dimensionless). Broadcast to state shape and summed withmu. Default0.0.instant_rate_events (
listorNone, optional) – Rate events to apply in the current step (delay_steps=0). Each event can be dict, tuple, or scalar. Default None.delayed_rate_events (
listorNone, optional) – Rate events to schedule with integer delays (delay_steps >= 0). Default None.noise (
ArrayLikeorNone, optional) – Custom noise samples \(\xi\) drawn from \(\mathcal{N}(0,1)\). If None, random samples are drawn internally. Useful for reproducibility or testing. Default None.
- Returns:
rate – Updated rate values with shape
self.varshape(float64).- Return type:
ndarray
Notes
Update sequence:
Extract current step index and state shape.
Drain queued delayed inputs scheduled for this step.
Schedule new delayed events and accumulate zero-delay events.
Accumulate instant events and split delta inputs by sign.
Draw noise (or use provided
noise).Compute stochastic exponential Euler step:
For \(\lambda > 0\): use OU-exact propagators.
For \(\lambda = 0\): use Euler-Maruyama.
Apply tanh nonlinearity to summed inputs (if
linear_summation=True) or use pre-transformed per-event values (ifFalse).Rectify output if
rectify_output=True.Update state variables and increment step counter.