queso-0.53.0
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 = GslVector, class M = GslMatrix>
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 55 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_require_equal_to_msg, and QUESO::VectorSet< V, M >::vectorSpace().

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  queso_require_equal_to_msg((size1+size2), size, "incompatible dimensions");
50 }
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
std::vector< const BaseJointPdf< V, M > * > m_densities
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 53 of file ConcatenatedJointPdf.C.

References QUESO::ConcatenatedJointPdf< V, M >::m_densities, queso_require_equal_to_msg, and QUESO::VectorSet< V, M >::vectorSpace().

57  :
58  BaseJointPdf<V,M>(((std::string)(prefix)+"concat").c_str(),concatenatedDomain),
59  m_densities (densities.size(),(const BaseJointPdf<V,M>*) NULL)
60 {
61  unsigned int sumSizes = 0;
62  for (unsigned i = 0; i < m_densities.size(); ++i) {
63  m_densities[i] = densities[i];
64  sumSizes += m_densities[i]->domainSet().vectorSpace().dimLocal();
65  }
66 
67  unsigned int size = concatenatedDomain.vectorSpace().dimLocal();
68 
69  queso_require_equal_to_msg(sumSizes, size, "incompatible dimensions");
70 }
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
std::vector< const BaseJointPdf< V, M > * > m_densities
template<class V , class M >
QUESO::ConcatenatedJointPdf< V, M >::~ConcatenatedJointPdf ( )

Destructor.

Definition at line 73 of file ConcatenatedJointPdf.C.

74 {
75 }

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 89 of file ConcatenatedJointPdf.C.

References queso_require_equal_to_msg, and queso_require_msg.

95 {
96  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
97  *m_env.subDisplayFile() << "Entering ConcatenatedJointPdf<V,M>::actualValue()"
98  << ": domainVector = " << domainVector
99  << std::endl;
100  }
101 
102  queso_require_equal_to_msg(domainVector.sizeLocal(), this->m_domainSet.vectorSpace().dimLocal(), "invalid input");
103 
104  queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect), "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
105 
106  std::vector<V*> vecs(m_densities.size(),(V*) NULL);
107  std::vector<double> values(m_densities.size(),0.);
108  double returnValue = 1.;
109  unsigned int cummulativeSize = 0;
110  for (unsigned int i = 0; i < vecs.size(); ++i) {
111  vecs[i] = new V(m_densities[i]->domainSet().vectorSpace().zeroVector());
112  domainVector.cwExtract(cummulativeSize,*(vecs[i]));
113  values[i] = m_densities[i]->actualValue(*(vecs[i]),NULL,NULL,NULL,NULL);
114  returnValue *= values[i];
115  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
116  *m_env.subDisplayFile() << "In ConcatenatedJointPdf<V,M>::actualValue()"
117  << ", *(vecs[" << i << "]) = " << *(vecs[i])
118  << ": values[" << i << "] = " << values[i]
119  << ", temporary cumulative value = " << returnValue
120  << std::endl;
121  }
122  cummulativeSize += vecs[i]->sizeLocal();
123  delete vecs[i];
124  }
125  //returnValue *= exp(m_logOfNormalizationFactor); // No need, because each PDF should be already normalized [PDF-11]
126 
127  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
128  *m_env.subDisplayFile() << "Leaving ConcatenatedJointPdf<V,M>::actualValue()"
129  << ": domainVector = " << domainVector
130  << ", returnValue = " << returnValue
131  << std::endl;
132  }
133 
134  return returnValue;
135 }
unsigned int displayVerbosity() const
Definition: Environment.C:396
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
const BaseEnvironment & m_env
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
std::vector< const BaseJointPdf< V, M > * > m_densities
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 187 of file ConcatenatedJointPdf.C.

188 {
189  double value = 0.;
190 
191  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
192  *m_env.subDisplayFile() << "Entering ConcatenatedJointPdf<V,M>::computeLogOfNormalizationFactor()"
193  << std::endl;
194  }
195  double volume = m_domainSet.volume();
196  if (((boost::math::isnan)(volume)) ||
197  (volume == -INFINITY ) ||
198  (volume == INFINITY ) ||
199  (volume <= 0. )) {
200  // Do nothing
201  }
202  else {
203  for (unsigned int i = 0; i < m_densities.size(); ++i) {
204  m_densities[i]->computeLogOfNormalizationFactor(numSamples, updateFactorInternally);
205  }
206  }
207  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
208  *m_env.subDisplayFile() << "Leaving ConcatenatedJointPdf<V,M>::computeLogOfNormalizationFactor()"
209  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
210  << std::endl;
211  }
212 
213  return value;
214 }
unsigned int displayVerbosity() const
Definition: Environment.C:396
double m_logOfNormalizationFactor
Definition: JointPdf.h:100
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
const BaseEnvironment & m_env
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
std::vector< const BaseJointPdf< V, M > * > m_densities
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 139 of file ConcatenatedJointPdf.C.

References queso_require_msg.

145 {
146  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
147  *m_env.subDisplayFile() << "Entering ConcatenatedJointPdf<V,M>::lnValue()"
148  << ": domainVector = " << domainVector
149  << std::endl;
150  }
151 
152  queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect), "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
153 
154  std::vector<V*> vecs(m_densities.size(),(V*) NULL);
155  std::vector<double> values(m_densities.size(),0.);
156  double returnValue = 0.;
157  unsigned int cummulativeSize = 0;
158  for (unsigned int i = 0; i < vecs.size(); ++i) {
159  vecs[i] = new V(m_densities[i]->domainSet().vectorSpace().zeroVector());
160  domainVector.cwExtract(cummulativeSize,*(vecs[i]));
161  values[i] = m_densities[i]->lnValue(*(vecs[i]),NULL,NULL,NULL,NULL);
162  returnValue += values[i];
163  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) { // gpmsa
164  *m_env.subDisplayFile() << "In ConcatenatedJointPdf<V,M>::lnValue()"
165  << ", *(vecs[" << i << "]) = " << *(vecs[i])
166  << ": values[" << i << "] = " << values[i]
167  << ", temporary cumulative value = " << returnValue
168  << std::endl;
169  }
170  cummulativeSize += vecs[i]->sizeLocal();
171  delete vecs[i];
172  }
173  //returnValue += m_logOfNormalizationFactor; // No need, because each PDF should be already normalized [PDF-11]
174 
175  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
176  *m_env.subDisplayFile() << "Leaving ConcatenatedJointPdf<V,M>::lnValue()"
177  << ": domainVector = " << domainVector
178  << ", returnValue = " << returnValue
179  << std::endl;
180  }
181 
182  return returnValue;
183 }
unsigned int displayVerbosity() const
Definition: Environment.C:396
const BaseEnvironment & m_env
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
std::vector< const BaseJointPdf< V, M > * > m_densities
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 79 of file ConcatenatedJointPdf.C.

80 {
81  for (unsigned i = 0; i < m_densities.size(); ++i) {
82  m_densities[i]->setNormalizationStyle(value);
83  }
84  return;
85 }
std::vector< const BaseJointPdf< V, M > * > m_densities

Member Data Documentation

template<class V = GslVector, class M = GslMatrix>
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 Jun 11 2015 13:52:35 for queso-0.53.0 by  doxygen 1.8.5