Created
February 3, 2021 16:41
-
-
Save vlavorini/020df771233120cdabe29ad7b9369044 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
from theano import shared | |
import pymc3 as pm | |
x = np.arange(len(df)) | |
# we set a shared tensor useful for inference | |
x_shared = shared(x) | |
y = df['totale_casi'].values | |
# This is the model created with PyMC3 | |
with pm.Model() as model: | |
# 'priors' distributions | |
par0 = pm.Normal("par0", mu=2.6e+05, sigma=2.6e+03) | |
par1 = pm.Normal("par1", mu=1.2, sigma=1) | |
par2 = pm.Normal("par2", mu=0.6, sigma=1) | |
par3 = pm.Normal("par3", mu=3.2, sigma=5) | |
gompertz = par0* np.exp(-par1*np.exp(-par2*(x_shared-par3))) | |
eps = pm.HalfNormal("err") | |
# The Likelihood | |
pm.Lognormal("L_italia", np.log(gompertz), eps, observed=y) | |
# MCMC | |
trace = pm.sample(tune=2000, target_accept=0.99, chains=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment