21 #ifndef DIFF_HESSIAN_H
22 #define DIFF_HESSIAN_H
44 template<
class Func,
class Model,
class Adapter>
49 const std::vector<double>& dx,
50 const Adapter& adapter
53 const size_t D = adapter.size(&x);
59 for(
size_t i = 0;
i <
D;
i++)
61 for(
size_t j = 0; j <
D; j++)
71 H(i, i) = (fxp - 2*fx + fxm) / (dx[i]*dx[i]);
89 H(i, j) = (fxpp - fxpm - fxmp + fxmm) / (4*dx[i]*dx[j]);
108 template<
class Func,
class Vec>
114 const std::vector<double>& dx
135 template<
class Func,
class Model,
class Adapter>
140 const std::vector<double>& dx,
141 const Adapter& adapter
144 const size_t D = adapter.size(&x);
150 for(
size_t i = 0;
i <
D;
i++)
152 for(
size_t j = 0; j <=
i; j++)
162 H(i, i) = (fxp - 2*fx + fxm) / (dx[i]*dx[i]);
181 H(i, j) = (fxpp - fxpm - fxmp + fxmm) / (4*dx[i]*dx[j]);
201 template<
class Func,
class Vec>
207 const std::vector<double>& dx
227 template<
class Func,
class Model,
class Adapter>
232 const std::vector<double>& dx,
233 const Adapter& adapter
236 const size_t D = adapter.size(&x);
242 for(
size_t i = 0;
i <
D;
i++)
244 for(
size_t j = 0; j <
D; j++)
254 H(i, i) = (fxp - 2*fx + fxm) / (dx[i]*dx[i]);
272 template<
class Func,
class Vec>
278 const std::vector<double>& dx
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
void move_param(Model &x, size_t i, double dv, const Adapter &aptr)
Helper function that moves a parameter by an amount.
Definition: diff_util.h:102
Matrix hessian_symmetric(const Func &f, const Model &x, const std::vector< double > &dx, const Adapter &adapter)
Computes the Hessian of a function, evaluated at a point, using finite differences. This function assumes that the Hessian is SYMMETRIC, and only computes the lower triangle of it.
Definition: diff_hessian.h:137
void move_params(Model &x, size_t i, size_t j, double dv, double dw, const Adapter &aptr)
Helper function that moves a pair of parameters by an amount.
Definition: diff_util.h:111
x
Definition: APPgetLargeConnectedEdges.m:100
Matrix hessian_diagonal(const Func &f, const Model &x, const std::vector< double > &dx, const Adapter &adapter)
Computes the diagonal Hessian of a function, evaluated at a point, using finite differences.
Definition: diff_hessian.h:229
Default adapter for the hessian function.
Definition: diff_util.h:42
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
D
Definition: APPgetLargeConnectedEdges.m:106
Matrix hessian(const Func &f, const Model &x, const std::vector< double > &dx, const Adapter &adapter)
Computes the Hessian of a function, evaluated at a point, using finite differences.
Definition: diff_hessian.h:46