| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Genfun::GaudiMathImplementation::NumericalDerivative Class Reference

Numerical derivative (using GSL adaptive numerical differentiation) More...

`#include <GaudiMath/NumericalDerivative.h>`

Inheritance diagram for Genfun::GaudiMathImplementation::NumericalDerivative:
[legend]
Collaboration diagram for Genfun::GaudiMathImplementation::NumericalDerivative:
[legend]

## 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. More...
| NumericalDerivative (const NumericalDerivative &right)
| copy constructor More...
virtual | ~NumericalDerivative ()=default
| virtual destructor More...
virtual unsigned int | dimensionality () const
| dimensionality of the problem More...
virtual double | operator() (double argument) const
| Function value. More...
virtual double | operator() (const Argument &argument) const
| Function value. More...
virtual bool | hasAnalyticDerivative () const
| Does this function have an analytic derivative? More...
virtual Derivative | partial (unsigned int index) const
| Derivatives. More...
const AbsFunction & | function () const
| access to the function itself More...
size_t | index () const
| index More...
const Type & | type () const
| type More...
const Type & | setType (const Type &value)
| change the type of the adaptive differentiation More...
double | result () const
| the result of the last call More...
double | error () const
| the absolute error estimate for the last call More...

## Protected Member Functions
StatusCode | Exception (const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
| Exception. More...

## Private Member Functions
| NumericalDerivative ()
NumericalDerivative & | operator= (const NumericalDerivative &)

## Private Attributes
std::unique_ptr< const AbsFunction > | m_function
size_t | m_index
size_t | m_DIM
Type | m_type
Argument | m_argument
double | m_result
double | m_error

## Detailed Description

Numerical derivative (using GSL adaptive numerical differentiation)

\[ {\mathcal{F}}_i \left(x_1, \dots , x_{i-1}, x_i , x_{i+1}, \dots , x_n \right) = \frac{\partial}{\partial x_i} f \left(x_1, \dots , x_{i-1}, x_i , x_{i+1}, \dots , x_n \right) \]

Author
  Vanya BELYAEV Ivan..nosp@m.Bely.nosp@m.aev@i.nosp@m.tep..nosp@m.ru

Date
  2003-08-27

Definition at line 34 of file NumericalDerivative.h.

## Member Enumeration Documentation

enum Genfun::GaudiMathImplementation::NumericalDerivative::Type

the type of numerical differentiation

Enumerator
Central |
Forward |
Backward |

Definition at line 38 of file NumericalDerivative.h.

39 { Central ,
40 Forward ,
41 Backward } ;
Genfun::GaudiMathImplementation::NumericalDerivative::Forward
Definition: NumericalDerivative.h:40
Genfun::GaudiMathImplementation::NumericalDerivative::Central
Definition: NumericalDerivative.h:39
Genfun::GaudiMathImplementation::NumericalDerivative::Backward
Definition: NumericalDerivative.h:41

## Constructor & Destructor Documentation

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

\[ {\mathcal{F}}_i \left(x_1, \dots , x_{i-1}, x_i , x_{i+1}, \dots , x_n \right) = \frac{\partial}{\partial x_i} f \left(x_1, \dots , x_{i-1}, x_i , x_{i+1}, \dots , x_n \right) \]

- The central difference algorithm `gsl_diff_central` is used for `type` = `Type::Central`
- The forward difference algorithm `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`
- The backward difference algorithm `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

Parameters

  function | the function
  index | the variable index

The standard constructor from AbsFunction and the index of the variable

Parameters

  function | the function
  index | the variable index

Definition at line 52 of file NumericalDerivative.cpp.

55 : AbsFunction ()
56 , m_function ( function.clone() )
57 , m_index ( index )
58 , m_DIM ( function.dimensionality() )
59 , m_type ( type )
60 , m_argument ( function.dimensionality() )
61 , m_result ( GSL_NEGINF )
62 , m_error ( GSL_POSINF )
63 {
64 if( m_index >= m_DIM )
65 { Exception ( "::constructor invalid variable index " ) ; };
66 }
Genfun::GaudiMathImplementation::NumericalDerivative::dimensionality
virtual unsigned int dimensionality() const
dimensionality of the problem
Definition: NumericalDerivative.h:96
Genfun::GaudiMathImplementation::NumericalDerivative::index
size_t index() const
index
Definition: NumericalDerivative.h:114
Genfun::GaudiMathImplementation::NumericalDerivative::type
const Type & type() const
type
Definition: NumericalDerivative.h:116
Genfun::GaudiMathImplementation::NumericalDerivative::m_argument
Argument m_argument
Definition: NumericalDerivative.h:145
Genfun::GaudiMathImplementation::NumericalDerivative::m_function
std::unique_ptr< const AbsFunction > m_function
Definition: NumericalDerivative.h:140
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:147
Genfun::GaudiMathImplementation::NumericalDerivative::m_index
size_t m_index
Definition: NumericalDerivative.h:141
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:142
Genfun::GaudiMathImplementation::NumericalDerivative::m_type
Type m_type
Definition: NumericalDerivative.h:143
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:146
Genfun::GaudiMathImplementation::NumericalDerivative::Exception
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
Definition: NumericalDerivative.cpp:175

Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative | ( | const NumericalDerivative & | right | ) |

copy constructor

Definition at line 73 of file NumericalDerivative.cpp.

74 : AbsFunction ()
75 , m_function ( right.m_function->clone() )
76 , m_index ( right.m_index )
77 , m_DIM ( right.m_DIM )
78 , m_type ( right.m_type )
79 , m_argument ( right.m_DIM )
80 , m_result ( GSL_NEGINF )
81 , m_error ( GSL_POSINF )
82 {}
std::right
T right(T...args)
Genfun::GaudiMathImplementation::NumericalDerivative::m_argument
Argument m_argument
Definition: NumericalDerivative.h:145
Genfun::GaudiMathImplementation::NumericalDerivative::m_function
std::unique_ptr< const AbsFunction > m_function
Definition: NumericalDerivative.h:140
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:147
Genfun::GaudiMathImplementation::NumericalDerivative::m_index
size_t m_index
Definition: NumericalDerivative.h:141
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:142
Genfun::GaudiMathImplementation::NumericalDerivative::m_type
Type m_type
Definition: NumericalDerivative.h:143
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:146

virtual Genfun::GaudiMathImplementation::NumericalDerivative::~NumericalDerivative | ( |  | ) |
| virtual default

virtual destructor

Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative | ( |  | ) |
| private

## Member Function Documentation

virtual unsigned int Genfun::GaudiMathImplementation::NumericalDerivative::dimensionality | ( |  | ) | const
| inline virtual

dimensionality of the problem

Definition at line 96 of file NumericalDerivative.h.

96 { return m_DIM ; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:142

double Genfun::GaudiMathImplementation::NumericalDerivative::error | ( |  | ) | const
| inline

the absolute error estimate for the last call

Definition at line 124 of file NumericalDerivative.h.

124 { return m_error ; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:147

StatusCode Genfun::GaudiMathImplementation::NumericalDerivative::Exception | ( | const std::string & | message,
|  | const StatusCode & | sc = `StatusCode::FAILURE`
| ) |  | const
| protected

Exception.

Definition at line 175 of file NumericalDerivative.cpp.

177 {
178 throw GaudiException( "NumericalDerivative" + message ,
179 "*GaudiMath*" , sc ) ;
180 return sc ;
181 }
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
merge_files.sc
int sc
Definition: merge_files.py:167

const AbsFunction& Genfun::GaudiMathImplementation::NumericalDerivative::function | ( |  | ) | const
| inline

access to the function itself

Definition at line 112 of file NumericalDerivative.h.

112 { return *m_function ; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_function
std::unique_ptr< const AbsFunction > m_function
Definition: NumericalDerivative.h:140

virtual bool Genfun::GaudiMathImplementation::NumericalDerivative::hasAnalyticDerivative | ( |  | ) | const
| inline virtual

Does this function have an analytic derivative?

Definition at line 104 of file NumericalDerivative.h.

104 { return true ;}

size_t Genfun::GaudiMathImplementation::NumericalDerivative::index | ( |  | ) | const
| inline

index

Definition at line 114 of file NumericalDerivative.h.

114 { return m_index ; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_index
size_t m_index
Definition: NumericalDerivative.h:141

double Genfun::GaudiMathImplementation::NumericalDerivative::operator() | ( | double | argument | ) | const
| virtual

Function value.

Definition at line 156 of file NumericalDerivative.cpp.

157 {
158 // reset the result and the error
159 m_result = GSL_NEGINF ;
160 m_error = GSL_POSINF ;
161
162 // check the argument
163 if( 1 != m_DIM ) { Exception ( "operator(): invalid argument size " ); }
164
165 Argument arg(1) ;
166 arg[0] = argument ;
167 return (*this)( arg ) ;
168 }
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:147
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:142
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:146
Genfun::GaudiMathImplementation::NumericalDerivative::Exception
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
Definition: NumericalDerivative.cpp:175

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 110 of file NumericalDerivative.cpp.

111 {
112 // reset the result and the error
113 m_result = GSL_NEGINF ;
114 m_error = GSL_POSINF ;
115
116 // check the argument
117 if( argument.dimension() != m_DIM )
118 { Exception ( "::operator():invalid argument size" ) ; };
119
121 {for( size_t i = 0 ; i < m_DIM ; ++i ){ m_argument[i] = argument[i];}}
122
123 // create the helper object
124 GSL_Helper helper( *m_function , m_argument , m_index );
125
127 gsl_function F ;
128 F.function = &GSL_Adaptor ;
129 F.params = &helper ;
130
131 double x = argument[m_index];
132 int ierrno = 0 ;
133 switch ( type() )
134 {
135 case Central :
136 ierrno = gsl_diff_central ( &F , x , &m_result , &m_error ) ; break ;
137 case Forward :
138 ierrno = gsl_diff_forward ( &F , x , &m_result , &m_error ) ; break ;
139 case Backward :
140 ierrno = gsl_diff_backward ( &F , x , &m_result , &m_error ) ; break ;
141 default:
142 Exception ( "::operator(): invalid diffrentiation type " ) ;
143 }
144
145 if( ierrno )
146 { gsl_error ( " NumericalDerivative:: the error from gsl_diff_XXXX" ,
147 __FILE__ , __LINE__ , ierrno ) ; }
148
149 return result() ;
150 }
Genfun::GaudiMathImplementation::NumericalDerivative::type
const Type & type() const
type
Definition: NumericalDerivative.h:116
Genfun::GaudiMathImplementation::NumericalDerivative::m_argument
Argument m_argument
Definition: NumericalDerivative.h:145
Genfun::GaudiMathImplementation::NumericalDerivative::m_function
std::unique_ptr< const AbsFunction > m_function
Definition: NumericalDerivative.h:140
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:147
Genfun::GaudiMathImplementation::NumericalDerivative::Forward
Definition: NumericalDerivative.h:40
Genfun::GaudiMathImplementation::NumericalDerivative::m_index
size_t m_index
Definition: NumericalDerivative.h:141
Genfun::GaudiMathImplementation::GSL_Adaptor
double GSL_Adaptor(double x, void *params)
Definition: Helpers.cpp:37
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:142
Genfun::GaudiMathImplementation::NumericalDerivative::Central
Definition: NumericalDerivative.h:39
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:146
Genfun::GaudiMathImplementation::NumericalDerivative::Backward
Definition: NumericalDerivative.h:41
Genfun::GaudiMathImplementation::NumericalDerivative::Exception
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
Definition: NumericalDerivative.cpp:175
ana.i
list i
Definition: ana.py:128
Genfun::GaudiMathImplementation::NumericalDerivative::result
double result() const
the result of the last call
Definition: NumericalDerivative.h:122

NumericalDerivative& Genfun::GaudiMathImplementation::NumericalDerivative::operator= | ( | const NumericalDerivative & |  | ) |
| private

Genfun::Derivative Genfun::GaudiMathImplementation::NumericalDerivative::partial | ( | unsigned int | index | ) | const
| virtual

Derivatives.

Definition at line 96 of file NumericalDerivative.cpp.

97 {
98 if( idx >= m_DIM )
99 { Exception ( "::partial(i): invalid variable index" ) ; }
100 const AbsFunction& aux =
101 NumericalDerivative( *this , idx , type() ) ;
102 return FunctionNoop( &aux ) ;
103 }
Genfun::GaudiMathImplementation::NumericalDerivative::type
const Type & type() const
type
Definition: NumericalDerivative.h:116
Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative
NumericalDerivative()
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:142
Genfun::GaudiMathImplementation::NumericalDerivative::Exception
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
Definition: NumericalDerivative.cpp:175

double Genfun::GaudiMathImplementation::NumericalDerivative::result | ( |  | ) | const
| inline

the result of the last call

Definition at line 122 of file NumericalDerivative.h.

122 { return m_result ; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:146

const NumericalDerivative::Type & Genfun::GaudiMathImplementation::NumericalDerivative::setType | ( | const Type & | value | ) |

change the type of the adaptive differentiation

Definition at line 89 of file NumericalDerivative.cpp.

90 { m_type = value ; return type() ; }
Genfun::GaudiMathImplementation::NumericalDerivative::type
const Type & type() const
type
Definition: NumericalDerivative.h:116
dump_component_properties.value
list value
Definition: dump_component_properties.py:12
Genfun::GaudiMathImplementation::NumericalDerivative::m_type
Type m_type
Definition: NumericalDerivative.h:143

const Type& Genfun::GaudiMathImplementation::NumericalDerivative::type | ( |  | ) | const
| inline

type

Definition at line 116 of file NumericalDerivative.h.

116 { return m_type ; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_type
Type m_type
Definition: NumericalDerivative.h:143

## Member Data Documentation

Argument Genfun::GaudiMathImplementation::NumericalDerivative::m_argument
| mutable private

Definition at line 145 of file NumericalDerivative.h.

size_t Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
| private

Definition at line 142 of file NumericalDerivative.h.

double Genfun::GaudiMathImplementation::NumericalDerivative::m_error
| mutable private

Definition at line 147 of file NumericalDerivative.h.

std::unique_ptr<const AbsFunction> Genfun::GaudiMathImplementation::NumericalDerivative::m_function
| private

Definition at line 140 of file NumericalDerivative.h.

size_t Genfun::GaudiMathImplementation::NumericalDerivative::m_index
| private

Definition at line 141 of file NumericalDerivative.h.

double Genfun::GaudiMathImplementation::NumericalDerivative::m_result
| mutable private

Definition at line 146 of file NumericalDerivative.h.

Type Genfun::GaudiMathImplementation::NumericalDerivative::m_type
| private

Definition at line 143 of file NumericalDerivative.h.

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

- GaudiGSL/GaudiMath/NumericalDerivative.h
- GaudiGSL/src/Lib/NumericalDerivative.cpp