queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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-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/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  queso_require_equal_to_msg(domainVector.sizeLocal(), this->m_domainSet.vectorSpace().dimLocal(), "invalid input");
90 
91  double value = m_srcDensity.actualValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect);
92 
93  queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect), "incomplete code for domainDirection, gradVector, hessianMatrix and hessianEffect calculations");
94 
95  double returnValue = pow(value,m_exponent);
96  returnValue *= exp(m_logOfNormalizationFactor); // [PDF-08] ???
97 
98  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
99  *m_env.subDisplayFile() << "Leaving PoweredJointPdf<V,M>::actualValue()"
100  << ": domainVector = " << domainVector
101  << ", returnValue = " << returnValue
102  << std::endl;
103  }
104 
105  return returnValue;
106 }
107 //--------------------------------------------------
108 template<class V, class M>
109 double
111  const V& domainVector,
112  const V* domainDirection,
113  V* gradVector,
114  M* hessianMatrix,
115  V* hessianEffect) const
116 {
117  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
118  *m_env.subDisplayFile() << "Entering PoweredJointPdf<V,M>::lnValue()"
119  << ": domainVector = " << domainVector
120  << std::endl;
121  }
122 
123  double value = m_srcDensity.lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect);
124 
125  queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect), "incomplete code for domainDirection, gradVector, hessianMatrix and hessianEffect calculations");
126 
127  double returnValue = m_exponent*value;
128  returnValue += m_logOfNormalizationFactor; // [PDF-08] ???
129 
130  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
131  *m_env.subDisplayFile() << "Leaving PoweredJointPdf<V,M>::lnValue()"
132  << ": domainVector = " << domainVector
133  << ", returnValue = " << returnValue
134  << std::endl;
135  }
136 
137  return returnValue;
138 }
139 //--------------------------------------------------
140 template<class V, class M>
141 double
142 PoweredJointPdf<V,M>::computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
143 {
144  double value = 0.;
145 
146  double volume = m_domainSet.volume();
147  if ((queso_isnan(volume)) ||
148  (volume == -INFINITY ) ||
149  (volume == INFINITY ) ||
150  (volume <= 0. )) {
151  // Do nothing
152  }
153  else {
154  queso_error_msg("incomplete code for computeLogOfNormalizationFactor()");
155  }
156 
157  return value;
158 }
159 
160 } // End namespace QUESO
161 
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...
~PoweredJointPdf()
Destructor.
double computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
TODO: Computes the logarithm of the normalization factor.
bool queso_isnan(T arg)
Definition: math_macros.h:39
const BaseEnvironment & m_env
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the powered PDF.
A templated (base) class for handling joint PDFs.
Definition: JointPdf.h:55
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.
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"))
unsigned int displayVerbosity() const
Definition: Environment.C:450
A class for handling a powered joint PDFs.
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