Skip to content

Commit

Permalink
Fix numerical instability in tutorial likelihood
Browse files Browse the repository at this point in the history
Expected counts of zero result in NaN log-likelihood gradient.
  • Loading branch information
oschulz committed Oct 20, 2023
1 parent c6d2c65 commit 3e10e78
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/src/tutorial_lit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ likelihood = let h = hist, f = fit_function
function bin_log_likelihood(i)
## Simple mid-point rule integration of fit function `f` over bin:
expected_counts = bin_widths[i] * f(params, bin_centers[i])
logpdf(Poisson(expected_counts), observed_counts[i])
# Avoid zero expected counts for numerical stability:
logpdf(Poisson(expected_counts + eps(expected_counts)), observed_counts[i])
end

## Sum log-likelihood over bins:
Expand Down

0 comments on commit 3e10e78

Please sign in to comment.