pymc

How to implement a function of a random variable in PyMC which could be sampled by MCMC Metropolis?

一笑奈何 提交于 2020-01-06 15:03:41
问题 If you have a random variable $X$ and a function $f$, you can define $y=f(X)$ as a new random variable with a probability density function as follows: $p(y)=(f^{-1})'(y)p(x)$. For details see here. Now I have defined a random variable alpha, with an exponential distribution in the following code. I want to add to my model, log(alpha) as a new random variable. How should I implement it in my model? I already made an effort but it seems that it is wrong, and the reason as been pointed out in

ImportError: cannot import name flib

爷,独闯天下 提交于 2020-01-05 13:08:14
问题 I want to use Python for trying out hddm. I installed anaconda, Python 2.7. When I try to follow the hddm tutorial in the command line window in spyder, the following happens, which seems to be a problem in pymc: import pandas as pd import matplotlib.pyplot as plt %matplotlib inline import hddm Traceback (most recent call last): File "<ipython-input-24-17365318b31c>", line 1, in <module> import hddm File "/Users/c/anaconda/lib/python2.7/site-packages/hddm/__init__.py", line 7, in <module>

PyMC: How can I describe a state space model?

夙愿已清 提交于 2020-01-05 12:12:26
问题 I used to code my MCMC using C. But I'd like to give PyMC a try. Suppose X_n is the underlying state whose dynamics following a Markov chain and Y_n is the observed data. In particular, Y_n has Poisson distribution with mean depending on X_n and a multidimensional unknown parameter theta X_n | X_{n-1} has distribution depending on theta How should I describe this model using PyMC? Another question: I can find conjugate priors for theta but not for X_n. Is it possible to specify which

PyMC: How can I describe a state space model?

▼魔方 西西 提交于 2020-01-05 12:12:24
问题 I used to code my MCMC using C. But I'd like to give PyMC a try. Suppose X_n is the underlying state whose dynamics following a Markov chain and Y_n is the observed data. In particular, Y_n has Poisson distribution with mean depending on X_n and a multidimensional unknown parameter theta X_n | X_{n-1} has distribution depending on theta How should I describe this model using PyMC? Another question: I can find conjugate priors for theta but not for X_n. Is it possible to specify which

Learning Discrete HMM parameters in PyMC

本秂侑毒 提交于 2020-01-03 04:55:12
问题 I am trying to learn the parameters of a simple discrete HMM using PyMC. I am modeling the rainy-sunny model from the Wiki page on HMM. The model looks as follows: I am using the following priors. theta_start_state ~ beta(20,10) theta_transition_rainy ~beta(8,2) theta_transition_sunny ~beta(2,8) theta_emission_rainy ~ Dirichlet(3,4,3) theta_emission_sunny ~ Dirichlet(10,6,4) Initially, I use this setup to create a training set as follows. ## Some not so informative priors! # Prior on start

Multinomial distribution in PyMC

烂漫一生 提交于 2020-01-02 22:11:12
问题 I am a newbie to pymc. I have read the required stuff on github and was doing fine till I was stuck with this problem. I want to make a collection of multinomial random variables which I can later sample using mcmc. But the best I can do is rv = [ Multinomial("rv", count[i], p_d[i]) for i in xrange(0, len(count)) ] for i in rv: print i.value i.random() for i in rv: print i.value But it is of no good since I want to be able to call rv.value and rv.random() , otherwise I won't be able to sample

PyMC: Getting zero or close-to-zero Categorical likelihood

橙三吉。 提交于 2020-01-02 05:20:09
问题 I am trying to estimate rates from a stochastic Petri Net model. I don't understand why, but I get a ZeroProbability Error, even when making up data data to correspond exactly to the expected number of observations given the initial values I define for the rates. For example, the following rates [0.01, 2, 10, 1] correpond to a probability of 3 different outcomes of [0.33, 0.66, 0.01]. If I observed, 100 outcomes, I would expect to observe that [33, 66, 1] fall within each of the outcomes. Yet

pymc warning: value is neither numerical nor array with floating-point dtype

对着背影说爱祢 提交于 2020-01-02 02:21:31
问题 I have a Bayes net (DAG) model which I created using pymc 2.3. All the variables in it are Bernoulli random variables. When I call the MAP.fit() method on it before sampling I get the following warning for all of my random variables: value is neither numerical nor array with floating-point dtype. Recommend fitting method fmin (default) From the github repo of pymc, it seems that this warning is printed if the underlying type of the stochastic variable is not a float. For Bernoulli RV the type

Using a complex likelihood in PyMC3

冷暖自知 提交于 2020-01-01 11:54:11
问题 pymc.__version__ = '3.0' theano.__version__ = '0.6.0.dev-RELEASE' I'm trying to use PyMC3 with a complex likelihood function: First question: Is this possible? Here's my attempt using Thomas Wiecki's post as a guide: import numpy as np import theano as th import pymc as pm import scipy as sp # Actual data I'm trying to fit x = np.array([52.08, 58.44, 60.0, 65.0, 65.10, 66.0, 70.0, 87.5, 110.0, 126.0]) y = np.array([0.522, 0.659, 0.462, 0.720, 0.609, 0.696, 0.667, 0.870, 0.889, 0.919]) yerr =

Fit two normal distributions (histograms) with MCMC using pymc?

吃可爱长大的小学妹 提交于 2020-01-01 04:19:12
问题 I am trying to fit line profiles as detected with a spectrograph on a CCD. For ease of consideration, I have included a demonstration that, if solved, is very similar to the one I actually want to solve. I've looked at this: https://stats.stackexchange.com/questions/46626/fitting-model-for-two-normal-distributions-in-pymc and various other questions and answers, but they are doing something fundamentally different than what I want to do. import pymc as mc import numpy as np import pylab as pl