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, thek-th output is the mean of thek-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 // wrows).This is a thin, standalone observation – it does not modify
brainmass.Simulator. It is the averaging complement to the point-decimationSimulator(sample_every=k)subsampling:sample_everykeeps everyk-th sample, whereasTemporalAverageaverages each window (smoother, anti-aliased). Apply it as a post-transform on a run trajectory (ta(res['output'], dt)); it is also used internally byHRFBoldto reduce neural activity to the convolution grid.- Parameters:
period (brainunit.Quantity) – Averaging-window length (default
4 * u.ms).
See also
brainmass.Simulatorsample_every=does point-decimation subsampling.HRFBolduses
TemporalAverageto 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]