tanh_rate_opn#
- class brainpy.state.tanh_rate_opn(in_size, tau=Quantity(10., 'ms'), sigma=1.0, mu=0.0, g=1.0, theta=0.0, mult_coupling=False, linear_summation=True, rate_initializer=Constant(value=0.0), noise_initializer=Constant(value=0.0), noisy_rate_initializer=Constant(value=0.0), name=None)#
NEST-compatible
tanh_rate_opnnonlinear rate neuron with output noise.Deterministic rate model with output-coupled additive noise and hyperbolic-tangent nonlinearity applied to network inputs, matching NEST’s
rate_neuron_opntemplate instantiated withtanh_rategain function.1. Model equations
The internal state \(X(t)\) evolves deterministically
\[\tau\frac{dX(t)}{dt}=-X(t)+\mu+\phi(\cdot),\]where the input nonlinearity is
\[\phi(h)=\tanh(g(h-\theta)).\]The observed rate includes white noise added at the output:
\[X_\mathrm{noisy}(t)=X(t)+\sqrt{\frac{\tau}{h}}\sigma\xi(t),\]with \(\xi(t) \sim \mathcal{N}(0,1)\) and \(h=dt\) the simulation step size. The noise is scaled by \(\sqrt{\tau/h}\) so that its variance is independent of the step size, matching NEST’s implementation.
2. Numerical integration
Deterministic exponential Euler integration:
\[\begin{split}P_1 &= \exp(-h / \tau), \\ P_2 &= 1 - P_1, \\ X_{n+1} &= P_1 X_n + P_2 \left[\mu + \phi(\cdot)\right].\end{split}\]The noisy rate for outgoing communication is computed as
\[X_{\mathrm{noisy},n} = X_n + \sqrt{\frac{\tau}{h}} \sigma \xi_n.\]3. Update ordering (matching NEST ``rate_neuron_opn`` with tanh)
Each simulation step proceeds as follows:
Draw
noise = sigma * xifrom the standard normal distribution.Build
noisy_ratefrom the currentrateby adding scaled noise.Store
noisy_rateas delayed outgoing value (for delayed connections).Propagate deterministic intrinsic dynamics with exponential Euler.
Add event-driven input contributions:
linear_summation=True: apply tanh to summed branch inputs.linear_summation=False: apply tanh per event before summation.
Store
noisy_rateas instantaneous outgoing value (for instant connections).
4. Timing semantics, assumptions, and constraints
Noise is added to the output only (internal state \(X\) remains deterministic).
Noise variance is independent of step size \(h\) due to \(\sqrt{\tau/h}\) scaling.
Multiplicative coupling factors are fixed to 1 for tanh_rate models (
mult_couplinghas no effect; kept for NEST API compatibility).Unlike input-noise models, there is no rectification option for output-noise models.
5. Computational implications
Per
update()call:Random number generation: \(O(\prod \mathrm{varshape})\).
Exponential operations for \(P_1, P_2\) (single exp call).
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.sigma (
ArrayLike, optional) – Output noise scale (dimensionless). Must be non-negative. Scales the Gaussian white noise added to the output. 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.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).noisy_rate_initializer (
Callable, optional) – Initializer for state variablenoisy_rate(output with noise). Defaultbraintools.init.Constant(0.0).name (
strorNone, optional) – Module name passed tobrainstate.nn.Dynamics.
Parameter Mapping
Table 20 Parameter mapping to model symbols# Parameter
Default
Math symbol
Semantics
tau10.0 * u.ms\(\tau\)
Time constant of rate dynamics (ms).
sigma1.0\(\sigma\)
Output 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).
- Raises:
ValueError – If
tau <= 0orsigma < 0.ValueError – If
instant_rate_eventsspecify non-zerodelay_steps, or ifdelayed_rate_eventsspecify negativedelay_steps.
See also
tanh_rate_ipnInput-noise variant of tanh_rate.
sigmoid_rate_opnSigmoid nonlinearity with output noise.
lin_rate_opnLinear (identity) nonlinearity with output noise.
gauss_rate_opnGaussian nonlinearity with output 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 (identical to
tanh_rate_ipn):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_opn( ... in_size=10, ... tau=10.0 * u.ms, ... sigma=0.5, ... mu=0.0, ... g=1.0, ... theta=0.0, ... ) ... net.init_all_states() ... rate = net.update(x=0.1) ... _ = rate.shape # (10,) ... _ = net.noisy_rate.value.shape # (10,)
- init_state(**kwargs)[source]#
Initialize state variables and internal buffers.
Create
rate,noise,noisy_rate,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_initializer,noise_initializer, andnoisy_rate_initializer. Bothinstant_rateanddelayed_rateare initialized as copies ofnoisy_rate.
- 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 deterministic exponential Euler integration, add output noise, process delayed and instant events, and apply tanh nonlinearity.
- 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 deterministic rate values with shape
self.varshape(float64). Note: the communicated output isnoisy_rate, notrate.- Return type:
ndarray
Notes
Update sequence:
Draw noise (or use provided
noise).Compute
noisy_ratefrom currentrateby adding scaled noise: \(X_{\mathrm{noisy}} = X + \sqrt{\tau/h} \sigma \xi\).Store
noisy_rateas delayed outgoing value.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.
Compute deterministic exponential Euler step: \(X_{n+1} = P_1 X_n + P_2 [\mu + \phi(\cdot)]\).
Apply tanh nonlinearity to summed inputs (if
linear_summation=True) or use pre-transformed per-event values (ifFalse).Store
noisy_rateas instantaneous outgoing value.Update state variables and increment step counter.