queso-0.53.0
JointPdf.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/JointPdf.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 
29 namespace QUESO {
30 
31 // Default constructor -----------------------------
32 template<class V, class M>
34  const char* prefix,
35  const VectorSet<V,M>& domainSet)
36  :
37  BaseScalarFunction<V,M>(((std::string)(prefix)+"pd_").c_str(), domainSet),
38  m_normalizationStyle(0),
39  m_logOfNormalizationFactor(0.)
40 {
41  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
42  *m_env.subDisplayFile() << "Entering BaseJointPdf<V,M>::constructor() [3]"
43  << ": prefix = " << m_prefix
44  << std::endl;
45  }
46 
47  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
48  *m_env.subDisplayFile() << "Leaving BaseJointPdf<V,M>::constructor() [3]"
49  << ": prefix = " << m_prefix
50  << std::endl;
51  }
52 }
53 // Destructor ---------------------------------------
54 template<class V, class M>
56 {
57 }
58 // Math methods -------------------------------------
59 template<class V,class M>
60 void
62 {
63  m_normalizationStyle = value;
64  return;
65 }
66 //---------------------------------------------------
67 template<class V,class M>
68 void
70 {
71  m_logOfNormalizationFactor = value;
72  return;
73 }
74 //---------------------------------------------------
75 template<class V,class M>
76 double
77 BaseJointPdf<V,M>::commonComputeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
78 {
79  double value = 0.;
80 
81  double volume = m_domainSet.volume();
82  if (((boost::math::isnan)(volume)) ||
83  (volume == -INFINITY ) ||
84  (volume == INFINITY ) ||
85  (volume <= 0. )) {
86  // Do nothing
87  }
88  else {
89  const BoxSubset<V,M>* boxSubset = dynamic_cast<const BoxSubset<V,M>* >(&m_domainSet);
90  if (boxSubset == NULL) {
91  // Do nothing
92  }
93  else {
94  V tmpVec(m_domainSet.vectorSpace().zeroVector());
95  double sum = 0.;
96  for (unsigned int i = 0; i < numSamples; ++i) {
97  tmpVec.cwSetUniform(boxSubset->minValues(),boxSubset->maxValues());
98  sum += this->actualValue(tmpVec,NULL,NULL,NULL,NULL);
99  }
100  double avgValue = sum/((double) numSamples);
101  value = -( log(avgValue) + log(volume) );
102  if (updateFactorInternally) {
103  m_logOfNormalizationFactor = value;
104  }
105  }
106  }
107 
108  return value;
109 }
110 
111 #if 0
112 template <class V, class M>
113 const BaseScalarPdf&
114 BaseJointPdf<V,M>::component(unsigned int componentId) const
115 {
116  if (componentId > m_components.size()) return m_dummyComponent;
117  if (m_components[componentId] == NULL) return m_dummyComponent;
118  return *(m_components[componentId]);
119 }
120 #endif
121 
122 } // End namespace QUESO
123 
unsigned int displayVerbosity() const
Definition: Environment.C:396
BaseJointPdf(const char *prefix, const VectorSet< V, M > &domainSet)
Default constructor.
Definition: JointPdf.C:33
A templated class for handling sets.
Definition: VectorSet.h:52
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 templated (base) class for handling scalar functions.
virtual void setNormalizationStyle(unsigned int value) const
Sets a value to be used in the normalization style (stored in the protected attribute m_normalization...
Definition: JointPdf.C:61
const BaseEnvironment & m_env
const V & maxValues() const
Vector of the maximum values of the box subset.
Definition: BoxSubset.C:79
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
const V & minValues() const
Vector of the minimum values of the box subset.
Definition: BoxSubset.C:73
void setLogOfNormalizationFactor(double value) const
Sets a logarithmic value to be used in the normalization factor (stored in the protected attribute m_...
Definition: JointPdf.C:69
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:44
virtual ~BaseJointPdf()
Destructor.
Definition: JointPdf.C:55

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