queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::ConcatenatedJointPdf< V, M > Class Template Reference

A class for handling concatenated PDFs. More...

#include <ConcatenatedJointPdf.h>

Inheritance diagram for QUESO::ConcatenatedJointPdf< V, M >:
QUESO::BaseJointPdf< V, M > QUESO::BaseScalarFunction< V, M >

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...
 
virtual void distributionMean (V &meanVector) const
 Mean value of the underlying random variable. More...
 
virtual void distributionVariance (M &covMatrix) const
 Covariance matrix of the underlying random variable. 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...
 
virtual void print (std::ostream &os) const
 Print method. Non-pure for backwards compatibility. More...
 
- Public Member Functions inherited from QUESO::BaseScalarFunction< V, M >
void setFiniteDifferenceStepSize (double fdStepSize)
 Sets the step size for finite differencing gradients. More...
 
void setFiniteDifferenceStepSize (unsigned int i, double fdStepSize)
 
 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...
 
virtual double lnValue (const V &domainVector) const
 Returns the logarithm of the function at domainVector. More...
 
virtual double lnValue (const V &domainVector, V &gradVector) const
 Returns the logarithm of the function and its gradient at domainVector. More...
 
virtual double lnValue (const V &domainVector, V &gradVector, const V &domainDirection, V &hessianEffect) const
 

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 53 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::queso_require_equal_to_msg, QUESO::size, 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 }
std::vector< const BaseJointPdf< V, M > * > m_densities
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"))
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::queso_require_equal_to_msg, QUESO::size, 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 }
std::vector< const BaseJointPdf< V, M > * > m_densities
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"))
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::queso_require_equal_to_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  double returnValue = 1.;
107  unsigned int cumulativeSize = 0;
108  for (unsigned int i = 0; i < m_densities.size(); ++i) {
109  V vec_i(m_densities[i]->domainSet().vectorSpace().zeroVector());
110  domainVector.cwExtract(cumulativeSize,vec_i);
111  double value_i = m_densities[i]->actualValue(vec_i,NULL,NULL,NULL,NULL);
112  returnValue *= value_i;
113  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
114  *m_env.subDisplayFile() << "In ConcatenatedJointPdf<V,M>::actualValue()"
115  << ", vec_" << i << ") = " << vec_i
116  << ": value_" << i << " = " << value_i
117  << ", temporary cumulative value = " << returnValue
118  << std::endl;
119  }
120  cumulativeSize += vec_i.sizeLocal();
121  }
122  //returnValue *= exp(m_logOfNormalizationFactor); // No need, because each PDF should be already normalized [PDF-11]
123 
124  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
125  *m_env.subDisplayFile() << "Leaving ConcatenatedJointPdf<V,M>::actualValue()"
126  << ": domainVector = " << domainVector
127  << ", returnValue = " << returnValue
128  << std::endl;
129  }
130 
131  return returnValue;
132 }
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
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"))
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
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 216 of file ConcatenatedJointPdf.C.

References QUESO::queso_isnan().

217 {
218  double value = 0.;
219 
220  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
221  *m_env.subDisplayFile() << "Entering ConcatenatedJointPdf<V,M>::computeLogOfNormalizationFactor()"
222  << std::endl;
223  }
224  double volume = m_domainSet.volume();
225  if ((queso_isnan(volume)) ||
226  (volume == -INFINITY ) ||
227  (volume == INFINITY ) ||
228  (volume <= 0. )) {
229  // Do nothing
230  }
231  else {
232  for (unsigned int i = 0; i < m_densities.size(); ++i) {
233  m_densities[i]->computeLogOfNormalizationFactor(numSamples, updateFactorInternally);
234  }
235  }
236  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
237  *m_env.subDisplayFile() << "Leaving ConcatenatedJointPdf<V,M>::computeLogOfNormalizationFactor()"
238  << ", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
239  << std::endl;
240  }
241 
242  return value;
243 }
double m_logOfNormalizationFactor
Definition: JointPdf.h:122
bool queso_isnan(T arg)
Definition: math_macros.h:39
const BaseEnvironment & m_env
std::vector< const BaseJointPdf< V, M > * > m_densities
const VectorSet< V, M > & m_domainSet
Domain set of the scalar function.
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class V , class M >
void QUESO::ConcatenatedJointPdf< V, M >::distributionMean ( V &  meanVector) const
virtual

Mean value of the underlying random variable.

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

Definition at line 202 of file ConcatenatedJointPdf.C.

203 {
204  unsigned int cumulativeSize = 0;
205  for (unsigned int i = 0; i < m_densities.size(); ++i) {
206  V vec_i(m_densities[i]->domainSet().vectorSpace().zeroVector());
207  m_densities[i]->distributionMean(vec_i);
208  meanVector.cwSet(cumulativeSize,vec_i);
209  cumulativeSize += vec_i.sizeLocal();
210  }
211 }
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
std::vector< const BaseJointPdf< V, M > * > m_densities
template<class V , class M >
void QUESO::ConcatenatedJointPdf< V, M >::distributionVariance ( M &  covMatrix) const
virtual

Covariance matrix of the underlying random variable.

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

Definition at line 181 of file ConcatenatedJointPdf.C.

References QUESO::Map::NumGlobalElements().

182 {
183  covMatrix.zeroLower();
184  covMatrix.zeroUpper();
185 
186  unsigned int cumulativeSize = 0;
187  for (unsigned int i = 0; i < m_densities.size(); ++i) {
188  const Map & map = m_densities[i]->domainSet().vectorSpace().map();
189  const unsigned int n_columns = map.NumGlobalElements();
190  M mat_i(m_densities[i]->domainSet().env(),
191  map, n_columns);
192  m_densities[i]->distributionVariance(mat_i);
193  covMatrix.cwSet(cumulativeSize,cumulativeSize,mat_i);
194 
195  cumulativeSize += n_columns;
196  }
197 }
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
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.

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

Definition at line 136 of file ConcatenatedJointPdf.C.

142 {
143  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
144  *m_env.subDisplayFile() << "Entering ConcatenatedJointPdf<V,M>::lnValue()"
145  << ": domainVector = " << domainVector
146  << std::endl;
147  }
148 
149  queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect), "incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
150 
151  double returnValue = 0.;
152  unsigned int cumulativeSize = 0;
153  for (unsigned int i = 0; i < m_densities.size(); ++i) {
154  V vec_i(m_densities[i]->domainSet().vectorSpace().zeroVector());
155  domainVector.cwExtract(cumulativeSize,vec_i);
156  double value_i = m_densities[i]->lnValue(vec_i,NULL,NULL,NULL,NULL);
157  returnValue += value_i;
158  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) { // gpmsa
159  *m_env.subDisplayFile() << "In ConcatenatedJointPdf<V,M>::lnValue()"
160  << ", vec_" << i << " = " << vec_i
161  << ": value_" << i << " = " << value_i
162  << ", temporary cumulative value = " << returnValue
163  << std::endl;
164  }
165  cumulativeSize += vec_i.sizeLocal();
166  }
167  //returnValue += m_logOfNormalizationFactor; // No need, because each PDF should be already normalized [PDF-11]
168 
169  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
170  *m_env.subDisplayFile() << "Leaving ConcatenatedJointPdf<V,M>::lnValue()"
171  << ": domainVector = " << domainVector
172  << ", returnValue = " << returnValue
173  << std::endl;
174  }
175 
176  return returnValue;
177 }
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:450
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
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 Tue Jun 5 2018 19:49:22 for queso-0.57.1 by  doxygen 1.8.5