queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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-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/GammaJointPdf.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 #include <queso/BasicPdfsBase.h>
29 
30 namespace QUESO {
31 
32 // Constructor -------------------------------------
33 template<class V,class M>
35  const char* prefix,
36  const VectorSet<V,M>& domainSet,
37  const V& a,
38  const V& b)
39  :
40  BaseJointPdf<V,M>(((std::string)(prefix)+"uni").c_str(),domainSet),
41  m_a(a),
42  m_b(b)
43 {
44  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
45  *m_env.subDisplayFile() << "Entering GammaJointPdf<V,M>::constructor()"
46  << ": prefix = " << m_prefix
47  << std::endl;
48  }
49 
50  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
51  *m_env.subDisplayFile() << "Leaving GammaJointPdf<V,M>::constructor()"
52  << ": prefix = " << m_prefix
53  << std::endl;
54  }
55 }
56 // Destructor --------------------------------------
57 template<class V,class M>
59 {
60 }
61 // Math methods-------------------------------------
62 template<class V, class M>
63 double
65  const V& domainVector,
66  const V* domainDirection,
67  V* gradVector,
68  M* hessianMatrix,
69  V* hessianEffect) const
70 {
71  queso_require_equal_to_msg(domainVector.sizeLocal(), this->m_domainSet.vectorSpace().dimLocal(), "invalid input");
72 
73  queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect), "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
74 
75  // No need to multiply by exp(m_logOfNormalizationFactor) because 'lnValue()' is called [PDF-06]
76  return exp(this->lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect));
77 }
78 //--------------------------------------------------
79 template<class V, class M>
80 double
82  const V& domainVector,
83  const V* domainDirection,
84  V* gradVector,
85  M* hessianMatrix,
86  V* hessianEffect) const
87 {
88  queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect), "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
89 
90  double aux = 0.;
91  double result = 0.;
92  for (unsigned int i = 0; i < domainVector.sizeLocal(); ++i) {
93  if (m_normalizationStyle == 0) {
94  aux = log(m_env.basicPdfs()->gammaPdfActualValue(domainVector[i],m_a[i],m_b[i]));
95  }
96  else {
97  aux = (m_a[i]-1.)*log(domainVector[i]) - domainVector[i]/m_b[i];
98  }
99  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
100  *m_env.subDisplayFile() << "In GammaJointPdf<V,M>::lnValue()"
101  << ", m_normalizationStyle = " << m_normalizationStyle
102  << ": domainVector[" << i << "] = " << domainVector[i]
103  << ", m_a[" << i << "] = " << m_a[i]
104  << ", m_b[" << i << "] = " << m_b[i]
105  << ", log(pdf)= " << aux
106  << std::endl;
107  }
108  result += aux;
109  }
110  result += m_logOfNormalizationFactor; // [PDF-06]
111 
112  return result;
113 }
114 //--------------------------------------------------
115 template<class V, class M>
116 void
118 {
119  queso_assert_equal_to(m_a.sizeLocal(), m_b.sizeLocal());
120  queso_assert_equal_to(m_a.sizeLocal(), meanVector.sizeLocal());
121 
122  for (unsigned int i = 0; i < m_a.sizeLocal(); ++i) {
123  meanVector[i] = m_a[i] * m_b[i];
124  }
125 }
126 //--------------------------------------------------
127 template<class V, class M>
128 void
130 {
131  queso_assert_equal_to(m_a.sizeLocal(), m_b.sizeLocal());
132  queso_assert_equal_to(m_a.sizeLocal(), covMatrix.numRowsGlobal());
133  queso_assert_equal_to(covMatrix.numCols(), covMatrix.numRowsGlobal());
134 
135  covMatrix.zeroLower();
136  covMatrix.zeroUpper();
137 
138  for (unsigned int i = 0; i < m_a.sizeLocal(); ++i) {
139  covMatrix(i,i) = m_a[i] * m_b[i] * m_b[i];
140  }
141 }
142 //--------------------------------------------------
143 template<class V, class M>
144 double
145 GammaJointPdf<V,M>::computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
146 {
147  double value = 0.;
148 
149  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
150  *m_env.subDisplayFile() << "Entering GammaJointPdf<V,M>::computeLogOfNormalizationFactor()"
151  << std::endl;
152  }
153  value = BaseJointPdf<V,M>::commonComputeLogOfNormalizationFactor(numSamples, updateFactorInternally);
154  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
155  *m_env.subDisplayFile() << "Leaving GammaJointPdf<V,M>::computeLogOfNormalizationFactor()"
156  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
157  << std::endl;
158  }
159 
160  return value;
161 }
162 
163 } // End namespace QUESO
164 
GammaJointPdf(const char *prefix, const VectorSet< V, M > &domainSet, const V &a, const V &b)
Definition: GammaJointPdf.C:34
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:81
A templated class for handling sets.
Definition: VectorSet.h:52
A class for handling Gamma joint PDFs.
Definition: GammaJointPdf.h:47
double computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Computes the logarithm of the normalization factor.
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
const BaseEnvironment & m_env
A templated (base) class for handling joint PDFs.
Definition: JointPdf.h:55
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"))
virtual void distributionVariance(M &covMatrix) const
Covariance matrix of the underlying random variable.
unsigned int displayVerbosity() const
Definition: Environment.C:450
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the Gamma PDF.
Definition: GammaJointPdf.C:64
~GammaJointPdf()
Destructor.
Definition: GammaJointPdf.C:58
virtual void distributionMean(V &meanVector) const
Mean value of the underlying random variable.
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:55 for queso-0.57.1 by  doxygen 1.8.5