pymc

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

萝らか妹 提交于 2019-12-05 17:47:22
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 if I run the following model, I get a ZeroProbability Error (I'm simplifying the prob function, which

PyMC: Parameter estimation in a Markov system

心已入冬 提交于 2019-12-05 14:32:31
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 true_vel = .2 true_pos = 0 true_positions = [.2 * step for step in range(100)] We assume that we have

Bayesian Probabilistic Matrix Factorization (BPMF) with PyMC3: PositiveDefiniteError using `NUTS`

我与影子孤独终老i 提交于 2019-12-05 13:00:50
This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 4 years ago . I've implemented the Bayesian Probabilistic Matrix Factorization algorithm using pymc3 in Python. I also implemented it's precursor, Probabilistic Matrix Factorization (PMF). See my previous question for a reference to the data used here. I'm having trouble drawing MCMC samples using the NUTS sampler. I initialize the model parameters using the MAP from PMF, and the hyperparameters using Gaussian random draws sprinkled around 0. However, I get a PositiveDefiniteError when

PYMC3 Seasonal Variables

前提是你 提交于 2019-12-05 06:04:20
I'm relatively new to PYMC3 and I'm trying to implement a Bayesian Structure Time Series (BSTS) without regressors, for instance the model fit here in R. The model is as follows: I can implement the local linear trend using a GaussianRandomWalk as follows: delta = pymc3.GaussianRandomWalk('delta',mu=0,sd=1,shape=99) mu = pymc3.GaussianRandomWalk('mu',mu=delta,sd=1,shape=100) However, I'm at a loss for how to encode the seasonal variable (tau) in PYMC3. Do I need to roll a custom random walk class or is there some other trick? You can use w = pm.Normal('w', sd=sigma_tau, shape=S) tau = w - tt

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],

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

戏子无情 提交于 2019-12-05 04:07:41
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 is (and should be) bool. Does this mean that the MAP step will have unstable results? 来源: https:/

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

Stochastic Optimization in Python

a 夏天 提交于 2019-12-04 22:17:39
问题 I am trying to combine cvxopt (an optimization solver) and PyMC (a sampler) to solve convex stochastic optimization problems . For reference, installing both packages with pip is straightforward: pip install cvxopt pip install pymc Both packages work independently perfectly well. Here is an example of how to solve an LP problem with cvxopt : # Testing that cvxopt works from cvxopt import matrix, solvers # Example from http://cvxopt.org/userguide/coneprog.html#linear-programming c = matrix([-4

Defining a custom PyMC distribution

≡放荡痞女 提交于 2019-12-04 11:21:39
问题 This is perhaps a silly question. I'm trying to fit data to a very strange PDF using MCMC evaluation in PyMC. For this example I just want to figure out how to fit to a normal distribution where I manually input the normal PDF. My code is: data = []; for count in range(1000): data.append(random.gauss(-200,15)); mean = mc.Uniform('mean', lower=min(data), upper=max(data)) std_dev = mc.Uniform('std_dev', lower=0, upper=50) # @mc.potential # def density(x = data, mu = mean, sigma = std_dev): #

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