3

If we consider the following linear regression example for PyMC3:

http://docs.pymc.io/notebooks/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!

desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

8

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

aloctavodia
  • 2,040
  • 21
  • 28