25 #include <queso/MetropolisAdjustedLangevinTK.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 #include <queso/GaussianJointPdf.h>
29 #include <queso/BayesianJointPdf.h>
33 template <
class V,
class M>
37 const std::vector<double> & scales,
40 BaseTKGroup<V, M>(prefix, targetPdf.domainSet().vectorSpace(), scales),
41 m_originalCovMatrix(covMatrix),
42 m_targetPdf(targetPdf),
52 <<
": m_scales.size() = " <<
m_scales.size()
54 <<
", m_rvs.size() = " <<
m_rvs.size()
67 template <
class V,
class M>
72 template <
class V,
class M>
79 template <
class V,
class M>
83 queso_require_not_equal_to(m_rvs.size(), 0);
84 queso_require(m_rvs[0]);
85 queso_require_greater(m_preComputingPositions.size(), stageId);
86 queso_require(m_preComputingPositions[stageId]);
88 if ((m_env.subDisplayFile() ) &&
89 (m_env.displayVerbosity() >= 10)) {
90 *m_env.subDisplayFile() <<
"In MetropolisAdjustedLangevinTK<V, M>::rv1()"
91 <<
", stageId = " << stageId
92 <<
": about to call m_rvs[0]->updateLawExpVector()"
93 <<
", vector = " << *m_preComputingPositions[stageId]
101 return (*gaussian_rv);
104 template <
class V,
class M>
108 queso_require_greater_equal(m_rvs.size(), stageIds.size());
109 queso_require(m_rvs[stageIds.size()-1]);
110 queso_require_greater(m_preComputingPositions.size(), stageIds[0]);
111 queso_require(m_preComputingPositions[stageIds[0]]);
113 if ((m_env.subDisplayFile() ) &&
114 (m_env.displayVerbosity() >= 10)) {
115 *m_env.subDisplayFile() <<
"In MetropolisAdjustedLangevinTK<V, M>::rv2()"
116 <<
", stageIds.size() = " << stageIds.size()
117 <<
", stageIds[0] = " << stageIds[0]
118 <<
": about to call m_rvs[stageIds.size()-1]->updateLawExpVector()"
119 <<
", vector = " << *m_preComputingPositions[stageIds[0]]
127 return (*gaussian_rv);
130 template <
class V,
class M>
134 queso_require_not_equal_to(m_rvs.size(), 0);
135 queso_require(m_rvs[0]);
143 V grad(this->m_targetPdf.domainSet().vectorSpace().zeroVector());
147 this->m_targetPdf.lnValue(position, grad);
150 grad *= 0.5 * this->m_time_step;
159 return (*gaussian_rv);
162 template <
class V,
class M>
166 for (
unsigned int i = 0; i < m_scales.size(); ++i) {
167 double factor = 1./m_scales[i]/m_scales[i];
168 if ((m_env.subDisplayFile() ) &&
169 (m_env.displayVerbosity() >= 10)) {
170 *m_env.subDisplayFile() <<
"In MetropolisAdjustedLangevinTK<V, M>::updateLawCovMatrix()"
171 <<
", m_scales.size() = " << m_scales.size()
173 <<
", m_scales[i] = " << m_scales[i]
174 <<
", factor = " << factor
175 <<
": about to call m_rvs[i]->updateLawCovMatrix()"
176 <<
", covMatrix = \n" << factor*covMatrix
183 template <
class V,
class M>
187 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
188 *m_env.subDisplayFile() <<
"Entering MetropolisAdjustedLangevinTK<V, M>::setPreComputingPosition()"
189 <<
": position = " << position
190 <<
", stageId = " << stageId
196 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
197 *m_env.subDisplayFile() <<
"In MetropolisAdjustedLangevinTK<V, M>::setPreComputingPosition()"
198 <<
", position = " << position
199 <<
", stageId = " << stageId
200 <<
": preComputingPos = " << *m_preComputingPositions[stageId];
201 if (stageId < m_scales.size()) {
202 *m_env.subDisplayFile() <<
", factor = " << 1./m_scales[stageId]/m_scales[stageId];
204 if (stageId < m_rvs.size()) {
206 *m_env.subDisplayFile() <<
", rvCov = " << pdfPtr->
lawCovMatrix();
208 *m_env.subDisplayFile() << std::endl;
211 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
212 *m_env.subDisplayFile() <<
"Leaving MetropolisAdjustedLangevinTK<V, M>::setPreComputingPosition()"
213 <<
": position = " << position
214 <<
", stageId = " << stageId
221 template <
class V,
class M>
228 template <
class V,
class M>
232 queso_require_not_equal_to(m_rvs.size(), 0);
233 queso_require_equal_to(m_rvs.size(), m_scales.size());
235 for (
unsigned int i = 0; i < m_scales.size(); ++i) {
236 double factor = 1./m_scales[i]/m_scales[i];
237 queso_require(!(m_rvs[i]));
240 m_vectorSpace->zeroVector(),
241 factor*m_time_step*m_originalCovMatrix);
245 template <
class V,
class M>
A class for handling Gaussian joint PDFs.
std::vector< const V * > m_preComputingPositions
A class representing a Gaussian vector RV.
const GaussianVectorRV< V, M > & rv(unsigned int stageId) const
Gaussian increment property to construct a transition kernel.
std::vector< BaseVectorRV< V, M > * > m_rvs
const BaseEnvironment & m_env
virtual void print(std::ostream &os) const
TODO: Prints the transition kernel.
virtual void clearPreComputingPositions()
Clears the pre-computing positions m_preComputingPositions[stageId].
void setRVsWithZeroMean()
Sets the mean of the RVs to zero.
void updateLawCovMatrix(const M &covMatrix)
Scales the covariance matrix.
void updateLawExpVector(const V &newLawExpVector)
Updates the vector that contains the mean values.
~MetropolisAdjustedLangevinTK()
Destructor.
bool setPreComputingPosition(const V &position, unsigned int stageId)
Sets the pre-computing positions m_preComputingPositions[stageId] with a new vector of size position...
std::vector< double > m_scales
const M & lawCovMatrix() const
Returns the covariance matrix; access to protected attribute m_lawCovMatrix.
void clearPreComputingPositions()
Clears the pre-computing positions m_preComputingPositions[stageId].
This base class allows the representation of a transition kernel.
MetropolisAdjustedLangevinTK(const char *prefix, const BayesianJointPdf< V, M > &targetPdf, const std::vector< double > &scales, const M &covMatrix)
Default constructor.
bool symmetric() const
Whether or not the matrix is symmetric. Always 'true'.
void print(std::ostream &os) const
TODO: Prints the transition kernel.
This class allows the representation of the MALA transition kernel with a scaled covariance matrix fo...
unsigned int displayVerbosity() const
virtual bool setPreComputingPosition(const V &position, unsigned int stageId)
Sets the pre-computing positions m_preComputingPositions[stageId] with a new vector of size position...
A class for handling Bayesian joint PDFs.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).