| The Gaudi Framework v30r0 (c919700c)

- 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...
| ~NumericalDerivative () override=default
| destructor More...
unsigned int | dimensionality () const override
| dimensionality of the problem More...
double | operator() (double argument) const override
| Function value. More...
double | operator() (const Argument &argument) const override
| Function value. More...
bool | hasAnalyticDerivative () const override
| Does this function have an analytic derivative? More...
Derivative | partial (unsigned int index) const override
| 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 44 of file NumericalDerivative.h.

## Member Enumeration Documentation

enum Genfun::GaudiMathImplementation::NumericalDerivative::Type

the type of numerical differentiation

Enumerator
Central |
Forward |
Backward |

Definition at line 48 of file NumericalDerivative.h.

48 { Central, Forward, Backward };
Genfun::GaudiMathImplementation::NumericalDerivative::Forward
Definition: NumericalDerivative.h:48
Genfun::GaudiMathImplementation::NumericalDerivative::Central
Definition: NumericalDerivative.h:48
Genfun::GaudiMathImplementation::NumericalDerivative::Backward
Definition: NumericalDerivative.h:48

## Constructor & Destructor Documentation

Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative | ( | const AbsFunction & | function,
|  | const size_t | index,
|  | const Type & | type = `Central`
| ) |  |

From CLHEP/GenericFunctions.

The standard constructor from AbsFunction and the index of the variable.

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
  function | the function
  index | the variable index

Definition at line 47 of file NumericalDerivative.cpp.

49 : AbsFunction()
50 , m_function( function.clone() )
51 , m_index( index )
52 , m_DIM( function.dimensionality() )
53 , m_type( type )
54 , m_argument( function.dimensionality() )
55 , m_result( GSL_NEGINF )
56 , m_error( GSL_POSINF )
57 {
58 if ( m_index >= m_DIM ) {
59 Exception( "::constructor invalid variable index " );
60 };
61 }
Genfun::GaudiMathImplementation::NumericalDerivative::index
size_t index() const
index
Definition: NumericalDerivative.h:116
Genfun::GaudiMathImplementation::NumericalDerivative::type
const Type & type() const
type
Definition: NumericalDerivative.h:118
Genfun::GaudiMathImplementation::NumericalDerivative::m_argument
Argument m_argument
Definition: NumericalDerivative.h:143
Genfun::GaudiMathImplementation::NumericalDerivative::m_function
std::unique_ptr< const AbsFunction > m_function
Definition: NumericalDerivative.h:138
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:145
Genfun::GaudiMathImplementation::NumericalDerivative::dimensionality
unsigned int dimensionality() const override
dimensionality of the problem
Definition: NumericalDerivative.h:99
Genfun::GaudiMathImplementation::NumericalDerivative::m_index
size_t m_index
Definition: NumericalDerivative.h:139
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:140
Genfun::GaudiMathImplementation::NumericalDerivative::m_type
Type m_type
Definition: NumericalDerivative.h:141
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:144
Genfun::GaudiMathImplementation::NumericalDerivative::Exception
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
Definition: NumericalDerivative.cpp:179

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

copy constructor

Definition at line 67 of file NumericalDerivative.cpp.

68 : AbsFunction()
69 , m_function( right.m_function->clone() )
70 , m_index( right.m_index )
71 , m_DIM( right.m_DIM )
72 , m_type( right.m_type )
73 , m_argument( right.m_DIM )
74 , m_result( GSL_NEGINF )
75 , m_error( GSL_POSINF )
76 {
77 }
std::right
T right(T...args)
Genfun::GaudiMathImplementation::NumericalDerivative::m_argument
Argument m_argument
Definition: NumericalDerivative.h:143
Genfun::GaudiMathImplementation::NumericalDerivative::m_function
std::unique_ptr< const AbsFunction > m_function
Definition: NumericalDerivative.h:138
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:145
Genfun::GaudiMathImplementation::NumericalDerivative::m_index
size_t m_index
Definition: NumericalDerivative.h:139
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:140
Genfun::GaudiMathImplementation::NumericalDerivative::m_type
Type m_type
Definition: NumericalDerivative.h:141
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:144

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

destructor

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

## Member Function Documentation

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

dimensionality of the problem

Definition at line 99 of file NumericalDerivative.h.

99 { return m_DIM; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:140

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

the absolute error estimate for the last call

Definition at line 126 of file NumericalDerivative.h.

126 { return m_error; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:145

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

Exception.

Definition at line 179 of file NumericalDerivative.cpp.

180 {
181 throw GaudiException( "NumericalDerivative" + message, "*GaudiMath*", sc );
182 return sc;
183 }
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22

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

access to the function itself

Definition at line 114 of file NumericalDerivative.h.

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

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

Does this function have an analytic derivative?

Definition at line 107 of file NumericalDerivative.h.

107 { return true; }

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

index

Definition at line 116 of file NumericalDerivative.h.

116 { return m_index; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_index
size_t m_index
Definition: NumericalDerivative.h:139

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

Function value.

Definition at line 159 of file NumericalDerivative.cpp.

160 {
161 // reset the result and the error
162 m_result = GSL_NEGINF;
163 m_error = GSL_POSINF;
164
165 // check the argument
166 if ( 1 != m_DIM ) {
167 Exception( "operator(): invalid argument size " );
168 }
169
170 Argument arg( 1 );
171 arg[0] = argument;
172 return ( *this )( arg );
173 }
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:145
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:140
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:144
Genfun::GaudiMathImplementation::NumericalDerivative::Exception
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
Definition: NumericalDerivative.cpp:179

double Genfun::GaudiMathImplementation::NumericalDerivative::operator() | ( | const Argument & | argument | ) | const
| override

Function value.

copy the argument

use GSL to evaluate the numerical derivative

Definition at line 106 of file NumericalDerivative.cpp.

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

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

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

Derivatives.

Definition at line 93 of file NumericalDerivative.cpp.

94 {
95 if ( idx >= m_DIM ) {
96 Exception( "::partial(i): invalid variable index" );
97 }
98 const AbsFunction& aux = NumericalDerivative( *this, idx, type() );
99 return FunctionNoop( &aux );
100 }
Genfun::GaudiMathImplementation::NumericalDerivative::type
const Type & type() const
type
Definition: NumericalDerivative.h:118
Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative
NumericalDerivative()
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:140
Genfun::GaudiMathImplementation::NumericalDerivative::Exception
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
Definition: NumericalDerivative.cpp:179

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

the result of the last call

Definition at line 124 of file NumericalDerivative.h.

124 { return m_result; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:144

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

change the type of the adaptive differentiation

Definition at line 83 of file NumericalDerivative.cpp.

84 {
85 m_type = value;
86 return type();
87 }
Genfun::GaudiMathImplementation::NumericalDerivative::type
const Type & type() const
type
Definition: NumericalDerivative.h:118
Genfun::GaudiMathImplementation::NumericalDerivative::m_type
Type m_type
Definition: NumericalDerivative.h:141

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

type

Definition at line 118 of file NumericalDerivative.h.

118 { return m_type; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_type
Type m_type
Definition: NumericalDerivative.h:141

## Member Data Documentation

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

Definition at line 143 of file NumericalDerivative.h.

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

Definition at line 140 of file NumericalDerivative.h.

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

Definition at line 145 of file NumericalDerivative.h.

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

Definition at line 138 of file NumericalDerivative.h.

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

Definition at line 139 of file NumericalDerivative.h.

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

Definition at line 144 of file NumericalDerivative.h.

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

Definition at line 141 of file NumericalDerivative.h.

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

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