gamma_sup_generator#
- class brainpy.state.gamma_sup_generator(in_size=1, rate=Quantity(0., 'Hz'), gamma_shape=1, n_proc=1, start=Quantity(0., 'ms'), stop=None, origin=Quantity(0., 'ms'), rng_seed=0, name=None)#
Superposition of independent gamma processes (NEST-compatible).
Description
gamma_sup_generatorre-implements NEST’s stimulation device of the same name. It emits, per output train and simulation step, the multiplicity of spikes produced by superimposingn_procindependent component renewal processes with gamma-distributed inter-spike intervals.1. State-space model, derivation, and update equations
Let \(k = \mathrm{gamma\_shape}\) and \(r = \mathrm{rate}\) in Hz. Each component gamma process is represented as a cyclic chain of
kexponential phases. Using an occupation vector per output train,\[\mathbf{occ} = (occ_0, \dots, occ_{k-1}), \qquad \sum_{i=0}^{k-1} occ_i = n_{\mathrm{proc}},\]a process in phase
itransitions to phasei+1(modk) with per-step probability\[p = r \cdot k \cdot \Delta t / 1000.\]This is the discrete-time hazard form used by NEST. For each bin
i,\[n_i \sim \mathrm{Binomial}(occ_i, p),\]except for NEST’s sparse/high-count approximation branch:
if
occ_i >= 100 and p <= 0.01, orif
occ_i >= 500 and p * occ_i <= 0.1,
use
Poisson(p * occ_i)and clip toocc_i.After sampling, all
n_iare moved simultaneously to preserve integer mass and avoid order-dependent updates. The emitted spike multiplicity for one train is\[K_n = n_{k-1},\]i.e., transitions leaving the last phase and re-entering phase 0. This allows per-step counts larger than 1, matching NEST
SpikeEventmultiplicity semantics.2. Timing semantics and activity window
Activity follows NEST
StimulationDevice::is_activefor spike generators:\[t_{\min} < t \le t_{\max}, \qquad t_{\min} = origin + start,\quad t_{\max} = origin + stop.\]Therefore
startis exclusive andstopis inclusive. Internally, finite times are projected to integer steps withround(time_ms / dt_ms)and checked ast_min_step < curr_step <= t_max_step.3. Assumptions, constraints, and computational implications
Parameters are scalarized to
float64/intbefore simulation. Enforced constraints arerate >= 0,gamma_shape >= 1,n_proc >= 1, andstop >= start. Ifdtis available, finiteorigin,start, andstopmust lie on the simulation grid (absolute tolerance1e-12intime/dtratio).Runtime complexity of
update()is \(O(\prod \mathrm{varshape} \cdot \mathrm{gamma\_shape})\), with state memory \(O(\prod \mathrm{varshape} \cdot \mathrm{gamma\_shape})\) from the occupation matrix. RNG sampling usesnumpy.random.Generator(seeded byrng_seed), so stochastic draws are CPU NumPy based rather than JAX-key based.- Parameters:
in_size (
Size, optional) – Output size specification consumed bybrainstate.nn.Dynamics. The exact shape returned byupdate()isself.varshapederived fromin_size; each element corresponds to one independent output train. Default is1.rate (
ArrayLike, optional) – Scalar component-process rate in spikes/s (Hz), shape()after conversion. Accepts a single-element numericArrayLikeor asaiunit.Quantityconvertible tou.Hz. Must satisfyrate >= 0. Default is0.0 * u.Hz.gamma_shape (
ArrayLike, optional) – Scalar integer gamma shape \(k\), shape()after conversion. Parsed via nearest-integer check with absolute tolerance1e-12. Must satisfygamma_shape >= 1. Default is1.n_proc (
ArrayLike, optional) – Scalar integer number of independent component processes per output train, shape()after conversion. Parsed by nearest-integer check with absolute tolerance1e-12. Must satisfyn_proc >= 1. Default is1.start (
ArrayLike, optional) – Scalar relative activation time in ms, shape()after conversion. Effective lower activity bound isorigin + startand is exclusive. Must be grid-representable whendtis available. Default is0.0 * u.ms.stop (
ArrayLikeorNone, optional) – Scalar relative deactivation time in ms, shape()after conversion. Effective upper activity bound isorigin + stopand is inclusive.Nonemaps to+inf. Must satisfystop >= startand be grid-representable when finite anddtis available. Default isNone.origin (
ArrayLike, optional) – Scalar time-origin offset in ms, shape()after conversion, added tostartandstopto compute absolute active bounds. Must be grid-representable when finite anddtis available. Default is0.0 * u.ms.rng_seed (
int, optional) – Seed used to initializenumpy.random.default_rngininit_state(). Default is0.name (
strorNone, optional) – Optional node name passed tobrainstate.nn.Dynamics.
Parameter Mapping
Table 35 Parameter mapping to model symbols# Parameter
Default
Math symbol
Semantics
rate0.0 * u.Hz\(r\)
Component-process rate in spikes/s.
gamma_shape1\(k\)
Number of cyclic exponential phases per component process.
n_proc1\(n_{\mathrm{proc}}\)
Number of superimposed component processes per output train.
start0.0 * u.ms\(t_{\mathrm{start,rel}}\)
Relative exclusive lower bound of activity.
stopNone\(t_{\mathrm{stop,rel}}\)
Relative inclusive upper bound;
Nonemaps to+\infty.origin0.0 * u.ms\(t_0\)
Global offset added to
startandstop.in_size1Defines
self.varshapefor independent output trains.rng_seed0Seed of the NumPy generator used for transition draws.
- Raises:
ValueError – If scalar conversion fails due to non-scalar inputs; if
rate < 0; ifgamma_shape < 1; ifn_proc < 1; ifstop < start; if integer-valued inputs are non-integral beyond tolerance; or if finiteorigin/start/stopare not multiples of simulation resolution whendtis available.TypeError – If unit conversion to
u.Hzoru.msfails for supplied inputs.KeyError – At runtime, if required simulation-context fields (for example
dtused bybrainstate.environ.get_dt()) are unavailable.
Notes
Initial occupation is the NEST equilibrium approximation used in
pre_run_hook():floor(n_proc / gamma_shape)in all bins, with the remainder added to the last bin.As in NEST, each output train maintains independent internal occupation states.
In the direct binomial branch,
transition_probis numerically clamped to[0, 1]before calling NumPy RNG to avoid invalid probability inputs in edge cases.
Examples
>>> import brainpy >>> import brainstate >>> import saiunit as u >>> with brainstate.environ.context(dt=0.1 * u.ms): ... gen = brainpy.state.gamma_sup_generator( ... in_size=(2, 3), ... rate=20.0 * u.Hz, ... gamma_shape=3, ... n_proc=50, ... start=5.0 * u.ms, ... stop=40.0 * u.ms, ... rng_seed=7, ... ) ... with brainstate.environ.context(t=12.0 * u.ms): ... counts = gen.update() ... _ = counts.shape
>>> import brainpy >>> import saiunit as u >>> gen = brainpy.state.gamma_sup_generator(rate=15.0 * u.Hz, gamma_shape=2) >>> gen.set(n_proc=20, stop=None, origin=1.0 * u.ms) >>> params = gen.get() >>> _ = params['gamma_shape'], params['n_proc']
See also
ppd_sup_generatorSuperposition with dead-time component processes.
sinusoidal_gamma_generatorInhomogeneous gamma generator with sinusoidal rate.
References
- get()[source]#
Return current public parameters as plain Python scalars.
- Returns:
out –
dictwith keysrate,gamma_shape,n_proc,start,stop, andorigin. Values arefloat/intin public units (Hz forrate, ms for times).- Return type:
- init_state(batch_size=None, **kwargs)[source]#
Initialize occupancy and RNG state for all output trains.
- set(*, rate=<object object>, gamma_shape=<object object>, n_proc=<object object>, start=<object object>, stop=<object object>, origin=<object object>)[source]#
Set public parameters with NEST-compatible semantics.
- Parameters:
rate (
ArrayLikeorobject, optional) – New scalar component rate in Hz._UNSETkeeps current value.gamma_shape (
ArrayLikeorobject, optional) – New scalar integer gamma shape>= 1._UNSETkeeps current value.n_proc (
ArrayLikeorobject, optional) – New scalar integer number of component processes>= 1._UNSETkeeps current value.start (
ArrayLikeorobject, optional) – New scalar relative start time in ms._UNSETkeeps current value.stop (
ArrayLike,object, orNone, optional) – New scalar relative stop time in ms;Nonemaps to+inf._UNSETkeeps current value.origin (
ArrayLikeorobject, optional) – New scalar origin time in ms._UNSETkeeps current value.
- Raises:
ValueError – If converted values violate model constraints or are non-scalar.
TypeError – If unit conversion to Hz/ms fails.
- update()[source]#
Advance one simulation step and return per-train spike multiplicity.
The method lazily initializes state, refreshes timing/probability cache when
dtchanges, applies the active-window test, then updates each train’s occupation vector using NEST-equivalent transition logic.- Returns:
out – JAX array with dtype
int64and shapeself.varshape. Each element is the number of emitted spikes for one output train in the current step.- Return type:
jax.Array- Raises:
ValueError – If cached times fail simulation-grid consistency checks during cache refresh.
KeyError – If required simulation context values (for example
dt) are unavailable inbrainstate.environ.