Custom likelihood in pymc3

后端 未结 1 1350

How can I define a custom likelihood in PyMC3? In PyMC2, I could use @pymc.potential. I tried to use pymc.Potential in PyMC3, however, it seems tha

1条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-31 21:14

    You need to use the DensityDist function to wrap your log likelihood. From the examples bundled with the source:

    with Model() as model:
        lam = Exponential('lam', 1)
    
        failure = np.array([0, 1])
        value = np.array([1, 0])
    
        def logp(failure, value):
            return sum(failure * log(lam) - lam * value)
    
        x = DensityDist('x', logp, observed=(failure, value))
    

    You can make arbitrary non-Theano deterministics using the @theano.compile.ops.as_op decorator, but not as easily for Stochastics.

    0 讨论(0)
提交回复
热议问题