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();
47 unsigned int size = concatenatedDomain.
vectorSpace().dimLocal();
52 template<
class V,
class M>
58 BaseJointPdf<V,M>(((std::string)(prefix)+
"concat").c_str(),concatenatedDomain),
59 m_densities (densities.size(),(const
BaseJointPdf<V,M>*) NULL)
61 unsigned int sumSizes = 0;
64 sumSizes +=
m_densities[i]->domainSet().vectorSpace().dimLocal();
67 unsigned int size = concatenatedDomain.
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 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
122 cummulativeSize += vecs[i]->sizeLocal();
127 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
128 *m_env.subDisplayFile() <<
"Leaving ConcatenatedJointPdf<V,M>::actualValue()"
129 <<
": domainVector = " << domainVector
130 <<
", returnValue = " << returnValue
137 template<
class V,
class M>
140 const V& domainVector,
141 const V* domainDirection,
144 V* hessianEffect)
const
146 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
147 *m_env.subDisplayFile() <<
"Entering ConcatenatedJointPdf<V,M>::lnValue()"
148 <<
": domainVector = " << domainVector
152 queso_require_msg(!(domainDirection || gradVector || hessianMatrix || hessianEffect),
"incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
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)) {
164 *m_env.subDisplayFile() <<
"In ConcatenatedJointPdf<V,M>::lnValue()"
165 <<
", *(vecs[" << i <<
"]) = " << *(vecs[i])
166 <<
": values[" << i <<
"] = " << values[i]
167 <<
", temporary cumulative value = " << returnValue
170 cummulativeSize += vecs[i]->sizeLocal();
175 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
176 *m_env.subDisplayFile() <<
"Leaving ConcatenatedJointPdf<V,M>::lnValue()"
177 <<
": domainVector = " << domainVector
178 <<
", returnValue = " << returnValue
185 template<
class V,
class M>
191 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
192 *m_env.subDisplayFile() <<
"Entering ConcatenatedJointPdf<V,M>::computeLogOfNormalizationFactor()"
195 double volume = m_domainSet.volume();
196 if (((boost::math::isnan)(volume)) ||
197 (volume == -INFINITY ) ||
198 (volume == INFINITY ) ||
203 for (
unsigned int i = 0; i < m_densities.size(); ++i) {
204 m_densities[i]->computeLogOfNormalizationFactor(numSamples, updateFactorInternally);
207 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
208 *m_env.subDisplayFile() <<
"Leaving ConcatenatedJointPdf<V,M>::computeLogOfNormalizationFactor()"
209 <<
", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
~ConcatenatedJointPdf()
Destructor.
A templated class for handling sets.
A templated (base) class for handling joint PDFs.
ConcatenatedJointPdf(const char *prefix, const BaseJointPdf< V, M > &density1, const BaseJointPdf< V, M > &density2, const VectorSet< V, M > &concatenatedDomain)
Constructor.
#define queso_require_equal_to_msg(expr1, expr2, msg)
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Calculates the actual values of each density.
#define queso_require_msg(asserted, msg)
A class for handling concatenated PDFs.
double computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Computes the logarithm of the normalization factor.
void setNormalizationStyle(unsigned int value) const
Sets the normalization style of all densities to value.
std::vector< const BaseJointPdf< V, M > * > m_densities
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Calculates the logarithm of the values of each density.
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.