User probability in pymc3

How to determine user truth in PyMC3? In PyMC2, I could use @pymc.potential . I tried using pymc.Potential in PyMC3, however it seems that the logical operations cannot be applied to the parameters (I get an error like this when I do this). For example, the following code does not work:

 from pymc import * with Model() as model: x = Normal('x', 1, 1) def z(u): if u > 0: #comparisons like this are not supported # if theano.tensor.lt(0,u): this is how comparison should be done return u ** 2 return -u**3 x2 = Potential('x2', z(x)) start = model.test_point h = find_hessian(start) step = Metropolis(model.vars, h) sample(100, step, start) 

It is not possible to change all comparisons within probability with Theano syntax (ie theano.tensor. {Lt, le, eq, neq, gt, ge}). Do I need to use a likelihood function similar to PyMC2?

+5
source share
1 answer

You need to use the DensityDist function to wrap the log probability. From source related examples:

 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 deans not related to teano using the @theano.compile.ops.as_op decorator, but not so easy for Stochastics.

+11
source

Source: https://habr.com/ru/post/1209443/


All Articles