Prior on multiple parameters

Hi! Just wondering if there is a way to implement this model: Constraint or prior dependent on multiple parameters - Questions - PyMC Discourse in numpyro?

i didn’t look at the post very closely but you should just be able to use factor, which is the equivalent of Potential. numpyro also has factor

Thanks Martin for that link! Can we also place a “prior” on the factor? In the PyMC3 discussion linked, the factor added is a ratio between two parameters, and a normal distribution prior was placed on this quantity.

hi @tcuongd please refer to the docs. afaik factor is more or less exactly equivalent to Potential and deterministic is more or less exactly equivalent to deterministic. if that isn’t enough information to enable you to do what you want to do please try to formulate a specific self-contained question about a specific model (without reference to external posts) and we can likely be of more help.

Thanks Martin, fair call and you’re totally right! I dug into the docs a little deeper and was able to replicate that bit of the PyMC3 code using factor. For completeness, I think the translation is:

PyMC3:

with pm.Model() as model:
    inv_b0 = pm.Flat('inv_b0')
    b1 = pm.Flat('b1')
    b0b1 = pm.Deterministic('b1/b0', b1*inv_b0)
    pm.Potential('constraint', pm.Normal.dist(5., 1.).logp(b0b1))
    ...

Numpyro:

import numpyro
import numpyro.dist as dist

def model():
    inv_b0 = numpyro.sample("inv_b0", dist.Uniform(0, 1))
    b1 = numpyro.sample("b1", dist.Uniform(0, 1))
    b0b1 = numpyro.deterministic("b0b1", b1 * inv_b0)
    constraint = dist.Normal(5, 1).log_prob(b0b1)
    numpyro.factor("constraint", constraint)
    ...