queso-0.56.1
Private Member Functions | Private Attributes | List of all members
QUESO::MetropolisAdjustedLangevinTK< V, M > Class Template Reference

This class allows the representation of the MALA transition kernel with a scaled covariance matrix for the purposes of delayed rejection. More...

#include <MetropolisAdjustedLangevinTK.h>

Inheritance diagram for QUESO::MetropolisAdjustedLangevinTK< V, M >:
Inheritance graph
[legend]
Collaboration diagram for QUESO::MetropolisAdjustedLangevinTK< V, M >:
Collaboration graph
[legend]

Public Member Functions

Constructor/Destructor methods
 MetropolisAdjustedLangevinTK (const char *prefix, const BayesianJointPdf< V, M > &targetPdf, const std::vector< double > &scales, const M &covMatrix)
 Default constructor. More...
 
 ~MetropolisAdjustedLangevinTK ()
 Destructor. More...
 
Statistical/Mathematical methods
bool symmetric () const
 Whether or not the matrix is symmetric. Always 'true'. More...
 
const GaussianVectorRV< V, M > & rv (unsigned int stageId) const
 Gaussian increment property to construct a transition kernel. More...
 
const GaussianVectorRV< V, M > & rv (const std::vector< unsigned int > &stageIds)
 Gaussian increment property to construct a transition kernel. More...
 
virtual const GaussianVectorRV
< V, M > & 
rv (const V &position) const
 Constructs transition kernel pdf based on internal m_stageId variable. More...
 
void updateLawCovMatrix (const M &covMatrix)
 Scales the covariance matrix. More...
 
Misc methods
bool setPreComputingPosition (const V &position, unsigned int stageId)
 Sets the pre-computing positions m_preComputingPositions[stageId] with a new vector of size position. More...
 
void clearPreComputingPositions ()
 Clears the pre-computing positions m_preComputingPositions[stageId]. More...
 
I/O methods
void print (std::ostream &os) const
 TODO: Prints the transition kernel. More...
 
- Public Member Functions inherited from QUESO::BaseTKGroup< V, M >
 BaseTKGroup ()
 Default constructor. More...
 
 BaseTKGroup (const char *prefix, const VectorSpace< V, M > &vectorSpace, const std::vector< double > &scales)
 Constructor. More...
 
virtual ~BaseTKGroup ()
 Destructor. More...
 
const BaseEnvironmentenv () const
 QUESO's environment. More...
 
const V & preComputingPosition (unsigned int stageId) const
 Pre-computing position; access to protected attribute *m_preComputingPositions[stageId]. More...
 
virtual unsigned int set_dr_stage (unsigned int stageId)
 Does nothing. Subclasses may re-implement. Returns the current stage id. More...
 

Private Member Functions

void setRVsWithZeroMean ()
 Sets the mean of the RVs to zero. More...
 

Private Attributes

m_originalCovMatrix
 
const BayesianJointPdf< V, M > & m_targetPdf
 
double m_time_step
 

Additional Inherited Members

- Protected Attributes inherited from QUESO::BaseTKGroup< V, M >
const EmptyEnvironmentm_emptyEnv
 
const BaseEnvironmentm_env
 
std::string m_prefix
 
const VectorSpace< V, M > * m_vectorSpace
 
std::vector< double > m_scales
 
std::vector< const V * > m_preComputingPositions
 
std::vector< BaseVectorRV< V,
M > * > 
m_rvs
 
unsigned int m_stageId
 

Detailed Description

template<class V = GslVector, class M = GslMatrix>
class QUESO::MetropolisAdjustedLangevinTK< V, M >

This class allows the representation of the MALA transition kernel with a scaled covariance matrix for the purposes of delayed rejection.

Definition at line 43 of file MetropolisAdjustedLangevinTK.h.

Constructor & Destructor Documentation

template<class V , class M >
QUESO::MetropolisAdjustedLangevinTK< V, M >::MetropolisAdjustedLangevinTK ( const char *  prefix,
const BayesianJointPdf< V, M > &  targetPdf,
const std::vector< double > &  scales,
const M &  covMatrix 
)

Default constructor.

Definition at line 34 of file MetropolisAdjustedLangevinTK.C.

References QUESO::BaseEnvironment::displayVerbosity(), QUESO::BaseTKGroup< V, M >::m_env, QUESO::MetropolisAdjustedLangevinTK< V, M >::m_originalCovMatrix, QUESO::BaseTKGroup< V, M >::m_preComputingPositions, QUESO::BaseTKGroup< V, M >::m_rvs, QUESO::BaseTKGroup< V, M >::m_scales, QUESO::MetropolisAdjustedLangevinTK< V, M >::setRVsWithZeroMean(), and QUESO::BaseEnvironment::subDisplayFile().

39  :
40  BaseTKGroup<V, M>(prefix, targetPdf.domainSet().vectorSpace(), scales),
41  m_originalCovMatrix(covMatrix),
42  m_targetPdf(targetPdf),
43  m_time_step(1.0)
44 {
45  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
46  *m_env.subDisplayFile() << "Entering MetropolisAdjustedLangevinTK<V, M>::constructor()"
47  << std::endl;
48  }
49 
50  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
51  *m_env.subDisplayFile() << "In MetropolisAdjustedLangevinTK<V, M>::constructor()"
52  << ": m_scales.size() = " << m_scales.size()
53  << ", m_preComputingPositions.size() = " << m_preComputingPositions.size()
54  << ", m_rvs.size() = " << m_rvs.size()
55  << ", m_originalCovMatrix = " << m_originalCovMatrix
56  << std::endl;
57  }
58 
60 
61  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
62  *m_env.subDisplayFile() << "Leaving MetropolisAdjustedLangevinTK<V, M>::constructor()"
63  << std::endl;
64  }
65 }
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
std::vector< const V * > m_preComputingPositions
Definition: TKGroup.h:110
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:111
unsigned int displayVerbosity() const
Definition: Environment.C:449
void setRVsWithZeroMean()
Sets the mean of the RVs to zero.
const BaseEnvironment & m_env
Definition: TKGroup.h:106
const BayesianJointPdf< V, M > & m_targetPdf
std::vector< double > m_scales
Definition: TKGroup.h:109
template<class V , class M >
QUESO::MetropolisAdjustedLangevinTK< V, M >::~MetropolisAdjustedLangevinTK ( )

Destructor.

Definition at line 68 of file MetropolisAdjustedLangevinTK.C.

69 {
70 }

Member Function Documentation

template<class V , class M >
void QUESO::MetropolisAdjustedLangevinTK< V, M >::clearPreComputingPositions ( )
virtual

Clears the pre-computing positions m_preComputingPositions[stageId].

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

Definition at line 223 of file MetropolisAdjustedLangevinTK.C.

References QUESO::BaseTKGroup< V, M >::clearPreComputingPositions().

224 {
226 }
virtual void clearPreComputingPositions()
Clears the pre-computing positions m_preComputingPositions[stageId].
Definition: TKGroup.C:111
template<class V , class M >
void QUESO::MetropolisAdjustedLangevinTK< V, M >::print ( std::ostream &  os) const
virtual

TODO: Prints the transition kernel.

Todo:
: implement me!

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

Definition at line 247 of file MetropolisAdjustedLangevinTK.C.

References QUESO::BaseTKGroup< V, M >::print().

248 {
250 }
virtual void print(std::ostream &os) const
TODO: Prints the transition kernel.
Definition: TKGroup.C:133
template<class V , class M >
const GaussianVectorRV< V, M > & QUESO::MetropolisAdjustedLangevinTK< V, M >::rv ( unsigned int  stageId) const
virtual

Gaussian increment property to construct a transition kernel.

Implements QUESO::BaseTKGroup< V, M >.

Definition at line 81 of file MetropolisAdjustedLangevinTK.C.

References queso_require, queso_require_greater, queso_require_not_equal_to, and QUESO::GaussianVectorRV< V, M >::updateLawExpVector().

82 {
84  queso_require(m_rvs[0]);
87 
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] // FIX ME: might demand parallelism
94  << std::endl;
95  }
96 
97  GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[0]);
98 
99  gaussian_rv->updateLawExpVector(*m_preComputingPositions[stageId]);
100 
101  return (*gaussian_rv);
102 }
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
std::vector< const V * > m_preComputingPositions
Definition: TKGroup.h:110
#define queso_require_not_equal_to(expr1, expr2)
Definition: asserts.h:116
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:111
#define queso_require_greater(expr1, expr2)
Definition: asserts.h:122
#define queso_require(asserted)
Definition: asserts.h:110
unsigned int displayVerbosity() const
Definition: Environment.C:449
const BaseEnvironment & m_env
Definition: TKGroup.h:106
template<class V , class M >
const GaussianVectorRV< V, M > & QUESO::MetropolisAdjustedLangevinTK< V, M >::rv ( const std::vector< unsigned int > &  stageIds)
virtual

Gaussian increment property to construct a transition kernel.

Implements QUESO::BaseTKGroup< V, M >.

Definition at line 106 of file MetropolisAdjustedLangevinTK.C.

References queso_require, queso_require_greater, queso_require_greater_equal, and QUESO::GaussianVectorRV< V, M >::updateLawExpVector().

107 {
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]);
112 
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]] // FIX ME: might demand parallelism
120  << std::endl;
121  }
122 
123  GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[stageIds.size()-1]);
124 
125  gaussian_rv->updateLawExpVector(*m_preComputingPositions[stageIds[0]]);
126 
127  return (*gaussian_rv);
128 }
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
std::vector< const V * > m_preComputingPositions
Definition: TKGroup.h:110
#define queso_require_greater_equal(expr1, expr2)
Definition: asserts.h:128
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:111
#define queso_require_greater(expr1, expr2)
Definition: asserts.h:122
#define queso_require(asserted)
Definition: asserts.h:110
unsigned int displayVerbosity() const
Definition: Environment.C:449
const BaseEnvironment & m_env
Definition: TKGroup.h:106
template<class V , class M >
const GaussianVectorRV< V, M > & QUESO::MetropolisAdjustedLangevinTK< V, M >::rv ( const V &  position) const
virtual

Constructs transition kernel pdf based on internal m_stageId variable.

Implements QUESO::BaseTKGroup< V, M >.

Definition at line 132 of file MetropolisAdjustedLangevinTK.C.

References queso_require, queso_require_not_equal_to, and QUESO::GaussianVectorRV< V, M >::updateLawExpVector().

133 {
135  queso_require(m_rvs[0]);
136 
137  GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[this->m_stageId]);
138 
139  // 'position' is a position in the chain? Hopefully? Anyway, assume it's a
140  // position in the chain and then that means we need to modify it slightly so
141  // to get the transition distribution for the next state in the chain.
142 
143  V grad(this->m_targetPdf.domainSet().vectorSpace().zeroVector());
144 
145  // Get the gradient of the log-posterior. This is so inefficient it's
146  // painful. We should be caching the gradient evaluations.
147  this->m_targetPdf.lnValue(position, NULL, &grad, NULL, NULL);
148 
149  // Euler time-step
150  grad *= 0.5 * this->m_time_step;
151 
152  // Add on current position
153  grad += position;
154 
155  // Update the mean of the transition kernel. The vector gets copied, so
156  // we're ok.
157  gaussian_rv->updateLawExpVector(grad);
158 
159  return (*gaussian_rv);
160 }
#define queso_require_not_equal_to(expr1, expr2)
Definition: asserts.h:116
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:111
#define queso_require(asserted)
Definition: asserts.h:110
unsigned int m_stageId
Definition: TKGroup.h:112
const BayesianJointPdf< V, M > & m_targetPdf
template<class V , class M >
bool QUESO::MetropolisAdjustedLangevinTK< V, M >::setPreComputingPosition ( const V &  position,
unsigned int  stageId 
)
virtual

Sets the pre-computing positions m_preComputingPositions[stageId] with a new vector of size position.

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

Definition at line 185 of file MetropolisAdjustedLangevinTK.C.

References QUESO::GaussianJointPdf< V, M >::lawCovMatrix(), and QUESO::BaseTKGroup< V, M >::setPreComputingPosition().

186 {
187  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
188  *m_env.subDisplayFile() << "Entering MetropolisAdjustedLangevinTK<V, M>::setPreComputingPosition()"
189  << ": position = " << position
190  << ", stageId = " << stageId
191  << std::endl;
192  }
193 
195 
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];
203  }
204  if (stageId < m_rvs.size()) {
205  const GaussianJointPdf<V, M>* pdfPtr = dynamic_cast< const GaussianJointPdf<V, M>* >(&(m_rvs[stageId]->pdf()));
206  *m_env.subDisplayFile() << ", rvCov = " << pdfPtr->lawCovMatrix(); // FIX ME: might demand parallelism
207  }
208  *m_env.subDisplayFile() << std::endl;
209  }
210 
211  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
212  *m_env.subDisplayFile() << "Leaving MetropolisAdjustedLangevinTK<V, M>::setPreComputingPosition()"
213  << ": position = " << position
214  << ", stageId = " << stageId
215  << std::endl;
216  }
217 
218  return true;
219 }
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
std::vector< const V * > m_preComputingPositions
Definition: TKGroup.h:110
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:111
virtual bool setPreComputingPosition(const V &position, unsigned int stageId)
Sets the pre-computing positions m_preComputingPositions[stageId] with a new vector of size position...
Definition: TKGroup.C:98
unsigned int displayVerbosity() const
Definition: Environment.C:449
const BaseEnvironment & m_env
Definition: TKGroup.h:106
std::vector< double > m_scales
Definition: TKGroup.h:109
template<class V , class M >
void QUESO::MetropolisAdjustedLangevinTK< V, M >::setRVsWithZeroMean ( )
private

Sets the mean of the RVs to zero.

Definition at line 230 of file MetropolisAdjustedLangevinTK.C.

References queso_require, queso_require_equal_to, and queso_require_not_equal_to.

Referenced by QUESO::MetropolisAdjustedLangevinTK< V, M >::MetropolisAdjustedLangevinTK().

231 {
233  queso_require_equal_to(m_rvs.size(), m_scales.size());
234 
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]));
238  m_rvs[i] = new GaussianVectorRV<V, M>(m_prefix.c_str(),
239  *m_vectorSpace,
240  m_vectorSpace->zeroVector(),
242  }
243 }
#define queso_require_not_equal_to(expr1, expr2)
Definition: asserts.h:116
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:111
#define queso_require_equal_to(expr1, expr2)
Definition: asserts.h:113
#define queso_require(asserted)
Definition: asserts.h:110
const VectorSpace< V, M > * m_vectorSpace
Definition: TKGroup.h:108
std::string m_prefix
Definition: TKGroup.h:107
std::vector< double > m_scales
Definition: TKGroup.h:109
template<class V , class M >
bool QUESO::MetropolisAdjustedLangevinTK< V, M >::symmetric ( ) const
virtual

Whether or not the matrix is symmetric. Always 'true'.

Todo:
: It only returns 'true', thus a test for its symmetricity must be included.

Implements QUESO::BaseTKGroup< V, M >.

Definition at line 74 of file MetropolisAdjustedLangevinTK.C.

75 {
76  return false;
77 }
template<class V , class M >
void QUESO::MetropolisAdjustedLangevinTK< V, M >::updateLawCovMatrix ( const M &  covMatrix)

Scales the covariance matrix.

The covariance matrix is scaled by a factor of $ 1/scales^2 $.

Definition at line 164 of file MetropolisAdjustedLangevinTK.C.

165 {
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()
172  << ", i = " << i
173  << ", m_scales[i] = " << m_scales[i]
174  << ", factor = " << factor
175  << ": about to call m_rvs[i]->updateLawCovMatrix()"
176  << ", covMatrix = \n" << factor*covMatrix // FIX ME: might demand parallelism
177  << std::endl;
178  }
179  dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[i])->updateLawCovMatrix(factor*m_time_step*covMatrix);
180  }
181 }
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:111
unsigned int displayVerbosity() const
Definition: Environment.C:449
void updateLawCovMatrix(const M &covMatrix)
Scales the covariance matrix.
const BaseEnvironment & m_env
Definition: TKGroup.h:106
std::vector< double > m_scales
Definition: TKGroup.h:109

Member Data Documentation

template<class V = GslVector, class M = GslMatrix>
M QUESO::MetropolisAdjustedLangevinTK< V, M >::m_originalCovMatrix
private
template<class V = GslVector, class M = GslMatrix>
const BayesianJointPdf<V, M>& QUESO::MetropolisAdjustedLangevinTK< V, M >::m_targetPdf
private

Definition at line 108 of file MetropolisAdjustedLangevinTK.h.

template<class V = GslVector, class M = GslMatrix>
double QUESO::MetropolisAdjustedLangevinTK< V, M >::m_time_step
private

Definition at line 110 of file MetropolisAdjustedLangevinTK.h.


The documentation for this class was generated from the following files:

Generated on Thu Dec 15 2016 13:23:15 for queso-0.56.1 by  doxygen 1.8.5