queso-0.51.1
PoweredJointPdf.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/PoweredJointPdf.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 BaseJointPdf<V,M>& srcDensity,
36  double exponent)
37  :
38  BaseJointPdf<V,M>(((std::string)(prefix)+"pow").c_str(),srcDensity.domainSet()),
39  m_srcDensity (srcDensity),
40  m_exponent (exponent)
41 {
42  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
43  *m_env.subDisplayFile() << "Entering PoweredJointPdf<V,M>::constructor()"
44  << ": prefix = " << m_prefix
45  << std::endl;
46  }
47 
48  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
49  *m_env.subDisplayFile() << "In PoweredJointPdf<V,M>::constructor()"
50  //<< ", prefix = " << m_prefix
51  << std::endl;
52  }
53 
54  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
55  *m_env.subDisplayFile() << "Leaving PoweredJointPdf<V,M>::constructor()"
56  << ": prefix = " << m_prefix
57  << std::endl;
58  }
59 }
60 // Destructor --------------------------------------
61 template<class V,class M>
63 {
64 }
65 // Math methods-------------------------------------
66 template<class V,class M>
67 void
69 {
70  m_srcDensity.setNormalizationStyle(value);
71  return;
72 }
73 //--------------------------------------------------
74 template<class V, class M>
75 double
77  const V& domainVector,
78  const V* domainDirection,
79  V* gradVector,
80  M* hessianMatrix,
81  V* hessianEffect) const
82 {
83  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
84  *m_env.subDisplayFile() << "Entering PoweredJointPdf<V,M>::actualValue()"
85  << ": domainVector = " << domainVector
86  << std::endl;
87  }
88 
89  UQ_FATAL_TEST_MACRO(domainVector.sizeLocal() != this->m_domainSet.vectorSpace().dimLocal(),
90  m_env.worldRank(),
91  "PoweredJointPdf<V,M>::actualValue()",
92  "invalid input");
93 
94  double value = m_srcDensity.actualValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect);
95 
96  UQ_FATAL_TEST_MACRO((domainDirection || gradVector || hessianMatrix || hessianEffect),
97  m_env.worldRank(),
98  "PoweredJointPdf<V,M>::actualValue()",
99  "incomplete code for domainDirection, gradVector, hessianMatrix and hessianEffect calculations");
100 
101  double returnValue = pow(value,m_exponent);
102  returnValue *= exp(m_logOfNormalizationFactor); // [PDF-08] ???
103 
104  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
105  *m_env.subDisplayFile() << "Leaving PoweredJointPdf<V,M>::actualValue()"
106  << ": domainVector = " << domainVector
107  << ", returnValue = " << returnValue
108  << std::endl;
109  }
110 
111  return returnValue;
112 }
113 //--------------------------------------------------
114 template<class V, class M>
115 double
117  const V& domainVector,
118  const V* domainDirection,
119  V* gradVector,
120  M* hessianMatrix,
121  V* hessianEffect) const
122 {
123  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
124  *m_env.subDisplayFile() << "Entering PoweredJointPdf<V,M>::lnValue()"
125  << ": domainVector = " << domainVector
126  << std::endl;
127  }
128 
129  double value = m_srcDensity.lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect);
130 
131  UQ_FATAL_TEST_MACRO((domainDirection || gradVector || hessianMatrix || hessianEffect),
132  m_env.worldRank(),
133  "PoweredJointPdf<V,M>::lnValue()",
134  "incomplete code for domainDirection, gradVector, hessianMatrix and hessianEffect calculations");
135 
136  double returnValue = m_exponent*value;
137  returnValue += m_logOfNormalizationFactor; // [PDF-08] ???
138 
139  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
140  *m_env.subDisplayFile() << "Leaving PoweredJointPdf<V,M>::lnValue()"
141  << ": domainVector = " << domainVector
142  << ", returnValue = " << returnValue
143  << std::endl;
144  }
145 
146  return returnValue;
147 }
148 //--------------------------------------------------
149 template<class V, class M>
150 double
151 PoweredJointPdf<V,M>::computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
152 {
153  double value = 0.;
154 
155  double volume = m_domainSet.volume();
156  if (((boost::math::isnan)(volume)) ||
157  (volume == -INFINITY ) ||
158  (volume == INFINITY ) ||
159  (volume <= 0. )) {
160  // Do nothing
161  }
162  else {
163  UQ_FATAL_TEST_MACRO(true,
164  m_env.worldRank(),
165  "PoweredJointPdf<V,M>::lnValue()",
166  "incomplete code for computeLogOfNormalizationFactor()");
167  }
168 
169  return value;
170 }
171 
172 } // End namespace QUESO
173 
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
void setNormalizationStyle(unsigned int value) const
Sets a value to be used in the normalization style of the powered PDF (ie, protected attribute m_srcD...
const BaseEnvironment & m_env
A class for handling a powered joint PDFs.
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the powered PDF.
PoweredJointPdf(const char *prefix, const BaseJointPdf< V, M > &srcDensity, double exponent)
Constructor.
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the powered PDF.
unsigned int displayVerbosity() const
Definition: Environment.C:436
~PoweredJointPdf()
Destructor.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
A templated (base) class for handling joint PDFs.
Definition: JointPdf.h:60
double computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
TODO: Computes the logarithm of the normalization factor.

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