pymc3

Problems with a hidden Markov model in PyMC3

不羁的心 提交于 2019-12-05 04:13:39
To learn PyMC, I'm trying to do a simple Hidden Markov Model as shown below: with pymc3.Model() as hmm: # Transition "matrix" a_t = np.ones(num_states) T = [pymc3.Dirichlet('T{0}'.format(i), a = a_t, shape = num_states) for i in xrange(num_states)] # Emission "matrix" a_e = np.ones(num_emissions) E = [pymc3.Dirichlet('E{0}'.format(i), a = a_e, shape = num_emissions) for i in xrange(num_states)] # State models p0 = np.ones(num_states) / num_states # No shape, so each state is a scalar tensor states = [pymc3.Categorical('s0', p = p0)] emissions = [pymc3.Categorical('z0', p = ifelse(eq(states[0],

Rewriting a pymc script for parameter estimation in dynamical systems in pymc3

纵然是瞬间 提交于 2019-12-05 00:05:39
问题 I'd like to use pymc3 to estimate unknown parameters and states in a Hodgkin Huxley neuron model. My code in pymc is based off of http://healthyalgorithms.com/2010/10/19/mcmc-in-python-how-to-stick-a-statistical-model-on-a-system-dynamics-model-in-pymc/ and executes reasonably well. #parameter priors @deterministic def HH(priors in here) #model equations #return numpy arrays that somehow contain the probability distributions as elements return V,n,m,h #Make V deterministic in one line. Seems

Multivariate linear regression in pymc3

元气小坏坏 提交于 2019-12-04 19:12:16
I've recently started learning pymc3 after exclusively using emcee for ages and I'm running into some conceptual problems. I'm practising with Chapter 7 of Hogg's Fitting a model to data . This involves a mcmc fit to a straight line with arbitrary 2d uncertainties. I've accomplished this quite easily in emcee , but pymc is giving me some problems. It essentially boils down to using a multivariate gaussian likelihood. Here is what I have so far. from pymc3 import * import numpy as np import matplotlib.pyplot as plt size = 200 true_intercept = 1 true_slope = 2 true_x = np.linspace(0, 1, size) #

Using a complex likelihood in PyMC3

末鹿安然 提交于 2019-12-04 10:03:15
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 = np.array([0.104, 0.071, 0.138, 0.035, 0.102, 0.096, 0.136, 0.031, 0.024, 0.035]) th.config.compute_test

Rewriting a pymc script for parameter estimation in dynamical systems in pymc3

坚强是说给别人听的谎言 提交于 2019-12-03 16:43:43
I'd like to use pymc3 to estimate unknown parameters and states in a Hodgkin Huxley neuron model. My code in pymc is based off of http://healthyalgorithms.com/2010/10/19/mcmc-in-python-how-to-stick-a-statistical-model-on-a-system-dynamics-model-in-pymc/ and executes reasonably well. #parameter priors @deterministic def HH(priors in here) #model equations #return numpy arrays that somehow contain the probability distributions as elements return V,n,m,h #Make V deterministic in one line. Seems to be the magic that makes this work. V = Lambda('V', lambda HH=HH: HH[0]) #set up the likelihood A =

Unable to create lambda function in hierarchical pymc3 model

空扰寡人 提交于 2019-12-02 04:22:02
I'm trying to create the model shown below with PyMC 3 but can't figure out how to properly map probabilities to the observed data with a lambda function. import numpy as np import pymc as pm data = np.array([[0, 0, 1, 1, 2], [0, 1, 2, 2, 2], [2, 2, 1, 1, 0], [1, 1, 2, 0, 1]]) (D, W) = data.shape V = len(set(data.ravel())) T = 3 a = np.ones(T) b = np.ones(V) with pm.Model() as model: theta = [pm.Dirichlet('theta_%s' % i, a, shape=T) for i in range(D)] z = [pm.Categorical('z_%i' % i, theta[i], shape=W) for i in range(D)] phi = [pm.Dirichlet('phi_%i' % i, b, shape=V) for i in range(T)] w = [pm

what does the 'find_MAP' output mean in pymc3?

♀尐吖头ヾ 提交于 2019-12-01 19:29:07
问题 What are the returned values of find_MAP in pymc3 ? It seems that pymc3.Normal and pymc3.Uniform variables are not considered the same: for pymc3.Normal variables, find_MAP returns a value that looks like the maximum a posteriori probability. But for pymc3.Uniform variables, I get a '_interval' suffix added to the name of the variable and I don't find anywhere in the doc the meaning of the returned value (that may seem absurd, not even within the physical limits). For example: import numpy as

How to write a custom Deterministic or Stochastic in pymc3 with theano.op?

笑着哭i 提交于 2019-12-01 10:29:54
I'm doing some pymc3 and I would like to create custom Stochastics, however there doesn't seem to be a lot documentation about how it's done. I know how to use the as_op way , however apparently that makes it impossible to use the NUTS sampler, in which case I don't see the advantage of pymc3 over pymc. The tutorial mentions that it can be done by inheriting from theano.Op. But can anyone show me how that would work (I'm still getting started on theano)? I have two Stochastics that I want to define. The first one should be easier, it's an N dimension vector F that has only constant parent

How to write a custom Deterministic or Stochastic in pymc3 with theano.op?

∥☆過路亽.° 提交于 2019-12-01 07:36:41
问题 I'm doing some pymc3 and I would like to create custom Stochastics, however there doesn't seem to be a lot documentation about how it's done. I know how to use the as_op way, however apparently that makes it impossible to use the NUTS sampler, in which case I don't see the advantage of pymc3 over pymc. The tutorial mentions that it can be done by inheriting from theano.Op. But can anyone show me how that would work (I'm still getting started on theano)? I have two Stochastics that I want to

Custom Theano Op to do numerical integration

一曲冷凌霜 提交于 2019-12-01 05:50:44
I'm attempting to write a custom Theano Op which numerically integrates a function between two values. The Op is a custom likelihood for PyMC3 which involves the numerical evaluation of some integrals. I can't simply use the @as_op decorator as I need to use HMC to do the MCMC step. Any help would be much appreciated, as this question seems to have come up several times but has never been solved (e.g. https://stackoverflow.com/questions/36853015/using-theano-with-numerical-integration , Theano: implementing an integral function ). Clearly one solution would be to write a numerical integrator