mcmc

MCMC Sampling a Maxwellian Curve Using Python's emcee

扶醉桌前 提交于 2020-01-05 04:59:17
问题 I am trying to introduce myself to MCMC sampling with emcee. I want to simply take a sample from a Maxwell Boltzmann distribution using a set of example code on github, https://github.com/dfm/emcee/blob/master/examples/quickstart.py. The example code is really excellent, but when I change the distribution from a Gaussian to a Maxwellian, I receive the error, TypeError: lnprob() takes exactly 2 arguments (3 given) However it is not called anywhere where it is not given the appropriate

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

Stan version of a JAGS model which includes a sum of discrete values - Is it possible?

时光毁灭记忆、已成空白 提交于 2019-12-24 14:34:08
问题 I was trying to run this model in Stan. I have a running JAGS version of it (that returns highly autocorrelated parameters) and I know how to formulate it as CDF of a double exponential (with two rates), which would probably run without problems. However, I would like to use this version as a starting point for similar but more complex models. By now I have the suspicion that a model like this is not possible in Stan. Maybe because of the discreteness introduces by taking the sum of a Boolean

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

马尔可夫链蒙特卡罗算法(MCMC)-(二)

99封情书 提交于 2019-12-22 00:38:02
在 马尔可夫链蒙特卡罗算法(MCMC)-(一) 中,我们讲到了如何用蒙特卡罗方法来随机模拟求解一些复杂的连续积分或者离散求和的方法,但是这个方法需要得到对应的概率分布的样本集,而想得到这样的样本集很困难。因此我们需要本篇讲到的马尔科夫链来帮忙。 一.马尔可夫链概述 马尔科夫链定义本身比较简单,它假设某一时刻状态转移的概率只依赖于它的前一个状态。举个形象的比喻,假如每天的天气是一个状态的话,那个今天是不是晴天只依赖于昨天的天气,而和前天的天气没有任何关系。当然这么说可能有些武断,但是这样做可以大大简化模型的复杂度,因此马尔科夫链在很多时间序列模型中得到广泛的应用,比如循环神经网络RNN,隐式马尔科夫模型HMM等,当然MCMC也需要它。 如果用精确的数学定义来描述,则假设我们的序列状态是...Xt−2,Xt−1,Xt,Xt+1...,那么我们的在时刻Xt+1的状态的条件概率仅仅依赖于时刻Xt,即: 既然某一时刻状态转移的概率只依赖于它的前一个状态,那么我们只要能求出系统中任意两个状态之间的转换概率,这个马尔科夫链的模型就定了。我们来看看下图这个马尔科夫链模型的具体的例子(来源于维基百科)。 这个马尔科夫链是表示股市模型的,共有三种状态:牛市(Bull market), 熊市(Bear market)和横盘(Stagnant market)。每一个状态都以一定的概率转化到下一个状态。比如

Maximize a function with many parameters (python)

梦想的初衷 提交于 2019-12-18 14:56:36
问题 first, let me say that I lack experiences with scientific math or statistics - so this might be a very well-known problem, but I don't know where to start. I have a function f(x1, x2, ..., xn) where I need to guess the x'ses and find the highest value for f . The function has the following properties: the total number or parameters is usually around 40 to 60, so a brute-force approach is impossible. the possible values for each x range from 0.01 to 2.99 the function is steady, meaning that a

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

ValueError: too many values to unpack (expected 3)?

这一生的挚爱 提交于 2019-12-14 03:35:13
问题 I have been having issues with the code I am trying to right with the model I am trying to code the following error has appeared and being a relative novice I am unsure of how to resolve it. ValueError Traceback (most recent call last) <ipython-input-2-5f21a0ce8185> in <module>() 26 proposed[j] = proposed[j] + np.random.normal(0,propsigma[j]) 27 if (proposed[j]>0): # automatically reject moves if proposed parameter <=0 ---> 28 alpha = np.exp(logistic_loglik(proposed,time,ExRatio,sig)-logistic

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