UniformDuration#

class braintools.cogtask.UniformDuration(min_val, max_val, key=None)[source]#

Uniform distribution for sampling time durations.

Examples

>>> import brainunit as u
>>> import jax
>>> from braintools.cogtask import Context, UniformDuration
>>> duration = UniformDuration(200 * u.ms, 400 * u.ms, key=jax.random.PRNGKey(0))
>>> duration
UniformDuration(200ms, 400ms)
>>> duration.min_value(), duration.max_value()
(Quantity(200, "ms"), Quantity(400, "ms"))
>>> d = duration()  # sample with the sampler's own key
>>> bool(200 * u.ms <= d) and bool(d < 400 * u.ms)
True
>>> # Inside ``trial_init`` pass the context to use the trial's RNG,
>>> # e.g. ``ctx['delay'] = duration(ctx)`` with a ``VariableDuration`` phase.
>>> ctx = Context(key=jax.random.PRNGKey(1))
>>> bool(200 * u.ms <= duration(ctx) < 400 * u.ms)
True
max_value()[source]#

Upper bound of the uniform range in the sampler’s time unit.

min_value()[source]#

Lower bound of the uniform range in the sampler’s time unit.