If we consider the following linear regression example for PyMC3:
https://www.pymc.io/projects/docs/en/v3/pymc-examples/examples/getting_started.html#A-Motivating-Example:-Linear-Regression
How would we include a constraint such as a + b1 + b2 = 1 or a^2 + b1^2 = 25
?
I understand that we can use Bound to create bounds for variables, but I wasn't sure how to add a more complex constraint.
Thanks for the help!
A general solution will be to use a Potential.
const = pm.Potential('const', pm.math.switch(pm.math.eq(a**2 + b1**2, 25),
0,
-np.inf))
A potential is an arbitrary factor that you can add to the model likelihood. In this example if the parameters satisfies you constraints you add nothing otherwise you add -inf.
For future reference you can also ask questions here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With