I’m dealing with a problem which involves a non-trivial simulation for the calculation of the likelihood.

The calculation of gradients of this kind of simulation is also non-trivial, therefore I lack an implementation to calculate them.

The current state of the art implementation of this kind of simulation, which would allow me to evaluate the likelihood of a point, is available in MatLab.

If I could call a MatLab function, an “external function” to provide the likelihood, I’d at least like to see how using Stan sampling with automatic differentiation turns out, since reimplementing the solving procedure as a Stan function would be very time demanding.

So,

What is the status of non-native external functions used as likelihood functions for a Stan model ? (In a way similar to the one in the “Custom Probability Functions” part of the manual for native functions)

Is it possible to use them if a C++ implementation is provided ? if so, Is this the only possible specification ?

What about (of course, inefficient) custom command line calls ?

Thanks in advance !!!