pymc3

accessing value of a random variable in PyMC3

蹲街弑〆低调 提交于 2019-12-23 11:52:30
问题 In PyMC2, there are methods random() and value() to generate a random value, and get the current value of random variables. Is there any way to do the same in PyMC3? p = pm.Dirichlet('p', theta=np.array([1., 1., 1.])) p.random() p.value 回答1: Not quite yet, but there is an almost done PR here: https://github.com/pymc-devs/pymc3/pull/784 There is no real .value as we store state outside of the RVs now. 来源: https://stackoverflow.com/questions/31485354/accessing-value-of-a-random-variable-in

What pymc3 Monte-Carlo stepper can I use for a custom categorical distribution?

穿精又带淫゛_ 提交于 2019-12-23 04:53:25
问题 I am working on implementing hidden-Markov-Chains in pymc3. I have gotten pretty far in implementing the hidden states. Below, I am showing a simple 2-state Markov-chain: import numpy as np import pymc3 as pm import theano.tensor as tt # Markov chain sample with 2 states that was created # to have prob 0->1 = 0.1 and prob 1->0 = 0.3 sample = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0,

Convert numpy function to theano

让人想犯罪 __ 提交于 2019-12-21 23:36:17
问题 I am using PyMC3 to calculate something which I won't get into here but you can get the idea from this link if interested. The '2-lambdas' case is basically a switch function, which needs to be compiled to a Theano function to avoid dtype errors and looks like this: import theano from theano.tensor import lscalar, dscalar, lvector, dvector, argsort @theano.compile.ops.as_op(itypes=[lscalar, dscalar, dscalar], otypes=[dvector]) def lambda_2_distributions(tau, lambda_1, lambda_2): """ Return

pymc3: hierarchical model with multiple obsesrved variables

余生长醉 提交于 2019-12-18 13:27:54
问题 I have a simple hierarchical model with lots of individuals for which I have small samples from a normal distribution. The means of these distributions also follow a normal distribution. import numpy as np n_individuals = 200 points_per_individual = 10 means = np.random.normal(30, 12, n_individuals) y = np.random.normal(means, 1, (points_per_individual, n_individuals)) I want to use PyMC3 to compute the model parameters from the sample. import pymc3 as pm import matplotlib.pyplot as plt model

Custom likelihood in pymc3

…衆ロ難τιáo~ 提交于 2019-12-18 13:23:47
问题 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 that boolean operations cannot be applied to the parameters (I get an error like this when I do that). For example, 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

Porting pymc2 code to pymc3: custom likelihood function

孤街醉人 提交于 2019-12-13 19:50:37
问题 I am trying to implement the censored data example in Lee&Wagenmakers' book (Chapter 5.5, page 70). In pymc2, I have the following model: nattempts = 950 nfails = 949 n = 50 # Number of questions y = np.zeros(nattempts) y[nattempts-1] = 1 z = 30 unobsmin = 15 unobsmax = 25 unobsrange = np.arange(unobsmin,unobsmax+1) theta = pymc.Uniform("theta",lower = .25, upper = 1) @pymc.observed def Ylike(value=z, theta = theta, n=n, censorn=nfails, unobs=unobsrange): ylikeobs = pymc.binomial_like(x=value

pymc3 likelihood math with non-theano function

天涯浪子 提交于 2019-12-13 16:25:19
问题 I'm new to doing Bayesian inference. I'm trying to adapt a grid search code I wrote to Bayesian Monte Carlo Markov Chain approach, and I'm using PyMC3. My problem is that the code has to call a function that can't be rewritten in theano syntax. (The function relies on a piece of Fortran code in an f2py wrapper.) Here's the code I'm working with: with pm.Model() as model: # Independent parameters x = pm.Normal('x', sx, sd=incx*float(nrangex)/2.0) y = pm.Normal('y', sy, sd=incy*float(nrangey)/2

failure to adapt pymc2 into pymc3

為{幸葍}努か 提交于 2019-12-13 07:07:40
问题 Can anyone tell me what's wrong in my code below ? I am a casual user of pymc2, generally for solving physical equations. I have troubles to adapt a fit to pymc3 and the documentation seems to me unclear. Also I did not recognize my problem on forums, probably because I don’t know what is my problem… I use the find_MAP method to get a first guess of fitted values but this first guess is completly wrong (not even inside the physical limits) and a warning tells me there are discrete variables

Using PYMC3 on Windows 10 - theano cannot import name 'floatX'

牧云@^-^@ 提交于 2019-12-12 04:19:24
问题 I'm struggling to get PYMC3 to install correctly on windows. I've tried using the Anaconda package via conda install -c conda-forge pymc3 and in a virtualenv using only pip as per the documentation. It seems to install ok, but fails when running an import pymc3 with the following error. Research suggests that there may be some dependencies which are getting missed. >>> import pymc3 WARNING (theano.sandbox.cuda): The cuda backend is deprecated and will be removed in the next release (v0.10).

PyMC2 and PyMC3 give different results…?

走远了吗. 提交于 2019-12-11 11:36:28
问题 I'm trying to get a simple PyMC2 model working in PyMC3. I've gotten the model to run but the models give very different MAP estimates for the variables. Here is my PyMC2 model: import pymc theta = pymc.Normal('theta', 0, .88) X1 = pymc.Bernoulli('X2', p=pymc.Lambda('a', lambda theta=theta:1./(1+np.exp(-(theta-(-0.75))))), value=[1],observed=True) X2 = pymc.Bernoulli('X3', p=pymc.Lambda('b', lambda theta=theta:1./(1+np.exp(-(theta-0)))), value=[1],observed=True) model = pymc.Model([theta, X1,