I would like to modify the priors in my model based on the results of a custom function. Something like:
with pm.Model() as model:
x1 = pm.Normal('x1', 0, 1)
x2 = pm.Normal('x2', 1, 2)
logp_scaler = my_custom_function(x1, x2)
...
Then how would:
- Modify the e.g.
x1.logp(value)
so that is equals x1.logp(value) * logp_scaler
- Compute and apply the normalising constant so that my modified probabilities behave like probabilities?
Many thanks
You can simply add logp_scalar
via a pymc.Potential
If you want to access the logp of x1
, you can write pm.logp(pm.Normal.dist(0, 1), x1)
If you wanted to add that 5 times, you could multiply by 4 (4 because the logp of x1 is already considered once).
Alternatively you could give x
a Flat
and consider it 5 times in the Potential alone.
with pm.Model() as m:
x = pm.Flat("x")
x_logp = pm.Potential("x_logp", pm.logp(pm.Normal.dist(0, 1), x) * 5)
The 5 in that example could be the output of your custom function.
I don’t know. That probably depends on the exact function you have. Is your question on the PyMC side or on the probability side?
2 Likes