Slide 32
Slide 32 text
Bayesian Approach: PyMC3 - Example
import pymc3 as pm
## set number of sample
## set t = time, from 0 to length of observations
samples = 5000 ## number of iteration
t = np.arange(0, len(z)) ## array of observation positions (time)
with pm.Model() as model:
## define uniform priors for the mean values
mu_a = pm.Uniform('mu_a', 0, 10)
mu_b = pm.Uniform('mu_b', 0, 10)
sigma = pm.HalfCauchy('sigma', np.std(z))
tau = pm.DiscreteUniform('tau', t.min(), t.max())
## define stochastic variable mu
mu = pm.math.switch(tau >= t, mu_a, mu_b)
observation = pm.Normal('observation', mu, sigma, observed = z)
trace = pm.sample(samples, step = pm.NUTS())
burned_trace = trace[1000:]