Gaudi Framework, version v23r0 |
Home | Generated: Mon Jan 30 2012 |
Numerical derivative (using GSL adaptive numerical differentiation) More...
#include <NumericalDerivative.h>
Public Types | |
enum | Type { Central, Forward, Backward } |
the type of numerical differentiation More... | |
Public Member Functions | |
NumericalDerivative (const AbsFunction &function, const size_t index, const Type &type=Central) | |
From CLHEP/GenericFunctions. | |
NumericalDerivative (const NumericalDerivative &right) | |
copy constructor | |
virtual | ~NumericalDerivative () |
virtual destructor | |
virtual unsigned int | dimensionality () const |
dimensionality of the problem | |
virtual double | operator() (double argument) const |
Function value. | |
virtual double | operator() (const Argument &argument) const |
Function value. | |
virtual bool | hasAnalyticDerivative () const |
Does this function have an analytic derivative? | |
virtual Derivative | partial (unsigned int index) const |
Derivatives. | |
const AbsFunction & | function () const |
access to the function itself | |
size_t | index () const |
index | |
const Type & | type () const |
type | |
const Type & | setType (const Type &value) |
change the type of the adaptive differentiation | |
double | result () const |
the result of the last call | |
double | error () const |
the absolute error estimate for the last call | |
Protected Member Functions | |
StatusCode | Exception (const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const |
Exception. | |
Private Member Functions | |
NumericalDerivative () | |
NumericalDerivative & | operator= (const NumericalDerivative &) |
Private Attributes | |
const AbsFunction * | m_function |
size_t | m_index |
size_t | m_DIM |
Type | m_type |
Argument | m_argument |
double | m_result |
double | m_error |
Numerical derivative (using GSL adaptive numerical differentiation)
Definition at line 36 of file NumericalDerivative.h.
the type of numerical differentiation
Definition at line 40 of file NumericalDerivative.h.
Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative | ( | const AbsFunction & | function, |
const size_t | index, | ||
const Type & | type = Central |
||
) |
From CLHEP/GenericFunctions.
from CLHEP/GenericFunctions
The standard constructor from AbsFunction and the index of the variable
The function, created with this constructor compute the numerical derivatived by finite differencing,. An adaptive algorithm is used to find teh best choice of finite difference and to estimate the error in derivative
gsl_diff_central
is used for type
= Type::Central
gsl_diff_forward
is used for type
= Type::Forward
. The function is evaluated only at points greater than x_i
and x_i
itself. This function should be used if f(x) has a singularity or if it is undefined for values less than x_i
gsl_diff_backward
is used for type
= Type::Backward
. The function is evaluated only at points smaller than x_i
and x_i
itself. This function should be used if f(x) has a singularity or if it is undefined for values greater than x_i
The adaptime numerical differentiation is used
function | the function |
index | the variable index |
The standard constructor from AbsFunction and the index of the variable
function | the function |
index | the variable index |
Definition at line 53 of file NumericalDerivative.cpp.
: AbsFunction () , m_function ( function.clone() ) , m_index ( index ) , m_DIM ( function.dimensionality() ) , m_type ( type ) , m_argument ( function.dimensionality() ) , m_result ( GSL_NEGINF ) , m_error ( GSL_POSINF ) { if( m_index >= m_DIM ) { Exception ( "::constructor invalid variable index " ) ; }; }
Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative | ( | const NumericalDerivative & | right ) |
copy constructor
Definition at line 74 of file NumericalDerivative.cpp.
Genfun::GaudiMathImplementation::NumericalDerivative::~NumericalDerivative | ( | ) | [virtual] |
virtual destructor
destructor
Definition at line 89 of file NumericalDerivative.cpp.
{ if( 0 != m_function ) { delete m_function ; m_function = 0 ; } }
Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative | ( | ) | [private] |
virtual unsigned int Genfun::GaudiMathImplementation::NumericalDerivative::dimensionality | ( | ) | const [inline, virtual] |
dimensionality of the problem
Definition at line 98 of file NumericalDerivative.h.
{ return m_DIM ; }
double Genfun::GaudiMathImplementation::NumericalDerivative::error | ( | ) | const [inline] |
the absolute error estimate for the last call
Definition at line 126 of file NumericalDerivative.h.
{ return m_error ; }
StatusCode Genfun::GaudiMathImplementation::NumericalDerivative::Exception | ( | const std::string & | message, |
const StatusCode & | sc = StatusCode::FAILURE |
||
) | const [protected] |
Exception.
Definition at line 183 of file NumericalDerivative.cpp.
{ throw GaudiException( "NumericalDerivative" + message , "*GaudiMath*" , sc ) ; return sc ; }
const AbsFunction& Genfun::GaudiMathImplementation::NumericalDerivative::function | ( | ) | const [inline] |
access to the function itself
Definition at line 114 of file NumericalDerivative.h.
{ return *m_function ; }
virtual bool Genfun::GaudiMathImplementation::NumericalDerivative::hasAnalyticDerivative | ( | ) | const [inline, virtual] |
Does this function have an analytic derivative?
Definition at line 106 of file NumericalDerivative.h.
{ return true ;}
size_t Genfun::GaudiMathImplementation::NumericalDerivative::index | ( | ) | const [inline] |
double Genfun::GaudiMathImplementation::NumericalDerivative::operator() | ( | double | argument ) | const [virtual] |
Function value.
Definition at line 164 of file NumericalDerivative.cpp.
double Genfun::GaudiMathImplementation::NumericalDerivative::operator() | ( | const Argument & | argument ) | const [virtual] |
Function value.
copy the argument
use GSL to evaluate the numerical derivative
Definition at line 118 of file NumericalDerivative.cpp.
{ // reset the result and the error m_result = GSL_NEGINF ; m_error = GSL_POSINF ; // check the argument if( argument.dimension() != m_DIM ) { Exception ( "::operator():invalid argument size" ) ; }; {for( size_t i = 0 ; i < m_DIM ; ++i ){ m_argument[i] = argument[i];}} // create the helper object GSL_Helper helper( *m_function , m_argument , m_index ); gsl_function F ; F.function = &GSL_Adaptor ; F.params = &helper ; double x = argument[m_index]; int ierrno = 0 ; switch ( type() ) { case Central : ierrno = gsl_diff_central ( &F , x , &m_result , &m_error ) ; break ; case Forward : ierrno = gsl_diff_forward ( &F , x , &m_result , &m_error ) ; break ; case Backward : ierrno = gsl_diff_backward ( &F , x , &m_result , &m_error ) ; break ; default: Exception ( "::operator(): invalid diffrentiation type " ) ; } if( ierrno ) { gsl_error ( " NumericalDerivative:: the error from gsl_diff_XXXX" , __FILE__ , __LINE__ , ierrno ) ; } return result() ; }
NumericalDerivative& Genfun::GaudiMathImplementation::NumericalDerivative::operator= | ( | const NumericalDerivative & | ) | [private] |
Genfun::Derivative Genfun::GaudiMathImplementation::NumericalDerivative::partial | ( | unsigned int | index ) | const [virtual] |
Derivatives.
Definition at line 104 of file NumericalDerivative.cpp.
{ if( idx >= m_DIM ) { Exception ( "::partial(i): invalid variable index" ) ; } const AbsFunction& aux = NumericalDerivative( *this , idx , type() ) ; return FunctionNoop( &aux ) ; }
double Genfun::GaudiMathImplementation::NumericalDerivative::result | ( | ) | const [inline] |
the result of the last call
Definition at line 124 of file NumericalDerivative.h.
{ return m_result ; }
const NumericalDerivative::Type & Genfun::GaudiMathImplementation::NumericalDerivative::setType | ( | const Type & | value ) |
change the type of the adaptive differentiation
Definition at line 97 of file NumericalDerivative.cpp.
const Type& Genfun::GaudiMathImplementation::NumericalDerivative::type | ( | ) | const [inline] |
Argument Genfun::GaudiMathImplementation::NumericalDerivative::m_argument [mutable, private] |
Definition at line 147 of file NumericalDerivative.h.
Definition at line 144 of file NumericalDerivative.h.
double Genfun::GaudiMathImplementation::NumericalDerivative::m_error [mutable, private] |
Definition at line 149 of file NumericalDerivative.h.
const AbsFunction* Genfun::GaudiMathImplementation::NumericalDerivative::m_function [private] |
Definition at line 142 of file NumericalDerivative.h.
Definition at line 143 of file NumericalDerivative.h.
double Genfun::GaudiMathImplementation::NumericalDerivative::m_result [mutable, private] |
Definition at line 148 of file NumericalDerivative.h.
Definition at line 145 of file NumericalDerivative.h.