25 #include <queso/BayesianJointPdf.h> 
   26 #include <queso/GslVector.h> 
   27 #include <queso/GslMatrix.h> 
   32 template<
class V,
class M>
 
   37         double                          likelihoodExponent,
 
   40   BaseJointPdf<V,M>(((std::string)(prefix)+
"bay").c_str(),intersectionDomain),
 
   41   m_priorDensity             (priorDensity),
 
   42   m_likelihoodFunction       (likelihoodFunction),
 
   43   m_likelihoodExponent       (likelihoodExponent),
 
   44   m_lastComputedLogPrior     (0.),
 
   45   m_lastComputedLogLikelihood(0.),
 
   46   m_tmpVector1               (m_domainSet.vectorSpace().zeroVector()),
 
   47   m_tmpVector2               (m_domainSet.vectorSpace().zeroVector()),
 
   48   m_tmpMatrix                (m_domainSet.vectorSpace().newMatrix())
 
   52 template<
class V,
class M>
 
   58 template<
class V,
class M>
 
   62   m_priorDensity.setNormalizationStyle(value);
 
   66 template<
class V,
class M>
 
   70   return m_lastComputedLogPrior;
 
   73 template<
class V,
class M>
 
   77   return m_lastComputedLogLikelihood;
 
   80 template<
class V, 
class M>
 
   83   const V& domainVector,
 
   84   const V* domainDirection,
 
   87         V* hessianEffect)
 const 
   89   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
 
   90     *m_env.subDisplayFile() << 
"Entering BayesianJointPdf<V,M>::actualValue()" 
   91                             << 
": domainVector = " << domainVector
 
   98   if (gradVector) gradVLike = &m_tmpVector1;
 
  100   M* hessianMLike = NULL;
 
  101   if (hessianMatrix) hessianMLike = m_tmpMatrix;
 
  103   V* hessianELike = NULL;
 
  104   if (hessianEffect) hessianELike = &m_tmpVector2;
 
  106   double value1 = m_priorDensity.actualValue (domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect);
 
  108   if (m_likelihoodExponent != 0.) {
 
  109     value2 = m_likelihoodFunction.actualValue(domainVector,domainDirection,gradVLike ,hessianMLike ,hessianELike );
 
  112   queso_require_msg(!(gradVector || hessianMatrix || hessianEffect), 
"incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
 
  114   double returnValue = value1;
 
  115   if (m_likelihoodExponent == 0.) {
 
  118   else if (m_likelihoodExponent == 1.) {
 
  119     returnValue *= value2;
 
  122     returnValue *= pow(value2,m_likelihoodExponent);
 
  124   returnValue *= exp(m_logOfNormalizationFactor); 
 
  126   m_lastComputedLogPrior      = log(value1);
 
  127   m_lastComputedLogLikelihood = m_likelihoodExponent*log(value2);
 
  129   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
 
  130     *m_env.subDisplayFile() << 
"Leaving BayesianJointPdf<V,M>::actualValue()" 
  131                             << 
": domainVector = " << domainVector
 
  132                             << 
", returnValue = "  << returnValue
 
  139 template<
class V, 
class M>
 
  143   double value1 = m_priorDensity.lnValue(domainVector);
 
  145   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
 
  146     *m_env.subDisplayFile() << 
"In BayesianJointPdf<V,M>::lnValue()" 
  147                             << 
", domainVector = " << domainVector
 
  148                             << 
": lnPrior = " << value1
 
  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()" 
  160   if (m_likelihoodExponent != 0.) {
 
  161     value2 = m_likelihoodFunction.lnValue(domainVector);
 
  164   double returnValue = value1;
 
  165   if (m_likelihoodExponent == 0.) {
 
  168   else if (m_likelihoodExponent == 1.) {
 
  169     returnValue += value2;
 
  172     returnValue += value2*m_likelihoodExponent;
 
  174   returnValue += m_logOfNormalizationFactor; 
 
  176   m_lastComputedLogPrior      = value1;
 
  177   m_lastComputedLogLikelihood = m_likelihoodExponent*value2;
 
  182 template<
class V, 
class M>
 
  186   double value1 = m_priorDensity.lnValue(domainVector, gradVector);
 
  188   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
 
  189     *m_env.subDisplayFile() << 
"In BayesianJointPdf<V,M>::lnValue()" 
  190                             << 
", domainVector = " << domainVector
 
  191                             << 
": lnPrior = " << value1
 
  196   if (m_likelihoodExponent != 0.) {
 
  197     value2 = m_likelihoodFunction.lnValue(domainVector, m_tmpVector1);
 
  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
 
  206     *m_env.subDisplayFile() << 
"In BayesianJointPdf<V,M>::lnValue()" 
  207                             << 
", domainVector = " << domainVector
 
  208                             << 
": gradVector = "   << gradVector
 
  209                             << 
", gradVLike = "    << m_tmpVector1
 
  213   gradVector += m_tmpVector1;
 
  215   double returnValue = value1;
 
  216   if (m_likelihoodExponent == 0.) {
 
  219   else if (m_likelihoodExponent == 1.) {
 
  220     returnValue += value2;
 
  223     returnValue += value2*m_likelihoodExponent;
 
  225   returnValue += m_logOfNormalizationFactor; 
 
  227   m_lastComputedLogPrior      = value1;
 
  228   m_lastComputedLogLikelihood = m_likelihoodExponent*value2;
 
  234 template<
class V, 
class M>
 
  240   double volume = m_domainSet.volume();
 
  242       (volume == -INFINITY         ) ||
 
  243       (volume ==  INFINITY         ) ||
 
  248     queso_error_msg(
"incomplete code for computeLogOfNormalizationFactor()");
 
A templated (base) class for handling scalar functions. 
double computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const 
TODO: Computes the logarithm of the normalization factor. 
double lastComputedLogLikelihood() const 
Returns the logarithm of the last computed likelihood value. Access to protected attribute m_lastComp...
virtual double lnValue(const V &domainVector) const 
Computes the logarithm of the value of the function. 
A templated class for handling sets. 
double lastComputedLogPrior() const 
Returns the logarithm of the last computed Prior value. Access to protected attribute m_lastComputedL...
void setNormalizationStyle(unsigned int value) const 
Sets a value to be used in the normalization style of the prior density PDF (ie, protected attribute ...
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const 
Actual value of the PDF (scalar function). 
BayesianJointPdf(const char *prefix, const BaseJointPdf< V, M > &priorDensity, const BaseScalarFunction< V, M > &likelihoodFunction, double likelihoodExponent, const VectorSet< V, M > &intersectionDomain)
Default constructor. 
A templated (base) class for handling joint PDFs. 
~BayesianJointPdf()
Destructor. 
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"))