ROOT   6.08/07 Reference Guide
GaussFunction.h
Go to the documentation of this file.
1
2 #include "Math/IParamFunction.h"
3 #include <cmath>
4
5
7
8 public:
9
10  enum {
11  kNPar = 3
12  };
13
14  GaussFunction(double _amp = 1, double _mean = 0, double _sigma = 1) {
15  fParams[0] = _amp;
16  fParams[1] = _mean;
17  fParams[2] = _sigma;
18  fLogAmp = std::log(_amp);
19  }
20
21  unsigned int NDim() const { return 1; }
22
23  unsigned int NPar() const { return kNPar; }
24
25  inline double amp() const { return fParams[0]; }
26  inline double logamp() const { return fLogAmp; }
27  inline double mean() const { return fParams[1]; }
28  inline double sigma() const { return fParams[2]; }
29
30  const double * Parameters() const { return fParams; }
31
32  void SetParameters(const double * p) { std::copy(p,p+kNPar,fParams); /* fLogAmp = std::log( p[0] ); */ }
33
34
35  ROOT::Math::IMultiGenFunction * Clone() const { return new GaussFunction(amp(), mean(), sigma() ); }
36
37
38  // implementing this is much faster
39  double operator()(const double *x, const double * p) {
40  double y = (x[0]-p[1])/p[2];
41  return p[0]*std::exp(-0.5*y*y);
42  }
43
45
46  void ParameterGradient(const double *x, const double * p, double * g) const {
47  double a = p[0];
48  double m = p[1];
49  double s = p[2];
50  double y = (x[0]- m )/s;
51  g[0] = std::exp(-0.5*y*y);
52  g[1] = a *g[0]*y/s;
53  g[2] = g[1]*y;
54  }
55
56
57 private:
58
59
60  double DoEvalPar(const double * x, const double * p) const {
61  double a = p[0];
62  double m = p[1];
63  double s = p[2];
64  double y = (x[0]-m)/s;
65  return a*std::exp(-0.5*y*y);
66  }
67
68  double DoDerivative(const double *x, unsigned int icoord) const {
69  (void)icoord;
70  assert (icoord == 0);
71  double dGdx = -(*this)(x) * (x[0]-mean())/(sigma()*sigma());
72  return dGdx;
73  }
74
75  double DoParameterDerivative(const double *x, const double * p, unsigned int ipar) const {
79  }
80
81
82  double fParams[kNPar];
83  double fLogAmp;
84 };
double amp() const
Definition: GaussFunction.h:25
void ParameterGradient(const double *x, const double *p, double *g) const
Evaluate the all the derivatives (gradient vector) of the function with respect to the parameters at ...
Definition: GaussFunction.h:46
TArc * a
Definition: textangle.C:12
double mean() const
Definition: GaussFunction.h:27
Double_t x[n]
Definition: legend1.C:17
double sigma() const
Definition: GaussFunction.h:28
double logamp() const
Definition: GaussFunction.h:26
unsigned int NDim() const
Retrieve the dimension of the function.
Definition: GaussFunction.h:21
double DoDerivative(const double *x, unsigned int icoord) const
Definition: GaussFunction.h:68
const double * Parameters() const
Access the parameter values.
Definition: GaussFunction.h:30
double fParams[kNPar]
Definition: GaussFunction.h:82
TMarker * m
Definition: textangle.C:8
GaussFunction(double _amp=1, double _mean=0, double _sigma=1)
Definition: GaussFunction.h:14
void SetParameters(const double *p)
Set the parameter values.
Definition: GaussFunction.h:32
double DoParameterDerivative(const double *x, const double *p, unsigned int ipar) const
Evaluate the partial derivative w.r.t a parameter ipar , to be implemented by the derived classes...
Definition: GaussFunction.h:75
Interface (abstract class) for parametric gradient multi-dimensional functions providing in addition ...
Double_t y[n]
Definition: legend1.C:17
double DoEvalPar(const double *x, const double *p) const
Implementation of the evaluation function using the x values and the parameters.
Definition: GaussFunction.h:60
ROOT::Math::IMultiGenFunction * Clone() const
Clone a function.
Definition: GaussFunction.h:35
typedef void((*Func_t)())
double operator()(const double *x, const double *p)
Definition: GaussFunction.h:39
unsigned int NPar() const
Return the number of Parameters.
Definition: GaussFunction.h:23
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:63
double exp(double)
double log(double)