prfmodel.models.impulse.shifted_gamma

Shifted gamma distribution impulse response.

Classes

ShiftedGammaImpulse

Shifted gamma distribution impulse response model.

Module Contents

class prfmodel.models.impulse.shifted_gamma.ShiftedGammaImpulse(duration: float = 32.0, offset: float = 0.0001, resolution: float = 1.0, default_parameters: dict[str, float] | None = None)[source]

Shifted gamma distribution impulse response model.

Predicts an impulse response that is a shifted gamma distribution. The model has three parameters: shape, rate, and shift.

Parameters:
  • duration (float, default=32.0) – The duration of the impulse response (in seconds).

  • offset (float, default=0.0001) – The offset of the impulse response (in seconds). By default a very small offset is added to prevent infinite response values at t = 0.

  • resolution (float, default=1.0) – The time resultion of the impulse response (in seconds), that is the number of points per second at which the impulse response function is evaluated.

  • default_parameters (dict of float, optional) – Dictionary with scalar default parameter values. Keys must be valid parameter names.

Notes

The predicted impulse response at time \(t\) with shape \(\alpha\), rate \(\lambda\), and shift \(\delta\) is:

\[f(t) = \hat{f}_{\text{gamma}}(t - \delta; \alpha, \lambda)\]

The density of the gamma distribution is divided by its maximum, so that its highest peak has an amplitude of 1:

\[\hat{f}_{\text{gamma}}(t; \alpha, \lambda, \delta) = \frac{f_{\text{gamma}}(t - \delta; \alpha, \lambda)} {\text{max}(f_{\text{gamma}}(t - \delta; \alpha, \lambda))}\]

Examples

>>> import pandas as pd
>>> params = pd.DataFrame({
>>>     "shape": [2.0, 1.0, 1.5],
>>>     "rate": [1.0, 1.0, 1.0],
>>>     "shift": [1.0, 2.0, 5.0],
>>> })
>>> impulse_model = ShiftedGammaImpulse(
>>>     duration=100.0 # 100 seconds
>>> )
>>> resp = impulse_model(params)
>>> print(resp.shape) # (num_rows, duration)
(3, 100)
property parameter_names: list[str]

Names of parameters used by the model.

Parameter names are: shape, rate, and shift.

__call__(parameters: pandas.DataFrame, dtype: str | None = None) prfmodel.typing.Tensor[source]

Predict the impulse response.

Parameters:
  • parameters (pandas.DataFrame) – Dataframe with columns containing different model parameters and rows containing parameter values for different batches. Must contain the columns shape, rate, and shift.

  • dtype (str, optional) – The dtype of the prediction result. If None (the default), uses the dtype from prfmodel.utils.get_dtype().

Returns:

The predicted impulse response with shape (num_batches, num_frames) and dtype dtype.

Return type:

Tensor

property num_frames: int

The total number of time frames at which the impulse response function is evaluated.

property frames: prfmodel.typing.Tensor

The time frames at which the impulse response function is evaluated.

Time frames are linearly interpolated between offset and duration and have shape (1, num_frames).