Skip to content

HalfCauchy, Gamma, Weibull and LogNormal moments #5148

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

Merged
merged 5 commits into from
Nov 7, 2021

Conversation

lucianopaz
Copy link
Member

Add moments and tests for the below distributions as part of #5078

  • pymc.distributions.continuous.HalfCauchy
  • pymc.distributions.continuous.Gamma
  • pymc.distributions.continuous.Weibull
  • pymc.distributions.continuous.LogNormal

@lucianopaz lucianopaz changed the title Lognormal moments HalfCauchy, Gamma, Weibull and LogNormal moments Nov 6, 2021
@codecov
Copy link

codecov bot commented Nov 6, 2021

Codecov Report

Merging #5148 (f5407b1) into main (a099292) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5148      +/-   ##
==========================================
+ Coverage   77.82%   77.86%   +0.03%     
==========================================
  Files          88       88              
  Lines       14145    14165      +20     
==========================================
+ Hits        11008    11029      +21     
+ Misses       3137     3136       -1     
Impacted Files Coverage Δ
pymc/distributions/continuous.py 95.80% <100.00%> (+0.10%) ⬆️
pymc/sampling.py 86.80% <0.00%> (+0.12%) ⬆️

@@ -2100,6 +2106,12 @@ def dist(cls, beta, *args, **kwargs):
assert_negative_support(beta, "beta", "HalfCauchy")
return super().dist([0.0, beta], **kwargs)

def get_moment(rv, size, loc, beta):
mean, _ = at.broadcast_arrays(at.as_tensor(0.0, dtype=rv.dtype), beta)
Copy link
Member

Choose a reason for hiding this comment

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

Does something like this also work?

Suggested change
mean, _ = at.broadcast_arrays(at.as_tensor(0.0, dtype=rv.dtype), beta)
mean = at.zeros_like(beta)

Copy link
Member

Choose a reason for hiding this comment

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

Is zero a good point to start sampling from this distribution?

Copy link
Member

Choose a reason for hiding this comment

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

Looking at V3 I think the median (beta) takes precedence over the mode (0), so we were probably using the former to initialize halfcauchys

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I'll use the median instead then. Maybe we should list the order of preference for the moments in #5078

@ricardoV94
Copy link
Member

ricardoV94 commented Nov 7, 2021

@lucianopaz seems like pre-commit is failing with import sorting

@lucianopaz
Copy link
Member Author

lucianopaz commented Nov 7, 2021

@lucianopaz seems like pre-commit is failing with import sorting

Yeah I messed up the pre commit while rebasing the PR. But now everything should be fixed

@twiecki twiecki merged commit 2efedc1 into pymc-devs:main Nov 7, 2021
@twiecki
Copy link
Member

twiecki commented Nov 7, 2021

👍

@twiecki twiecki mentioned this pull request Nov 7, 2021
51 tasks
@lucianopaz lucianopaz deleted the lognormal_moments branch November 8, 2021 08:23
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.

3 participants