Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
FCNBase.h
Go to the documentation of this file.
1// @(#)root/minuit2:$Id$
2// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7 * *
8 **********************************************************************/
9
10#ifndef ROOT_Minuit2_FCNBase
11#define ROOT_Minuit2_FCNBase
12
13#include "Minuit2/MnConfig.h"
14
15#include <ROOT/RSpan.hxx>
16
17#include <vector>
18
19namespace ROOT::Minuit2 {
20
21/// \defgroup Minuit Minuit2 Minimization Library
22///
23/// New Object-oriented implementation of the MINUIT minimization package.
24/// More information is available at the home page of the \ref Minuit2Page "Minuit2" minimization package".
25///
26/// \ingroup Math
27
31};
32
33/// Interface (abstract class) defining the function to be minimized, which has to be implemented by the user.
34///
35/// \ingroup Minuit
36
37class FCNBase {
38
39public:
40 virtual ~FCNBase() = default;
41
42 /// The meaning of the vector of parameters is of course defined by the user,
43 /// who uses the values of those parameters to calculate their function Value.
44 /// The order and the position of these parameters is strictly the one specified
45 /// by the user when supplying the starting values for minimization. The starting
46 /// values must be specified by the user, either via an std::vector<double> or the
47 /// MnUserParameters supplied as input to the MINUIT minimizers such as
48 /// VariableMetricMinimizer or MnMigrad. Later values are determined by MINUIT
49 /// as it searches for the Minimum or performs whatever analysis is requested by
50 /// the user.
51 ///
52 /// @param v function parameters as defined by the user.
53 ///
54 /// @return the Value of the function.
55 ///
56 /// @see MnUserParameters
57 /// @see VariableMetricMinimizer
58 /// @see MnMigrad
59
60 virtual double operator()(std::vector<double> const &v) const = 0;
61
62 /// Error definition of the function. MINUIT defines Parameter errors as the
63 /// change in Parameter Value required to change the function Value by up. Normally,
64 /// for chisquared fits it is 1, and for negative log likelihood, its Value is 0.5.
65 /// If the user wants instead the 2-sigma errors for chisquared fits, it becomes 4,
66 /// as Chi2(x+n*sigma) = Chi2(x) + n*n.
67 ///
68 /// Comment a little bit better with links!!!!!!!!!!!!!!!!!
69
70 virtual double ErrorDef() const { return Up(); }
71
72 /// Error definition of the function. MINUIT defines Parameter errors as the
73 /// change in Parameter Value required to change the function Value by up. Normally,
74 /// for chisquared fits it is 1, and for negative log likelihood, its Value is 0.5.
75 /// If the user wants instead the 2-sigma errors for chisquared fits, it becomes 4,
76 /// as Chi2(x+n*sigma) = Chi2(x) + n*n.
77 ///
78 /// \todo Comment a little bit better with links!!!!!!!!!!!!!!!!! Idem for ErrorDef()
79
80 virtual double Up() const = 0;
81
82 /// add interface to set dynamically a new error definition
83 /// Re-implement this function if needed.
84 virtual void SetErrorDef(double) {};
85
86 virtual bool HasGradient() const { return false; }
87
88 /// Return the gradient vector of the function at the given parameter point.
89 ///
90 /// By default, returns an empty vector (no analytic gradient provided).
91 /// Override this method if an analytic gradient is available.
92 ///
93 /// @param v Parameter vector.
94 /// @return Gradient vector with respect to the parameters.
95 virtual std::vector<double> Gradient(std::vector<double> const &) const { return {}; }
96
97 /// \warning Not meant to be overridden! This is a requirement for an
98 /// internal optimization in RooFit that might go away with any refactoring.
99 virtual std::vector<double> GradientWithPrevResult(std::vector<double> const &parameters, double * /*previous_grad*/,
100 double * /*previous_g2*/, double * /*previous_gstep*/) const
101 {
102 return Gradient(parameters);
103 };
104
105 /// \warning Not meant to be overridden! This is a requirement for an
106 /// internal optimization in RooFit that might go away with any refactoring.
108
109 /// Return the diagonal elements of the Hessian (second derivatives).
110 ///
111 /// By default, returns an empty vector. Override this method if analytic second derivatives
112 /// (per-parameter curvature) are available.
113 ///
114 /// @param v Parameter vector.
115 /// @return Vector of second derivatives with respect to each parameter.
116 virtual std::vector<double> G2(std::vector<double> const &) const { return {}; }
117
118 /// Return the full Hessian matrix of the function.
119 ///
120 /// By default, returns an empty vector. Override this method if the full analytic Hessian
121 /// (matrix of second derivatives) is available.
122 ///
123 /// @param v Parameter vector.
124 /// @return Flattened Hessian matrix.
125 virtual std::vector<double> Hessian(std::vector<double> const &) const { return {}; }
126
127 virtual bool HasHessian() const { return false; }
128
129 virtual bool HasG2() const { return false; }
130};
131
132} // namespace ROOT::Minuit2
133
134#endif // ROOT_Minuit2_FCNBase
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition FCNBase.h:37
virtual double Up() const =0
Error definition of the function.
virtual ~FCNBase()=default
virtual bool HasHessian() const
Definition FCNBase.h:127
virtual double operator()(std::vector< double > const &v) const =0
The meaning of the vector of parameters is of course defined by the user, who uses the values of thos...
virtual std::vector< double > GradientWithPrevResult(std::vector< double > const &parameters, double *, double *, double *) const
Definition FCNBase.h:99
virtual std::vector< double > G2(std::vector< double > const &) const
Return the diagonal elements of the Hessian (second derivatives).
Definition FCNBase.h:116
virtual std::vector< double > Hessian(std::vector< double > const &) const
Return the full Hessian matrix of the function.
Definition FCNBase.h:125
virtual void SetErrorDef(double)
add interface to set dynamically a new error definition Re-implement this function if needed.
Definition FCNBase.h:84
virtual GradientParameterSpace gradParameterSpace() const
Definition FCNBase.h:107
virtual double ErrorDef() const
Error definition of the function.
Definition FCNBase.h:70
virtual std::vector< double > Gradient(std::vector< double > const &) const
Return the gradient vector of the function at the given parameter point.
Definition FCNBase.h:95
virtual bool HasG2() const
Definition FCNBase.h:129
virtual bool HasGradient() const
Definition FCNBase.h:86
GradientParameterSpace
Definition FCNBase.h:28