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