Re-coding a partial pooling from pymc to pymc3

I’d like to recode an old pymc partial pooling model in pymc3 :

Here is the model an explanations :

I have a very hard time to understand this old pymc syntax :

def hyperpriors(value=[1.0, 1.0]):
    a, b = value[0], value[1]
    if a <= 0 or b <= 0:
        return -np.inf
        return np.log(np.power((a + b), -2.5))

a = hyperpriors[0]
b = hyperpriors[1]

I think I understand the function (It’s a logp for a pair of a & b parameters), so I guess that I’ll have to translate that in a ‘Deterministic’…

But I totally don’t understant the last 2 lines : It look like a function call but I where are the function parameters ? And what does means the [0] and [1] there?

Any help will be appreciated.

Dont know about pymc2 that much, but I think it generate a 2d random variable, and unpack it with the last two lines.

To rewrite it in PyMC3 I guess the most straightforward way is to write it as a Potential, something like:

with pm.Model() as m:
    a = pm.HalfFlat('a')
    b = pm.HalfFlat('b')
    true_rates = pm.Beta('true_rates', a, b, shape=10)
    observed_values = pm.Binomial('observed_values', n=trials, p=true_rates, observed=successes)
    pm.Potential('hyperprior', tt.log(tt.power((a + b), -2.5)))
    trace = pm.sample()
1 Like