Skip to content

Instantly share code, notes, and snippets.

@bbbales2
Created May 23, 2017 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbbales2/718f65ccfc8210783c59a8925327bc4d to your computer and use it in GitHub Desktop.
Save bbbales2/718f65ccfc8210783c59a8925327bc4d to your computer and use it in GitHub Desktop.
Jacobian adjustment thing
#%%
import matplotlib.pyplot as plt
import pystan
import numpy
model_code = """
data {
int<lower=1> N;
vector[N] y;
}
parameters {
real a;
real<lower = 0.0> b;
}
model {
y ~ normal(a, b);
}
"""
sm1 = pystan.StanModel(model_code = model_code)
#%%
model_code = """
data {
int<lower=1> N; // Number of single samples
vector[N] y;
}
parameters {
real a;
real<lower=0.0> b;
}
model {
vector[N] yh;
yh = (y - a) / b;
yh ~ normal(0.0, 1.0);
target += N * log(abs(1 / b));
}
"""
sm2 = pystan.StanModel(model_code = model_code)
#%%
N = 100
y = 3.0 + 5.0 * numpy.random.randn(N)
print "First model"
print sm1.sampling({'N' : N, 'y' : y})
print "Second model"
print sm2.sampling({'N' : N, 'y' : y})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment