pymc

How can I make a discrete state Markov model with pymc?

℡╲_俬逩灬. 提交于 2019-12-31 22:21:44
问题 I am trying to figure out how to properly make a discrete state Markov chain model with pymc. As an example (view in nbviewer), lets make a chain of length T=10 where the Markov state is binary, the initial state distribution is [0.2, 0.8] and that the probability of switching states in state 1 is 0.01 while in state 2 it is 0.5 import numpy as np import pymc as pm T = 10 prior0 = [0.2, 0.8] transMat = [[0.99, 0.01], [0.5, 0.5]] To make the model, I make an array of state variables and an

Dirichlet process in PyMC 3

偶尔善良 提交于 2019-12-24 00:20:49
问题 I would like to implement to implement the Dirichlet process example referenced in Implementing Dirichlet processes for Bayesian semi-parametric models (source: here) in PyMC 3. In the example the stick-breaking probabilities are computed using the pymc.deterministic decorator: v = pymc.Beta('v', alpha=1, beta=alpha, size=N_dp) @pymc.deterministic def p(v=v): """ Calculate Dirichlet probabilities """ # Probabilities from betas value = [u*np.prod(1-v[:i]) for i,u in enumerate(v)] # Enforce sum

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

PyMC: Parameter estimation in a Markov system

♀尐吖头ヾ 提交于 2019-12-22 08:55:30
问题 A Simple Markow Chain Let's say we want to estimate parameters of a system such that we can predict the state of the system at timestep t+1 given the state at timestep t. PyMC should be able to deal with this easily. Let our toy system consist of a moving object in a 1D world. The state is the position of the object. We want to estimate the latent variable/the speed of the object. The next state depends on the previous state and the latent variable the speed. # define the system and the data

PyMC: Estimating population parameters where each observation is the sum of two Weibull-distributed variables

巧了我就是萌 提交于 2019-12-22 07:05:14
问题 I have a list of n observations, each of which is the sum of two Weibull-distributed variables: x[i] = t1[i] + t2[i] t1[i] ~ Weibull(shape1, scale1) t2[i] ~ Weibull(shape2, scale2) My goal is: 1) Estimate the shape and scale parameters for both Weibull distributions (shape1, scale1, shape2, scale2), 2) For each observation x[i], estimate t1[i] (and t2[i] follows from this). ( Aside: Each observation x[i] is the age of cancer diagnosis, and t1[i] and t2[i] are two different time periods in the

Trying to install pymc on Anaconda(python) in Windows 7 and getting weird error?

余生颓废 提交于 2019-12-20 04:55:07
问题 I want to run some data science algorithms using Markov Chain Monte Carlo for Bayesian analysis and am trying to install PyMC but am frustratingly getting this error... File "C:\Anaconda\lib\site-packages\numpy\distutils\fcompiler\gnu.py", line 333, in get_libraries raise NotImplementedError("Only MS compiler supported with gfortran on win64") NotImplementedError: Only MS compiler supported with gfortran on win64 Why would this happen and what can I do to solve it that doesnt require me

PyMC - variance-covariance matrix estimation

断了今生、忘了曾经 提交于 2019-12-19 04:59:51
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 5 years ago . I read the following paper(http://www3.stat.sinica.edu.tw/statistica/oldpdf/A10n416.pdf) where they model the variance-covariance matrix Σ as: Σ = diag(S)*R*diag(S) (Equation 1 in the paper) S is the k×1 vector of standard deviations, diag(S) is the diagonal matrix with diagonal elements S, and R is the k×k correlation matrix. How can I implement this using PyMC ? Here is some

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

Difficulties on pymc3 vs. pymc2 when discrete variables are involved

旧城冷巷雨未停 提交于 2019-12-14 00:17:05
问题 I'm updating some calculations where I used pymc2 to pymc3 and I'm having some problems with samplers behavior when I have some discrete random variables on my model. As an example, consider the following model using pymc2: import pymc as pm N = 100 data = 10 p = pm.Beta('p', alpha=1.0, beta=1.0) q = pm.Beta('q', alpha=1.0, beta=1.0) A = pm.Binomial('A', N, p) X = pm.Binomial('x', A, q, observed=True, value=data) It's not really representative of anything, it's just a model where one of the

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