queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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-2017 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 ((queso_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 ((queso_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 void
118 {
119  m_domainSet.centroid(meanVector);
120 }
121 //--------------------------------------------------
122 template<class V, class M>
123 void
125 {
126  m_domainSet.moments(covMatrix);
127 }
128 //--------------------------------------------------
129 template<class V, class M>
130 double
131 UniformJointPdf<V,M>::computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
132 {
133  double value = 0.;
134 
135  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
136  *m_env.subDisplayFile() << "Entering UniformJointPdf<V,M>::computeLogOfNormalizationFactor()"
137  << std::endl;
138  }
139  value = BaseJointPdf<V,M>::commonComputeLogOfNormalizationFactor(numSamples, updateFactorInternally);
140  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
141  *m_env.subDisplayFile() << "Leaving UniformJointPdf<V,M>::computeLogOfNormalizationFactor()"
142  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
143  << std::endl;
144  }
145 
146  return value;
147 }
148 
149 } // End namespace QUESO
150 
UniformJointPdf(const char *prefix, const VectorSet< V, M > &domainSet)
Constructor.
virtual void distributionMean(V &meanVector) const
Mean value of the underlying random variable.
bool queso_isnan(T arg)
Definition: math_macros.h:39
A templated class for handling sets.
Definition: VectorSet.h:52
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the uniform PDF.
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:115
~UniformJointPdf()
Destructor.
virtual void distributionVariance(M &covMatrix) const
Covariance matrix of the underlying random variable.
const BaseEnvironment & m_env
A templated (base) class for handling joint PDFs.
Definition: JointPdf.h:55
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the uniform PDF.
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"))
A class for handling uniform joint PDFs.
unsigned int displayVerbosity() const
Definition: Environment.C:450
double computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Computes the logarithm of the normalization factor.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320

Generated on Tue Jun 5 2018 19:48:56 for queso-0.57.1 by  doxygen 1.8.5