Created
January 9, 2017 15:33
-
-
Save Spaak/99dc94577a700a65b63ef4864f0a0d50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymc3 as mc | |
import theano.tensor as T | |
## generate some data | |
nb = 6 | |
nx = 200 | |
b_true_mean = np.random.normal(size=nb) * 5 | |
b_true_cov = np.random.normal(size=(nb,nb)) | |
# make symmetric and positive semidefinite | |
b_true_cov = np.dot(b_true_cov, b_true_cov.T) | |
x = np.random.multivariate_normal(b_true_mean, b_true_cov, size=nx) | |
y = np.dot(b_true_mean, x.T) + np.random.normal(size=nx) | |
## generate model | |
model = mc.Model() | |
with model: | |
sigma = mc.HalfCauchy('sigma', beta=10, testval=np.asarray(2, dtype='float32'), dtype='float32') | |
intercept = mc.Normal('intercept', 0, sd=10, testval=np.asarray(2, dtype='float32'), dtype='float32') | |
b_model = mc.Normal('b_model', 0, sd=20, shape=(nb,), testval=np.zeros((nb,), dtype='float32'), dtype='float32') | |
likelihood = mc.Normal('y', mu=intercept + T.dot(b_model, x.T), sd=sigma, | |
observed=y.astype('float32'), dtype='float32') | |
step = mc.Metropolis() | |
trace = mc.sample(50000, step=step) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
does a theano flag have to be set somewhere?