queso-0.52.0
GammaJointPdf.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/GammaJointPdf.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  const V& a,
37  const V& b)
38  :
39  BaseJointPdf<V,M>(((std::string)(prefix)+"uni").c_str(),domainSet),
40  m_a(a),
41  m_b(b)
42 {
43  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
44  *m_env.subDisplayFile() << "Entering GammaJointPdf<V,M>::constructor()"
45  << ": prefix = " << m_prefix
46  << std::endl;
47  }
48 
49  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
50  *m_env.subDisplayFile() << "Leaving GammaJointPdf<V,M>::constructor()"
51  << ": prefix = " << m_prefix
52  << std::endl;
53  }
54 }
55 // Destructor --------------------------------------
56 template<class V,class M>
58 {
59 }
60 // Math methods-------------------------------------
61 template<class V, class M>
62 double
64  const V& domainVector,
65  const V* domainDirection,
66  V* gradVector,
67  M* hessianMatrix,
68  V* hessianEffect) const
69 {
70  UQ_FATAL_TEST_MACRO(domainVector.sizeLocal() != this->m_domainSet.vectorSpace().dimLocal(),
71  m_env.worldRank(),
72  "GammaJointPdf<V,M>::actualValue()",
73  "invalid input");
74 
75  UQ_FATAL_TEST_MACRO((domainDirection || gradVector || hessianMatrix || hessianEffect),
76  m_env.worldRank(),
77  "GammaJointPdf<V,M>::actualValue()",
78  "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
79 
80  // No need to multiply by exp(m_logOfNormalizationFactor) because 'lnValue()' is called [PDF-06]
81  return exp(this->lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect));
82 }
83 //--------------------------------------------------
84 template<class V, class M>
85 double
87  const V& domainVector,
88  const V* domainDirection,
89  V* gradVector,
90  M* hessianMatrix,
91  V* hessianEffect) const
92 {
93  UQ_FATAL_TEST_MACRO((domainDirection || gradVector || hessianMatrix || hessianEffect),
94  m_env.worldRank(),
95  "GammaJointPdf<V,M>::lnValue()",
96  "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
97 
98  double aux = 0.;
99  double result = 0.;
100  for (unsigned int i = 0; i < domainVector.sizeLocal(); ++i) {
101  if (m_normalizationStyle == 0) {
102  //aux = log(gsl_ran_gamma_pdf(domainVector[i],m_a[i],m_b[i]));
103  aux = log(m_env.basicPdfs()->gammaPdfActualValue(domainVector[i],m_a[i],m_b[i]));
104  }
105  else {
106  aux = (m_a[i]-1.)*log(domainVector[i]) - domainVector[i]/m_b[i];
107  }
108  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
109  *m_env.subDisplayFile() << "In GammaJointPdf<V,M>::lnValue()"
110  << ", m_normalizationStyle = " << m_normalizationStyle
111  << ": domainVector[" << i << "] = " << domainVector[i]
112  << ", m_a[" << i << "] = " << m_a[i]
113  << ", m_b[" << i << "] = " << m_b[i]
114  << ", log(pdf)= " << aux
115  << std::endl;
116  }
117  result += aux;
118  }
119  result += m_logOfNormalizationFactor; // [PDF-06]
120 
121  return result;
122 }
123 //--------------------------------------------------
124 template<class V, class M>
125 double
126 GammaJointPdf<V,M>::computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
127 {
128  double value = 0.;
129 
130  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
131  *m_env.subDisplayFile() << "Entering GammaJointPdf<V,M>::computeLogOfNormalizationFactor()"
132  << std::endl;
133  }
134  value = BaseJointPdf<V,M>::commonComputeLogOfNormalizationFactor(numSamples, updateFactorInternally);
135  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
136  *m_env.subDisplayFile() << "Leaving GammaJointPdf<V,M>::computeLogOfNormalizationFactor()"
137  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
138  << std::endl;
139  }
140 
141  return value;
142 }
143 
144 } // End namespace QUESO
145 
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the Gamma PDF.
Definition: GammaJointPdf.C:86
A templated class for handling sets.
Definition: VectorSet.h:49
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
GammaJointPdf(const char *prefix, const VectorSet< V, M > &domainSet, const V &a, const V &b)
Constructor.
Definition: GammaJointPdf.C:33
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
double computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Computes the logarithm of the normalization factor.
A templated (base) class for handling joint PDFs.
Definition: JointPdf.h:60
A class for handling Gamma joint PDFs.
Definition: GammaJointPdf.h:49
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
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the Gamma PDF.
Definition: GammaJointPdf.C:63
~GammaJointPdf()
Destructor.
Definition: GammaJointPdf.C:57
unsigned int displayVerbosity() const
Definition: Environment.C:436
const BaseEnvironment & m_env

Generated on Thu Apr 23 2015 19:30:54 for queso-0.52.0 by  doxygen 1.8.5