1 #ifndef STAN_MATH_MIX_MAT_FUNCTOR_HESSIAN_TIMES_VECTOR_HPP
2 #define STAN_MATH_MIX_MAT_FUNCTOR_HESSIAN_TIMES_VECTOR_HPP
18 const Eigen::Matrix<double, Dynamic, 1>& x,
19 const Eigen::Matrix<double, Dynamic, 1>& v,
21 Eigen::Matrix<double, Dynamic, 1>& Hv) {
27 Matrix<var, Dynamic, 1> x_var(x.size());
28 for (
int i = 0; i < x_var.size(); ++i)
31 var grad_fx_var_dot_v;
36 for (
int i = 0; i < x.size(); ++i)
37 Hv(i) = x_var(i).adj();
38 }
catch (
const std::exception&
e) {
44 template <
typename T,
typename F>
47 const Eigen::Matrix<T, Dynamic, 1>& x,
48 const Eigen::Matrix<T, Dynamic, 1>& v,
50 Eigen::Matrix<T, Dynamic, 1>& Hv) {
52 Matrix<T, Dynamic, 1>
grad;
53 Matrix<T, Dynamic, Dynamic> H;
void gradient_dot_vector(const F &f, const Eigen::Matrix< T1, Dynamic, 1 > &x, const Eigen::Matrix< T2, Dynamic, 1 > &v, T1 &fx, T1 &grad_fx_dot_v)
static void grad(chainable *vi)
Compute the gradient for all variables starting from the specified root variable implementation.
void hessian_times_vector(const F &f, const Eigen::Matrix< double, Dynamic, 1 > &x, const Eigen::Matrix< double, Dynamic, 1 > &v, double &fx, Eigen::Matrix< double, Dynamic, 1 > &Hv)
Independent (input) and dependent (output) variables for gradients.
vari * vi_
Pointer to the implementation of this variable.
double e()
Return the base of the natural logarithm.
void hessian(const F &f, const Eigen::Matrix< double, Dynamic, 1 > &x, double &fx, Eigen::Matrix< double, Dynamic, 1 > &grad, Eigen::Matrix< double, Dynamic, Dynamic > &H)
Calculate the value, the gradient, and the Hessian, of the specified function at the specified argume...
static void recover_memory_nested()
Recover only the memory used for the top nested call.
double val() const
Return the value of this variable.
static void start_nested()
Record the current position so that recover_memory_nested() can find it.