queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::GenericScalarFunction< V, M > Class Template Reference

A class for handling generic scalar functions. More...

#include <GenericScalarFunction.h>

Inheritance diagram for QUESO::GenericScalarFunction< V, M >:
QUESO::BaseScalarFunction< V, M >

Public Member Functions

Constructor/Destructor methods
 GenericScalarFunction (const char *prefix, const VectorSet< V, M > &domainSet, double(*valueRoutinePtr)(const V &domainVector, const V *domainDirection, const void *routinesDataPtr, V *gradVector, M *hessianMatrix, V *hessianEffect), const void *routinesDataPtr, bool routineIsForLn)
 Default constructor. More...
 
virtual ~GenericScalarFunction ()
 Virtual destructor. More...
 
Mathematical method
double actualValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Calculates the actual value of this scalar function. More...
 
double lnValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Calculates the logarithm of value of this scalar function. More...
 
- Public Member Functions inherited from QUESO::BaseScalarFunction< V, M >
void setFiniteDifferenceStepSize (double fdStepSize)
 Sets the step size for finite differencing gradients. More...
 
void setFiniteDifferenceStepSize (unsigned int i, double fdStepSize)
 
 BaseScalarFunction (const char *prefix, const VectorSet< V, M > &domainSet)
 Default constructor. More...
 
virtual ~BaseScalarFunction ()
 Destructor. More...
 
const VectorSet< V, M > & domainSet () const
 Access to the protected attribute m_domainSet: domain set of the scalar function. More...
 
virtual double lnValue (const V &domainVector) const
 Returns the logarithm of the function at domainVector. More...
 
virtual double lnValue (const V &domainVector, V &gradVector) const
 Returns the logarithm of the function and its gradient at domainVector. More...
 
virtual double lnValue (const V &domainVector, V &gradVector, const V &domainDirection, V &hessianEffect) const
 

Protected Attributes

double(* m_valueRoutinePtr )(const V &domainVector, const V *domainDirection, const void *routinesDataPtr, V *gradVector, M *hessianMatrix, V *hessianEffect)
 Routine defining a scalar function. More...
 
const void * m_routinesDataPtr
 
bool m_routineIsForLn
 
- Protected Attributes inherited from QUESO::BaseScalarFunction< V, M >
const BaseEnvironmentm_env
 
std::string m_prefix
 
const VectorSet< V, M > & m_domainSet
 Domain set of the scalar function. More...
 

Detailed Description

template<class V = GslVector, class M = GslMatrix>
class QUESO::GenericScalarFunction< V, M >

A class for handling generic scalar functions.

This class allows the mathematical definition of a scalar function such as: \( f: B \subset R \rightarrow R \). It is derived from BaseScalarFunction.

Definition at line 46 of file GenericScalarFunction.h.

Constructor & Destructor Documentation

template<class V , class M >
QUESO::GenericScalarFunction< V, M >::GenericScalarFunction ( const char *  prefix,
const VectorSet< V, M > &  domainSet,
double(*)(const V &domainVector, const V *domainDirection, const void *routinesDataPtr, V *gradVector, M *hessianMatrix, V *hessianEffect)  valueRoutinePtr,
const void *  routinesDataPtr,
bool  routineIsForLn 
)

Default constructor.

Instantiates an object of this class given its prefix, domain set and a pointer to a routine. This routine plays the role of a scalar math function, and it is useful, for instance, to calculate the likelihood (and its image set).

Definition at line 39 of file GenericScalarFunction.C.

44  : BaseScalarFunction<V,M>(((std::string)(prefix)+"gen").c_str(), domainSet),
45  m_valueRoutinePtr (valueRoutinePtr),
46  m_routinesDataPtr (routinesDataPtr),
47  m_routineIsForLn (routineIsForLn)
48 {
49 }
double(* m_valueRoutinePtr)(const V &domainVector, const V *domainDirection, const void *routinesDataPtr, V *gradVector, M *hessianMatrix, V *hessianEffect)
Routine defining a scalar function.
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
template<class V , class M >
QUESO::GenericScalarFunction< V, M >::~GenericScalarFunction ( )
virtual

Virtual destructor.

Definition at line 53 of file GenericScalarFunction.C.

54 {
55 }

Member Function Documentation

template<class V , class M >
double QUESO::GenericScalarFunction< V, M >::actualValue ( const V &  domainVector,
const V *  domainDirection,
V *  gradVector,
M *  hessianMatrix,
V *  hessianEffect 
) const
virtual

Calculates the actual value of this scalar function.

Implements QUESO::BaseScalarFunction< V, M >.

Definition at line 59 of file GenericScalarFunction.C.

64 {
65  queso_require_msg(m_valueRoutinePtr, "m_valueRoutinePtr = NULL");
66 
67  double value = m_valueRoutinePtr(domainVector, domainDirection, m_routinesDataPtr, gradVector, hessianMatrix, hessianEffect);
68  if (m_routineIsForLn) {
69  value = std::exp(value);
70 
71  if ((domainDirection != NULL) ||
72  (gradVector != NULL) ||
73  (hessianMatrix != NULL) ||
74  (hessianEffect != NULL))
75  queso_not_implemented();
76  }
77  return value;
78 }
double(* m_valueRoutinePtr)(const V &domainVector, const V *domainDirection, const void *routinesDataPtr, V *gradVector, M *hessianMatrix, V *hessianEffect)
Routine defining a scalar function.
template<class V , class M >
double QUESO::GenericScalarFunction< V, M >::lnValue ( const V &  domainVector,
const V *  domainDirection,
V *  gradVector,
M *  hessianMatrix,
V *  hessianEffect 
) const
virtual

Calculates the logarithm of value of this scalar function.

It is used in routines that calculate the likelihood and expect the logarithm of value.

Reimplemented from QUESO::BaseScalarFunction< V, M >.

Definition at line 82 of file GenericScalarFunction.C.

87 {
88  queso_require_msg(m_valueRoutinePtr, "m_valueRoutinePtr = NULL");
89 
90  double value = m_valueRoutinePtr(domainVector, domainDirection, m_routinesDataPtr, gradVector, hessianMatrix, hessianEffect);
91  if (m_routineIsForLn == false) {
92  value = log(value);
93 
94  if ((domainDirection != NULL) ||
95  (gradVector != NULL) ||
96  (hessianMatrix != NULL) ||
97  (hessianEffect != NULL))
98  queso_not_implemented();
99  }
100  return value;
101 }
double(* m_valueRoutinePtr)(const V &domainVector, const V *domainDirection, const void *routinesDataPtr, V *gradVector, M *hessianMatrix, V *hessianEffect)
Routine defining a scalar function.

Member Data Documentation

template<class V = GslVector, class M = GslMatrix>
bool QUESO::GenericScalarFunction< V, M >::m_routineIsForLn
protected

Definition at line 83 of file GenericScalarFunction.h.

template<class V = GslVector, class M = GslMatrix>
const void* QUESO::GenericScalarFunction< V, M >::m_routinesDataPtr
protected

Definition at line 82 of file GenericScalarFunction.h.

template<class V = GslVector, class M = GslMatrix>
double(* QUESO::GenericScalarFunction< V, M >::m_valueRoutinePtr)(const V &domainVector, const V *domainDirection, const void *routinesDataPtr, V *gradVector, M *hessianMatrix, V *hessianEffect)
protected

Routine defining a scalar function.

The presence of the parameters gradVectors, hessianMatrices and hessianEffects allows the user to calculate gradient vectors, Hessian matrices and Hessian effects; which can hold important information about her/his statistical application. Used, for instance to define the likelihood.

Definition at line 81 of file GenericScalarFunction.h.


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

Generated on Tue Jun 5 2018 19:49:00 for queso-0.57.1 by  doxygen 1.8.5