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

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

#include <ScalarFunctionSynchronizer.h>

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

Public Member Functions

Constructor/Destructor methods
 BayesianJointPdf (const char *prefix, const BaseJointPdf< V, M > &priorDensity, const BaseScalarFunction< V, M > &likelihoodFunction, double likelihoodExponent, const VectorSet< V, M > &intersectionDomain)
 Default constructor. More...
 
 ~BayesianJointPdf ()
 Destructor. More...
 
Math methods
double actualValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Actual value of the PDF (scalar function). More...
 
virtual double lnValue (const V &domainVector) const
 Computes the logarithm of the value of the function. More...
 
virtual double lnValue (const V &domainVector, V &gradVector) const
 Returns the logarithm of the function and its gradient at domainVector. 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
 TODO: Computes the logarithm of the normalization factor. More...
 
void setNormalizationStyle (unsigned int value) const
 Sets a value to be used in the normalization style of the prior density PDF (ie, protected attribute m_priorDensity). More...
 
double lastComputedLogPrior () const
 Returns the logarithm of the last computed Prior value. Access to protected attribute m_lastComputedLogPrior. More...
 
double lastComputedLogLikelihood () const
 Returns the logarithm of the last computed likelihood value. Access to protected attribute m_lastComputedLogLikelihood. 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...
 
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 V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Logarithm of the value of the scalar function. Deprecated. More...
 
virtual double lnValue (const V &domainVector, V &gradVector, const V &domainDirection, V &hessianEffect) const
 

Protected Attributes

const BaseJointPdf< V, M > & m_priorDensity
 
const BaseScalarFunction< V, M > & m_likelihoodFunction
 
double m_likelihoodExponent
 
double m_lastComputedLogPrior
 
double m_lastComputedLogLikelihood
 
m_tmpVector1
 
m_tmpVector2
 
M * m_tmpMatrix
 
- 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, class M>
class QUESO::BayesianJointPdf< V, M >

A class for handling Bayesian joint PDFs.

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

Definition at line 36 of file ScalarFunctionSynchronizer.h.

Constructor & Destructor Documentation

template<class V, class M>
QUESO::BayesianJointPdf< V, M >::BayesianJointPdf ( const char *  prefix,
const BaseJointPdf< V, M > &  priorDensity,
const BaseScalarFunction< V, M > &  likelihoodFunction,
double  likelihoodExponent,
const VectorSet< V, M > &  intersectionDomain 
)

Default constructor.

Instantiates an object of this class given a prefix and a scalar function. The domain of the scalar function is assigned to the protected attribute m_domainSet, and the scalar fiction is also itself copied to the protected attribute m_scalarFunction.

Definition at line 33 of file BayesianJointPdf.C.

39  :
40  BaseJointPdf<V,M>(((std::string)(prefix)+"bay").c_str(),intersectionDomain),
41  m_priorDensity (priorDensity),
42  m_likelihoodFunction (likelihoodFunction),
43  m_likelihoodExponent (likelihoodExponent),
46  m_tmpVector1 (m_domainSet.vectorSpace().zeroVector()),
47  m_tmpVector2 (m_domainSet.vectorSpace().zeroVector()),
48  m_tmpMatrix (m_domainSet.vectorSpace().newMatrix())
49 {
50 }
const BaseScalarFunction< V, M > & m_likelihoodFunction
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
const BaseJointPdf< V, M > & m_priorDensity
template<class V , class M >
QUESO::BayesianJointPdf< V, M >::~BayesianJointPdf ( )

Destructor.

Definition at line 53 of file BayesianJointPdf.C.

54 {
55  delete m_tmpMatrix;
56 }

Member Function Documentation

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

Actual value of the PDF (scalar function).

If the exponent of the likelihood function (likelihoodExponent) is zero, i.e. the likelihood is constant and unitary, then the actual value is the value of the prior PDF; otherwise, the actual value is scaled (multiplied) by a power of the value of the likelihood function.

Implements QUESO::BaseJointPdf< V, M >.

Definition at line 82 of file BayesianJointPdf.C.

References QUESO::queso_require_equal_to_msg.

88 {
89  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
90  *m_env.subDisplayFile() << "Entering BayesianJointPdf<V,M>::actualValue()"
91  << ": domainVector = " << domainVector
92  << std::endl;
93  }
94 
95  queso_require_equal_to_msg(domainVector.sizeLocal(), this->m_domainSet.vectorSpace().dimLocal(), "invalid input");
96 
97  V* gradVLike = NULL;
98  if (gradVector) gradVLike = &m_tmpVector1;
99 
100  M* hessianMLike = NULL;
101  if (hessianMatrix) hessianMLike = m_tmpMatrix;
102 
103  V* hessianELike = NULL;
104  if (hessianEffect) hessianELike = &m_tmpVector2;
105 
106  double value1 = m_priorDensity.actualValue (domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect);
107  double value2 = 1.;
108  if (m_likelihoodExponent != 0.) {
109  value2 = m_likelihoodFunction.actualValue(domainVector,domainDirection,gradVLike ,hessianMLike ,hessianELike );
110  }
111 
112  queso_require_msg(!(gradVector || hessianMatrix || hessianEffect), "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
113 
114  double returnValue = value1;
115  if (m_likelihoodExponent == 0.) {
116  // Do nothing
117  }
118  else if (m_likelihoodExponent == 1.) {
119  returnValue *= value2;
120  }
121  else {
122  returnValue *= pow(value2,m_likelihoodExponent);
123  }
124  returnValue *= exp(m_logOfNormalizationFactor); // [PDF-02] ???
125 
126  m_lastComputedLogPrior = log(value1);
128 
129  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
130  *m_env.subDisplayFile() << "Leaving BayesianJointPdf<V,M>::actualValue()"
131  << ": domainVector = " << domainVector
132  << ", returnValue = " << returnValue
133  << std::endl;
134  }
135 
136  return returnValue;
137 }
double m_logOfNormalizationFactor
Definition: JointPdf.h:122
const BaseEnvironment & m_env
const BaseScalarFunction< V, M > & m_likelihoodFunction
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.
unsigned int displayVerbosity() const
Definition: Environment.C:450
const BaseJointPdf< V, M > & m_priorDensity
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class V , class M >
double QUESO::BayesianJointPdf< V, M >::computeLogOfNormalizationFactor ( unsigned int  numSamples,
bool  updateFactorInternally 
) const
virtual

TODO: Computes the logarithm of the normalization factor.

Todo:
: implement me!

Implements QUESO::BaseJointPdf< V, M >.

Definition at line 236 of file BayesianJointPdf.C.

References QUESO::queso_isnan().

237 {
238  double value = 0.;
239 
240  double volume = m_domainSet.volume();
241  if ((queso_isnan(volume)) ||
242  (volume == -INFINITY ) ||
243  (volume == INFINITY ) ||
244  (volume <= 0. )) {
245  // Do nothing
246  }
247  else {
248  queso_error_msg("incomplete code for computeLogOfNormalizationFactor()");
249  }
250 
251  return value;
252 }
bool queso_isnan(T arg)
Definition: math_macros.h:39
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
template<class V, class M>
virtual void QUESO::BayesianJointPdf< V, M >::distributionMean ( V &  meanVector) const
inlinevirtual

Mean value of the underlying random variable.

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

Definition at line 81 of file BayesianJointPdf.h.

81 { queso_not_implemented(); }
template<class V, class M>
virtual void QUESO::BayesianJointPdf< V, M >::distributionVariance ( M &  covMatrix) const
inlinevirtual

Covariance matrix of the underlying random variable.

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

Definition at line 84 of file BayesianJointPdf.h.

84 { queso_not_implemented(); };
template<class V , class M >
double QUESO::BayesianJointPdf< V, M >::lastComputedLogLikelihood ( ) const

Returns the logarithm of the last computed likelihood value. Access to protected attribute m_lastComputedLogLikelihood.

Definition at line 75 of file BayesianJointPdf.C.

76 {
78 }
template<class V , class M >
double QUESO::BayesianJointPdf< V, M >::lastComputedLogPrior ( ) const

Returns the logarithm of the last computed Prior value. Access to protected attribute m_lastComputedLogPrior.

Definition at line 68 of file BayesianJointPdf.C.

69 {
71 }
template<class V, class M >
double QUESO::BayesianJointPdf< V, M >::lnValue ( const V &  domainVector) const
virtual

Computes the logarithm of the value of the function.

Analogously to the method actualValue(), if the exponent of the likelihood function (likelihoodExponent) is zero then the Logarithm of the value of the function is the logarithm of the value of the prior PDF; otherwise, the value is scaled (added) by a power of the value of the likelihood function.

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

Definition at line 141 of file BayesianJointPdf.C.

142 {
143  double value1 = m_priorDensity.lnValue(domainVector);
144 
145  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
146  *m_env.subDisplayFile() << "In BayesianJointPdf<V,M>::lnValue()"
147  << ", domainVector = " << domainVector
148  << ": lnPrior = " << value1
149  << std::endl;
150  }
151 
152  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
153  *m_env.subDisplayFile() << "In BayesianJointPdf<V,M>::lnValue()"
154  << ", domainVector = " << domainVector
155  << ": about to call likelihood()"
156  << std::endl;
157  }
158 
159  double value2 = 0.;
160  if (m_likelihoodExponent != 0.) {
161  value2 = m_likelihoodFunction.lnValue(domainVector);
162  }
163 
164  double returnValue = value1;
165  if (m_likelihoodExponent == 0.) {
166  // Do nothing
167  }
168  else if (m_likelihoodExponent == 1.) {
169  returnValue += value2;
170  }
171  else {
172  returnValue += value2*m_likelihoodExponent;
173  } // prudenci 2010/03/05
174  returnValue += m_logOfNormalizationFactor; // [PDF-02] ???
175 
176  m_lastComputedLogPrior = value1;
178 
179  return returnValue;
180 }
double m_logOfNormalizationFactor
Definition: JointPdf.h:122
const BaseEnvironment & m_env
const BaseScalarFunction< V, M > & m_likelihoodFunction
unsigned int displayVerbosity() const
Definition: Environment.C:450
const BaseJointPdf< V, M > & m_priorDensity
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class V, class M >
double QUESO::BayesianJointPdf< V, M >::lnValue ( const V &  domainVector,
V &  gradVector 
) const
virtual

Returns the logarithm of the function and its gradient at domainVector.

Default implementation calls above method successively to fill up gradVector with a finite difference approximation.

Note, gradVector should be filled with the gradient of the logarithm of the function, not the gradient of the function.

QUESO calls this method when it needs to evaluate the function, needs first order derivative information, but doesn't need second order derivative information.

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

Definition at line 184 of file BayesianJointPdf.C.

185 {
186  double value1 = m_priorDensity.lnValue(domainVector, gradVector);
187 
188  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
189  *m_env.subDisplayFile() << "In BayesianJointPdf<V,M>::lnValue()"
190  << ", domainVector = " << domainVector
191  << ": lnPrior = " << value1
192  << std::endl;
193  }
194 
195  double value2 = 0.;
196  if (m_likelihoodExponent != 0.) {
197  value2 = m_likelihoodFunction.lnValue(domainVector, m_tmpVector1);
198  }
199 
200  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
201  *m_env.subDisplayFile() << "In BayesianJointPdf<V,M>::lnValue()"
202  << ", domainVector = " << domainVector
203  << ": value1 = " << value1
204  << ", value2 = " << value2
205  << std::endl;
206  *m_env.subDisplayFile() << "In BayesianJointPdf<V,M>::lnValue()"
207  << ", domainVector = " << domainVector
208  << ": gradVector = " << gradVector
209  << ", gradVLike = " << m_tmpVector1
210  << std::endl;
211  }
212 
213  gradVector += m_tmpVector1;
214 
215  double returnValue = value1;
216  if (m_likelihoodExponent == 0.) {
217  // Do nothing
218  }
219  else if (m_likelihoodExponent == 1.) {
220  returnValue += value2;
221  }
222  else {
223  returnValue += value2*m_likelihoodExponent;
224  } // prudenci 2010/03/05
225  returnValue += m_logOfNormalizationFactor; // [PDF-02] ???
226 
227  m_lastComputedLogPrior = value1;
229 
230  return returnValue;
231 }
double m_logOfNormalizationFactor
Definition: JointPdf.h:122
const BaseEnvironment & m_env
const BaseScalarFunction< V, M > & m_likelihoodFunction
unsigned int displayVerbosity() const
Definition: Environment.C:450
const BaseJointPdf< V, M > & m_priorDensity
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class V , class M >
void QUESO::BayesianJointPdf< V, M >::setNormalizationStyle ( unsigned int  value) const
virtual

Sets a value to be used in the normalization style of the prior density PDF (ie, protected attribute m_priorDensity).

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

Definition at line 60 of file BayesianJointPdf.C.

61 {
62  m_priorDensity.setNormalizationStyle(value);
63  return;
64 }
const BaseJointPdf< V, M > & m_priorDensity

Member Data Documentation

template<class V, class M>
double QUESO::BayesianJointPdf< V, M >::m_lastComputedLogLikelihood
mutableprotected

Definition at line 116 of file BayesianJointPdf.h.

template<class V, class M>
double QUESO::BayesianJointPdf< V, M >::m_lastComputedLogPrior
mutableprotected

Definition at line 115 of file BayesianJointPdf.h.

template<class V, class M>
double QUESO::BayesianJointPdf< V, M >::m_likelihoodExponent
protected

Definition at line 114 of file BayesianJointPdf.h.

template<class V, class M>
const BaseScalarFunction<V,M>& QUESO::BayesianJointPdf< V, M >::m_likelihoodFunction
protected

Definition at line 113 of file BayesianJointPdf.h.

template<class V, class M>
const BaseJointPdf<V,M>& QUESO::BayesianJointPdf< V, M >::m_priorDensity
protected

Definition at line 112 of file BayesianJointPdf.h.

template<class V, class M>
M* QUESO::BayesianJointPdf< V, M >::m_tmpMatrix
mutableprotected

Definition at line 120 of file BayesianJointPdf.h.

template<class V, class M>
V QUESO::BayesianJointPdf< V, M >::m_tmpVector1
mutableprotected

Definition at line 118 of file BayesianJointPdf.h.

template<class V, class M>
V QUESO::BayesianJointPdf< V, M >::m_tmpVector2
mutableprotected

Definition at line 119 of file BayesianJointPdf.h.


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

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