Hello,
I implemented a bayesian inference model in matlab. Unfortunately, issues occurred and I thought it would be better doing it within the mc-stan/matlabstan environment.

My problem is similar to the mentioned example in section 2 http://www.stat.columbia.edu/~gelman/research/published/stan_jebs_2.pdf
Instead of using an exponential equation I would like to use a much more complex one, which is written in matlab and consists of hundreds of lines. So it is not easy to convert it in stan language.

My question: Is it possible to use a matlab written model in stan?

The short answer is no. The long answer is yes if you have the function and the gradients with respect to the parameters of the model and those things can be called from c++. It’s a lot of work to make that work, but it’s possible.

Hopefully it’s easier than you think. Matlab (language) isn’t too dissimilar to Stan. Unless you’ve written in the style of using vectorized operations within Matlab.

My guess is that it’ll be much easier to write in Stan than to try to get the C++ to work.

Thanks for the quick reply. Of course I didn’t want to hear something like that, so I have to see how to handle it.
Hopefully I get the matlab hmc to work.

I might have problems with matlab, because my problem has a constrained parameter space. Probably stan would be better, since I can declare the contraints directly. But I have to go deeper…

Thanks alot for the provided source code for NUTS.
What I figured out is, that epsilon is iterated to zero and thus no sampling is possible.
The gradient seem to be pretty high and the parameter space is constrained, which makes it more difficult probably.
It would be very nice, if someone has a hint.