nemos.observation_models.GammaObservations.deviance#

GammaObservations.deviance(neural_activity, predicted_rate, scale=1.0)[source]#

Compute the residual deviance for a Gamma model.

Parameters:
  • neural_activity (Array) – The spike coun activity. Shape (n_time_bins, ) or (n_time_bins, n_neurons) for population models.

  • predicted_rate (Array) – The predicted firing rates. Shape (n_time_bins, ) or (n_time_bins, n_neurons) for population models.

  • scale (Union[float, Array]) – Scale parameter of the model.

Return type:

Array

Returns:

The residual deviance of the model.

Notes

The deviance is a measure of the goodness of fit of a statistical model. For a Gamma model, the residual deviance is computed as:

\[\begin{split}\begin{aligned} D(y_{tn}, \hat{y}_{tn}) &= 2 \left[ -\log \frac{ y_{tn}}{\hat{y}_{tn}} + \frac{y_{tn} - \hat{y}_{tn}}{\hat{y}_{tn}}\right]\\\ &= 2 \left( \text{LL}\left(y_{tn} | y_{tn}\right) - \text{LL}\left(y_{tn} | \hat{y}_{tn}\right) \right) \end{aligned}\end{split}\]

where \(y\) is the observed data, \(\hat{y}\) is the predicted data, and \(\text{LL}\) is the model log-likelihood. Lower values of deviance indicate a better fit.