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(const std::vector<double> &params) : par(params) {}
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 ~ParametricFunction() override {}
69
70 /**
71
72 Sets the parameters of the ParametricFunction.
73
74 @param params vector containing the Parameter values
75
76 */
77
78 virtual void SetParameters(const std::vector<double> &params) const
79 {
80
81 assert(params.size() == par.size());
82 par = params;
83 }
84
85 /**
86
87 Accessor for the state of the parameters.
88
89 @return vector containing the present Parameter settings
90
91 */
92
93 virtual const std::vector<double> &GetParameters() const { return par; }
94
95 /**
96
97 Accessor for the number of parameters.
98
99 @return the number of function parameters
100
101 */
102 virtual unsigned int NumberOfParameters() const { return par.size(); }
103
104 // Why do I need to declare it here, it should be inherited without
105 // any problems, no?
106
107 /**
108
109 Evaluates the function with the given coordinates.
110
111 @param x vector containing the input coordinates
112
113 @return the result of the function evaluation with the given
114 coordinates.
115
116 */
117
118 double operator()(const std::vector<double> &x) const override = 0;
119
120 /**
121
122 Evaluates the function with the given coordinates and Parameter
123 values. This member function is useful to implement when speed
124 is an issue as it is faster to call only one function instead
125 of two (SetParameters and operator()). The default implementation,
126 provided for convenience, does the latter.
127
128 @param x vector containing the input coordinates
129
130 @param params vector containing the Parameter values
131
132 @return the result of the function evaluation with the given
133 coordinates and parameters
134
135 */
136
137 virtual double operator()(const std::vector<double> &x, const std::vector<double> &params) const
138 {
139 SetParameters(params);
140 return operator()(x);
141 }
142
143 /**
144
145 Member function returning the Gradient of the function with respect
146 to its variables (but without including gradients with respect to
147 its internal parameters).
148
149 @param x vector containing the coordinates of the point where the
150 Gradient is to be calculated.
151
152 @return the Gradient vector of the function at the given point.
153
154 */
155
156 virtual std::vector<double> GetGradient(const std::vector<double> &x) const;
157
158protected:
159 /**
160
161 The vector containing the parameters of the function
162 It is mutable for "historical reasons" as in the hierarchy
163 methods and classes are const and all the implications of changing
164 them back to non-const are not clear.
165
166 */
167
168 mutable std::vector<double> par;
169};
170
171} // namespace Minuit2
172
173} // namespace ROOT
174
175#endif // ROOT_Minuit2_ParametricFunction
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition FCNBase.h:45
Function which has parameters.
ParametricFunction(int nparams)
Constructor which initializes the ParametricFunction by setting the number of parameters.
ParametricFunction(const std::vector< double > &params)
Constructor which initializes the ParametricFunction with the parameters given as input.
virtual double operator()(const std::vector< double > &x, const std::vector< double > &params) const
Evaluates the function with the given coordinates and Parameter values.
virtual void SetParameters(const std::vector< double > &params) const
Sets the parameters of the ParametricFunction.
virtual unsigned int NumberOfParameters() const
Accessor for the number of parameters.
virtual std::vector< double > GetGradient(const std::vector< double > &x) const
Member function returning the Gradient of the function with respect to its variables (but without inc...
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 operator()(const std::vector< double > &x) const override=0
Evaluates the function with the given coordinates.
Double_t x[n]
Definition legend1.C:17
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.