-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Implement Chi distribution helper #239
Conversation
class TestChi(BaseTestDistributionRandom): | ||
pymc_dist = Chi | ||
pymc_dist_params = {"nu": 3.0} | ||
expected_rv_op_params = {"nu": 3.0} | ||
reference_dist_params = {"df": 3.0} | ||
reference_dist = seeded_scipy_distribution_builder("chi") | ||
tests_to_run = [ | ||
"check_pymc_params_match_rv_op", | ||
"check_pymc_draws_match_reference", | ||
"check_rv_size", | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test isn't needed
Your snippet is using |
@pytest.mark.parametrize( | ||
"nu, size, expected", | ||
[ | ||
(1, None, 1), | ||
(1, 5, np.full(5, 1)), | ||
(np.arange(1, 6), None, np.arange(1, 6)), | ||
], | ||
) | ||
def test_chi_moment(self, nu, size, expected): | ||
with pm.Model() as model: | ||
Chi("x", nu=nu, size=size) | ||
assert_moment_is_expected(model, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this. We are adding default moments to CustomDist in pymc-devs/pymc#6873
@ricardoV94 Thanks for your help! I've removed those superfluous tests. Also thanks for catching the issue with my snippet! Here's the correct snippet: import pymc as pm
from pymc_experimental.distributions import Chi
with pm.Model() as model:
Chi("x", nu=1)
print(model.initial_point()) results in
|
Alright, I fixed one problem and found another. I was passing the import pymc as pm
from pymc_experimental.distributions import Chi
with pm.Model() as model:
Chi("x", nu=1)
print(model.initial_point())
# {'x_log__': array(-inf)} |
That will be solved by the linked PR which implements initial values for CustomDist. For now we can provide a maxwell_moment function to the moment kwarg of CustomDist. Probably it's good enough to set the moment to ones. In that case we should reintroduce the moment test that was commented out |
Do you also want to add a helper for the Maxwell distribution? |
The failing tests should be fixed by #240 |
Rebased from main, tests should now pass and we can merge |
If tests are concerned about float32 they should manually set it with `pytensor.config.change_flags`
Following the discussion here and obsolete PRs here and here, I have attempted to implement a Chi distribution helper class using
CustomDist
.The distribution is functionally correct in that it is able to reproduce the
scipy
chi PDF.There is an issue with adding this distribution to a
pymc
model, however. For example:results in
I can't quite narrow down this issue, so any help would be appreciated!