00001 // @(#)root/minuit2:$Id: ParametricFunction.h 20880 2007-11-19 11:23:41Z rdm $ 00002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT * 00007 * * 00008 **********************************************************************/ 00009 00010 #ifndef ROOT_Minuit2_ParametricFunction 00011 #define ROOT_Minuit2_ParametricFunction 00012 00013 #include "Minuit2/MnConfig.h" 00014 #include <vector> 00015 #include <cassert> 00016 00017 #include "Minuit2/FCNBase.h" 00018 00019 namespace ROOT { 00020 00021 namespace Minuit2 { 00022 00023 00024 00025 /** 00026 00027 Function which has parameters. For example, one could define 00028 a one-dimensional Gaussian, by considering x as an input coordinate 00029 for the evaluation of the function, and the mean and the square root 00030 of the variance as parameters. 00031 <p> 00032 AS OF NOW PARAMETRICFUNCTION INHERITS FROM FCNBASE INSTEAD OF 00033 GENERICFUNCTION. THIS IS ONLY BECAUSE NUMERICAL2PGRADIENTCALCULATOR 00034 NEEDS AN FCNBASE OBJECT AND WILL BE CHANGED!!!!!!!!!!!!!!!! 00035 00036 @ingroup Minuit 00037 00038 \todo ParametricFunction and all the classes that inherit from it 00039 are inheriting also FCNBase so that the Gradient calculation has 00040 the Up() member function. That is not really good... 00041 00042 00043 */ 00044 00045 class ParametricFunction : public FCNBase { 00046 00047 public: 00048 00049 00050 /** 00051 00052 Constructor which initializes the ParametricFunction with the 00053 parameters given as input. 00054 00055 @param params vector containing the initial Parameter values 00056 00057 */ 00058 00059 ParametricFunction(const std::vector<double>& params) : par(params) {} 00060 00061 00062 00063 /** 00064 00065 Constructor which initializes the ParametricFunction by setting 00066 the number of parameters. 00067 00068 @param nparams number of parameters of the parametric function 00069 00070 */ 00071 00072 ParametricFunction(int nparams) : par(nparams) {} 00073 00074 00075 00076 virtual ~ParametricFunction() {} 00077 00078 00079 00080 /** 00081 00082 Sets the parameters of the ParametricFunction. 00083 00084 @param params vector containing the Parameter values 00085 00086 */ 00087 00088 virtual void SetParameters(const std::vector<double>& params) const { 00089 00090 assert(params.size() == par.size()); 00091 par = params; 00092 00093 } 00094 00095 00096 00097 /** 00098 00099 Accessor for the state of the parameters. 00100 00101 @return vector containing the present Parameter settings 00102 00103 */ 00104 00105 virtual const std::vector<double> & GetParameters() const { return par; } 00106 00107 00108 00109 00110 /** 00111 00112 Accessor for the number of parameters. 00113 00114 @return the number of function parameters 00115 00116 */ 00117 virtual unsigned int NumberOfParameters() const { return par.size(); } 00118 00119 // Why do I need to declare it here, it should be inherited without 00120 // any problems, no? 00121 00122 /** 00123 00124 Evaluates the function with the given coordinates. 00125 00126 @param x vector containing the input coordinates 00127 00128 @return the result of the function evaluation with the given 00129 coordinates. 00130 00131 */ 00132 00133 virtual double operator()(const std::vector<double>& x) const=0; 00134 00135 00136 00137 /** 00138 00139 Evaluates the function with the given coordinates and Parameter 00140 values. This member function is useful to implement when speed 00141 is an issue as it is faster to call only one function instead 00142 of two (SetParameters and operator()). The default implementation, 00143 provided for convenience, does the latter. 00144 00145 @param x vector containing the input coordinates 00146 00147 @param params vector containing the Parameter values 00148 00149 @return the result of the function evaluation with the given 00150 coordinates and parameters 00151 00152 */ 00153 00154 virtual double operator()(const std::vector<double>& x, const std::vector<double>& params) const { 00155 SetParameters(params); 00156 return operator()(x); 00157 00158 } 00159 00160 00161 /** 00162 00163 Member function returning the Gradient of the function with respect 00164 to its variables (but without including gradients with respect to 00165 its internal parameters). 00166 00167 @param x vector containing the coordinates of the point where the 00168 Gradient is to be calculated. 00169 00170 @return the Gradient vector of the function at the given point. 00171 00172 */ 00173 00174 virtual std::vector<double> GetGradient(const std::vector<double>& x) const; 00175 00176 00177 00178 00179 protected: 00180 00181 /** 00182 00183 The vector containing the parameters of the function 00184 It is mutable for "historical reasons" as in the hierarchy 00185 methods and classes are const and all the implications of changing 00186 them back to non-const are not clear. 00187 00188 */ 00189 00190 00191 mutable std::vector<double> par; 00192 00193 }; 00194 00195 } // namespace Minuit2 00196 00197 } // namespace ROOT 00198 00199 #endif // ROOT_Minuit2_ParametricFunction