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

A class for handling Gamma joint PDFs. More...

#include <GammaJointPdf.h>

Inheritance diagram for QUESO::GammaJointPdf< V, M >:
QUESO::BaseJointPdf< V, M > QUESO::BaseScalarFunction< V, M >

Public Member Functions

Constructor/Destructor methods
 GammaJointPdf (const char *prefix, const VectorSet< V, M > &domainSet, const V &a, const V &b)
 
 ~GammaJointPdf ()
 Destructor. More...
 
Math methods
double actualValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Actual value of the Gamma PDF. More...
 
double lnValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Logarithm of the value of the Gamma PDF. More...
 
virtual void distributionMean (V &meanVector) const
 Mean value of the underlying random variable. More...
 
virtual void distributionVariance (M &covMatrix) const
 Covariance matrix of the underlying random variable. More...
 
double computeLogOfNormalizationFactor (unsigned int numSamples, bool updateFactorInternally) const
 Computes the logarithm of the normalization factor. More...
 
- Public Member Functions inherited from QUESO::BaseJointPdf< V, M >
 BaseJointPdf (const char *prefix, const VectorSet< V, M > &domainSet)
 Default constructor. More...
 
virtual ~BaseJointPdf ()
 Destructor. More...
 
virtual void setNormalizationStyle (unsigned int value) const
 
void setLogOfNormalizationFactor (double value) const
 Sets a logarithmic value to be used in the normalization factor (stored in the protected attribute m_normalizationStyle.) More...
 
virtual void print (std::ostream &os) const
 Print method. Non-pure for backwards compatibility. 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

m_a
 
m_b
 
- Protected Attributes inherited from QUESO::BaseJointPdf< V, M >
unsigned int m_normalizationStyle
 
double m_logOfNormalizationFactor
 
- 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...
 

Additional Inherited Members

- Protected Member Functions inherited from QUESO::BaseJointPdf< V, M >
double commonComputeLogOfNormalizationFactor (unsigned int numSamples, bool updateFactorInternally) const
 Common method (to the derived classes) to compute the logarithm of the normalization factor. More...
 

Detailed Description

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

A class for handling Gamma joint PDFs.

This class allows the mathematical definition of a Gamma Joint PDF.

Definition at line 47 of file GammaJointPdf.h.

Constructor & Destructor Documentation

template<class V , class M >
QUESO::GammaJointPdf< V, M >::GammaJointPdf ( const char *  prefix,
const VectorSet< V, M > &  domainSet,
const V &  a,
const V &  b 
)

Constructor for a shape-scale parameterisation of a Gamma(a,b) pdf defined on domainSet.

Constructs a new object of the class, given a prefix, the domain set, and the parameters a and b of the Gamma PDF.

The parameters a and b are the shape and scale parameters, respectively. That is, the pdf is

\[ f(x) = C x^{a-1} \exp \left( x / b \right), \]

where C is a normalising constant.

Indeed, a and b are vectors and in multiple dimensions the pdf is just the product of Gamma(a_i, b_i) pdfs distributions in each dimension. That is, they are independent.

Note: the parameters a and b correspond to the shape and scale parameters k and \(\theta\) in the Wikipedia entry for the Gamma distribution.

Definition at line 34 of file GammaJointPdf.C.

References QUESO::BaseEnvironment::displayVerbosity(), QUESO::BaseScalarFunction< V, M >::m_env, QUESO::BaseScalarFunction< V, M >::m_prefix, and QUESO::BaseEnvironment::subDisplayFile().

39  :
40  BaseJointPdf<V,M>(((std::string)(prefix)+"uni").c_str(),domainSet),
41  m_a(a),
42  m_b(b)
43 {
44  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
45  *m_env.subDisplayFile() << "Entering GammaJointPdf<V,M>::constructor()"
46  << ": prefix = " << m_prefix
47  << std::endl;
48  }
49 
50  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
51  *m_env.subDisplayFile() << "Leaving GammaJointPdf<V,M>::constructor()"
52  << ": prefix = " << m_prefix
53  << std::endl;
54  }
55 }
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
const BaseEnvironment & m_env
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class V , class M >
QUESO::GammaJointPdf< V, M >::~GammaJointPdf ( )

Destructor.

Definition at line 58 of file GammaJointPdf.C.

59 {
60 }

Member Function Documentation

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

Actual value of the Gamma PDF.

This routine calls method lnValue() and returns the exponent of the returning value of such method.

Implements QUESO::BaseJointPdf< V, M >.

Definition at line 64 of file GammaJointPdf.C.

References QUESO::queso_require_equal_to_msg.

70 {
71  queso_require_equal_to_msg(domainVector.sizeLocal(), this->m_domainSet.vectorSpace().dimLocal(), "invalid input");
72 
73  queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect), "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
74 
75  // No need to multiply by exp(m_logOfNormalizationFactor) because 'lnValue()' is called [PDF-06]
76  return exp(this->lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect));
77 }
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the Gamma PDF.
Definition: GammaJointPdf.C:81
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
template<class V , class M >
double QUESO::GammaJointPdf< V, M >::computeLogOfNormalizationFactor ( unsigned int  numSamples,
bool  updateFactorInternally 
) const
virtual

Computes the logarithm of the normalization factor.

This routine calls BaseJointPdf::commonComputeLogOfNormalizationFactor().

Implements QUESO::BaseJointPdf< V, M >.

Definition at line 145 of file GammaJointPdf.C.

References QUESO::BaseJointPdf< V, M >::commonComputeLogOfNormalizationFactor().

146 {
147  double value = 0.;
148 
149  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
150  *m_env.subDisplayFile() << "Entering GammaJointPdf<V,M>::computeLogOfNormalizationFactor()"
151  << std::endl;
152  }
153  value = BaseJointPdf<V,M>::commonComputeLogOfNormalizationFactor(numSamples, updateFactorInternally);
154  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
155  *m_env.subDisplayFile() << "Leaving GammaJointPdf<V,M>::computeLogOfNormalizationFactor()"
156  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
157  << std::endl;
158  }
159 
160  return value;
161 }
double m_logOfNormalizationFactor
Definition: JointPdf.h:122
double commonComputeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Common method (to the derived classes) to compute the logarithm of the normalization factor...
Definition: JointPdf.C:115
const BaseEnvironment & m_env
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class V , class M >
void QUESO::GammaJointPdf< V, M >::distributionMean ( V &  meanVector) const
virtual

Mean value of the underlying random variable.

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

Definition at line 117 of file GammaJointPdf.C.

118 {
119  queso_assert_equal_to(m_a.sizeLocal(), m_b.sizeLocal());
120  queso_assert_equal_to(m_a.sizeLocal(), meanVector.sizeLocal());
121 
122  for (unsigned int i = 0; i < m_a.sizeLocal(); ++i) {
123  meanVector[i] = m_a[i] * m_b[i];
124  }
125 }
template<class V , class M >
void QUESO::GammaJointPdf< V, M >::distributionVariance ( M &  covMatrix) const
virtual

Covariance matrix of the underlying random variable.

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

Definition at line 129 of file GammaJointPdf.C.

130 {
131  queso_assert_equal_to(m_a.sizeLocal(), m_b.sizeLocal());
132  queso_assert_equal_to(m_a.sizeLocal(), covMatrix.numRowsGlobal());
133  queso_assert_equal_to(covMatrix.numCols(), covMatrix.numRowsGlobal());
134 
135  covMatrix.zeroLower();
136  covMatrix.zeroUpper();
137 
138  for (unsigned int i = 0; i < m_a.sizeLocal(); ++i) {
139  covMatrix(i,i) = m_a[i] * m_b[i] * m_b[i];
140  }
141 }
template<class V , class M >
double QUESO::GammaJointPdf< V, M >::lnValue ( const V &  domainVector,
const V *  domainDirection,
V *  gradVector,
M *  hessianMatrix,
V *  hessianEffect 
) const
virtual

Logarithm of the value of the Gamma PDF.

If the normalization style (m_normalizationStyle) is zero, then this routine calls a environment method which handles basic PDFs, e.g. basicPdfs()->gammaPdfActualValue() and adds the log of the normalization factor (m_logOfNormalizationFactor) to it; otherwise the method uses the formula: \( lnValue = \sum[ (a_i-1)*log(domainVector_i) -domainVector_i/b_i + m_logOfNormalizationFactor \), where a and b are the parameters of the Gamma PDF.

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

Definition at line 81 of file GammaJointPdf.C.

87 {
88  queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect), "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
89 
90  double aux = 0.;
91  double result = 0.;
92  for (unsigned int i = 0; i < domainVector.sizeLocal(); ++i) {
93  if (m_normalizationStyle == 0) {
94  aux = log(m_env.basicPdfs()->gammaPdfActualValue(domainVector[i],m_a[i],m_b[i]));
95  }
96  else {
97  aux = (m_a[i]-1.)*log(domainVector[i]) - domainVector[i]/m_b[i];
98  }
99  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
100  *m_env.subDisplayFile() << "In GammaJointPdf<V,M>::lnValue()"
101  << ", m_normalizationStyle = " << m_normalizationStyle
102  << ": domainVector[" << i << "] = " << domainVector[i]
103  << ", m_a[" << i << "] = " << m_a[i]
104  << ", m_b[" << i << "] = " << m_b[i]
105  << ", log(pdf)= " << aux
106  << std::endl;
107  }
108  result += aux;
109  }
110  result += m_logOfNormalizationFactor; // [PDF-06]
111 
112  return result;
113 }
double m_logOfNormalizationFactor
Definition: JointPdf.h:122
const BaseEnvironment & m_env
const BasicPdfsBase * basicPdfs() const
Access to Basic PDFs.
Definition: Environment.C:490
virtual double gammaPdfActualValue(double x, double a, double b) const =0
TODO: Actual value of the Gamma PDF (calculated via either Boost or GSL libraries). See template specialization.
unsigned int m_normalizationStyle
Definition: JointPdf.h:121
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320

Member Data Documentation

template<class V = GslVector, class M = GslMatrix>
V QUESO::GammaJointPdf< V, M >::m_a
protected

Definition at line 113 of file GammaJointPdf.h.

template<class V = GslVector, class M = GslMatrix>
V QUESO::GammaJointPdf< V, M >::m_b
protected

Definition at line 114 of file GammaJointPdf.h.


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

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