daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import theano.tensor as tt
  2. with pm.Model() as marginal:
  3.     # parameterize the priors with sample mean and standard deviation and a derived metric
  4.     alpha = 1 / data.actual.mean()
  5.     beta = 1 / data.actual.std()
  6.     gamma = 1
  7.  
  8.     # normal distribution priors - mu and std for before and after
  9.     mu = pm.Exponential('mu', lam=alpha, shape=[2,])
  10.     sd = pm.Exponential('sd', lam=beta, shape=[2,])
  11.     nu = pm.Exponential('nu', lam=gamma, testval=.1)
  12.    
  13.     # get our time index
  14.     t = np.arange(data.shape[0])
  15.    
  16.     tau = pm.Beta('tau', alpha=1.1, beta=1.1)
  17.     tau_scaled = tau * t.max()
  18.     switch_proportion = pm.math.sigmoid(tau_scaled - t)
  19.     _mu = (1-switch_proportion) * mu[0] + switch_proportion * mu[1]
  20.     _sd = (1-switch_proportion) * sd[0] + switch_proportion * sd[1]
  21.    
  22.     # StudentT has other parameters too.
  23.     observation = pm.StudentT('observation', nu=nu, mu=_mu, sd=_sd, observed=data.actual)
  24.  
  25. with marginal:
  26.     # note large tuning period
  27.     trace_marginal = pm.sample(draws=2000, tune=8000, cores=2)
  28.     pm.traceplot(trace_marginal);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top