queso-0.57.0
Protected Attributes | List of all members
QUESO::BetaJointPdf< V, M > Class Template Reference

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

#include <BetaJointPdf.h>

Inheritance diagram for QUESO::BetaJointPdf< V, M >:
Inheritance graph
[legend]
Collaboration diagram for QUESO::BetaJointPdf< V, M >:
Collaboration graph
[legend]

Public Member Functions

Constructor/Destructor methods
 BetaJointPdf (const char *prefix, const VectorSet< V, M > &domainSet, const V &alpha, const V &beta)
 Constructor. More...
 
 ~BetaJointPdf ()
 Destructor. More...
 
Math methods
double actualValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Actual value of the Beta PDF. More...
 
double lnValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Logarithm of the value of the Beta 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_alpha
 
m_beta
 
- 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::BetaJointPdf< V, M >

A class for handling Beta joint PDFs.

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

Definition at line 47 of file BetaJointPdf.h.

Constructor & Destructor Documentation

template<class V , class M >
QUESO::BetaJointPdf< V, M >::BetaJointPdf ( const char *  prefix,
const VectorSet< V, M > &  domainSet,
const V &  alpha,
const V &  beta 
)

Constructor.

Constructs a new object of the class, given a prefix, the domain set, and the parameters alpha and beta of the Beta PDF.

Definition at line 34 of file BetaJointPdf.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_alpha(alpha),
42  m_beta (beta)
43 {
44  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
45  *m_env.subDisplayFile() << "Entering BetaJointPdf<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 BetaJointPdf<V,M>::constructor()"
52  << ": prefix = " << m_prefix
53  << std::endl;
54  }
55 }
const BaseEnvironment & m_env
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
unsigned int displayVerbosity() const
Definition: Environment.C:450
template<class V , class M >
QUESO::BetaJointPdf< V, M >::~BetaJointPdf ( )

Destructor.

Definition at line 58 of file BetaJointPdf.C.

59 {
60 }

Member Function Documentation

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

Actual value of the Beta 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 BetaJointPdf.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  queso_require_msg(!(domainDirection || hessianMatrix || hessianEffect), "incomplete code for hessianMatrix and hessianEffect calculations");
73 
74  // No need to multiply by exp(m_logOfNormalizationFactor) because 'lnValue()' is called
75  double value = std::exp(this->lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect));
76 
77  if (gradVector) {
78  // DM: This transformation may have issues near the boundary. I haven't
79  // fully explored this yet.
80  //
81  // This evaluation is also normalised (if m_normalizationStyle is zero) and
82  // so the gradient in physical space contains the normalisation constant.
83  (*gradVector) *= value;
84  }
85 
86  return value;
87 }
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the Beta PDF.
Definition: BetaJointPdf.C:91
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
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"))
template<class V , class M >
double QUESO::BetaJointPdf< 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 170 of file BetaJointPdf.C.

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

171 {
172  double value = 0.;
173 
174  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
175  *m_env.subDisplayFile() << "Entering BetaJointPdf<V,M>::computeLogOfNormalizationFactor()"
176  << std::endl;
177  }
178  value = BaseJointPdf<V,M>::commonComputeLogOfNormalizationFactor(numSamples, updateFactorInternally);
179  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
180  *m_env.subDisplayFile() << "Leaving BetaJointPdf<V,M>::computeLogOfNormalizationFactor()"
181  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
182  << std::endl;
183  }
184 
185  return value;
186 }
const BaseEnvironment & m_env
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
double m_logOfNormalizationFactor
Definition: JointPdf.h:122
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
unsigned int displayVerbosity() const
Definition: Environment.C:450
template<class V , class M >
void QUESO::BetaJointPdf< V, M >::distributionMean ( V &  meanVector) const
virtual

Mean value of the underlying random variable.

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

Definition at line 138 of file BetaJointPdf.C.

139 {
140  unsigned int n_params = meanVector.sizeLocal();
141  queso_assert_equal_to (n_params, m_alpha.sizeLocal());
142 
143  for (unsigned int i = 0; i < n_params; ++i) {
144  meanVector[i] = m_alpha[i] / (m_alpha[i] + m_beta[i]);
145  }
146 }
template<class V , class M >
void QUESO::BetaJointPdf< V, M >::distributionVariance ( M &  covMatrix) const
virtual

Covariance matrix of the underlying random variable.

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

Definition at line 150 of file BetaJointPdf.C.

151 {
152  unsigned int n_params = m_alpha.sizeLocal();
153  queso_assert_equal_to (n_params, m_beta.sizeLocal());
154  queso_assert_equal_to (n_params, covMatrix.numCols());
155  queso_assert_equal_to (covMatrix.numCols(), covMatrix.numRowsGlobal());
156 
157  covMatrix.zeroLower();
158  covMatrix.zeroUpper();
159 
160  for (unsigned int i = 0; i < n_params; ++i) {
161  covMatrix(i,i) = (m_alpha[i] * m_beta[i]) /
162  ((m_alpha[i] + m_beta[i]) *
163  (m_alpha[i] + m_beta[i]) *
164  (m_alpha[i] + m_beta[i] + 1));
165  }
166 }
template<class V , class M >
double QUESO::BetaJointPdf< V, M >::lnValue ( const V &  domainVector,
const V *  domainDirection,
V *  gradVector,
M *  hessianMatrix,
V *  hessianEffect 
) const
virtual

Logarithm of the value of the Beta PDF.

If the normalization style (m_normalizationStyle) is zero, then this routine calls a environment method which handles basic PDFs, e.g. basicPdfs()->betaPdfActualValue() and adds the log of the normalization factor (m_logOfNormalizationFactor) to it; otherwise the method uses the formula: $ lnValue = \sum[ (alpha_i-1)*log(domainVector_i) + (beta_i-1)*log(1-domainVector_i)] + m_logOfNormalizationFactor $.

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

Definition at line 91 of file BetaJointPdf.C.

97 {
98  queso_require_msg(!(domainDirection || hessianMatrix || hessianEffect), "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
99 
100  double aux = 0.;
101  double result = 0.;
102  for (unsigned int i = 0; i < domainVector.sizeLocal(); ++i) {
103  if (m_normalizationStyle == 0) {
104  aux = log(m_env.basicPdfs()->betaPdfActualValue(domainVector[i],m_alpha[i],m_beta[i]));
105  }
106  else {
107  aux = (m_alpha[i]-1.)*log(domainVector[i]) + (m_beta[i]-1.)*log(1.-domainVector[i]);
108  }
109 
110  // The log of the beta pdf is
111  // f(x) = (alpha - 1) * log(x) + (beta - 1) * log(1 - x)
112  // Therefore
113  // df/dx (x) = ((alpha - 1) / x) + ((1 - beta) / (1 - x))
114  if (gradVector) {
115  // We're computing grad of log of p which is p' / p
116  (*gradVector)[i] = (m_alpha[i] - 1.0) / domainVector[i] +
117  (1.0 - m_beta[i]) / (1.0 - domainVector[i]);
118  }
119 
120  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
121  *m_env.subDisplayFile() << "In BetaJointPdf<V,M>::lnValue()"
122  << ", m_normalizationStyle = " << m_normalizationStyle
123  << ": domainVector[" << i << "] = " << domainVector[i]
124  << ", m_alpha[" << i << "] = " << m_alpha[i]
125  << ", m_beta[" << i << "] = " << m_beta[i]
126  << ", log(pdf)= " << aux
127  << std::endl;
128  }
129  result += aux;
130  }
131  result += m_logOfNormalizationFactor;
132 
133  return result;
134 }
const BasicPdfsBase * basicPdfs() const
Access to Basic PDFs.
Definition: Environment.C:490
const BaseEnvironment & m_env
unsigned int m_normalizationStyle
Definition: JointPdf.h:121
double m_logOfNormalizationFactor
Definition: JointPdf.h:122
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
unsigned int displayVerbosity() const
Definition: Environment.C:450
virtual double betaPdfActualValue(double x, double alpha, double beta) const =0
TODO: Actual value of the Beta PDF (calculated via either Boost or GSL libraries). See template specialization.

Member Data Documentation

template<class V = GslVector, class M = GslMatrix>
V QUESO::BetaJointPdf< V, M >::m_alpha
protected

Definition at line 92 of file BetaJointPdf.h.

template<class V = GslVector, class M = GslMatrix>
V QUESO::BetaJointPdf< V, M >::m_beta
protected

Definition at line 93 of file BetaJointPdf.h.


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

Generated on Sat Apr 22 2017 14:04:40 for queso-0.57.0 by  doxygen 1.8.5