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)
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