Logo ROOT  
Reference Guide
ExternalInternalGradientCalculator.cxx
Go to the documentation of this file.
1// @(#)root/minuit2:$Id$
2// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei, E.G.P. Bos 2003-2017
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7 * *
8 **********************************************************************/
9
10#include <vector>
16#include "Minuit2/MnPrint.h"
17
18namespace ROOT {
19namespace Minuit2 {
20
22{
23 std::vector<double> par_vec;
24 par_vec.resize(par.Vec().size());
25 for (std::size_t ix = 0; ix < par.Vec().size(); ++ix) {
26 par_vec[ix] = par.Vec()(ix);
27 }
28
29 std::vector<double> grad = fGradCalc.Gradient(par_vec);
30 assert(grad.size() == fTransformation.Parameters().size());
31
32 MnAlgebraicVector v(par.Vec().size());
33 for (unsigned int i = 0; i < par.Vec().size(); i++) {
34 unsigned int ext = fTransformation.ExtOfInt(i);
35 v(i) = grad[ext];
36 }
37
38 MnPrint print("ExternalInternalGradientCalculator");
39 print.Debug("User given gradient in Minuit2", v);
40
41 return FunctionGradient(v);
42}
43
46{
47 std::vector<double> par_vec;
48 par_vec.resize(par.Vec().size());
49 for (std::size_t ix = 0; ix < par.Vec().size(); ++ix) {
50 par_vec[ix] = par.Vec()(ix);
51 }
52
53 std::vector<double> previous_grad(functionGradient.Grad().Data(), functionGradient.Grad().Data() + functionGradient.Grad().size());
54 std::vector<double> previous_g2(functionGradient.G2().Data(), functionGradient.G2().Data() + functionGradient.G2().size());
55 std::vector<double> previous_gstep(functionGradient.Gstep().Data(), functionGradient.Gstep().Data() + functionGradient.Gstep().size());
56
57 std::vector<double> grad = fGradCalc.GradientWithPrevResult(par_vec, previous_grad.data(), previous_g2.data(), previous_gstep.data());
58 assert(grad.size() == fTransformation.Parameters().size());
59
60 MnAlgebraicVector v(par.Vec().size());
61 MnAlgebraicVector v_g2(par.Vec().size());
62 MnAlgebraicVector v_gstep(par.Vec().size());
63 for (unsigned int i = 0; i < par.Vec().size(); i++) {
64 unsigned int ext = fTransformation.ExtOfInt(i);
65 v(i) = grad[ext];
66 v_g2(i) = previous_g2[ext];
67 v_gstep(i) = previous_gstep[ext];
68 }
69
70 MnPrint print("ExternalInternalGradientCalculator");
71 print.Debug("User given gradient in Minuit2", v, "g2", v_g2, "step size", v_gstep);
72
73 return FunctionGradient(v, v_g2, v_gstep);
74}
75
76} // namespace Minuit2
77} // namespace ROOT
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
FunctionGradient operator()(const MinimumParameters &) const override
virtual std::vector< double > Gradient(const std::vector< double > &) const =0
virtual std::vector< double > GradientWithPrevResult(const std::vector< double > &parameters, double *, double *, double *) const
const MnAlgebraicVector & Gstep() const
const MnAlgebraicVector & Grad() const
const MnAlgebraicVector & G2() const
const double * Data() const
Definition: LAVector.h:223
unsigned int size() const
Definition: LAVector.h:227
const MnAlgebraicVector & Vec() const
void Debug(const Ts &... args)
Definition: MnPrint.h:138
unsigned int ExtOfInt(unsigned int internal) const
const std::vector< MinuitParameter > & Parameters() const
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.