Skip to content
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

Make suffstats and fit_mle type-generic for Normal{T} #1560

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

gdalle
Copy link

@gdalle gdalle commented May 30, 2022

In the spirit of #1558, here is a prototype PR that:

  • removes type constraints for x and w in fit_mle (they can both be AbstractVector{<:Real})
  • adds a type parameter to NormalStats (which becomes NormalStats{T})
  • makes sure that fit_mle(Normal{Float32}, x, w) will return a Normal{Float32}

I haven't added type tests yet, waiting on confirmation from the maintainers that this is a welcome addition. If so, I can implement similar changes for a few more standard distributions.

Note: this PR originated from a discussion with @matbesancon. Looking at methods(suffstats) makes it clear that some homogeneization wouldn't hurt there.

@gdalle gdalle changed the title Make suffstats and fit_mle type generic for Normal{T} Make suffstats and fit_mle type-generic for Normal{T} May 30, 2022
@matbesancon
Copy link
Member

ping @devmotion since it started with your PR

src/univariate/continuous/normal.jl Show resolved Hide resolved
src/univariate/continuous/normal.jl Outdated Show resolved Hide resolved
src/univariate/continuous/normal.jl Outdated Show resolved Hide resolved
src/univariate/continuous/normal.jl Outdated Show resolved Hide resolved
src/univariate/continuous/normal.jl Outdated Show resolved Hide resolved
src/univariate/continuous/normal.jl Outdated Show resolved Hide resolved
src/univariate/continuous/normal.jl Outdated Show resolved Hide resolved
if isnan(mu)
if isnan(sigma)
fit_mle(Normal, suffstats(Normal, x))
fit_mle(D, suffstats(Normal, x))
else
g = NormalKnownSigma(sigma)
Copy link
Member

Choose a reason for hiding this comment

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

We should find a way to preserve/forward the type of D in these cases as well.

Copy link
Author

Choose a reason for hiding this comment

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

Which eltype should we pick for D though, the one of g or the one of the suffstats?

Copy link
Author

Choose a reason for hiding this comment

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

I added a conversion in my latest commit, what do you think?

src/univariate/continuous/normal.jl Outdated Show resolved Hide resolved
src/univariate/continuous/normal.jl Outdated Show resolved Hide resolved
@gdalle gdalle requested a review from devmotion June 9, 2023 17:12
@codecov-commenter
Copy link

codecov-commenter commented Jun 9, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (c1705a3) 85.94% compared to head (9203e63) 85.95%.

Files Patch % Lines
src/univariate/continuous/normal.jl 95.65% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1560      +/-   ##
==========================================
+ Coverage   85.94%   85.95%   +0.01%     
==========================================
  Files         144      144              
  Lines        8658     8666       +8     
==========================================
+ Hits         7441     7449       +8     
  Misses       1217     1217              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gdalle
Copy link
Author

gdalle commented Jan 13, 2024

Now the behavior is that:

  • suffstats does the necessary promotions
  • fit_mle brings it back to the type of Normal{T} if T is specified

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