Skip to content

[mle] Replace np.sum with @, fix typos, and use gammaln for stable Poisson log-likelihood #473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

suda-yuga
Copy link

Replace np.sum(a * b) with a @ b
#463

Fix typos in Tex

Replaced np.log(factorial(y)) with scipy.special.gammaln(y + 1) for improved numerical stability and accuracy, especially for large values of y.

…ve numerical stability using scipy.special.gammaln
Copy link
Member

@oyamad oyamad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the code of (the original version of) ProbitRegression correct? y = self.y seems to be missing in the methods logL, G, H.

lectures/mle.md Outdated
@@ -458,7 +458,7 @@ class PoissonRegression:
def logL(self):
y = self.y
μ = self.μ()
return np.sum(y * np.log(μ) - μ - np.log(factorial(y)))
return np.sum(y * np.log(μ) - μ - scipy.special.gammaln(y + 1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Add gammaln to from scipy.special import factorial.
  • I second this change, but an explanation should be given in the text, why gammaln(y + 1) is preferred to np.log(factorial(y)).

@mmcky mmcky requested a review from HumphreyYang July 1, 2025 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants