queso-0.50.1
Protected Attributes | List of all members
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 >:
Inheritance graph
[legend]
Collaboration diagram for QUESO::GenericScalarFunction< V, M >:
Collaboration graph
[legend]

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 >
 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...
 

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, class M>
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 43 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.

References UQ_FATAL_TEST_MACRO.

64 {
66  m_env.worldRank(),
67  "GenericScalarFunction<V,M>::actualValue()",
68  "m_valueRoutinePtr = NULL");
69 
70  double value = m_valueRoutinePtr(domainVector, domainDirection, m_routinesDataPtr, gradVector, hessianMatrix, hessianEffect);
71  if (m_routineIsForLn) {
72 #ifdef QUESO_EXPECTS_LN_LIKELIHOOD_INSTEAD_OF_MINUS_2_LN
73  value = std::exp(value);
74 #else
75  value = std::exp(-.5*value);
76 #endif
77  UQ_FATAL_TEST_MACRO((domainDirection != NULL) ||
78  (gradVector != NULL) ||
79  (hessianMatrix != NULL) ||
80  (hessianEffect != NULL),
81  m_env.worldRank(),
82  "GenericScalarFunction<V,M>::gradOfActual()",
83  "INCOMPLETE CODE");
84  }
85  return value;
86 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:222
double(* m_valueRoutinePtr)(const V &domainVector, const V *domainDirection, const void *routinesDataPtr, V *gradVector, M *hessianMatrix, V *hessianEffect)
Routine defining a scalar function.
const BaseEnvironment & m_env
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.

Implements QUESO::BaseScalarFunction< V, M >.

Definition at line 90 of file GenericScalarFunction.C.

References UQ_FATAL_TEST_MACRO.

95 {
97  m_env.worldRank(),
98  "GenericScalarFunction<V,M>::lnValue()",
99  "m_valueRoutinePtr = NULL");
100 
101  double value = m_valueRoutinePtr(domainVector, domainDirection, m_routinesDataPtr, gradVector, hessianMatrix, hessianEffect);
102  if (m_routineIsForLn == false) {
103 #ifdef QUESO_EXPECTS_LN_LIKELIHOOD_INSTEAD_OF_MINUS_2_LN
104  value = log(value);
105 #else
106  value = -2.*log(value);
107 #endif
108  UQ_FATAL_TEST_MACRO((domainDirection != NULL) ||
109  (gradVector != NULL) ||
110  (hessianMatrix != NULL) ||
111  (hessianEffect != NULL),
112  m_env.worldRank(),
113  "GenericScalarFunction<V,M>::gradOfLn()",
114  "INCOMPLETE CODE");
115  }
116  return value;
117 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:222
double(* m_valueRoutinePtr)(const V &domainVector, const V *domainDirection, const void *routinesDataPtr, V *gradVector, M *hessianMatrix, V *hessianEffect)
Routine defining a scalar function.
const BaseEnvironment & m_env

Member Data Documentation

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

Definition at line 80 of file GenericScalarFunction.h.

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

Definition at line 79 of file GenericScalarFunction.h.

template<class V , class M >
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 78 of file GenericScalarFunction.h.


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

Generated on Thu Apr 23 2015 19:18:36 for queso-0.50.1 by  doxygen 1.8.5