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

Add test for MarginalModel where variable depends on two marginalized variables #286

Closed
ricardoV94 opened this issue Dec 15, 2023 · 0 comments · Fixed by #285
Closed

Add test for MarginalModel where variable depends on two marginalized variables #286

ricardoV94 opened this issue Dec 15, 2023 · 0 comments · Fixed by #285
Labels
good first issue Good for newcomers

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Dec 15, 2023

I am positively surprised this is working! Would probably be worth adding as a test.

We already have a test for when multiple RVs depend on a marginalized RV or when there are nested marginalized RVs. This will also create a nested marginalized RV even though x and y are independent a priori

import pymc as pm
from pymc_experimental.model.marginal_model import MarginalModel
import numpy as np

with MarginalModel() as m:
    x = pm.Bernoulli("x", 0.1)
    y = pm.Bernoulli("y", 0.3)
    z = pm.DiracDelta("z", c=x+y)
    
m.marginalize([x, y])
logp = m.compile_logp()

np.testing.assert_allclose(np.exp(logp({"z": 0})), 0.9 * 0.7)
np.testing.assert_allclose(np.exp(logp({"z": 1})), 0.9 * 0.3 + 0.1 * 0.7)
np.testing.assert_allclose(np.exp(logp({"z": 2})), 0.1 * 0.3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant