Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import theano.tensor as tt
- with pm.Model() as marginal:
- # parameterize the priors with sample mean and standard deviation and a derived metric
- alpha = 1 / data.actual.mean()
- beta = 1 / data.actual.std()
- gamma = 1
- # normal distribution priors - mu and std for before and after
- mu = pm.Exponential('mu', lam=alpha, shape=[2,])
- sd = pm.Exponential('sd', lam=beta, shape=[2,])
- nu = pm.Exponential('nu', lam=gamma, testval=.1)
- # get our time index
- t = np.arange(data.shape[0])
- tau = pm.Beta('tau', alpha=1.1, beta=1.1)
- tau_scaled = tau * t.max()
- switch_proportion = pm.math.sigmoid(tau_scaled - t)
- _mu = (1-switch_proportion) * mu[0] + switch_proportion * mu[1]
- _sd = (1-switch_proportion) * sd[0] + switch_proportion * sd[1]
- # StudentT has other parameters too.
- observation = pm.StudentT('observation', nu=nu, mu=_mu, sd=_sd, observed=data.actual)
- with marginal:
- # note large tuning period
- trace_marginal = pm.sample(draws=2000, tune=8000, cores=2)
- pm.traceplot(trace_marginal);
Add Comment
Please, Sign In to add comment