Logo ROOT   6.13/01
Reference Guide
ParamFunction.h
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Authors: L. Moneta, A. Zsenei 08/2005
3 
4  /**********************************************************************
5  * *
6  * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU General Public License *
10  * as published by the Free Software Foundation; either version 2 *
11  * of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this library (see file COPYING); if not, write *
20  * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21  * 330, Boston, MA 02111-1307 USA, or contact the author. *
22  * *
23  **********************************************************************/
24 
25 // Header file for class ParamFunction
26 //
27 // Base class for Parametric functions
28 //
29 // Created by: Lorenzo Moneta at Wed Nov 10 16:38:34 2004
30 //
31 // Last update: Wed Nov 10 16:38:34 2004
32 //
33 #ifndef ROOT_Math_ParamFunction
34 #define ROOT_Math_ParamFunction
35 
36 
37 #include "Math/IParamFunction.h"
38 
39 #include <vector>
40 
41 namespace ROOT {
42 namespace Math {
43 
44 //_____________________________________________________________________________________
45  /**
46  Base template class for all Parametric Functions.
47  The template argument is the type of parameteric function interface is implementing like
48  Parameteric 1D, Multi-Dim or gradient parametric.
49 
50  A parameteric function is a Generic Function with parameters, so
51  it is a function object which carries a state, the parameters.
52  The parameters are described with a standard vector of doubles.
53 
54  This class contains the default implementations for the methods defined in the
55  IParamFunction interface for dealing with parameters
56  Specific parameteric function classes should derive from this class if they want to profit from
57  default implementations for the abstract methods.
58  The derived classes need to implement only the DoEvalPar( x, p) and Clone() methods for non-gradient
59  parameteric functions or DoParameterDerivative(x,p,ipar) for gradient par functions
60 
61 
62  @ingroup ParamFunc
63  */
64 
65 
66 template <class IPFType>
67 class ParamFunction : public IPFType {
68 
69 public:
70 
71  typedef IPFType BaseParFunc;
72  typedef typename IPFType::BaseFunc BaseFunc;
73 
74  /**
75  Construct a parameteric function with npar parameters
76  @param npar number of parameters (default is zero)
77  */
78  ParamFunction(unsigned int npar = 0) :
79  fNpar(npar),
80  fParams( std::vector<double>(npar) )
81  { }
82 
83 
84  // destructor
85  virtual ~ParamFunction() {}
86 
87 
88  // copying constructors (can use default ones)
89 
90 
91 
92 
93  /**
94  Access the parameter values
95  */
96  virtual const double * Parameters() const { return &fParams.front(); }
97 
98  /**
99  Set the parameter values
100  @param p vector of doubles containing the parameter values.
101  */
102  virtual void SetParameters(const double * p)
103  {
104  //fParams = std::vector<double>(p,p+fNpar);
105  assert(fParams.size() == fNpar);
106  std::copy(p,p+fNpar,fParams.begin());
107  }
108 
109  /**
110  Return the number of parameters
111  */
112  unsigned int NPar() const { return fNpar; }
113 
114 
115  //using BaseFunc::operator();
116 
117  /**
118  Return \a true if the calculation of derivatives is implemented
119  */
120 // bool ProvidesGradient() const { return fProvGrad; }
121 
122  /**
123  Return \a true if the calculation of derivatives with respect to the Parameters is implemented
124  */
125  //bool ProvidesParameterGradient() const { return fProvParGrad; }
126 
127 // const std::vector<double> & GetParGradient( double x) {
128 // BaseParFunc::ParameterGradient(x,&fParGradient[0]);
129 // return fParGradient;
130 // }
131 
132 
133 
134 private:
135 
136  // cache number of Parameters for speed efficiency
137  unsigned int fNpar;
138 
139 protected:
140 
141  // Parameters (make protected to be accessible directly by derived classes)
142  std::vector<double> fParams;
143 
144 };
145 
146 } // namespace Math
147 } // namespace ROOT
148 
149 #endif /* ROOT_Math_ParamFunction */
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
STL namespace.
IPFType::BaseFunc BaseFunc
Definition: ParamFunction.h:72
unsigned int fNpar
Return true if the calculation of derivatives is implemented.
virtual const double * Parameters() const
Access the parameter values.
Definition: ParamFunction.h:96
virtual void SetParameters(const double *p)
Set the parameter values.
Base template class for all Parametric Functions.
Definition: ParamFunction.h:67
std::vector< double > fParams
Namespace for new Math classes and functions.
unsigned int NPar() const
Return the number of parameters.
ParamFunction(unsigned int npar=0)
Construct a parameteric function with npar parameters.
Definition: ParamFunction.h:78