1 #ifndef STAN_MATH_MIX_MAT_FUNCTOR_HESSIAN_HPP
2 #define STAN_MATH_MIX_MAT_FUNCTOR_HESSIAN_HPP
47 const Eigen::Matrix<double, Dynamic, 1>& x,
49 Eigen::Matrix<double, Dynamic, 1>&
grad,
50 Eigen::Matrix<double, Dynamic, Dynamic>& H) {
51 H.resize(x.size(), x.size());
52 grad.resize(x.size());
54 for (
int i = 0; i < x.size(); ++i) {
56 Eigen::Matrix<fvar<var>, Dynamic, 1> x_fvar(x.size());
57 for (
int j = 0; j < x.size(); ++j)
61 if (i == 0) fx = fx_fvar.
val_.
val();
63 for (
int j = 0; j < x.size(); ++j)
64 H(i, j) = x_fvar(j).val_.adj();
67 }
catch (
const std::exception&
e) {
73 template <
typename T,
typename F>
76 const Eigen::Matrix<T, Dynamic, 1>& x,
78 Eigen::Matrix<T, Dynamic, 1>&
grad,
79 Eigen::Matrix<T, Dynamic, Dynamic>& H) {
80 H.resize(x.size(), x.size());
81 grad.resize(x.size());
82 Eigen::Matrix<fvar<fvar<T> >, Dynamic, 1> x_fvar(x.size());
83 for (
int i = 0; i < x.size(); ++i) {
84 for (
int j = i; j < x.size(); ++j) {
85 for (
int k = 0; k < x.size(); ++k)
90 fx = fx_fvar.
val_.val_;
93 H(i, j) = fx_fvar.
d_.d_;
static void grad(chainable *vi)
Compute the gradient for all variables starting from the specified root variable implementation.
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.