Skip to content

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

Merged
mmcky merged 3 commits intoQuantEcon:mainfrom
suda-yuga:suda-yuga-patch-2
Jul 21, 2025
Merged

[mle] Replace np.sum with @, fix typos, and use gammaln for stable Poisson log-likelihood#473
mmcky merged 3 commits intoQuantEcon:mainfrom
suda-yuga:suda-yuga-patch-2

Conversation

@suda-yuga
Copy link
Contributor

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
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
Copy link
Member

@HumphreyYang HumphreyYang left a comment

Choose a reason for hiding this comment

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

Thanks @suda-yuga @oyamad and @mmcky! This looks great to me.

@mmcky
Copy link
Contributor

mmcky commented Jul 21, 2025

Thanks @suda-yuga and @HumphreyYang

@mmcky mmcky merged commit abc7292 into QuantEcon:main Jul 21, 2025
6 checks passed
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.

4 participants