25 #include <queso/BetaJointPdf.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 #include <queso/BasicPdfsBase.h>
33 template<
class V,
class M>
40 BaseJointPdf<V,M>(((std::string)(prefix)+
"uni").c_str(),domainSet),
57 template<
class V,
class M>
62 template<
class V,
class M>
65 const V& domainVector,
66 const V* domainDirection,
69 V* hessianEffect)
const
72 queso_require_msg(!(domainDirection || hessianMatrix || hessianEffect),
"incomplete code for hessianMatrix and hessianEffect calculations");
75 double value = std::exp(this->lnValue(domainVector,domainDirection,gradVector,hessianMatrix,hessianEffect));
83 (*gradVector) *= value;
89 template<
class V,
class M>
92 const V& domainVector,
93 const V* domainDirection,
96 V* hessianEffect)
const
98 queso_require_msg(!(domainDirection || hessianMatrix || hessianEffect),
"incomplete code for gradVector, hessianMatrix and hessianEffect calculations");
102 for (
unsigned int i = 0; i < domainVector.sizeLocal(); ++i) {
103 if (m_normalizationStyle == 0) {
104 aux = log(m_env.basicPdfs()->betaPdfActualValue(domainVector[i],m_alpha[i],m_beta[i]));
107 aux = (m_alpha[i]-1.)*log(domainVector[i]) + (m_beta[i]-1.)*log(1.-domainVector[i]);
116 (*gradVector)[i] = (m_alpha[i] - 1.0) / domainVector[i] +
117 (1.0 - m_beta[i]) / (1.0 - domainVector[i]);
120 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
121 *m_env.subDisplayFile() <<
"In BetaJointPdf<V,M>::lnValue()"
122 <<
", m_normalizationStyle = " << m_normalizationStyle
123 <<
": domainVector[" << i <<
"] = " << domainVector[i]
124 <<
", m_alpha[" << i <<
"] = " << m_alpha[i]
125 <<
", m_beta[" << i <<
"] = " << m_beta[i]
126 <<
", log(pdf)= " << aux
131 result += m_logOfNormalizationFactor;
136 template<
class V,
class M>
140 unsigned int n_params = meanVector.sizeLocal();
141 queso_assert_equal_to (n_params, m_alpha.sizeLocal());
143 for (
unsigned int i = 0; i < n_params; ++i) {
144 meanVector[i] = m_alpha[i] / (m_alpha[i] + m_beta[i]);
148 template<
class V,
class M>
152 unsigned int n_params = m_alpha.sizeLocal();
153 queso_assert_equal_to (n_params, m_beta.sizeLocal());
154 queso_assert_equal_to (n_params, covMatrix.numCols());
155 queso_assert_equal_to (covMatrix.numCols(), covMatrix.numRowsGlobal());
157 covMatrix.zeroLower();
158 covMatrix.zeroUpper();
160 for (
unsigned int i = 0; i < n_params; ++i) {
161 covMatrix(i,i) = (m_alpha[i] * m_beta[i]) /
162 ((m_alpha[i] + m_beta[i]) *
163 (m_alpha[i] + m_beta[i]) *
164 (m_alpha[i] + m_beta[i] + 1));
168 template<
class V,
class M>
174 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
175 *m_env.subDisplayFile() <<
"Entering BetaJointPdf<V,M>::computeLogOfNormalizationFactor()"
179 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
180 *m_env.subDisplayFile() <<
"Leaving BetaJointPdf<V,M>::computeLogOfNormalizationFactor()"
181 <<
", m_logOfNormalizationFactor = " << m_logOfNormalizationFactor
BetaJointPdf(const char *prefix, const VectorSet< V, M > &domainSet, const V &alpha, const V &beta)
Constructor.
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the Beta PDF.
double computeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Computes the logarithm of the normalization factor.
virtual void distributionVariance(M &covMatrix) const
Covariance matrix of the underlying random variable.
A templated class for handling sets.
~BetaJointPdf()
Destructor.
double commonComputeLogOfNormalizationFactor(unsigned int numSamples, bool updateFactorInternally) const
Common method (to the derived classes) to compute the logarithm of the normalization factor...
const BaseEnvironment & m_env
A templated (base) class for handling joint PDFs.
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"))
virtual void distributionMean(V &meanVector) const
Mean value of the underlying random variable.
unsigned int displayVerbosity() const
A class for handling Beta joint PDFs.
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the Beta PDF.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).