queso-0.56.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 
59 //---------------------------------------------------
60 template<class V,class M>
61 void
63 {
65 }
66 
67 //---------------------------------------------------
68 template<class V,class M>
69 void
71 {
73 }
74 
75 // Math methods -------------------------------------
76 template<class V,class M>
77 void
79 {
80  m_normalizationStyle = value;
81  return;
82 }
83 //---------------------------------------------------
84 template<class V,class M>
85 void
87 {
88  m_logOfNormalizationFactor = value;
89  return;
90 }
91 
92 template <class V, class M>
93 void
94 BaseJointPdf<V, M>::print(std::ostream & os) const
95 {
96  // Print m_env?
97  // Print mean?
98  // Print var?
99 
100  os << "Start printing BaseJointPdf<V, M>" << std::endl;
101  os << "m_prefix:" << std::endl;
102  os << this->m_prefix << std::endl;
103  os << "m_domainSet:" << std::endl;
104  os << this->m_domainSet << std::endl;
105  os << "m_normalizationStyle:" << std::endl;
106  os << this->m_normalizationStyle << std::endl;
107  os << "m_logOfNormalizationFactor:" << std::endl;
108  os << this->m_logOfNormalizationFactor << std::endl;
109  os << "End printing BaseJointPdf<V, M>" << std::endl;
110 }
111 
112 //---------------------------------------------------
113 template<class V,class M>
114 double
115 BaseJointPdf<V,M>::commonComputeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
116 {
117  double value = 0.;
118 
119  double volume = m_domainSet.volume();
120  if ((queso_isnan(volume)) ||
121  (volume == -INFINITY ) ||
122  (volume == INFINITY ) ||
123  (volume <= 0. )) {
124  // Do nothing
125  }
126  else {
127  const BoxSubset<V,M>* boxSubset = dynamic_cast<const BoxSubset<V,M>* >(&m_domainSet);
128  if (boxSubset == NULL) {
129  // Do nothing
130  }
131  else {
132  V tmpVec(m_domainSet.vectorSpace().zeroVector());
133  double sum = 0.;
134  for (unsigned int i = 0; i < numSamples; ++i) {
135  tmpVec.cwSetUniform(boxSubset->minValues(),boxSubset->maxValues());
136  sum += this->actualValue(tmpVec,NULL,NULL,NULL,NULL);
137  }
138  double avgValue = sum/((double) numSamples);
139  value = -( log(avgValue) + log(volume) );
140  if (updateFactorInternally) {
141  m_logOfNormalizationFactor = value;
142  }
143  }
144  }
145 
146  return value;
147 }
148 
149 #if 0
150 template <class V, class M>
151 const BaseScalarPdf&
152 BaseJointPdf<V,M>::component(unsigned int componentId) const
153 {
154  if (componentId > m_components.size()) return m_dummyComponent;
155  if (m_components[componentId] == NULL) return m_dummyComponent;
156  return *(m_components[componentId]);
157 }
158 #endif
159 
160 } // End namespace QUESO
161 
A templated (base) class for handling scalar functions.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
virtual void distributionMean(V &meanVector) const
Definition: JointPdf.C:62
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:86
virtual void print(std::ostream &os) const
Print method. Non-pure for backwards compatibility.
Definition: JointPdf.C:94
virtual ~BaseJointPdf()
Destructor.
Definition: JointPdf.C:55
A templated (base) class for handling joint PDFs.
Definition: JointPdf.h:55
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:44
BaseJointPdf(const char *prefix, const VectorSet< V, M > &domainSet)
Default constructor.
Definition: JointPdf.C:33
virtual void distributionVariance(M &covMatrix) const
Definition: JointPdf.C:70
bool queso_isnan(T arg)
Definition: math_macros.h:39
A templated class for handling sets.
Definition: VectorSet.h:52
#define queso_not_implemented()
Definition: asserts.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:115
unsigned int displayVerbosity() const
Definition: Environment.C:449
const BaseEnvironment & m_env
const V & minValues() const
Vector of the minimum values of the box subset.
Definition: BoxSubset.C:95
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:78
const V & maxValues() const
Vector of the maximum values of the box subset.
Definition: BoxSubset.C:101

Generated on Tue Nov 29 2016 10:53:11 for queso-0.56.0 by  doxygen 1.8.5