Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParametricFunction.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_ParametricFunction
11#define ROOT_Minuit2_ParametricFunction
12
13#include "Minuit2/MnConfig.h"
14#include <vector>
15#include <cassert>
16
17#include "Minuit2/FCNBase.h"
18
19namespace ROOT {
20
21namespace Minuit2 {
22
23/**
24
25Function which has parameters. For example, one could define
26a one-dimensional Gaussian, by considering x as an input coordinate
27for the evaluation of the function, and the mean and the square root
28of the variance as parameters.
29<p>
30AS OF NOW PARAMETRICFUNCTION INHERITS FROM FCNBASE INSTEAD OF
31GENERICFUNCTION. THIS IS ONLY BECAUSE NUMERICAL2PGRADIENTCALCULATOR
32NEEDS AN FCNBASE OBJECT AND WILL BE CHANGED!!!!!!!!!!!!!!!!
33
34@ingroup Minuit
35
36\todo ParametricFunction and all the classes that inherit from it
37are inheriting also FCNBase so that the Gradient calculation has
38the Up() member function. That is not really good...
39
40
41 */
42
44
45public:
46 /**
47
48 Constructor which initializes the ParametricFunction with the
49 parameters given as input.
50
51 @param params vector containing the initial Parameter values
52
53 */
54
55 ParametricFunction(std::span<const double> params) : par(params.begin(), params.end()) {}
56
57 /**
58
59 Constructor which initializes the ParametricFunction by setting
60 the number of parameters.
61
62 @param nparams number of parameters of the parametric function
63
64 */
65
66 ParametricFunction(int nparams) : par(nparams) {}
67
68 /**
69
70 Sets the parameters of the ParametricFunction.
71
72 @param params vector containing the Parameter values
73
74 */
75
76 virtual void SetParameters(std::vector<double> const& params) const
77 {
78
79 assert(params.size() == par.size());
80 par.assign(params.begin(), params.end());
81 }
82
83 /**
84
85 Accessor for the state of the parameters.
86
87 @return vector containing the present Parameter settings
88
89 */
90
91 virtual const std::vector<double> &GetParameters() const { return par; }
92
93 /**
94
95 Accessor for the number of parameters.
96
97 @return the number of function parameters
98
99 */
100 virtual unsigned int NumberOfParameters() const { return par.size(); }
101
102 // Why do I need to declare it here, it should be inherited without
103 // any problems, no?
104
105 /**
106
107 Evaluates the function with the given coordinates.
108
109 @param x vector containing the input coordinates
110
111 @return the result of the function evaluation with the given
112 coordinates.
113
114 */
115
116 double operator()(std::vector<double> const& x) const override = 0;
117
118 /**
119
120 Evaluates the function with the given coordinates and Parameter
121 values. This member function is useful to implement when speed
122 is an issue as it is faster to call only one function instead
123 of two (SetParameters and operator()). The default implementation,
124 provided for convenience, does the latter.
125
126 @param x vector containing the input coordinates
127
128 @param params vector containing the Parameter values
129
130 @return the result of the function evaluation with the given
131 coordinates and parameters
132
133 */
134
135 virtual double operator()(std::vector<double> const& x, std::vector<double> const& params) const
136 {
137 SetParameters(params);
138 return operator()(x);
139 }
140
141 /**
142
143 Member function returning the Gradient of the function with respect
144 to its variables (but without including gradients with respect to
145 its internal parameters).
146
147 @param x vector containing the coordinates of the point where the
148 Gradient is to be calculated.
149
150 @return the Gradient vector of the function at the given point.
151
152 */
153
154 virtual std::vector<double> GetGradient(std::vector<double> const& x) const;
155
156protected:
157 /**
158
159 The vector containing the parameters of the function
160 It is mutable for "historical reasons" as in the hierarchy
161 methods and classes are const and all the implications of changing
162 them back to non-const are not clear.
163
164 */
165
166 mutable std::vector<double> par;
167};
168
169} // namespace Minuit2
170
171} // namespace ROOT
172
173#endif // ROOT_Minuit2_ParametricFunction
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition FCNBase.h:51
Function which has parameters.
ParametricFunction(int nparams)
Constructor which initializes the ParametricFunction by setting the number of parameters.
double operator()(std::vector< double > const &x) const override=0
Evaluates the function with the given coordinates.
ParametricFunction(std::span< const double > params)
Constructor which initializes the ParametricFunction with the parameters given as input.
virtual std::vector< double > GetGradient(std::vector< double > const &x) const
Member function returning the Gradient of the function with respect to its variables (but without inc...
virtual unsigned int NumberOfParameters() const
Accessor for the number of parameters.
virtual double operator()(std::vector< double > const &x, std::vector< double > const &params) const
Evaluates the function with the given coordinates and Parameter values.
virtual void SetParameters(std::vector< double > const &params) const
Sets the parameters of the ParametricFunction.
std::vector< double > par
The vector containing the parameters of the function It is mutable for "historical reasons" as in the...
virtual const std::vector< double > & GetParameters() const
Accessor for the state of the parameters.
Double_t x[n]
Definition legend1.C:17
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...