mcmc

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

北城以北 提交于 2019-12-07 06:30:13
问题 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

System time for parallel and serial processing

◇◆丶佛笑我妖孽 提交于 2019-12-07 04:38:32
问题 I'm running a Bayesian MCMC probit model, and I'm trying to implement it in parallel. I'm getting confusing results about the performance of my machine when comparing parallel to serial. I don't have a lot of experience doing parallel processing, so it is possible I'm not doing it right. I'm using MCMCprobit in the MCMCpack package for the probit model, and for parallel processing I'm using parLapply in the parallel package. Here's my code for the serial run, and the results from system.time

Embedding Stan in C++ application

蓝咒 提交于 2019-12-05 13:55:38
I wanted to know whether it is possible to incorporate Stan in another C++ application. Since Stan is also written in C++, there should be a way. Currently, I am using RInside to achieve this but then you have all this data transferring which is time-consuming. What specifically did you want from Stan? We're going to separate out the math library into a standalone include for Stan 2.7 --- that contains all the matrix, probability, and autodiff code. Our repos already reflect this structure. All of the MCMC and transform and I/O code is callable through C++, as is the translator from a Stan

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

System time for parallel and serial processing

谁都会走 提交于 2019-12-05 07:46:04
I'm running a Bayesian MCMC probit model, and I'm trying to implement it in parallel. I'm getting confusing results about the performance of my machine when comparing parallel to serial. I don't have a lot of experience doing parallel processing, so it is possible I'm not doing it right. I'm using MCMCprobit in the MCMCpack package for the probit model, and for parallel processing I'm using parLapply in the parallel package. Here's my code for the serial run, and the results from system.time : system.time(serial<-MCMCprobit(formula=econ_model,data=mydata,mcmc=10000,burnin=100)) user system

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) #

MCMCglmm multinomial model in R

℡╲_俬逩灬. 提交于 2019-12-04 11:49:04
问题 I'm trying to create a model using the MCMCglmm package in R. The data are structured as follows, where dyad, focal, other are all random effects, predict1-2 are predictor variables, and response 1-5 are outcome variables that capture # of observed behaviors of different subtypes: dyad focal other r present village resp1 resp2 resp3 resp4 resp5 1 10101 14302 0.5 3 1 0 0 4 0 5 2 10405 11301 0.0 5 0 0 0 1 0 1 … So a model with only one outcome (teaching) is as follows: prior_overdisp_i <- list

马尔科夫链蒙特卡罗方法(MCMC)

蹲街弑〆低调 提交于 2019-12-04 07:35:40
一.蒙特卡罗法的缺陷 通常的蒙特卡罗方法可以模拟生成满足某个分布的随机向量,但是蒙特卡罗方法的缺陷就是难以对高维分布进行模拟。对于高维分布的模拟,最受欢迎的算法当属 马尔科夫链蒙特卡罗算法(MCMC), 他通过构造一条马尔科夫链来分步生成随机向量来逼近制定的分布,以达到减小运算量的目的。 二.马尔科夫链方法概要 马尔科夫链蒙特卡罗方法的基本思路就是想办法构造一个马尔科夫链,使得其平稳分布是给定的某分布,再逐步生模拟该马尔科夫链产生随机向量序列。其基本思路如下。就像是普通的蒙特卡罗方法本质上依赖于概率论中的大数定理,蒙特卡罗方法的理论支撑是 具有遍历性的马尔科夫链的大数定理 。马尔科夫链蒙特卡罗方法的大体思路如下: (1)给定某个分布$p(x)$, 构造某个马尔科夫链$\lbrace X_{t}\rbrace_{t\in\mathbb{N}}$使得$p$是其平稳分布,且满足一定的特殊条件; (2)从一点$x_{0}$出发,依照马尔科夫链$\lbrace X_{t}\rbrace_{t\in\mathbb{N}}$随机生成向量序列$x_{0},x_{1},...$; (3)蒙特卡罗积分估计:计算$E_{p}(f)\approx\sum_{t=1}^{N}f(x_{t})$ 三.MCMC的数学基础——马尔科夫链的遍历性,大数定理 MCMC为什么可以近似计算积分?