bayesian

Using emcee with Gaussian Priors

大憨熊 提交于 2019-12-11 03:35:52
问题 I'm trying to use a gaussian prior using emcee and can't seem to fully figure it out. Basically I want to replace def lnprior(theta): a, b, c = theta if 1.0 < a < 2.0 and 1.0 < b < 2.0 and 1.0 < c < 2.0: return 0.0 return -np.inf with something that would sample 'a' from a gaussian distribution with a mu and sigma. How would I do that? Like this? def lnprior(theta): a, b, c = theta if 1.0 < b < 2.0 and 1.0 < c < 2.0: return 0.0 if 0<a<20: mu=10 sigma=1 s=np.random.normal(mu, sigma) return s

Running a multivariate ordered logit in PyMC3

强颜欢笑 提交于 2019-12-11 02:49:22
问题 I'm trying to build a Bayesian multivariate ordered logit model using PyMC3. I have gotten a toy multivariate logit model working based on the examples in this book. I've also gotten an ordered logistic regression model running based on the example at the bottom of this page. However, I cannot get an ordered, multivariate logistic regression to run. I think the issue could be the way the cutpoints are specified, specifically the shape parameter, but I'm not sure why it would be different if

Prediction with cpdist using “probabilities” as evidence

僤鯓⒐⒋嵵緔 提交于 2019-12-11 02:39:29
问题 I have a very quick question with an easy reproducible example that is related to my work on prediction with bnlearn library(bnlearn) Learning.set4=cbind(c("Yes","Yes","Yes","No","No","No"),c(9,10,8,3,2,1)) Learning.set4=as.data.frame(Learning.set4) Learning.set4[,c(2)]=as.numeric(as.character(Learning.set4[,c(2)])) colnames(Learning.set4)=c("Cause","Cons") b.network=empty.graph(colnames(Learning.set4)) struct.mat=matrix(0,2,2) colnames(struct.mat)=colnames(Learning.set4) rownames(struct.mat)

making 3d array with arma::cube in Rcpp shows cube error

扶醉桌前 提交于 2019-12-11 00:57:00
问题 I am making a Rcpp code for Gibbs sampling. Inside the code, I first want to make a 3 dimensional array with row number= number of iteration (500), column number=number of parameter(4) and slice number= number of chain(3). I wrote it in this way: #include <RcppArmadillo.h> #include <math.h> // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace std; using namespace arma; //Gibbs sampling code starts here Rcpp::List mcmc(const int iter,const int chains, const NumericVector

Bayesian fit of cosine wave taking longer than expected

旧巷老猫 提交于 2019-12-11 00:33:53
问题 In a recent homework, I was asked to perform a Bayesian fit over a set of data a and b using a Metropolis algorithm. The relationship between a and b is given: e(t) = e_0*cos(w*t) w = 2 * pi The Metropolis algorithm is (it works fine with other fit): def metropolis(logP, args, v0, Nsteps, stepSize): vCur = v0 logPcur = logP(vCur, *args) v = [] Nattempts = 0 for i in range(Nsteps): while(True): #Propose step: vNext = vCur + stepSize*np.random.randn(*vCur.shape) logPnext = logP(vNext, *args)

OpenBUGS: missing value in Bernoulli distribution

ⅰ亾dé卋堺 提交于 2019-12-10 16:50:42
问题 I'm trying to model the observation "time" as random variable with OpenBUGS via R (R2OpenBUGS). If all the observation times are available (no NA's) everything works, but if I set one of the times to NA, nothing happens. I tested the same code with WinBUGS, and I get trap error 'NIL dereference (read)'. So my question is that is there something really wrong in my code, or is my model too weird for BUGS? My model is like this: model{ for(i in 1:k){ obs[i] ~ dbern(p) #is the observation done at

PyMC - wishart distribution for covariance estimate

时光毁灭记忆、已成空白 提交于 2019-12-10 11:49:41
问题 I need to model and estimate a variance-covariance matrix from asset class returns so I was looking at the stock returns example given in chapter 6 of https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers Here is my simple implementation where I start with a sample using a multivariate normal with a known mean and variance-covariance matrix. I then try to estimate it using a non-informative priror. The estimate is different from the known prior so I'm

ChoiceModelR - Hierarchical Bayes Multinomial Logit Model

匆匆过客 提交于 2019-12-10 11:41:21
问题 I hope that some of you are a bit experienced with the R package ChoiceModelR by Sermas and Colias, to estimate a Hierarchical Bayes Multinomial Logit Model. Actually, I am quite a newbie on both R and Hierarchical Bayes. However, I tried to get some estimates by using the script provided by Sermas and Colias in the help file. I have a data set in the same structure as they use (ID, choice set, alternative, independent variables, and choice variable). I have four independent variables all of

Convergence issues on hierarchical probit model with NUTS and Metropolis

痞子三分冷 提交于 2019-12-10 11:38:22
问题 I am trying to extend the hierarchical model from Gelman and Hill reproduced in PyMC3 here to binary outcome data by adding a probit transformation and making the outcome follow a Bernoulli distribution. Right now I'm using toy data, so I know the true values. Alpha should be .1, beta should be .5. The model runs fine with a NUTS sampler before the extension. Once I add it, the estimates slowly increase and keep increasing until the model stalls anywhere between 10 and 200 iterations. Here's

How to Simulate a Biased 6-sided Dice using Pymc3?

99封情书 提交于 2019-12-10 10:55:51
问题 How do I simulate a 6-side Dice roll using Pymc3? Also, what is I know that different sides of the dice have different distributions? 回答1: The easiest way to simulate 1000 rolls of a fair 6-sided die in PyMC3 is import pymc3 as pm with pm.Model(): rolls = pm.DiscreteUniform('rolls', lower=1, upper=6) trace = pm.sample(1000) trace['rolls'] # shows you the result of 1000 rolls Note that this is slower, but equivalent, to just calling np.random.randint(1, 7, size=1000) . For 1000 rolls of an