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

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

#include <BayesianJointPdf.h>

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

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...
 
double lnValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Computes the logarithm of the value of the function. 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...
 
- 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

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 49 of file BayesianJointPdf.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 UQ_FATAL_TEST_MACRO.

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  UQ_FATAL_TEST_MACRO(domainVector.sizeLocal() != this->m_domainSet.vectorSpace().dimLocal(),
96  m_env.worldRank(),
97  "BayesianJointPdf<V,M>::actualValue()",
98  "invalid input");
99 
100  V* gradVLike = NULL;
101  if (gradVector) gradVLike = &m_tmpVector1;
102 
103  M* hessianMLike = NULL;
104  if (hessianMatrix) hessianMLike = m_tmpMatrix;
105 
106  V* hessianELike = NULL;
107  if (hessianEffect) hessianELike = &m_tmpVector2;
108 
109  double value1 = m_priorDensity.actualValue (domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect);
110  double value2 = 1.;
111  if (m_likelihoodExponent != 0.) {
112  value2 = m_likelihoodFunction.actualValue(domainVector,domainDirection,gradVLike ,hessianMLike ,hessianELike );
113  }
114 
115  UQ_FATAL_TEST_MACRO((gradVector || hessianMatrix || hessianEffect),
116  m_env.worldRank(),
117  "BayesianJointPdf<V,M>::actualValue()",
118  "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
119 
120  double returnValue = value1;
121  if (m_likelihoodExponent == 0.) {
122  // Do nothing
123  }
124  else if (m_likelihoodExponent == 1.) {
125  returnValue *= value2;
126  }
127  else {
128  returnValue *= pow(value2,m_likelihoodExponent);
129  }
130  returnValue *= exp(m_logOfNormalizationFactor); // [PDF-02] ???
131 
132  m_lastComputedLogPrior = log(value1);
134 
135  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
136  *m_env.subDisplayFile() << "Leaving BayesianJointPdf<V,M>::actualValue()"
137  << ": domainVector = " << domainVector
138  << ", returnValue = " << returnValue
139  << std::endl;
140  }
141 
142  return returnValue;
143 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
const BaseScalarFunction< V, M > & m_likelihoodFunction
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
double m_logOfNormalizationFactor
Definition: JointPdf.h:104
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:222
unsigned int displayVerbosity() const
Definition: Environment.C:436
const BaseEnvironment & m_env
const BaseJointPdf< V, M > & m_priorDensity
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 257 of file BayesianJointPdf.C.

References UQ_FATAL_TEST_MACRO.

258 {
259  double value = 0.;
260 
261  double volume = m_domainSet.volume();
262  if (((boost::math::isnan)(volume)) ||
263  (volume == -INFINITY ) ||
264  (volume == INFINITY ) ||
265  (volume <= 0. )) {
266  // Do nothing
267  }
268  else {
269  UQ_FATAL_TEST_MACRO(true,
270  m_env.worldRank(),
271  "BayesianJointPdf<V,M>::lnValue()",
272  "incomplete code for computeLogOfNormalizationFactor()");
273  }
274 
275  return value;
276 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:222
const BaseEnvironment & m_env
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 V *  domainDirection,
V *  gradVector,
M *  hessianMatrix,
V *  hessianEffect 
) 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.

Implements QUESO::BaseJointPdf< V, M >.

Definition at line 147 of file BayesianJointPdf.C.

153 {
154  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
155  *m_env.subDisplayFile() << "Entering BayesianJointPdf<V,M>::lnValue()"
156  << ": domainVector = " << domainVector
157  << std::endl;
158  }
159 
160  V* gradVLike = NULL;
161  if (gradVector) gradVLike = &m_tmpVector1;
162 
163  M* hessianMLike = NULL;
164  if (hessianMatrix) hessianMLike = m_tmpMatrix;
165 
166  V* hessianELike = NULL;
167  if (hessianEffect) hessianELike = &m_tmpVector2;
168 
169  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
170  *m_env.subDisplayFile() << "In BayesianJointPdf<V,M>::lnValue()"
171  << ", domainVector = " << domainVector
172  << ": about to call prior()"
173  << std::endl;
174  }
175 
176  double value1 = m_priorDensity.lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect);
177 
178  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
179  *m_env.subDisplayFile() << "In BayesianJointPdf<V,M>::lnValue()"
180  << ", domainVector = " << domainVector
181  << ": lnPrior = " << value1
182  << std::endl;
183  }
184 
185  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
186  *m_env.subDisplayFile() << "In BayesianJointPdf<V,M>::lnValue()"
187  << ", domainVector = " << domainVector
188  << ": about to call likelihood()"
189  << std::endl;
190  }
191 
192  double value2 = 0.;
193  if (m_likelihoodExponent != 0.) {
194  value2 = m_likelihoodFunction.lnValue(domainVector,domainDirection,gradVLike, hessianMLike, hessianELike );
195  }
196 
197  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
198  *m_env.subDisplayFile() << "In BayesianJointPdf<V,M>::lnValue()"
199  << ", domainVector = " << domainVector
200  << ": value1 = " << value1
201  << ", value2 = " << value2
202  << std::endl;
203  if (gradVector) {
204  *m_env.subDisplayFile() << "In BayesianJointPdf<V,M>::lnValue()"
205  << ", domainVector = " << domainVector
206  << ": gradVector = " << *gradVector
207  << ", gradVLike = " << *gradVLike
208  << std::endl;
209  }
210  if (hessianMatrix) {
211  *m_env.subDisplayFile() << "In BayesianJointPdf<V,M>::lnValue()"
212  << ", domainVector = " << domainVector
213  << ": hessianMatrix = " << *hessianMatrix
214  << ", hessianMLike = " << *hessianMLike
215  << std::endl;
216  }
217  if (hessianEffect) {
218  *m_env.subDisplayFile() << "In BayesianJointPdf<V,M>::lnValue()"
219  << ", domainVector = " << domainVector
220  << ": hessianEffect = " << *hessianEffect
221  << ", hessianELike = " << *hessianELike
222  << std::endl;
223  }
224  }
225 
226  if (gradVector ) *gradVector += *gradVLike;
227  if (hessianMatrix) *hessianMatrix += *hessianMLike;
228  if (hessianEffect) *hessianEffect += *hessianELike;
229 
230  double returnValue = value1;
231  if (m_likelihoodExponent == 0.) {
232  // Do nothing
233  }
234  else if (m_likelihoodExponent == 1.) {
235  returnValue += value2;
236  }
237  else {
238  returnValue += value2*m_likelihoodExponent;
239  } // prudenci 2010/03/05
240  returnValue += m_logOfNormalizationFactor; // [PDF-02] ???
241 
242  m_lastComputedLogPrior = value1;
244 
245  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
246  *m_env.subDisplayFile() << "Leaving BayesianJointPdf<V,M>::lnValue()"
247  << ": domainVector = " << domainVector
248  << ", returnValue = " << returnValue
249  << std::endl;
250  }
251 
252  return returnValue;
253 }
const BaseScalarFunction< V, M > & m_likelihoodFunction
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
double m_logOfNormalizationFactor
Definition: JointPdf.h:104
unsigned int displayVerbosity() const
Definition: Environment.C:436
const BaseEnvironment & m_env
const BaseJointPdf< V, M > & m_priorDensity
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 107 of file BayesianJointPdf.h.

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

Definition at line 106 of file BayesianJointPdf.h.

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

Definition at line 105 of file BayesianJointPdf.h.

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

Definition at line 104 of file BayesianJointPdf.h.

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

Definition at line 103 of file BayesianJointPdf.h.

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

Definition at line 111 of file BayesianJointPdf.h.

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

Definition at line 109 of file BayesianJointPdf.h.

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

Definition at line 110 of file BayesianJointPdf.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