queso-0.51.1
Protected Attributes | List of all members
QUESO::ConcatenatedJointPdf< V, M > Class Template Reference

A class for handling concatenated PDFs. More...

#include <ConcatenatedJointPdf.h>

Inheritance diagram for QUESO::ConcatenatedJointPdf< V, M >:
Inheritance graph
[legend]
Collaboration diagram for QUESO::ConcatenatedJointPdf< V, M >:
Collaboration graph
[legend]

Public Member Functions

Constructor/Destructor methods
 ConcatenatedJointPdf (const char *prefix, const BaseJointPdf< V, M > &density1, const BaseJointPdf< V, M > &density2, const VectorSet< V, M > &concatenatedDomain)
 Constructor. More...
 
 ConcatenatedJointPdf (const char *prefix, const std::vector< const BaseJointPdf< V, M > * > &densities, const VectorSet< V, M > &concatenatedDomain)
 Constructor. More...
 
 ~ConcatenatedJointPdf ()
 Destructor. More...
 
Math methods
double actualValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Calculates the actual values of each density. More...
 
double lnValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Calculates the logarithm of the values of each density. More...
 
void setNormalizationStyle (unsigned int value) const
 Sets the normalization style of all densities to value. More...
 
double computeLogOfNormalizationFactor (unsigned int numSamples, bool updateFactorInternally) const
 Computes the logarithm of the normalization factor. More...
 
- Public Member Functions inherited from QUESO::BaseJointPdf< V, M >
 BaseJointPdf (const char *prefix, const VectorSet< V, M > &domainSet)
 Default constructor. More...
 
virtual ~BaseJointPdf ()
 Destructor. More...
 
void setLogOfNormalizationFactor (double value) const
 Sets a logarithmic value to be used in the normalization factor (stored in the protected attribute m_normalizationStyle.) More...
 
- Public Member Functions inherited from QUESO::BaseScalarFunction< V, M >
 BaseScalarFunction (const char *prefix, const VectorSet< V, M > &domainSet)
 Default constructor. More...
 
virtual ~BaseScalarFunction ()
 Destructor. More...
 
const VectorSet< V, M > & domainSet () const
 Access to the protected attribute m_domainSet: domain set of the scalar function. More...
 

Protected Attributes

std::vector< const
BaseJointPdf< V, M > * > 
m_densities
 
- Protected Attributes inherited from QUESO::BaseJointPdf< V, M >
unsigned int m_normalizationStyle
 
double m_logOfNormalizationFactor
 
- Protected Attributes inherited from QUESO::BaseScalarFunction< V, M >
const BaseEnvironmentm_env
 
std::string m_prefix
 
const VectorSet< V, M > & m_domainSet
 Domain set of the scalar function. More...
 

Additional Inherited Members

- Protected Member Functions inherited from QUESO::BaseJointPdf< V, M >
double commonComputeLogOfNormalizationFactor (unsigned int numSamples, bool updateFactorInternally) const
 Common method (to the derived classes) to compute the logarithm of the normalization factor. More...
 

Detailed Description

template<class V, class M>
class QUESO::ConcatenatedJointPdf< V, M >

A class for handling concatenated PDFs.

This class allows the user to defines concatenated probability density distributions, i.e, two or more distinct PDFs can be concatenated into one single PDF. This class used, for instance, to concatenate priors from two or more RVs, where one of them has a uniform distribution whereas the other one(s) has a Gaussian distribution.

Definition at line 52 of file ConcatenatedJointPdf.h.

Constructor & Destructor Documentation

template<class V , class M >
QUESO::ConcatenatedJointPdf< V, M >::ConcatenatedJointPdf ( const char *  prefix,
const BaseJointPdf< V, M > &  density1,
const BaseJointPdf< V, M > &  density2,
const VectorSet< V, M > &  concatenatedDomain 
)

Constructor.

Concatenates two PDFs: density1 and density2 into one vector PDF, given a prefix and the concatenated domain of such PDFs.

Definition at line 33 of file ConcatenatedJointPdf.C.

References QUESO::ConcatenatedJointPdf< V, M >::m_densities, QUESO::BaseScalarFunction< V, M >::m_env, UQ_FATAL_TEST_MACRO, QUESO::VectorSet< V, M >::vectorSpace(), and QUESO::BaseEnvironment::worldRank().

38  :
39  BaseJointPdf<V,M>(((std::string)(prefix)+"concat").c_str(),concatenatedDomain),
40  m_densities (2,(const BaseJointPdf<V,M>*) NULL)
41 {
42  m_densities[0] = &density1;
43  m_densities[1] = &density2;
44 
45  unsigned int size1 = m_densities[0]->domainSet().vectorSpace().dimLocal();
46  unsigned int size2 = m_densities[1]->domainSet().vectorSpace().dimLocal();
47  unsigned int size = concatenatedDomain.vectorSpace().dimLocal();
48 
49  UQ_FATAL_TEST_MACRO((size1+size2) != size,
50  m_env.worldRank(),
51  "ConcatenatedJointPdf<V,M>::constructor(1)",
52  "incompatible dimensions");
53 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
const BaseEnvironment & m_env
std::vector< const BaseJointPdf< V, M > * > m_densities
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
template<class V , class M >
QUESO::ConcatenatedJointPdf< V, M >::ConcatenatedJointPdf ( const char *  prefix,
const std::vector< const BaseJointPdf< V, M > * > &  densities,
const VectorSet< V, M > &  concatenatedDomain 
)

Constructor.

Concatenates a sequence of PDFs, given by: std::vector<const BaseJointPdf<V,M>* >& densities into one single PDF, given a prefix and the concatenated domain of such PDFs.

Definition at line 56 of file ConcatenatedJointPdf.C.

References QUESO::ConcatenatedJointPdf< V, M >::m_densities, QUESO::BaseScalarFunction< V, M >::m_env, UQ_FATAL_TEST_MACRO, QUESO::VectorSet< V, M >::vectorSpace(), and QUESO::BaseEnvironment::worldRank().

60  :
61  BaseJointPdf<V,M>(((std::string)(prefix)+"concat").c_str(),concatenatedDomain),
62  m_densities (densities.size(),(const BaseJointPdf<V,M>*) NULL)
63 {
64  unsigned int sumSizes = 0;
65  for (unsigned i = 0; i < m_densities.size(); ++i) {
66  m_densities[i] = densities[i];
67  sumSizes += m_densities[i]->domainSet().vectorSpace().dimLocal();
68  }
69 
70  unsigned int size = concatenatedDomain.vectorSpace().dimLocal();
71 
72  UQ_FATAL_TEST_MACRO(sumSizes != size,
73  m_env.worldRank(),
74  "ConcatenatedJointPdf<V,M>::constructor(2)",
75  "incompatible dimensions");
76 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
const BaseEnvironment & m_env
std::vector< const BaseJointPdf< V, M > * > m_densities
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
template<class V , class M >
QUESO::ConcatenatedJointPdf< V, M >::~ConcatenatedJointPdf ( )

Destructor.

Definition at line 79 of file ConcatenatedJointPdf.C.

80 {
81 }

Member Function Documentation

template<class V , class M >
double QUESO::ConcatenatedJointPdf< V, M >::actualValue ( const V &  domainVector,
const V *  domainDirection,
V *  gradVector,
M *  hessianMatrix,
V *  hessianEffect 
) const
virtual

Calculates the actual values of each density.

The final actual value is the multiplication of all values calculated.

Implements QUESO::BaseJointPdf< V, M >.

Definition at line 95 of file ConcatenatedJointPdf.C.

References UQ_FATAL_TEST_MACRO.

101 {
102  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
103  *m_env.subDisplayFile() << "Entering ConcatenatedJointPdf<V,M>::actualValue()"
104  << ": domainVector = " << domainVector
105  << std::endl;
106  }
107 
108  UQ_FATAL_TEST_MACRO(domainVector.sizeLocal() != this->m_domainSet.vectorSpace().dimLocal(),
109  m_env.worldRank(),
110  "ConcatenatedJointPdf<V,M>::actualValue()",
111  "invalid input");
112 
113  UQ_FATAL_TEST_MACRO((domainDirection || gradVector || hessianMatrix || hessianEffect),
114  m_env.worldRank(),
115  "ConcatenatedJointPdf<V,M>::actualValue()",
116  "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
117 
118  std::vector<V*> vecs(m_densities.size(),(V*) NULL);
119  std::vector<double> values(m_densities.size(),0.);
120  double returnValue = 1.;
121  unsigned int cummulativeSize = 0;
122  for (unsigned int i = 0; i < vecs.size(); ++i) {
123  vecs[i] = new V(m_densities[i]->domainSet().vectorSpace().zeroVector());
124  domainVector.cwExtract(cummulativeSize,*(vecs[i]));
125  values[i] = m_densities[i]->actualValue(*(vecs[i]),NULL,NULL,NULL,NULL);
126  returnValue *= values[i];
127  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
128  *m_env.subDisplayFile() << "In ConcatenatedJointPdf<V,M>::actualValue()"
129  << ", *(vecs[" << i << "]) = " << *(vecs[i])
130  << ": values[" << i << "] = " << values[i]
131  << ", temporary cumulative value = " << returnValue
132  << std::endl;
133  }
134  cummulativeSize += vecs[i]->sizeLocal();
135  delete vecs[i];
136  }
137  //returnValue *= exp(m_logOfNormalizationFactor); // No need, because each PDF should be already normalized [PDF-11]
138 
139  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
140  *m_env.subDisplayFile() << "Leaving ConcatenatedJointPdf<V,M>::actualValue()"
141  << ": domainVector = " << domainVector
142  << ", returnValue = " << returnValue
143  << std::endl;
144  }
145 
146  return returnValue;
147 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
const BaseEnvironment & m_env
std::vector< const BaseJointPdf< V, M > * > m_densities
unsigned int displayVerbosity() const
Definition: Environment.C:436
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
template<class V , class M >
double QUESO::ConcatenatedJointPdf< V, M >::computeLogOfNormalizationFactor ( unsigned int  numSamples,
bool  updateFactorInternally 
) const
virtual

Computes the logarithm of the normalization factor.

This method calls the computeLogOfNormalizationFactor() for each one of the densities that have been concatenated.

Implements QUESO::BaseJointPdf< V, M >.

Definition at line 202 of file ConcatenatedJointPdf.C.

203 {
204  double value = 0.;
205 
206  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
207  *m_env.subDisplayFile() << "Entering ConcatenatedJointPdf<V,M>::computeLogOfNormalizationFactor()"
208  << std::endl;
209  }
210  double volume = m_domainSet.volume();
211  if (((boost::math::isnan)(volume)) ||
212  (volume == -INFINITY ) ||
213  (volume == INFINITY ) ||
214  (volume <= 0. )) {
215  // Do nothing
216  }
217  else {
218  for (unsigned int i = 0; i < m_densities.size(); ++i) {
219  m_densities[i]->computeLogOfNormalizationFactor(numSamples, updateFactorInternally);
220  }
221  }
222  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
223  *m_env.subDisplayFile() << "Leaving ConcatenatedJointPdf<V,M>::computeLogOfNormalizationFactor()"
224  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
225  << std::endl;
226  }
227 
228  return value;
229 }
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
double m_logOfNormalizationFactor
Definition: JointPdf.h:104
const BaseEnvironment & m_env
std::vector< const BaseJointPdf< V, M > * > m_densities
unsigned int displayVerbosity() const
Definition: Environment.C:436
template<class V , class M >
double QUESO::ConcatenatedJointPdf< V, M >::lnValue ( const V &  domainVector,
const V *  domainDirection,
V *  gradVector,
M *  hessianMatrix,
V *  hessianEffect 
) const
virtual

Calculates the logarithm of the values of each density.

The final logarithm value is the addition of all values calculated.

Implements QUESO::BaseJointPdf< V, M >.

Definition at line 151 of file ConcatenatedJointPdf.C.

References UQ_FATAL_TEST_MACRO.

157 {
158  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
159  *m_env.subDisplayFile() << "Entering ConcatenatedJointPdf<V,M>::lnValue()"
160  << ": domainVector = " << domainVector
161  << std::endl;
162  }
163 
164  UQ_FATAL_TEST_MACRO((domainDirection || gradVector || hessianMatrix || hessianEffect),
165  m_env.worldRank(),
166  "ConcatenatedJointPdf<V,M>::lnValue()",
167  "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
168 
169  std::vector<V*> vecs(m_densities.size(),(V*) NULL);
170  std::vector<double> values(m_densities.size(),0.);
171  double returnValue = 0.;
172  unsigned int cummulativeSize = 0;
173  for (unsigned int i = 0; i < vecs.size(); ++i) {
174  vecs[i] = new V(m_densities[i]->domainSet().vectorSpace().zeroVector());
175  domainVector.cwExtract(cummulativeSize,*(vecs[i]));
176  values[i] = m_densities[i]->lnValue(*(vecs[i]),NULL,NULL,NULL,NULL);
177  returnValue += values[i];
178  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) { // gpmsa
179  *m_env.subDisplayFile() << "In ConcatenatedJointPdf<V,M>::lnValue()"
180  << ", *(vecs[" << i << "]) = " << *(vecs[i])
181  << ": values[" << i << "] = " << values[i]
182  << ", temporary cumulative value = " << returnValue
183  << std::endl;
184  }
185  cummulativeSize += vecs[i]->sizeLocal();
186  delete vecs[i];
187  }
188  //returnValue += m_logOfNormalizationFactor; // No need, because each PDF should be already normalized [PDF-11]
189 
190  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
191  *m_env.subDisplayFile() << "Leaving ConcatenatedJointPdf<V,M>::lnValue()"
192  << ": domainVector = " << domainVector
193  << ", returnValue = " << returnValue
194  << std::endl;
195  }
196 
197  return returnValue;
198 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
const BaseEnvironment & m_env
std::vector< const BaseJointPdf< V, M > * > m_densities
unsigned int displayVerbosity() const
Definition: Environment.C:436
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
template<class V , class M >
void QUESO::ConcatenatedJointPdf< V, M >::setNormalizationStyle ( unsigned int  value) const
virtual

Sets the normalization style of all densities to value.

Reimplemented from QUESO::BaseJointPdf< V, M >.

Definition at line 85 of file ConcatenatedJointPdf.C.

86 {
87  for (unsigned i = 0; i < m_densities.size(); ++i) {
88  m_densities[i]->setNormalizationStyle(value);
89  }
90  return;
91 }
std::vector< const BaseJointPdf< V, M > * > m_densities

Member Data Documentation

template<class V, class M>
std::vector<const BaseJointPdf<V,M>* > QUESO::ConcatenatedJointPdf< V, M >::m_densities
protected

The documentation for this class was generated from the following files:

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