probsys / sppl

Probabilistic programming system for fast and exact symbolic inference
Apache License 2.0
76 stars 10 forks source link

Fix equality checking for instances of `rv_discrete` #121

Open fsaad opened 2 years ago

fsaad commented 2 years ago
>>> from sppl.distributions import rv_discrete
>>> from sppl.spe import DiscreteLeaf
>>> d1 = rv_discrete(values=((1, 2), (.5, .5)))
>>> d2 = rv_discrete(values=((1, 2), (.8, .2)))
>>> l1 = Id("X") >> a
>>> l2 = Id("X") >> b
>>> l1 == l2
True

The problem is that scipy does not store the values under the kwds in the frozen rv_discrete object, that is

>>> l1.dist.kwds
{}
>>> l2.dist.kwds
{}

and so the equality logic checking passes: https://github.com/probcomp/sppl/blob/efff34fb3d3703247dd7001c36970069c5ac3825/src/spe.py#L828-L836

The kwds field is populated by scipy for all other distributions norm, poisson, etc.