I am working on a simple Hierarchical AB testing model with beta - binomial distributions.
I am following this tutorial which is written for pymc2.
import pymc
@pymc.stochastic(dtype=np.float64)
def hyperpriors(value=[1.0, 1.0]):
a, b = value[0], value[1]
if a <= 0 or b <= 0:
return -np.inf
else:
return np.log(np.power((a + b), -2.5))
a = hyperpriors[0]
b = hyperpriors[1]
# This is what we don't know, but would like to find out
true_rates = pymc.Beta('true_rates', a, b, size=10)
# This is what we observed
trials = np.array([100, 100, 100, 100, 100, 100, 100, 100, 100, 100])
successes = np.array([40, 44, 47, 54, 63, 46, 44, 49, 58, 50])
observed_values = pymc.Binomial('observed_values', trials, true_rates, observed=True, value=successes)
model = pymc.Model([a, b, true_rates, observed_values])
mcmc = pymc.MCMC(model)
mcmc.sample(1000000, 500000)
I can’t find the right way to replicate the hyperpriors stochastic function in PyMC3. Googling returns hints about using a pm.Potential method but I’m at a loss as to how to constrain the “prior sample size” a+b.