queso-0.53.0
UniformJointPdf.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/UniformJointPdf.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 
29 namespace QUESO {
30 
31 // Constructor -------------------------------------
32 template<class V,class M>
34  const char* prefix,
35  const VectorSet<V,M>& domainSet)
36  :
37  BaseJointPdf<V,M>(((std::string)(prefix)+"uni").c_str(),
38  domainSet)
39 {
40  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
41  *m_env.subDisplayFile() << "Entering UniformJointPdf<V,M>::constructor()"
42  << ": prefix = " << m_prefix
43  << std::endl;
44  }
45 
46  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
47  *m_env.subDisplayFile() << "Leaving UniformJointPdf<V,M>::constructor()"
48  << ": prefix = " << m_prefix
49  << std::endl;
50  }
51 }
52 // Destructor --------------------------------------
53 template<class V,class M>
55 {
56 }
57 // Math methods-------------------------------------
58 template<class V, class M>
59 double
61  const V& domainVector,
62  const V* domainDirection,
63  V* gradVector,
64  M* hessianMatrix,
65  V* hessianEffect) const
66 {
67  queso_require_equal_to_msg(domainVector.sizeLocal(), this->m_domainSet.vectorSpace().dimLocal(), "invalid input");
68 
69  if (gradVector ) *gradVector = m_domainSet.vectorSpace().zeroVector();
70  if (hessianMatrix) *hessianMatrix *= 0.;
71  if (hessianEffect) *hessianEffect = m_domainSet.vectorSpace().zeroVector();
72 
73  if (domainDirection) {}; // just to remove compiler warning
74 
75  double volume = m_domainSet.volume();
76  if (((boost::math::isnan)(volume)) ||
77  (volume == -INFINITY ) ||
78  (volume == INFINITY ) ||
79  (volume <= 0. ) ||
80  (m_normalizationStyle != 0 )) {
81  volume = 1.;
82  }
83 
84  return 1./volume; // No need to multiply by exp(m_logOfNormalizationFactor) [PDF-04]
85 }
86 //--------------------------------------------------
87 template<class V, class M>
88 double
90  const V& domainVector,
91  const V* domainDirection,
92  V* gradVector,
93  M* hessianMatrix,
94  V* hessianEffect) const
95 {
96  if (gradVector ) *gradVector = m_domainSet.vectorSpace().zeroVector();
97  if (hessianMatrix) *hessianMatrix *= 0.;
98  if (hessianEffect) *hessianEffect = m_domainSet.vectorSpace().zeroVector();
99 
100  if (domainVector[0]) {}; // just to remove compiler warning
101  if (domainDirection) {}; // just to remove compiler warning
102 
103  double volume = m_domainSet.volume();
104  if (((boost::math::isnan)(volume)) ||
105  (volume == -INFINITY ) ||
106  (volume == INFINITY ) ||
107  (volume <= 0. ) ||
108  (m_normalizationStyle != 0 )) {
109  volume = 1.;
110  }
111 
112  return -log(volume);
113 }
114 //--------------------------------------------------
115 template<class V, class M>
116 double
117 UniformJointPdf<V,M>::computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
118 {
119  double value = 0.;
120 
121  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
122  *m_env.subDisplayFile() << "Entering UniformJointPdf<V,M>::computeLogOfNormalizationFactor()"
123  << std::endl;
124  }
125  value = BaseJointPdf<V,M>::commonComputeLogOfNormalizationFactor(numSamples, updateFactorInternally);
126  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
127  *m_env.subDisplayFile() << "Leaving UniformJointPdf<V,M>::computeLogOfNormalizationFactor()"
128  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
129  << std::endl;
130  }
131 
132  return value;
133 }
134 
135 } // End namespace QUESO
136 
unsigned int displayVerbosity() const
Definition: Environment.C:396
UniformJointPdf(const char *prefix, const VectorSet< V, M > &domainSet)
Constructor.
A templated class for handling sets.
Definition: VectorSet.h:52
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the uniform PDF.
A templated (base) class for handling joint PDFs.
Definition: JointPdf.h:56
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:77
A class for handling uniform joint PDFs.
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
const BaseEnvironment & m_env
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
~UniformJointPdf()
Destructor.
double computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Computes the logarithm of the normalization factor.
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the uniform PDF.

Generated on Thu Jun 11 2015 13:52:33 for queso-0.53.0 by  doxygen 1.8.5