poisson_generator_ps#
- class brainpy.state.poisson_generator_ps(in_size=1, rate=Quantity(0., 'Hz'), dead_time=Quantity(0., 'ms'), start=Quantity(0., 'ms'), stop=None, origin=Quantity(0., 'ms'), rng_seed=0, name=None)#
Precise-time Poisson spike generator with dead time (NEST-compatible).
Description
poisson_generator_psre-implements NEST’s precise-time stimulation devicepoisson_generator_psand emits off-grid spike times generated by an absolute-refractory renewal process.1. Renewal process with dead time
Let
rbe the configured mean rate (spikes/s) and \(t_{\mathrm{dead}}\) be dead time (ms). Inter-spike intervals (ISIs) are sampled as\[\Delta t = t_{\mathrm{dead}} + \xi \alpha, \qquad \xi \sim \mathrm{Exp}(1), \qquad \alpha = \frac{1000}{r} - t_{\mathrm{dead}}.\]The mean ISI is
\[\mathbb{E}[\Delta t] = t_{\mathrm{dead}} + \alpha = \frac{1000}{r},\]so the stationary mean rate is preserved exactly when \(\alpha \ge 0\), which is equivalent to
dead_time <= 1000 / rateforrate > 0.When a stream is (re)initialized at an active step, the first offset from the local active left boundary is sampled from the stationary backward-recurrence distribution used by NEST:
uniform branch on
[0, dead_time)with probabilitydead_time * rate / 1000,shifted exponential branch on
[dead_time, +inf)otherwise.
This avoids transient rate bias immediately after activation.
2. Activity window and update ordering
For one simulation step with left edge \(t\) and width \(dt\) (both in ms), define
\[t_{\min} = \max(t,\, origin + start), \qquad t_{\max} = \min(t + dt,\, origin + stop).\]If
t_min < t_maxandrate > 0, spikes are emitted usingt_min < spike_time <= t_max(left-open, right-closed on the active slice). This matches NESTpoisson_generator_ps.cppordering semantics.3. Assumptions, constraints, and computational implications
rate,dead_time,start,stop, andoriginare scalar public parameters converted tofloat64(Hz/ms).startandoriginmust be finite;stopmust be finite or+inf;stop >= start.Per-target streams are independent
numpy.random.Generatorinstances spawned fromrng_seedvianumpy.random.SeedSequence.update()cost is \(O(N + S)\) per step where \(N=\prod \mathrm{varshape}\) and \(S\) is the number of spikes emitted in the step across all streams.
- Parameters:
in_size (
Size, optional) – Output size specification forbrainstate.nn.Dynamics. The generated multiplicity tensor fromupdate()has shapeself.varshapederived fromin_size. Each element corresponds to one independent output train. Default is1.rate (
ArrayLike, optional) – Scalar mean firing rate in spikes/s (Hz). Accepts anyArrayLikewith exactly one element, optionally asaiunit.Quantityconvertible tou.Hz. Must satisfyrate >= 0. Default is0.0 * u.Hz.dead_time (
ArrayLike, optional) – Scalar absolute dead time in ms. Accepts one-elementArrayLikeor quantity convertible tou.ms. Must satisfydead_time >= 0anddead_time <= 1000 / ratewhenrate > 0. Default is0.0 * u.ms.start (
ArrayLike, optional) – Scalar relative activation time in ms. Effective lower activity bound isorigin + start. Must be finite after conversion. Default is0.0 * u.ms.stop (
ArrayLikeorNone, optional) – Scalar relative deactivation time in ms. Effective upper activity bound isorigin + stop.Nonemaps to+inf. Must satisfystop >= startafter conversion. Default isNone.origin (
ArrayLike, optional) – Scalar global time offset in ms added tostartandstop. Must be finite after conversion. Default is0.0 * u.ms.rng_seed (
int, optional) – Seed passed tonumpy.random.SeedSequencefor per-target RNG stream construction ininit_state(). Default is0.name (
strorNone, optional) – Optional node name passed tobrainstate.nn.Dynamics.
Parameter Mapping
Table 32 Parameter mapping to model symbols# Parameter
Default
Math symbol
Semantics
rate0.0 * u.Hz\(r\)
Target stationary rate in spikes/s.
dead_time0.0 * u.ms\(t_{\mathrm{dead}}\)
Absolute refractory interval added to every ISI.
start0.0 * u.ms\(t_{\mathrm{start,rel}}\)
Relative activity-window lower bound (inclusive in slicing step).
stopNone\(t_{\mathrm{stop,rel}}\)
Relative activity-window upper bound;
Nonemaps to+\infty.origin0.0 * u.ms\(t_0\)
Global offset added to
startandstop.in_size1Defines
self.varshapeand number of independent trains.rng_seed0Root seed used to spawn independent per-target RNG streams.
- Raises:
ValueError – If
rate < 0;dead_time < 0;stop < start;startororiginis non-finite;stopis neither finite nor+inf; ordead_time > 1000 / ratewhenrate > 0.TypeError – If supplied
ArrayLikevalues cannot be converted to scalar Hz/ms.KeyError – At update time, if required simulation context entries such as
dtare unavailable throughbrainstate.environ.
Notes
Unlike the grid-constrained
poisson_generator, this model tracks and emits off-grid spike times with sub-step precision.last_spike_timestores the latest emitted precise time per output.last_spike_offsetstores(t + dt) - last_spike_timeat the step where that spike was emitted, using ms units.Calling
set()withrate=...resetsnext_spike_timestate, mirroring NEST behavior.
Examples
>>> import brainpy >>> import brainstate >>> import saiunit as u >>> with brainstate.environ.context(dt=0.1 * u.ms): ... gen = brainpy.state.poisson_generator_ps( ... in_size=(2,), ... rate=800.0 * u.Hz, ... dead_time=0.5 * u.ms, ... start=5.0 * u.ms, ... stop=30.0 * u.ms, ... rng_seed=7, ... ) ... with brainstate.environ.context(t=10.0 * u.ms): ... counts, times = gen.update(return_precise_times=True) ... _ = counts.shape, len(times)
>>> import brainpy >>> import saiunit as u >>> gen = brainpy.state.poisson_generator_ps(rate=500.0 * u.Hz) >>> gen.set(dead_time=0.8 * u.ms, stop=None) >>> params = gen.get() >>> _ = params["rate"], params["dead_time"], params["stop"]
See also
poisson_generatorGrid-constrained homogeneous Poisson generator.
inhomogeneous_poisson_generatorTime-varying Poisson generator.
References
- get()[source]#
Return current public parameters as plain Python scalars.
- Returns:
params – Dictionary with five
floatentries:'rate'– mean firing rate in spikes/s (Hz).'dead_time'– absolute refractory dead time in ms.'start'– relative exclusive-lower activity bound in ms.'stop'– relative inclusive-upper activity bound in ms;infwhen deactivation is disabled (stop=Nonewas passed).'origin'– global time offset in ms.
- Return type:
Notes
Returned values are plain Python
floatscalars (float64precision). They mirror the internal scalar attributes set in__init__()or updated byset()and are not bound to anysaiunitquantities.See also
poisson_generator_ps.setUpdate one or more parameters in place.
Examples
>>> import brainpy >>> import saiunit as u >>> gen = brainpy.state.poisson_generator_ps( ... rate=800.0 * u.Hz, ... dead_time=0.5 * u.ms, ... start=5.0 * u.ms, ... stop=100.0 * u.ms, ... origin=2.0 * u.ms, ... ) >>> params = gen.get() >>> params['rate'] 800.0 >>> params['dead_time'] 0.5 >>> params['stop'] 100.0
- init_state(batch_size=None, **kwargs)[source]#
Initialize precise-spike state buffers and per-target RNG streams.
- Parameters:
Notes
Calling
init_state()resets all state buffers and re-seeds all RNG streams. Repeated calls therefore restart the stochastic sequence from the beginning.update()calls this method lazily on the first step ifinit_state()has not been invoked explicitly.See also
poisson_generator_ps.updateConsumes state buffers populated here.
Examples
>>> import brainstate >>> import saiunit as u >>> from brainpy.state import poisson_generator_ps >>> with brainstate.environ.context(dt=0.1 * u.ms): ... gen = poisson_generator_ps(in_size=4, rate=800.0 * u.Hz, rng_seed=7) ... gen.init_state()
- set(*, rate=<object object>, dead_time=<object object>, start=<object object>, stop=<object object>, origin=<object object>)[source]#
Update public parameters and refresh generator state when required.
Only keyword arguments that are explicitly passed are modified; omitted arguments retain their current values.
- Parameters:
rate (
ArrayLikeorobject, optional) – New scalar mean firing rate in spikes/s (Hz). Accepts anyArrayLikewith exactly one element, or asaiunit.Quantityconvertible tou.Hz. Must satisfyrate >= 0after conversion. Setting this parameter resetsnext_spike_timestate to-inffor all targets, matching NEST behavior. Omit to keep the current value.dead_time (
ArrayLikeorobject, optional) – New scalar absolute dead time in ms. Accepts one-elementArrayLikeor quantity convertible tou.ms. Must satisfydead_time >= 0anddead_time <= 1000 / ratewhenrate > 0after conversion. Omit to keep the current value.start (
ArrayLikeorobject, optional) – New scalar relative activation time in ms. Effective lower activity bound isorigin + start. Must be finite after conversion. Omit to keep the current value.stop (
ArrayLikeorNoneorobject, optional) – New scalar relative deactivation time in ms.Nonemaps to+inf. Must satisfystop >= startafter conversion. Omit to keep the current value.origin (
ArrayLikeorobject, optional) – New scalar global time offset in ms added tostartandstop. Must be finite after conversion. Omit to keep the current value.
- Raises:
ValueError – If updated parameters violate model constraints: negative
rate/dead_time,stop < start, non-finiteorigin/start, ordead_time > 1000 / rateforrate > 0.TypeError – If any supplied parameter cannot be converted to scalar Hz/ms.
See also
poisson_generator_ps.getRead-back current parameter values.
Examples
>>> import brainpy >>> import saiunit as u >>> gen = brainpy.state.poisson_generator_ps(rate=500.0 * u.Hz) >>> gen.set(rate=1000.0 * u.Hz, dead_time=0.5 * u.ms) >>> params = gen.get() >>> _ = params['rate'], params['dead_time']
- property step_spike_times_ms#
Precise spike times emitted in the most recent
update()call.- Returns:
spike_times – Tuple of length
np.prod(self.varshape). Each element is a one-dimensionalnumpy.ndarraywith dtypefloat64containing the emitted precise spike times (ms) for that flattened output train in the latest simulation step. Arrays are empty when no spikes were emitted for the train in the most recent step.- Return type:
tupleofnumpy.ndarray
Notes
The tuple is replaced atomically at each
update()call. Holding a reference to a previous value is safe because each call creates new arrays. Spike times are in the half-open interval(t_min_active, t_max_active]corresponding to the step window.See also
poisson_generator_ps.updateProduces the spike-time arrays stored here.
- update(return_precise_times=False)[source]#
Advance one simulation step and emit precise Poisson events.
- Parameters:
return_precise_times (
bool, optional) – IfFalse(default), return only per-target spike multiplicities. IfTrue, also return per-target precise spike times emitted in the current step.- Returns:
counts (
numpy.ndarray) – Integer array with dtypeint64and shapeself.varshapecontaining per-step spike multiplicities. Returned in both modes.Active and
rate > 0: each element counts how many spikes fell in(t_min_active, t_max_active]for that output train.Inactive or
rate <= 0: all entries are exactly0.
spike_times_tuple (
tupleofnumpy.ndarray,only when ``return_precise_times=True``) – Tuple of lengthnp.prod(self.varshape). Each element is a one-dimensionalfloat64array of emitted precise spike times (ms) for the corresponding flattened output train in this step. Arrays are empty when no spikes were emitted. Also accessible viastep_spike_times_msafter the call.
- Raises:
ValueError – If simulation step size
dtis non-positive after conversion from the runtime environment.KeyError – If required runtime entries (notably
dt) are unavailable inbrainstate.environ.TypeError – If environment values cannot be converted to scalar milliseconds.
Notes
The update proceeds as follows each call:
Lazy init – If
next_spike_timehas not been created byinit_state(), it is initialized automatically withself.rng_seed.Window clipping – Computes
t_min_activeandt_max_activeby intersecting the step interval[t, t + dt]with the configured activity window. Returns zeros immediately if the window is empty orrate <= 0.Stream initialization – For any target whose
next_spike_timeis-inf(first call or after a rate reset), the initial spike is placed att_min_active + _sample_initial_offset_ms(...)using the stationary backward-recurrence distribution.Spike emission loop – Advances each target stream forward, emitting spikes at
next_t <= t_max_activeand drawing new ISIs via_sample_isi_ms()until the next spike lies outside the current step.State update – Writes back
next_spike_time,last_spike_time, andlast_spike_offsetstates and caches per-target spike-time arrays instep_spike_times_ms.
See also
poisson_generator_ps.init_stateState buffers consumed here.
poisson_generator_ps.setUpdate parameters between runs.
poisson_generator_ps.step_spike_times_msAccess precise times after update without the overhead of the return value.