nemos.observation_models.PoissonObservations.log_likelihood#
- PoissonObservations.log_likelihood(y, predicted_rate, scale=1.0, aggregate_sample_scores=<function mean>)[source]#
Compute the Poisson negative log-likelihood.
This computes the Poisson negative log-likelihood of the predicted rates for the observed spike counts up to a constant.
- Parameters:
y (
Array
) – The target spikes to compare against. Shape(n_time_bins, )
, or(n_time_bins, n_neurons)
.predicted_rate (
Array
) – The predicted rate of the current model. Shape(n_time_bins, )
, or(n_time_bins, n_neurons)
.scale (
Union
[float
,Array
]) – The scale parameter of the model.aggregate_sample_scores (
Callable
) – Function that aggregates the log-likelihood of each sample.
- Returns:
The Poisson negative log-likehood. Shape (1,).
Notes
The formula for the Poisson mean log-likelihood is the following,
\[\begin{split}\begin{aligned} \text{LL}(\hat{\lambda} | y) &= \frac{1}{T \cdot N} \sum_{n=1}^{N} \sum_{t=1}^{T} [y_{tn} \log(\hat{\lambda}_{tn}) - \hat{\lambda}_{tn} - \log({y_{tn}!})] \\\ &= \frac{1}{T \cdot N} \sum_{n=1}^{N} \sum_{t=1}^{T} [y_{tn} \log(\hat{\lambda}_{tn}) - \hat{\lambda}_{tn} - \Gamma({y_{tn}+1})] \\\ &= \frac{1}{T \cdot N} \sum_{n=1}^{N} \sum_{t=1}^{T} [y_{tn} \log(\hat{\lambda}_{tn}) - \hat{\lambda}_{tn}] + \text{const} \end{aligned}\end{split}\]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.