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 
19 namespace ROOT {
20 
21 namespace Minuit2 {
22 
23 /**
24 
25 Function which has parameters. For example, one could define
26 a one-dimensional Gaussian, by considering x as an input coordinate
27 for the evaluation of the function, and the mean and the square root
28 of the variance as parameters.
29 <p>
30 AS OF NOW PARAMETRICFUNCTION INHERITS FROM FCNBASE INSTEAD OF
31 GENERICFUNCTION. THIS IS ONLY BECAUSE NUMERICAL2PGRADIENTCALCULATOR
32 NEEDS AN FCNBASE OBJECT AND WILL BE CHANGED!!!!!!!!!!!!!!!!
33 
34 @ingroup Minuit
35 
36 \todo ParametricFunction and all the classes that inherit from it
37 are inheriting also FCNBase so that the Gradient calculation has
38 the Up() member function. That is not really good...
39 
40 
41  */
42 
43 class ParametricFunction : public FCNBase {
44 
45 public:
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  virtual ~ParametricFunction() {}
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  virtual double operator()(const std::vector<double> &x) const = 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 
158 protected:
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
ROOT::Minuit2::ParametricFunction::GetGradient
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...
Definition: ParametricFunction.cxx:24
ROOT::Minuit2::ParametricFunction::SetParameters
virtual void SetParameters(const std::vector< double > &params) const
Sets the parameters of the ParametricFunction.
Definition: ParametricFunction.h:78
ROOT::Minuit2::ParametricFunction::par
std::vector< double > par
The vector containing the parameters of the function It is mutable for "historical reasons" as in the...
Definition: ParametricFunction.h:168
ROOT::Minuit2::ParametricFunction
Function which has parameters.
Definition: ParametricFunction.h:43
ROOT::Minuit2::FCNBase
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition: FCNBase.h:45
ROOT::Minuit2::ParametricFunction::~ParametricFunction
virtual ~ParametricFunction()
Definition: ParametricFunction.h:68
ROOT::Minuit2::ParametricFunction::operator()
virtual double operator()(const std::vector< double > &x, const std::vector< double > &params) const
Evaluates the function with the given coordinates and Parameter values.
Definition: ParametricFunction.h:137
x
Double_t x[n]
Definition: legend1.C:17
ROOT::Minuit2::ParametricFunction::NumberOfParameters
virtual unsigned int NumberOfParameters() const
Accessor for the number of parameters.
Definition: ParametricFunction.h:102
ROOT::Minuit2::ParametricFunction::ParametricFunction
ParametricFunction(const std::vector< double > &params)
Constructor which initializes the ParametricFunction with the parameters given as input.
Definition: ParametricFunction.h:55
ROOT::Minuit2::ParametricFunction::operator()
virtual double operator()(const std::vector< double > &x) const =0
Evaluates the function with the given coordinates.
ROOT::Minuit2::ParametricFunction::ParametricFunction
ParametricFunction(int nparams)
Constructor which initializes the ParametricFunction by setting the number of parameters.
Definition: ParametricFunction.h:66
FCNBase.h
ROOT::Minuit2::ParametricFunction::GetParameters
virtual const std::vector< double > & GetParameters() const
Accessor for the state of the parameters.
Definition: ParametricFunction.h:93
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
MnConfig.h