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
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.
If it’s at all complicated, you’ll want to run / implement NUTS. Tuning is difficult with HMC. And you’ll need transforms too.
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…
There are NUTS implementations for Matlab. This one is based on Matt Hoffman’s original code with adaptation added https://github.com/gpstuff-dev/gpstuff/blob/master/mc/hmc_nuts.m
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.