Add `opt_sample` that performs optimizations prior to calling `pymc.sample`
Includes building blocks for https://github.com/pymc-devs/pymc-experimental/issues/358
import pymc as pm
import pymc_experimental as pmx
with pm.Model() as m:
p = pm.Beta("p", 1, 1, shape=(1000,))
y = pm.Binomial("y", n=100, p=p, observed=[1, 50, 99, 50]*250)
idata = pm.sample(verbose=True)
# Applied optimization: beta_binomial_conjugacy 1x
# ConjugateRVSampler: [p]
CC @wd60622 @theorashid
Hopefully it will make it easy for follow-up PRs to add more cases
Need to try out. This example in description is different than the docstrings. Both work?
import pymc as pm import pymc_experimental as pmx with pm.Model() as m: p = pm.Beta("p", 1, 1, shape=(1000,)) y = pm.Binomial("y", n=100, p=p, observed=[1, 50, 99, 50]*250) idata = pm.sample(verbose=True) # Applied optimization: beta_binomial_conjugacy 1x # ConjugateRVSampler: [p]
Need to try out. This example in description is different than the docstrings. Both work?
import pymc as pm import pymc_experimental as pmx with pm.Model() as m: p = pm.Beta("p", 1, 1, shape=(1000,)) y = pm.Binomial("y", n=100, p=p, observed=[1, 50, 99, 50]*250) idata = pm.sample(verbose=True) # Applied optimization: beta_binomial_conjugacy 1x # ConjugateRVSampler: [p]
Yes, I wanted an example that is faster than NUTS, but for testing it would be overkill
@wd60622 I had forgot to push the updates. I wasn't trying to gaslight you :D
Any objection to cleaning this up and merging it? I think it's nice to have around, and I might have found an actual use case in DPs, see this discussion
No objections
I've resolved the conflicts
pre-commit.ci autofix