cedalion.models.glm.design_matrix

Functions to create the design matrix for the GLM.

Functions

average_short_channel_regressor(ts_short)

Create a regressor by averaging all short channels.

build_stim_array(time, onsets, durations, values)

Build an array indicating active stimulus periods.

closest_short_channel_regressor(ts_long, ...)

Create channel-wise regressors using the closest nearby short channel.

drift_regressors(ts, drift_order)

Create drift regressors.

hrf_regressors(ts, stim, basis_function)

Create regressors modelling the hemodynamic response to stimuli.

max_corr_short_channel_regressor(ts_long, ...)

Create channel-wise regressors using the most correlated short channels.

Classes

DesignMatrix(common, channel_wise)

class cedalion.models.glm.design_matrix.DesignMatrix(
common: 'xr.DataArray | None' = None,
channel_wise: 'list[xr.DataArray]' = <factory>,
)[source]

Bases: object

common: DataArray | None = None[source]
channel_wise: list[DataArray][source]
property regressors[source]
iter_computational_groups(
ts: cdt.NDTimeSeries,
channel_groups: list[int] | None = None,
)[source]

Combine universal and channel-wise regressors and yield a DM for each group.

Parameters:
  • ts – The time series to be modeled.

  • channel_groups – Optional list of channel groups.

Yields:

A tuple containing – - dim3 (str): The third dimension name. - group_y (cdt.NDTimeSeries): The grouped time series. - group_design_matrix (xr.DataArray): The grouped design matrix.

cedalion.models.glm.design_matrix.hrf_regressors(
ts: cdt.NDTimeSeries,
stim: DataFrame,
basis_function: TemporalBasisFunction,
) DesignMatrix[source]

Create regressors modelling the hemodynamic response to stimuli.

Parameters:
  • ts (NDTimeSeries) – Time series data.

  • stim (pd.DataFrame) – Stimulus DataFrame.

  • basis_function (TemporalBasisFunction) – TemporalBasisFunction object defining the HRF.

Returns:

A DataArray containing the regressors.

Return type:

regressors (xr.DataArray)

cedalion.models.glm.design_matrix.drift_regressors(
ts: cdt.NDTimeSeries,
drift_order,
) DesignMatrix[source]

Create drift regressors.

Parameters:
  • ts (cdt.NDTimeSeries) – Time series data.

  • drift_order (int) – The highest polynomial order of the drift terms.

Returns:

A DataArray containing the drift regressors.

Return type:

xr.DataArray

cedalion.models.glm.design_matrix.build_stim_array(
time: ArrayLike,
onsets: ArrayLike,
durations: None | ArrayLike,
values: ArrayLike,
) np.ndarray[source]

Build an array indicating active stimulus periods.

The resuting array values are set from values between onset and onset+duration and zero everywhere else.

Parameters:
  • time – the time axis

  • onsets – times of stimulus onsets

  • durations – either durations of each stimulus or None, in which case the stimulus duration is set to one sample.

  • values – Stimulus values.

Returns:

The array denoting

cedalion.models.glm.design_matrix.closest_short_channel_regressor(
ts_long: cdt.NDTimeSeries,
ts_short: cdt.NDTimeSeries,
geo3d: cdt.LabeledPointCloud,
)[source]

Create channel-wise regressors using the closest nearby short channel.

Parameters:
  • ts_long (NDTimeSeries) – Time series of long channels

  • ts_short (NDTimeSeries) – Time series of short channels

  • geo3d (LabeledPointCloud) – Probe geometry

Returns:

Channel-wise regressor

Return type:

regressors (xr.DataArray)

cedalion.models.glm.design_matrix.max_corr_short_channel_regressor(ts_long: cdt.NDTimeSeries, ts_short: cdt.NDTimeSeries)[source]

Create channel-wise regressors using the most correlated short channels.

For each long channel the short channel is selected that has the highest correleation coefficient in any wavelength or chromophore.

Parameters:
  • ts_long (NDTimeSeries) – time series of long channels

  • ts_short (NDTimeSeries) – time series of short channels

Returns:

channel-wise regressors

Return type:

xr.DataArray

cedalion.models.glm.design_matrix.average_short_channel_regressor(ts_short: cdt.NDTimeSeries)[source]

Create a regressor by averaging all short channels.

Parameters:

ts_short (NDTimeSeries) – time series of short channels

Returns:

regressors

Return type:

xr.DataArray