-
Notifications
You must be signed in to change notification settings - Fork 48
Compiling Stan components from Matlab
Brian Lau edited this page Jan 21, 2014
·
5 revisions
Before any model fitting can be done, Stan models must be translated to C++ code and compiled. This can be done automatically when using the stan function. In addition, the StanModel class exposes a method for compiling models, as well as the underlying Stan components. For example, to build the stan compiler:
m = StanModel('verbose',true);
m.compile('stanc');
We could then define a model and compile that too:
model_code = {
'data {'
' int<lower=0> N;'
' int<lower=0,upper=1> y[N];'
'}'
'parameters {'
' real<lower=0,upper=1> theta;'
'}'
'model {'
'for (n in 1:N)'
' y[n] ~ bernoulli(theta);'
'}'
};
m.set('model_code',model_code,'model_name','bernoulli');
m.compile();