Dear Stan Community,
As part of a Markov chain Monte Carlo sampling algorithm, I need to compute the following expression
\nabla |\nabla \xi(x)|
for some function \xi that maps a high dimensional real space to a real number. Using the reverse mode ‘gradient’ function, I can compute
in Stan, but I’m unable to implement the additional gradient without using the `hessian’ function. This last function, however, seems currently not fully implemented in Stan.
Would someone have an idea on how to compute the expression above using only the ‘gradient’ functionality in Stan? The main technical problem is that I can’t seem to use a
Eigen::Matrix<var, Eigen::Dynamic, 1> grad_fx
to store the gradient when calling
gradient(f, x, fx, grad_fx).
Only the numerical type ‘double’ is allowed.
Any tips on how to implement this ?