Observation Models#
Observation models map region-level neural activity to a measurable signal by
post-processing a simulated trajectory. brainmass ships two complementary
observation paths:
Convolution BOLD –
HRFBoldconvolves (temporally-averaged) neural activity with a closed-form hemodynamic response function (HRF) kernel and decimates to the fMRI repetition time (TR). It is a single linear operator that is differentiable in its few scalar parameters, so it is the BOLD path of choice for fitting.Temporal averaging –
TemporalAverageis a standalone, anti-aliased downsampler (block mean over non-overlapping windows). It is the averaging complement to the point-decimationSimulator(sample_every=k)subsampling and the downsamplerHRFBolduses internally.
The biophysical Balloon-Windkessel BOLDSignal ODE and the EEG/MEG
lead-field forwards live on Forward Models; pick BOLDSignal over
HRFBold when biophysical realism (flow, volume, deoxyhemoglobin) matters
more than speed or differentiability.
HRF kernels#
A hemodynamic response function (HRF) is the impulse response of the
neural-to-BOLD transform. Each kernel below is a callable instance –
h = kernel(t) returns a dimensionless \(h(t)\) (t is a time
Quantity, or a plain array interpreted as milliseconds, the TVB
convention). They differ only in their closed form:
Kernel |
Closed form / reference |
|---|---|
TVB canonical first-order Volterra (underdamped damped oscillator; Friston et al. 2000) |
|
Peak-normalised gamma probability density (Boynton et al. 1996) |
|
Difference of damped oscillations (Polonsky et al. 2000) |
|
Difference of two gammas / SPM canonical HRF (Glover 1999) |
HRFKernel is the shared abstract base; subclass it to add a new kernel.
API Reference#
HRF kernel family#
Base class for hemodynamic response function (HRF) kernels. |
|
First-order Volterra kernel of the hemodynamic system (TVB canonical). |
|
Gamma HRF kernel (Boynton et al. 1996). |
|
Double-exponential (damped-oscillation difference) HRF kernel. |
|
Mixture-of-gammas HRF kernel (Glover 1999). |
Convolution BOLD#
Convolution-based fMRI BOLD observation (HRF kernel). |
HRFBold downsamples the neural trajectory (via TemporalAverage),
convolves it with the chosen HRF kernel, and decimates to the TR:
where \(y_{\text{ds}}\) is the temporally-averaged neural activity, \(h\) the HRF kernel and \(*\) 1-D convolution along time.
Temporal averaging#
Downsample a trajectory by averaging over non-overlapping time windows. |
TemporalAverage downsamples a trajectory by averaging over non-overlapping
windows of w = round(period / dt) samples
(y[k] = mean(signal[k*w : (k+1)*w]); the trailing partial window is dropped). It
preserves units and is smoother / anti-aliased relative to point decimation.
Examples#
A closed-form HRF kernel is a callable returning a dimensionless impulse response:
>>> import brainmass
>>> import brainunit as u
>>> import jax.numpy as jnp
>>> kernel = brainmass.MixtureOfGammasHRFKernel()
>>> t = jnp.arange(0., 20000., 100.) # 20 s grid in ms
>>> h = kernel(t)
>>> h.shape
(200,)
>>> bool(jnp.all(jnp.isfinite(h)))
True
Convolve a slow neural drive to a BOLD trace, then average a signal down a second way:
>>> t = jnp.arange(2000.)
>>> z = 1.0 + 0.5 * jnp.sin(2 * jnp.pi * t[:, None] / 800.0) # (2000, 1) drive
>>> bold = brainmass.HRFBold(
... period=200. * u.ms, downsample_period=4. * u.ms,
... kernel=brainmass.FirstOrderVolterraHRFKernel(duration=400. * u.ms),
... )
>>> y = bold(z, dt=1. * u.ms)
>>> y.shape[1]
1
>>> signal = jnp.arange(20.).reshape(20, 1)
>>> brainmass.TemporalAverage(period=5. * u.ms)(signal, dt=1. * u.ms).shape
(4, 1)
See Also#
Forward Models – the Balloon-Windkessel
BOLDSignalODE and the EEG/MEG lead-field forwards.Orchestration –
Simulator(sample_every=k)point-decimation subsampling and the FCD-distribution objectives that consume BOLD traces.Neural Mass Models – the neural mass models whose activity these observers transform.