The PoissonObservations is designed to model count observations, such as neural spike counts, based on
a Poisson distribution with a given rate. It provides methods for computing the negative log-likelihood,
generating samples, and computing the residual deviance for the given count data.
Notes
This class is not meant to be used on its own. It is intended to be passed to a model
such as GLM, which relies on it to compute the log-likelihood and
to set the default inverse link function.
This uses PEP-487 [1] to set the set_{method}_request methods. It
looks for the information available in the set default values which are
set using __metadata_request__* class attributes, or inferred
from method signatures.
The __metadata_request__* class attributes are used when a method
does not explicitly accept a metadata through its arguments or if the
developer would like to specify a request value for those metadata
which are different from the default None.
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.
Assign 1 to the scale parameter of the Poisson model.
For the Poisson exponential family distribution, the scale parameter \(\phi\) is always 1.
This property is consistent with the fact that the variance equals the mean in a Poisson distribution.
As given in the general exponential family expression:
\[\text{var}(Y) = \frac{V(\mu)}{a(\phi)},\]
for the Poisson family, it simplifies to \(\text{var}(Y) = \mu\) since \(a(\phi) = 1\)
and \(V(\mu) = \mu\).
predicted_rate (Array) – The predicted rate values. This is not used in the Poisson model for estimating scale,
but is retained for compatibility with the abstract method signature.
Because \(\Gamma(k+1)=k!\), see wikipedia for explanation.
The \(\log({y_{tn}!})\) term is not a function of the parameters and can be disregarded
when computing the loss-function. This is why we incorporated it into the const term.
Compute the pseudo-\(R^2\) metric for the GLM, as defined by McFadden et al. [2]
or by Cohen et al. [3].
This metric evaluates the goodness-of-fit of the model relative to a null (baseline) model that assumes a
constant mean for the observations. While the pseudo-\(R^2\) is bounded between 0 and 1 for the
training set, it can yield negative values on out-of-sample data, indicating potential over-fitting.
Parameters:
y (Array) – The observations. Expected shape: (n_time_bins,)
predicted_rate (Array) – The predicted mean. Expected shape: (n_time_bins,)
score_type (Literal['pseudo-r2-McFadden', 'pseudo-r2-Cohen']) – The pseudo-\(R^2\) type.
The pseudo-\(R^2\) of the model. A value closer to 1 indicates a better model fit,
whereas a value closer to 0 suggests that the model doesn’t improve much over the null model.
where \(L_M\), \(L_0\) and \(L_s\) are the likelihood of the fitted model, the null model (a
model with only the intercept term), and the saturated model (a model with one parameter per
sample, i.e. the maximum value that the likelihood could possibly achieve). \(D_M\) and \(D_0\) are
the model and the null deviance, \(D_i = -2 \left[ \log(L_s) - \log(L_i) \right]\) for \(i=M,0\).
The method works on simple estimators as well as on nested objects
(such as Pipeline). The latter have
parameters of the form <component>__<parameter> so that it’s
possible to update each component of a nested object.