queso-0.51.1
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,2009,2010,2011,2012,2013 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  UQ_FATAL_TEST_MACRO(domainVector.sizeLocal() != this->m_domainSet.vectorSpace().dimLocal(),
68  m_env.worldRank(),
69  "UniformJointPdf<V,M>::actualValue()",
70  "invalid input");
71 
72  if (gradVector ) *gradVector = m_domainSet.vectorSpace().zeroVector();
73  if (hessianMatrix) *hessianMatrix *= 0.;
74  if (hessianEffect) *hessianEffect = m_domainSet.vectorSpace().zeroVector();
75 
76  if (domainDirection) {}; // just to remove compiler warning
77 
78  double volume = m_domainSet.volume();
79  if (((boost::math::isnan)(volume)) ||
80  (volume == -INFINITY ) ||
81  (volume == INFINITY ) ||
82  (volume <= 0. ) ||
83  (m_normalizationStyle != 0 )) {
84  volume = 1.;
85  }
86 
87  return 1./volume; // No need to multiply by exp(m_logOfNormalizationFactor) [PDF-04]
88 }
89 //--------------------------------------------------
90 template<class V, class M>
91 double
93  const V& domainVector,
94  const V* domainDirection,
95  V* gradVector,
96  M* hessianMatrix,
97  V* hessianEffect) const
98 {
99  if (gradVector ) *gradVector = m_domainSet.vectorSpace().zeroVector();
100  if (hessianMatrix) *hessianMatrix *= 0.;
101  if (hessianEffect) *hessianEffect = m_domainSet.vectorSpace().zeroVector();
102 
103  if (domainVector[0]) {}; // just to remove compiler warning
104  if (domainDirection) {}; // just to remove compiler warning
105 
106  double volume = m_domainSet.volume();
107  if (((boost::math::isnan)(volume)) ||
108  (volume == -INFINITY ) ||
109  (volume == INFINITY ) ||
110  (volume <= 0. ) ||
111  (m_normalizationStyle != 0 )) {
112  volume = 1.;
113  }
114 
115  return log(volume); // No need to add m_logOfNormalizationFactor [PDF-04]
116 }
117 //--------------------------------------------------
118 template<class V, class M>
119 double
120 UniformJointPdf<V,M>::computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
121 {
122  double value = 0.;
123 
124  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
125  *m_env.subDisplayFile() << "Entering UniformJointPdf<V,M>::computeLogOfNormalizationFactor()"
126  << std::endl;
127  }
128  value = BaseJointPdf<V,M>::commonComputeLogOfNormalizationFactor(numSamples, updateFactorInternally);
129  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
130  *m_env.subDisplayFile() << "Leaving UniformJointPdf<V,M>::computeLogOfNormalizationFactor()"
131  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
132  << std::endl;
133  }
134 
135  return value;
136 }
137 
138 } // End namespace QUESO
139 
A templated class for handling sets.
Definition: VectorSet.h:49
A class for handling uniform joint PDFs.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the uniform PDF.
~UniformJointPdf()
Destructor.
const BaseEnvironment & m_env
double computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Computes the logarithm of the normalization factor.
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
unsigned int displayVerbosity() const
Definition: Environment.C:436
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the uniform PDF.
UniformJointPdf(const char *prefix, const VectorSet< V, M > &domainSet)
Constructor.
A templated (base) class for handling joint PDFs.
Definition: JointPdf.h:60

Generated on Thu Apr 23 2015 19:26:16 for queso-0.51.1 by  doxygen 1.8.5