I am Stan beginner, I have a short question.
Can I generate a sample using the HMC method in Stan if I do not know the analytical density and distribution functions?
I can numerically calculate the value of the density function and the value of its gradients at any point. I would like to implement the HMC algorithm using Stan to generate a sample from an this unknown distribution and estimate its parameters.
If this is not possible, can I at least use Stan to select the optimal parameters of the HMC algorithm that I wrote?
When you say you can numerically compute these, do you mean you have existing code that does so? In which language?
Yes. I have python code that takes the values of generalized coordinates q as arguments, and outputs the energy value of the system and its gradients at a point.
As a density function, I use \pi(q) = e^{-E(q)}.
You may find the responses on this thread interesting: Fitting external models with Stan
Depending on how complicated the density is, you may be able to code it in Stan, but usually this question comes up when the density depends on some expensive, complicated, or implemented-in-Fortran-by-someone-else calculation, in which case using Stan directly becomes more difficult
Unfortunately the source code is really very complicated. It is mostly written in Fortran and uses third-party programs and libraries.
But anyway, thanks))
The final suggestion in that thread (using nutpie) should be viable!