25 #include <queso/ConcatenatedJointPdf.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
32 template<
class V,
class M>
39 BaseJointPdf<V,M>(((std::string)(prefix)+
"concat").c_str(),concatenatedDomain),
45 unsigned int size1 =
m_densities[0]->domainSet().vectorSpace().dimLocal();
46 unsigned int size2 =
m_densities[1]->domainSet().vectorSpace().dimLocal();
52 template<
class V,
class M>
58 BaseJointPdf<V,M>(((std::string)(prefix)+
"concat").c_str(),concatenatedDomain),
61 unsigned int sumSizes = 0;
64 sumSizes +=
m_densities[i]->domainSet().vectorSpace().dimLocal();
72 template<
class V,
class M>
77 template<
class V,
class M>
81 for (
unsigned i = 0; i < m_densities.size(); ++i) {
82 m_densities[i]->setNormalizationStyle(value);
87 template<
class V,
class M>
90 const V& domainVector,
91 const V* domainDirection,
94 V* hessianEffect)
const
96 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
97 *m_env.subDisplayFile() <<
"Entering ConcatenatedJointPdf<V,M>::actualValue()"
98 <<
": domainVector = " << domainVector
104 queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect),
"incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
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
120 cumulativeSize += vec_i.sizeLocal();
124 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
125 *m_env.subDisplayFile() <<
"Leaving ConcatenatedJointPdf<V,M>::actualValue()"
126 <<
": domainVector = " << domainVector
127 <<
", returnValue = " << returnValue
134 template<
class V,
class M>
137 const V& domainVector,
138 const V* domainDirection,
141 V* hessianEffect)
const
143 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
144 *m_env.subDisplayFile() <<
"Entering ConcatenatedJointPdf<V,M>::lnValue()"
145 <<
": domainVector = " << domainVector
149 queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect),
"incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
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)) {
159 *m_env.subDisplayFile() <<
"In ConcatenatedJointPdf<V,M>::lnValue()"
160 <<
", vec_" << i <<
" = " << vec_i
161 <<
": value_" << i <<
" = " << value_i
162 <<
", temporary cumulative value = " << returnValue
165 cumulativeSize += vec_i.sizeLocal();
169 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
170 *m_env.subDisplayFile() <<
"Leaving ConcatenatedJointPdf<V,M>::lnValue()"
171 <<
": domainVector = " << domainVector
172 <<
", returnValue = " << returnValue
179 template<
class V,
class M>
183 covMatrix.zeroLower();
184 covMatrix.zeroUpper();
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();
190 M mat_i(m_densities[i]->domainSet().env(),
192 m_densities[i]->distributionVariance(mat_i);
193 covMatrix.cwSet(cumulativeSize,cumulativeSize,mat_i);
195 cumulativeSize += n_columns;
200 template<
class V,
class M>
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();
214 template<
class V,
class M>
220 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
221 *m_env.subDisplayFile() <<
"Entering ConcatenatedJointPdf<V,M>::computeLogOfNormalizationFactor()"
224 double volume = m_domainSet.volume();
226 (volume == -INFINITY ) ||
227 (volume == INFINITY ) ||
232 for (
unsigned int i = 0; i < m_densities.size(); ++i) {
233 m_densities[i]->computeLogOfNormalizationFactor(numSamples, updateFactorInternally);
236 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
237 *m_env.subDisplayFile() <<
"Leaving ConcatenatedJointPdf<V,M>::computeLogOfNormalizationFactor()"
238 <<
", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
A class for partitioning vectors and matrices.
A class for handling concatenated PDFs.
ConcatenatedJointPdf(const char *prefix, const BaseJointPdf< V, M > &density1, const BaseJointPdf< V, M > &density2, const VectorSet< V, M > &concatenatedDomain)
Constructor.
A templated class for handling sets.
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
virtual void distributionVariance(M &covMatrix) const
Covariance matrix of the underlying random variable.
A templated (base) class for handling joint PDFs.
double computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Computes the logarithm of the normalization factor.
int NumGlobalElements() const
Returns the total number of elements across all processors.
std::vector< const BaseJointPdf< V, M > * > m_densities
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Calculates the actual values of each density.
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Calculates the logarithm of the values of each density.
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"))
~ConcatenatedJointPdf()
Destructor.
void setNormalizationStyle(unsigned int value) const
Sets the normalization style of all densities to value.
virtual void distributionMean(V &meanVector) const
Mean value of the underlying random variable.