pymc3

pymc3 with custom likelihood function from kernel density estimation

时光总嘲笑我的痴心妄想 提交于 2019-12-10 10:18:54
问题 I'm trying to use pymc3 with a likelihood function derived from some observed data. This observed data doesn't fit any nice, standard distribution, so I want to define my own, based on these observations. One approach is to use kernel density estimation over the observations. This was possible in pymc2, but doesn't play nicely with the Theano variables in pymc3. In my code below I'm just generating some dummy data that is normally distributed. As my prior, I'm essentially assuming a uniform

PyMC3 & Theano - Theano code that works stop working after pymc3 import

余生长醉 提交于 2019-12-08 17:06:13
问题 Some simple theano code that works perfectly, stop working when I import pymc3 Here some snipets in order to reproduce the error: #Initial Theano Code (this works) import theano.tensor as tsr x = tsr.dscalar('x') y = tsr.dscalar('y') z = x + y #Snippet 1 import pymc3 as pm import theano.tensor as tsr x = tsr.dscalar('x') y = tsr.dscalar('y') z = x + y #Snippet 2 import theano.tensor as tsr import pymc3 as pm x = tsr.dscalar('x') y = tsr.dscalar('y') z = x + y #Snippet 3 import pymc3 as pm x =

PyMC3 - Differences in ways observations are passed to model -> difference in results?

依然范特西╮ 提交于 2019-12-08 04:50:03
问题 I'm trying to understand if there is any meaningful difference in the ways of passing data into a model - either aggregated or as single trials (note this will only be a sensical question for certain distributions e.g. Binomial). Predicting p for a yes/no trail, using a simple model with a Binomial distribution. What is the difference in the computation/results of the following models (if any)? I choose the two extremes, either passing in a single trail at once (reducing to Bernoulli) or

Can you use sample weights in pystan or pymc3?

老子叫甜甜 提交于 2019-12-08 01:19:56
问题 If my observed dataset has weights (for example tracking multiplicity) is it possible to provide this either to pystan or pymc3, similar to the function signature (http://mc-stan.org/rstanarm/reference/stan_glm.html) in the rstanarm package: stan_glm(formula, family = gaussian(), data, weights, subset, na.action = NULL, offset = NULL, model = TRUE, x = FALSE, y = TRUE, contrasts = NULL, ..., prior = normal(), prior_intercept = normal(), prior_aux = exponential(), prior_PD = FALSE, algorithm =

Bayesian Correlation with PyMC3

断了今生、忘了曾经 提交于 2019-12-07 14:05:10
问题 I'm trying to convert this example of Bayesian correlation for PyMC2 to PyMC3, but get completely different results. Most importantly, the mean of the multivariate Normal distribution quickly goes to zero, whereas it should be around 400 (as it is for PyMC2). Consequently, the estimated correlation quickly goes towards 1, which is wrong as well. The full code is available in this notebook for PyMC2 and in this notebook for PyMC3. The relevant code for PyMC2 is def analyze(data): # priors

What are the interval transforms in pymc3 for uniform distributions?

喜夏-厌秋 提交于 2019-12-07 09:38:06
问题 I've noticed that when using uniform distributions in pymc3, the sampler also scans over an _interval parameter as well unless a transform is specified for example: with fitModel6: normMu = pm.Uniform('normMu',lower=0,upper=1000) will result in not only sampling over normMu, but also, normMu_interval: trace plot of interval trace plot of parameter Normally, when I am using an uniform prior for scale parameter like a normalization, I will of course sample over the log interval. Is pymc3

PYMC3 Seasonal Variables

ぐ巨炮叔叔 提交于 2019-12-07 03:04:01
问题 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

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

大憨熊 提交于 2019-12-06 07:49:21
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? 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 unfair die probs = np.array([0.1, 0.2, 0.3, 0.2, 0.1, 0.1]) with pm.Model(): rolls = pm.Multinomial('rolls', n

Bayesian Correlation with PyMC3

一笑奈何 提交于 2019-12-05 21:45:04
I'm trying to convert this example of Bayesian correlation for PyMC2 to PyMC3, but get completely different results. Most importantly, the mean of the multivariate Normal distribution quickly goes to zero, whereas it should be around 400 (as it is for PyMC2). Consequently, the estimated correlation quickly goes towards 1, which is wrong as well. The full code is available in this notebook for PyMC2 and in this notebook for PyMC3 . The relevant code for PyMC2 is def analyze(data): # priors might be adapted here to be less flat mu = pymc.Normal('mu', 0, 0.000001, size=2) sigma = pymc.Uniform(

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