|
16 | 16 |
|
17 | 17 | #include <vector> |
18 | 18 |
|
19 | | -namespace ROOT { |
| 19 | +namespace ROOT::Minuit2 { |
20 | 20 |
|
21 | | -namespace Minuit2 { |
22 | | - |
23 | | -/** |
24 | | -
|
25 | | - \defgroup Minuit Minuit2 Minimization Library |
26 | | -
|
27 | | - New Object-oriented implementation of the MINUIT minimization package. |
28 | | - More information is available at the home page of the \ref Minuit2Page "Minuit2" minimization package". |
29 | | -
|
30 | | - \ingroup Math |
31 | | -*/ |
| 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 |
32 | 27 |
|
33 | 28 | enum class GradientParameterSpace { |
34 | | - External, Internal |
| 29 | + External, |
| 30 | + Internal |
35 | 31 | }; |
36 | 32 |
|
37 | | -//______________________________________________________________________________ |
38 | | -/** |
39 | | -
|
40 | | -
|
41 | | -Interface (abstract class) defining the function to be minimized, which has to be implemented by the user. |
42 | | -
|
43 | | -@author Fred James and Matthias Winkler; modified by Andras Zsenei and Lorenzo Moneta |
44 | | -
|
45 | | -\ingroup Minuit |
46 | | -
|
47 | | - */ |
| 33 | +/// Interface (abstract class) defining the function to be minimized, which has to be implemented by the user. |
| 34 | +/// |
| 35 | +/// \ingroup Minuit |
48 | 36 |
|
49 | 37 | class FCNBase { |
50 | 38 |
|
51 | 39 | public: |
52 | | - |
53 | 40 | virtual ~FCNBase() = default; |
54 | 41 |
|
55 | | - /** |
56 | | -
|
57 | | - The meaning of the vector of parameters is of course defined by the user, |
58 | | - who uses the values of those parameters to calculate their function Value. |
59 | | - The order and the position of these parameters is strictly the one specified |
60 | | - by the user when supplying the starting values for minimization. The starting |
61 | | - values must be specified by the user, either via an std::vector<double> or the |
62 | | - MnUserParameters supplied as input to the MINUIT minimizers such as |
63 | | - VariableMetricMinimizer or MnMigrad. Later values are determined by MINUIT |
64 | | - as it searches for the Minimum or performs whatever analysis is requested by |
65 | | - the user. |
66 | | -
|
67 | | - @param v function parameters as defined by the user. |
68 | | -
|
69 | | - @return the Value of the function. |
70 | | -
|
71 | | - @see MnUserParameters |
72 | | - @see VariableMetricMinimizer |
73 | | - @see MnMigrad |
74 | | -
|
75 | | - */ |
| 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 |
76 | 59 |
|
77 | 60 | virtual double operator()(std::vector<double> const &v) const = 0; |
78 | 61 |
|
79 | | - /** |
80 | | -
|
81 | | - Error definition of the function. MINUIT defines Parameter errors as the |
82 | | - change in Parameter Value required to change the function Value by up. Normally, |
83 | | - for chisquared fits it is 1, and for negative log likelihood, its Value is 0.5. |
84 | | - If the user wants instead the 2-sigma errors for chisquared fits, it becomes 4, |
85 | | - as Chi2(x+n*sigma) = Chi2(x) + n*n. |
86 | | -
|
87 | | - Comment a little bit better with links!!!!!!!!!!!!!!!!! |
88 | | -
|
89 | | - */ |
| 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!!!!!!!!!!!!!!!!! |
90 | 69 |
|
91 | 70 | virtual double ErrorDef() const { return Up(); } |
92 | 71 |
|
93 | | - /** |
94 | | -
|
95 | | - Error definition of the function. MINUIT defines Parameter errors as the |
96 | | - change in Parameter Value required to change the function Value by up. Normally, |
97 | | - for chisquared fits it is 1, and for negative log likelihood, its Value is 0.5. |
98 | | - If the user wants instead the 2-sigma errors for chisquared fits, it becomes 4, |
99 | | - as Chi2(x+n*sigma) = Chi2(x) + n*n. |
100 | | -
|
101 | | - \todo Comment a little bit better with links!!!!!!!!!!!!!!!!! Idem for ErrorDef() |
102 | | -
|
103 | | - */ |
| 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() |
104 | 79 |
|
105 | 80 | virtual double Up() const = 0; |
106 | 81 |
|
107 | | - /** |
108 | | - add interface to set dynamically a new error definition |
109 | | - Re-implement this function if needed. |
110 | | - */ |
111 | | - virtual void SetErrorDef(double){}; |
| 82 | + /// add interface to set dynamically a new error definition |
| 83 | + /// Re-implement this function if needed. |
| 84 | + virtual void SetErrorDef(double) {}; |
112 | 85 |
|
113 | 86 | virtual bool HasGradient() const { return false; } |
114 | 87 |
|
115 | | - virtual std::vector<double> Gradient(std::vector<double> const&) const { return {}; } |
116 | | - |
117 | | - /// In some cases, the gradient algorithm will use information from the previous step, these can be passed |
118 | | - /// in with this overload. The `previous_*` arrays can also be used to return second derivative and step size |
119 | | - /// so that these can be passed forward again as well at the call site, if necessary. |
120 | | - virtual std::vector<double> GradientWithPrevResult(std::vector<double> const& parameters, double * /*previous_grad*/, |
| 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 ¶meters, double * /*previous_grad*/, |
121 | 100 | double * /*previous_g2*/, double * /*previous_gstep*/) const |
122 | 101 | { |
123 | 102 | return Gradient(parameters); |
124 | 103 | }; |
125 | 104 |
|
126 | | - virtual GradientParameterSpace gradParameterSpace() const { |
127 | | - return GradientParameterSpace::External; |
128 | | - }; |
129 | | - |
130 | | - /// return second derivatives (diagonal of the Hessian matrix) |
131 | | - virtual std::vector<double> G2(std::vector<double> const&) const { return {};} |
132 | | - |
133 | | - /// return Hessian |
134 | | - virtual std::vector<double> Hessian(std::vector<double> const&) const { return {};} |
| 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. |
| 107 | + virtual GradientParameterSpace gradParameterSpace() const { return GradientParameterSpace::External; }; |
| 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 {}; } |
135 | 126 |
|
136 | 127 | virtual bool HasHessian() const { return false; } |
137 | 128 |
|
138 | 129 | virtual bool HasG2() const { return false; } |
139 | 130 | }; |
140 | 131 |
|
141 | | -} // namespace Minuit2 |
142 | | - |
143 | | -} // namespace ROOT |
| 132 | +} // namespace ROOT::Minuit2 |
144 | 133 |
|
145 | 134 | #endif // ROOT_Minuit2_FCNBase |
0 commit comments