31 for (
unsigned int i = 0; i < par.
Vec().
size(); i++) {
34 v(i) = dd * grad[ext];
37 MnPrint print(
"AnalyticalGradientCalculator");
38 print.
Debug(
"User given gradient in Minuit2",
v);
46 if (!this->
G2(par, g2)) {
47 print.
Error(
"Error computing G2");
73 assert(hmat.
size() ==
n *(
n+1)/2);
77 if (extHessian.empty()) {
78 MnPrint print(
"AnalyticalGradientCalculator::Hessian");
79 print.
Info(
"FCN cannot compute Hessian matrix");
82 unsigned int next = sqrt(extHessian.size());
85 for (
unsigned int i = 0; i <
n; i++) {
88 for (
unsigned int j = i; j <
n; j++) {
91 hmat(i, j) = dxdi * extHessian[iext*next+ jext] * dxdj;
95 hmat(i, j) += d2xdi2 * extGradient[iext];
105 const unsigned int n = par.
Vec().
size();
106 assert(g2.
size() ==
n);
108 MnPrint print(
"AnalyticalGradientCalculator::G2");
115 std::vector<double> extG2 =
fGradFunc.
G2(extParams);
117 print.
Info(
"FCN cannot compute the 2nd derivatives vector (G2)");
121 for (
unsigned int i = 0; i <
n; i++) {
125 g2(i) = dxdi * dxdi * extG2[iext] + d2xdi2 * extGradient[iext];
132 print.
Info(
"FCN cannot compute the 2nd derivatives vector (G2) or the Hessian");
137 if (extHessian.empty()) {
138 print.
Info(
"FCN cannot compute Hessian matrix (needed to derive G2)");
143 const unsigned int nExt =
static_cast<unsigned int>(std::lround(std::sqrt(
static_cast<double>(extHessian.size()))));
144 if (nExt * nExt != extHessian.size()) {
145 print.
Error(
"Unexpected Hessian size; cannot derive G2 from Hessian diagonal");
151 for (
unsigned int i = 0; i <
n; i++) {
153 const double diag = extHessian[iext * nExt + iext];
156 g2(i) = dxdi * dxdi * diag + d2xdi2 * extGradient[iext];
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
virtual bool CanComputeG2() const
bool G2(const MinimumParameters &, MnAlgebraicVector &) const override
compute second derivatives (diagonal of Hessian)
virtual bool CanComputeHessian() const
const MnUserTransformation & fTransformation
const FCNBase & fGradFunc
FunctionGradient operator()(const MinimumParameters &) const override
bool Hessian(const MinimumParameters &, MnAlgebraicSymMatrix &) const override
compute Hessian matrix
virtual bool HasHessian() const
virtual std::vector< double > G2(std::vector< double > const &) const
Return the diagonal elements of the Hessian (second derivatives).
virtual std::vector< double > Hessian(std::vector< double > const &) const
Return the full Hessian matrix of the function.
virtual std::vector< double > Gradient(std::vector< double > const &) const
Return the gradient vector of the function at the given parameter point.
virtual bool HasG2() const
Class describing a symmetric matrix of size n.
unsigned int size() const
unsigned int size() const
const MnAlgebraicVector & Vec() const
void Debug(const Ts &... args)
void Error(const Ts &... args)
void Info(const Ts &... args)