TemporalAverage

TemporalAverage#

class brainmass.TemporalAverage(period=Quantity(4., 'ms'))#

Downsample a trajectory by averaging over non-overlapping time windows.

For a window of w = round(period / dt) samples, the k-th output is the mean of the k-th block:

\[y_k = \frac{1}{w}\sum_{j=0}^{w-1} y[k\,w + j], \qquad k = 0, \dots, \lfloor T / w \rfloor - 1.\]

Trailing samples that do not fill a complete window are dropped. The output is sampled at period (i.e. n_win = T // w rows).

This is a thin, standalone observation – it does not modify brainmass.Simulator. It is the averaging complement to the point-decimation Simulator(sample_every=k) subsampling: sample_every keeps every k-th sample, whereas TemporalAverage averages each window (smoother, anti-aliased). Apply it as a post-transform on a run trajectory (ta(res['output'], dt)); it is also used internally by HRFBold to reduce neural activity to the convolution grid.

Parameters:

period (brainunit.Quantity) – Averaging-window length (default 4 * u.ms).

See also

brainmass.Simulator

sample_every= does point-decimation subsampling.

HRFBold

uses TemporalAverage to build its convolution grid.

Examples

>>> import brainmass
>>> import brainunit as u
>>> import jax.numpy as jnp
>>> signal = jnp.arange(20.).reshape(20, 1)
>>> ta = brainmass.TemporalAverage(period=5. * u.ms)
>>> y = ta(signal, dt=1. * u.ms)
>>> y.shape
(4, 1)
>>> [float(v) for v in y[:, 0]]
[2.0, 7.0, 12.0, 17.0]
__init__(period=Quantity(4., 'ms'))[source]#