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::MultiNumGradFunction Class Reference

Description

MultiNumGradFunction class to wrap a normal function in a gradient function using numerical gradient calculation provided by the class Derivator (based on GSL numerical derivation)

Definition at line 49 of file MultiNumGradFunction.h.

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

Public Types

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

Public Member Functions

 MultiNumGradFunction (const IMultiGenFunction &f)
 
template<class FuncType >
 MultiNumGradFunction (FuncType f, int n)
 
 ~MultiNumGradFunction ()
 
IMultiGenFunctionClone () const
 
Derivative (const T *x, unsigned int icoord=0) const
 
virtual void FdF (const T *x, T &f, T *df) const
 
virtual void Gradient (const T *x, T *grad) const
 
unsigned int NCalls () const
 
unsigned int NDim () const
 
virtual unsigned int NDim () const=0
 
operator() (const T *x) const
 
void SetOwnership (bool on=true)
 

Static Public Member Functions

static double GetDerivPrecision ()
 get precision value used for calculating the derivative step-size More...
 
static void SetDerivPrecision (double eps)
 precision value used for calculating the derivative step-size h = eps * |x|. The default is 0.001, give a smaller in case function chanes rapidly More...
 

Private Member Functions

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

Private Attributes

unsigned int fDim
 
const IMultiGenFunctionfFunc
 
unsigned int fNCalls
 
bool fOwner
 

Static Private Attributes

static double fgEps
 

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

◆ MultiNumGradFunction() [1/2]

ROOT::Math::MultiNumGradFunction::MultiNumGradFunction ( const IMultiGenFunction f)
inline

Constructor from a IMultiGenFunction interface

Definition at line 57 of file MultiNumGradFunction.h.

57  :
58  fFunc(&f),
59  fDim(f.NDim() ),
60  fNCalls(0),
61  fOwner(false)
62  {}

Referenced by Clone().

◆ MultiNumGradFunction() [2/2]

template<class FuncType >
ROOT::Math::MultiNumGradFunction::MultiNumGradFunction ( FuncType  f,
int  n 
)
inline

Constructor from a generic function (pointer or reference) and number of dimension implementiong operator () (double * x)

Definition at line 70 of file MultiNumGradFunction.h.

70  :
71  fDim( n ),
72  fNCalls(0),
73  fOwner(true)
74  {
75  // create a wrapped function
77  }

References fFunc.

◆ ~MultiNumGradFunction()

ROOT::Math::MultiNumGradFunction::~MultiNumGradFunction ( )
inline

Destructor (no operations)

Definition at line 82 of file MultiNumGradFunction.h.

82  {
83  if (fOwner) delete fFunc;
84  }

References fFunc, and fOwner.

Member Function Documentation

◆ Clone()

IMultiGenFunction* ROOT::Math::MultiNumGradFunction::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 93 of file MultiNumGradFunction.h.

93  {
94  if (!fOwner)
95  return new MultiNumGradFunction(*fFunc);
96  else {
97  // we need to copy the pointer to the wrapped function
99  f->fOwner = true;
100  return f;
101  }
102  }
virtual IBaseFunctionMultiDimTempl< T > * Clone() const =0
MultiNumGradFunction(const IMultiGenFunction &f)

References MultiNumGradFunction(), ROOT::Math::IBaseFunctionMultiDimTempl< T >::Clone(), fFunc, and fOwner.

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::MultiNumGradFunction::DoDerivative ( const double *  x,
unsigned int  icoord 
) const
private

◆ DoEval()

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

Definition at line 118 of file MultiNumGradFunction.h.

118  {
119  fNCalls++;
120  return (*fFunc)(x);
121  }

References fFunc, and fNCalls.

◆ FdF()

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:

◆ GetDerivPrecision()

static double ROOT::Math::MultiNumGradFunction::GetDerivPrecision ( )
static

get precision value used for calculating the derivative step-size

◆ Gradient()

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:

◆ NCalls()

unsigned int ROOT::Math::MultiNumGradFunction::NCalls ( ) const
inline

Definition at line 91 of file MultiNumGradFunction.h.

91 { return fNCalls; }

References fNCalls.

◆ NDim() [1/2]

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

Retrieve the dimension of the function

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

Definition at line 89 of file MultiNumGradFunction.h.

89 { return fDim; }

References fDim.

◆ 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:

◆ SetDerivPrecision()

static void ROOT::Math::MultiNumGradFunction::SetDerivPrecision ( double  eps)
static

precision value used for calculating the derivative step-size h = eps * |x|. The default is 0.001, give a smaller in case function chanes rapidly

◆ SetOwnership()

void ROOT::Math::MultiNumGradFunction::SetOwnership ( bool  on = true)
inline

Definition at line 105 of file MultiNumGradFunction.h.

105 { fOwner = on; }

References fOwner.

Member Data Documentation

◆ fDim

unsigned int ROOT::Math::MultiNumGradFunction::fDim
private

Definition at line 128 of file MultiNumGradFunction.h.

Referenced by NDim().

◆ fFunc

const IMultiGenFunction* ROOT::Math::MultiNumGradFunction::fFunc
private

Definition at line 127 of file MultiNumGradFunction.h.

Referenced by MultiNumGradFunction(), ~MultiNumGradFunction(), Clone(), and DoEval().

◆ fgEps

double ROOT::Math::MultiNumGradFunction::fgEps
staticprivate

Definition at line 132 of file MultiNumGradFunction.h.

◆ fNCalls

unsigned int ROOT::Math::MultiNumGradFunction::fNCalls
mutableprivate

Definition at line 129 of file MultiNumGradFunction.h.

Referenced by DoEval(), and NCalls().

◆ fOwner

bool ROOT::Math::MultiNumGradFunction::fOwner
private

Definition at line 130 of file MultiNumGradFunction.h.

Referenced by ~MultiNumGradFunction(), Clone(), and SetOwnership().


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