BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ROOT::Math::LSResidualFunc Class Reference

Description

LSResidualFunc class description. Internal class used for accessing the residuals of the Least Square function and their derivates which are estimated numerically using GSL numerical derivation. The class contains a pointer to the fit method function and an index specifying the i-th residual and wraps it in a multi-dim gradient function interface ROOT::Math::IGradientFunctionMultiDim. The class is used by ROOT::Math::GSLNLSMinimizer (GSL non linear least square fitter)

Definition at line 67 of file GSLNLSMinimizer.h.

Inheritance diagram for ROOT::Math::LSResidualFunc:
[legend]
Collaboration diagram for ROOT::Math::LSResidualFunc:
[legend]

Public Types

typedef T BackendType
 
typedef IBaseFunctionMultiDimTempl< T > BaseFunc
 
typedef IGradientMultiDimTempl< T > BaseGrad
 

Public Member Functions

 LSResidualFunc ()
 
 LSResidualFunc (const LSResidualFunc &rhs)
 
 LSResidualFunc (const ROOT::Math::FitMethodFunction &func, unsigned int i)
 
IMultiGenFunctionClone () const
 
Derivative (const T *x, unsigned int icoord=0) const
 
void FdF (const double *x, double &f, double *g) const
 
virtual void FdF (const T *x, T &f, T *df) const
 
void Gradient (const double *x, double *g) const
 
virtual void Gradient (const T *x, T *grad) const
 
unsigned int NDim () const
 
virtual unsigned int NDim () const=0
 
operator() (const T *x) const
 
LSResidualFuncoperator= (const LSResidualFunc &rhs)
 

Private Member Functions

double DoDerivative (const double *x, unsigned int icoord) const
 
double DoEval (const double *x) const
 

Private Attributes

const ROOT::Math::FitMethodFunctionfChi2
 
unsigned int fIndex
 
std::vector< double > fX2
 

Member Typedef Documentation

◆ BackendType

template<class T >
typedef T ROOT::Math::IBaseFunctionMultiDimTempl< T >::BackendType
inherited

Definition at line 66 of file IFunction.h.

◆ BaseFunc

Definition at line 330 of file IFunction.h.

◆ BaseGrad

template<class T >
typedef IGradientMultiDimTempl<T> ROOT::Math::IGradientFunctionMultiDimTempl< T >::BaseGrad
inherited

Definition at line 331 of file IFunction.h.

Constructor & Destructor Documentation

◆ LSResidualFunc() [1/3]

ROOT::Math::LSResidualFunc::LSResidualFunc ( )
inline

Definition at line 71 of file GSLNLSMinimizer.h.

71  : fIndex(0), fChi2(0)
72  {}
const ROOT::Math::FitMethodFunction * fChi2

Referenced by Clone().

◆ LSResidualFunc() [2/3]

ROOT::Math::LSResidualFunc::LSResidualFunc ( const ROOT::Math::FitMethodFunction func,
unsigned int  i 
)
inline

Definition at line 75 of file GSLNLSMinimizer.h.

75  :
76  fIndex(i),
77  fChi2(&func),
78  fX2(std::vector<double>(func.NDim() ) )
79  {}
virtual unsigned int NDim() const
std::vector< double > fX2

◆ LSResidualFunc() [3/3]

ROOT::Math::LSResidualFunc::LSResidualFunc ( const LSResidualFunc rhs)
inline

Definition at line 83 of file GSLNLSMinimizer.h.

83  :
86  {
87  operator=(rhs);
88  }
LSResidualFunc & operator=(const LSResidualFunc &rhs)
IGradientFunctionMultiDim IMultiGradFunction
Definition: IFunctionfwd.h:43
IMultiGenFunctionTempl< double > IMultiGenFunction
Definition: IFunctionfwd.h:34

References operator=().

Here is the call graph for this function:

Member Function Documentation

◆ Clone()

IMultiGenFunction* ROOT::Math::LSResidualFunc::Clone ( ) const
inlinevirtual

Clone a function. Each derived class must implement their version of the Clone method

Implements ROOT::Math::IBaseFunctionMultiDimTempl< T >.

Definition at line 99 of file GSLNLSMinimizer.h.

99  {
100  return new LSResidualFunc(*fChi2,fIndex);
101  }

References LSResidualFunc(), fChi2, and fIndex.

Here is the call graph for this function:

◆ Derivative()

template<class T >
T ROOT::Math::IGradientMultiDimTempl< T >::Derivative ( const T *  x,
unsigned int  icoord = 0 
) const
inlineinherited

Return the partial derivative with respect to the passed coordinate

Definition at line 217 of file IFunction.h.

217 { return DoDerivative(x, icoord); }
virtual T DoDerivative(const T *x, unsigned int icoord) const =0

References ROOT::Math::IGradientMultiDimTempl< T >::DoDerivative().

Referenced by ROOT::Math::MinimTransformFunction::DoDerivative(), and ROOT::Math::IGradientFunctionMultiDimTempl< T >::Gradient().

Here is the call graph for this function:

◆ DoDerivative()

double ROOT::Math::LSResidualFunc::DoDerivative ( const double *  x,
unsigned int  icoord 
) const
inlineprivate

Definition at line 132 of file GSLNLSMinimizer.h.

132  {
133  //return ROOT::Math::Derivator::Eval(*this, x, icoord, 1E-8);
134  std::copy(x,x+NDim(),fX2.begin());
135  const double kEps = 1.0E-4;
136  fX2[icoord] += kEps;
137  return ( DoEval(&fX2.front()) - DoEval(x) )/kEps;
138  }
double DoEval(const double *x) const
unsigned int NDim() const

References DoEval(), fX2, and NDim().

Here is the call graph for this function:

◆ DoEval()

double ROOT::Math::LSResidualFunc::DoEval ( const double *  x) const
inlineprivate

Definition at line 128 of file GSLNLSMinimizer.h.

128  {
129  return fChi2->DataElement(x, fIndex);
130  }
virtual double DataElement(const double *x, unsigned int i, double *g=0) const =0

References ROOT::Math::BasicFitMethodFunction< FunctionType >::DataElement(), fChi2, and fIndex.

Referenced by DoDerivative(), and FdF().

Here is the call graph for this function:

◆ FdF() [1/2]

void ROOT::Math::LSResidualFunc::FdF ( const double *  x,
double &  f,
double *  g 
) const
inline

Definition at line 110 of file GSLNLSMinimizer.h.

110  {
111 // unsigned int n = NDim();
112 // std::copy(x,x+n,fX2.begin());
113 // const double kEps = 1.0E-4;
114 // f = DoEval(x);
115 // for (unsigned int i = 0; i < n; ++i) {
116 // fX2[i] += kEps;
117 // g[i] = ( DoEval(&fX2.front()) - f )/kEps;
118 // fX2[i] = x[i];
119 // }
120  // BornAgain -> G.P. Fast derivative calculation using values caching
121  f = DoEval(x);
122  fChi2->DataElement(x, fIndex, g);
123  }

References ROOT::Math::BasicFitMethodFunction< FunctionType >::DataElement(), DoEval(), fChi2, and fIndex.

Referenced by Gradient().

Here is the call graph for this function:

◆ FdF() [2/2]

template<class T >
virtual void ROOT::Math::IGradientFunctionMultiDimTempl< T >::FdF ( const T *  x,
T &  f,
T *  df 
) const
inlinevirtualinherited

Optimized method to evaluate at the same time the function value and derivative at a point x. Often both value and derivatives are needed and it is often more efficient to compute them at the same time. Derived class should implement this method if performances play an important role and if it is faster to evaluate value and derivative at the same time

Implements ROOT::Math::IGradientMultiDimTempl< T >.

Definition at line 357 of file IFunction.h.

358  {
359  f = BaseFunc::operator()(x);
360  Gradient(x, df);
361  }
virtual void Gradient(const T *x, T *grad) const
Definition: IFunction.h:342

References ROOT::Math::IGradientFunctionMultiDimTempl< T >::Gradient(), and ROOT::Math::IBaseFunctionMultiDimTempl< T >::operator()().

Here is the call graph for this function:

◆ Gradient() [1/2]

void ROOT::Math::LSResidualFunc::Gradient ( const double *  x,
double *  g 
) const
inline

Definition at line 105 of file GSLNLSMinimizer.h.

105  {
106  double f0 = 0;
107  FdF(x,f0,g);
108  }
void FdF(const double *x, double &f, double *g) const

References FdF().

Here is the call graph for this function:

◆ Gradient() [2/2]

template<class T >
virtual void ROOT::Math::IGradientFunctionMultiDimTempl< T >::Gradient ( const T *  x,
T *  grad 
) const
inlinevirtualinherited

Evaluate all the vector of function derivatives (gradient) at a point x. Derived classes must re-implement it if more efficient than evaluting one at a time

Implements ROOT::Math::IGradientMultiDimTempl< T >.

Definition at line 342 of file IFunction.h.

343  {
344  unsigned int ndim = NDim();
345  for (unsigned int icoord = 0; icoord < ndim; ++icoord)
346  grad[icoord] = BaseGrad::Derivative(x, icoord);
347  }
virtual unsigned int NDim() const=0
T Derivative(const T *x, unsigned int icoord=0) const
Definition: IFunction.h:217

References ROOT::Math::IGradientMultiDimTempl< T >::Derivative(), and ROOT::Math::IGradientFunctionMultiDimTempl< T >::NDim().

Referenced by ROOT::Math::IGradientFunctionMultiDimTempl< T >::FdF().

Here is the call graph for this function:

◆ NDim() [1/2]

unsigned int ROOT::Math::LSResidualFunc::NDim ( ) const
inlinevirtual

Retrieve the dimension of the function

Implements ROOT::Math::IBaseFunctionMultiDimTempl< T >.

Definition at line 103 of file GSLNLSMinimizer.h.

103 { return fChi2->NDim(); }

References fChi2, and ROOT::Math::BasicFitMethodFunction< FunctionType >::NDim().

Referenced by DoDerivative().

Here is the call graph for this function:

◆ NDim() [2/2]

template<class T >
virtual unsigned int ROOT::Math::IBaseFunctionMultiDimTempl< T >::NDim
inherited

◆ operator()()

template<class T >
T ROOT::Math::IBaseFunctionMultiDimTempl< T >::operator() ( const T *  x) const
inlineinherited

Evaluate the function at a point x[]. Use the pure virtual private method DoEval which must be implemented by the sub-classes

Definition at line 92 of file IFunction.h.

93  {
94  return DoEval(x);
95  }
virtual T DoEval(const T *x) const =0

References ROOT::Math::IBaseFunctionMultiDimTempl< T >::DoEval().

Referenced by ROOT::Math::IGradientFunctionMultiDimTempl< T >::FdF().

Here is the call graph for this function:

◆ operator=()

LSResidualFunc& ROOT::Math::LSResidualFunc::operator= ( const LSResidualFunc rhs)
inline

Definition at line 91 of file GSLNLSMinimizer.h.

92  {
93  fIndex = rhs.fIndex;
94  fChi2 = rhs.fChi2;
95  fX2 = rhs.fX2;
96  return *this;
97  }

References fChi2, fIndex, and fX2.

Referenced by LSResidualFunc().

Member Data Documentation

◆ fChi2

const ROOT::Math::FitMethodFunction* ROOT::Math::LSResidualFunc::fChi2
private

Definition at line 141 of file GSLNLSMinimizer.h.

Referenced by Clone(), DoEval(), FdF(), NDim(), and operator=().

◆ fIndex

unsigned int ROOT::Math::LSResidualFunc::fIndex
private

Definition at line 140 of file GSLNLSMinimizer.h.

Referenced by Clone(), DoEval(), FdF(), and operator=().

◆ fX2

std::vector<double> ROOT::Math::LSResidualFunc::fX2
mutableprivate

Definition at line 142 of file GSLNLSMinimizer.h.

Referenced by DoDerivative(), and operator=().


The documentation for this class was generated from the following file: