Skip to content

Instantly share code, notes, and snippets.

@WillKoehrsen
Created February 9, 2018 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save WillKoehrsen/934c67bef0d9c04a0c5fda9da5c63609 to your computer and use it in GitHub Desktop.
Save WillKoehrsen/934c67bef0d9c04a0c5fda9da5c63609 to your computer and use it in GitHub Desktop.
with pm.Model() as sleep_model:
# Create the alpha and beta parameters
# Assume a normal distribution
alpha = pm.Normal('alpha', mu=0.0, tau=0.05, testval=0.0)
beta = pm.Normal('beta', mu=0.0, tau=0.05, testval=0.0)
# The sleep probability is modeled as a logistic function
p = pm.Deterministic('p', 1. / (1. + tt.exp(beta * time + alpha)))
# Create the bernoulli parameter which uses observed data to inform the algorithm
observed = pm.Bernoulli('obs', p, observed=sleep_obs)
# Using Metropolis Hastings Sampling
step = pm.Metropolis()
# Draw the specified number of samples
sleep_trace = pm.sample(N_SAMPLES, step=step);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment