Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #381 from Nicky027/master
Browse files Browse the repository at this point in the history
More numerically stable log likelihood calculation for beta_geo_fitter
  • Loading branch information
CamDavidsonPilon authored Jul 6, 2020
2 parents d6ac2ba + 85ac65f commit 65f5803
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lifetimes/fitters/beta_geo_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ def _negative_log_likelihood(
A_3 = -(r + freq) * np.log(alpha + T)
A_4 = np.log(a) - np.log(b + np.maximum(freq, 1) - 1) - (r + freq) * np.log(rec + alpha)

max_A_3_A_4 = np.maximum(A_3, A_4)

penalizer_term = penalizer_coef * sum(params ** 2)
ll = weights * (A_1 + A_2 + np.log(np.exp(A_3) + np.exp(A_4) * (freq > 0)))
ll = weights * (A_1 + A_2 + np.log(np.exp(A_3 - max_A_3_A_4) + np.exp(A_4 - max_A_3_A_4) * (freq > 0)) + max_A_3_A_4)

return -ll.sum() / weights.sum() + penalizer_term

Expand Down

0 comments on commit 65f5803

Please sign in to comment.