-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Extend Rice distribution #3289
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
Extend Rice distribution #3289
Conversation
First of all, this is really great! About the error you're getting, it's because the ops you wrote inherit from |
@lucianopaz thank you for your reply. I tried to naively Elemwise the scalar ops (replicating the logic of
Do you know how to fix this? Also, do I need the inplace op, and if yes where to use it? |
Issue fixed. Rice distribution now accepts multiple parameters and observations and is usable with NUTS. Here is an example of inference on nu[0], nu[1] and sigma: import pymc3 as pm
import numpy as np
from scipy import stats
true_nu = np.array([4., 7.])
true_sigma = 2.
np.random.seed(123)
observed = stats.rice(b=true_nu / true_sigma, scale=true_sigma).rvs(
size=(1000, len(true_nu))
)
with pm.Model() as model:
nu = pm.Uniform("nu", 0.1, 20., shape=len(true_nu))
sigma = pm.Uniform("sigma", 0.1, 10.)
x = pm.Rice("y", nu=nu, sd=sigma, observed=observed)
with model:
step = pm.NUTS()
trace = pm.sample(1000, step=[step], chains=4, cores=1, seed=123)
axes = pm.traceplot(trace)
for i, nu in enumerate(true_nu):
axes[0, 0].axvline(nu, linestyle="--", color="k", label=f"true_nu[{i}]")
axes[0, 0].legend()
axes[1, 0].axvline(true_sigma, linestyle="--", color="k") Can someone please review this PR? I'll rebase it on top of master as soon as preliminary PR #3287 is merged. |
@@ -1178,7 +1178,9 @@ def test_multidimensional_beta_construction(self): | |||
|
|||
def test_rice(self): | |||
self.pymc3_matches_scipy(Rice, Rplus, {'nu': Rplus, 'sd': Rplusbig}, | |||
lambda value, nu, sd: sp.rice.logpdf(value, b=nu, loc=0, scale=sd)) | |||
lambda value, nu, sd: sp.rice.logpdf(value, b=nu / sd, loc=0, scale=sd)) | |||
self.pymc3_matches_scipy(Rice, Rplus, {'b': Rplus, 'sd': Rplusbig}, |
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.
Does this test work before your last commit with the elementwise fixes? If not, we might want to add one.
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.
Thanks, this looks like it wasn't trivial to figure out! |
Caveat: This PR is at the moment at the top of #3287.
I'm trying to do some inference on the parameters of a Rice distribution:
Initially, this code thew
I defined the gradient of
pymc3.distributions.dist_math.i0e
in this PR, now the single-observation inference works.However, if I use multiple observations I obtain:
Any idea how to fix that?