This is my first time with STAN (PySTAN) and before investing my time to learn seriously, I would like to kindly ask you following questions:
1. I calculate the data using a code (Forward Model) written in Python, which include one main code and two subroutines used in main code. I suppose I can’t call my forward model code directly in the model block. In this case, my question is: Do I have to re-write my forward model code ? should it be in STAN language ?
2. If I end up writing the code in the language suggested in (1.), How should I call it in the model block ?
3. If there are examples explaining something I asked, Kindly refer those also.
Looking forward for your kind replies. I will appreciate your great help.
The code has to be written in C++ to link to everything else though. I don’t know about Pystan. The other question is the autodiff. Do you want to let autodiff compute your gradients or do you want do specify them manually?
As a beginner, I will prefer to use autodiff for the calculations of gradients.
So, if I consider the option 1 of the second thread you suggested, means writing my forward model code in the STAN language. I will be able to call it in the model block, right?
Well that thread is for writing your model in C++ and then calling that from Stan. If you can write your model in Stan directly though, just do that. Head over the manual for examples of what Stan functions can do: 18.1 Basic Functions | Stan User’s Guide
Dear all
The following STAN code giving me the error. For me it looks ok. I was trying to learn how to use function so that I can go further.
function{
real myline_log(real m, vector x, real c){
return m*x+c;
}
}
data{
int<lower=0> N;
vector[N] x;
vector[N] y;
}
parameters {
real alpha;
real beta;
}
model {
y ~ myline(beta,x,alpha);
}
Error
ValueError: Failed to parse Stan model 'anon_model_b11665170a1781410689a7afd516a0bb'. Error message:
PARSER EXPECTED: whitespace to end of file.
FOUND AT line 2:
function{
real myline_log(real m, vector x, real c){
return m*x+c;
}
}
data{
int<lower=0> N;
vector[N] x;
vector[N] y;
}
parameters {
real alpha;
real beta;
}
model {
y ~ myline(beta,x,alpha);
}