queso-0.52.0
WignerJointPdf.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/WignerJointPdf.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& centerPos,
37  double radius)
38  :
39  BaseJointPdf<V,M>(((std::string)(prefix)+"uni").c_str(),
40  domainSet),
41  m_centerPos(new V(centerPos)),
42  m_radius (radius)
43 {
44  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
45  *m_env.subDisplayFile() << "Entering WignerJointPdf<V,M>::constructor()"
46  << ": prefix = " << m_prefix
47  << std::endl;
48  }
49 
51  m_env.worldRank(),
52  "WignerJointPdf<V,M>::constructor()",
53  "invalid radius");
54 
55  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
56  *m_env.subDisplayFile() << "Leaving WignerJointPdf<V,M>::constructor()"
57  << ": prefix = " << m_prefix
58  << std::endl;
59  }
60 }
61 // Destructor --------------------------------------
62 template<class V,class M>
64 {
65  delete m_centerPos;
66 }
67 // Math methods-------------------------------------
68 template<class V, class M>
69 double
71  const V& domainVector,
72  const V* domainDirection,
73  V* gradVector,
74  M* hessianMatrix,
75  V* hessianEffect) const
76 {
77  UQ_FATAL_TEST_MACRO(domainVector.sizeLocal() != this->m_domainSet.vectorSpace().dimLocal(),
78  m_env.worldRank(),
79  "WignerJointPdf<V,M>::actualValue()",
80  "invalid input");
81 
82  if (gradVector ) *gradVector = m_domainSet.vectorSpace().zeroVector();
83  if (hessianMatrix) *hessianMatrix *= 0.;
84  if (hessianEffect) *hessianEffect = m_domainSet.vectorSpace().zeroVector();
85 
86  double returnValue = 0.;
87  double distanceRatio = (domainVector - *m_centerPos).norm2()/m_radius;
88  if (distanceRatio < 1.) {
89  returnValue = 2.*m_radius*m_radius*sqrt(1. - distanceRatio*distanceRatio)/M_PI;
90  }
91  returnValue *= exp(m_logOfNormalizationFactor); // [PDF-09]
92 
93  return returnValue;
94 }
95 //--------------------------------------------------
96 template<class V, class M>
97 double
99  const V& domainVector,
100  const V* domainDirection,
101  V* gradVector,
102  M* hessianMatrix,
103  V* hessianEffect) const
104 {
105  if (gradVector ) *gradVector = m_domainSet.vectorSpace().zeroVector();
106  if (hessianMatrix) *hessianMatrix *= 0.;
107  if (hessianEffect) *hessianEffect = m_domainSet.vectorSpace().zeroVector();
108 
109  // No need to add m_logOfNormalizationFactor because 'actualValue()' is called [PDF-09]
110  return log(this->actualValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect));
111 }
112 //--------------------------------------------------
113 template<class V, class M>
114 double
115 WignerJointPdf<V,M>::computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
116 {
117  double value = 0.;
118 
119  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
120  *m_env.subDisplayFile() << "Entering WignerJointPdf<V,M>::computeLogOfNormalizationFactor()"
121  << std::endl;
122  }
123  value = BaseJointPdf<V,M>::commonComputeLogOfNormalizationFactor(numSamples, updateFactorInternally);
124  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
125  *m_env.subDisplayFile() << "Leaving WignerJointPdf<V,M>::computeLogOfNormalizationFactor()"
126  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
127  << std::endl;
128  }
129 
130  return value;
131 }
132 
133 } // End namespace QUESO
134 
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Computes the logarithm of the value of the function.
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
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
WignerJointPdf(const char *prefix, const VectorSet< V, M > &domainSet, const V &centerPos, double radius)
Constructor.
#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 class for handling Wigner joint PDFs.
A templated (base) class for handling joint PDFs.
Definition: JointPdf.h:60
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
~WignerJointPdf()
Destructor.
unsigned int displayVerbosity() const
Definition: Environment.C:436
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the PDF (scalar function).
const BaseEnvironment & m_env

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