Skip to content

Instantly share code, notes, and snippets.

@recluze
Created September 17, 2015 04:32
Show Gist options
  • Save recluze/460157afc6a7492555bb to your computer and use it in GitHub Desktop.
Save recluze/460157afc6a7492555bb to your computer and use it in GitHub Desktop.
model = Model()
# Y = [1, 0, 0, 1, 1, ... 1, 0, 1] # binary computed from n_predictors features
with model:
# Priors for unknown model parameters
# alpha = Beta('alpha', alpha=0.5, beta=0.5)
beta = Normal('beta', mu=0, tau=2. ** -2, shape=(1, n_predictors))
# expected probability
p = tinvlogit(sum(beta * predictors, 1))
# Likelihood (sampling distribution) of observations
Y_obs = Bernoulli('Y_obs', p=p, observed=Y)
with model:
try:
trace = load('trace.sqlite')
except:
backend = SQLite('trace.sqlite')
# obtain starting values via MAP
start = find_MAP()
# instantiate sampler
step = NUTS(scaling=start)
# draw posterior samples
trace = sample(sample_size, step, start, trace=backend)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment