如果我们考虑PyMC3的以下线性回归示例:
http://docs.pymc.io/notebooks/getting_started.html#A-Motivating-Example:-Linear-Regression
我们如何包含诸如a + b1 + b2 = 1 or a^2 + b1^2 = 25?之类的约束?
我知道我们可以使用Bound为变量创建边界,但我不知道如何添加更复杂的约束.
谢谢您的帮助!
一般的解决方案是使用潜力.
const = pm.Potential('const', pm.math.switch(pm.math.eq(a**2 + b1**2, 25),
0,
-np.inf))
Run Code Online (Sandbox Code Playgroud)
潜力是您可以添加到模型可能性的任意因素.在此示例中,如果参数满足您的约束,则不添加任何内容,否则添加-inf.
为了将来参考,您也可以在这里提问