queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::ScaledCovMatrixTKGroup< V, M > Class Template Reference

This class allows the representation of a transition kernel with a scaled covariance matrix. More...

#include <ScaledCovMatrixTKGroup.h>

Inheritance diagram for QUESO::ScaledCovMatrixTKGroup< V, M >:
QUESO::BaseTKGroup< V, M >

Public Member Functions

Constructor/Destructor methods
 ScaledCovMatrixTKGroup (const char *prefix, const VectorSpace< V, M > &vectorSpace, const std::vector< double > &scales, const M &covMatrix)
 Default constructor. More...
 
 ~ScaledCovMatrixTKGroup ()
 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...
 
virtual unsigned int set_dr_stage (unsigned int stageId)
 Sets the internal m_stageId varialbe to stageId. More...
 
virtual bool covMatrixIsDirty ()
 
virtual void cleanCovMatrix ()
 
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 void updateTK ()
 

Private Member Functions

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

Private Attributes

m_originalCovMatrix
 

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::ScaledCovMatrixTKGroup< V, M >

This class allows the representation of a transition kernel with a scaled covariance matrix.

Definition at line 44 of file ScaledCovMatrixTKGroup.h.

Constructor & Destructor Documentation

template<class V , class M >
QUESO::ScaledCovMatrixTKGroup< V, M >::ScaledCovMatrixTKGroup ( const char *  prefix,
const VectorSpace< V, M > &  vectorSpace,
const std::vector< double > &  scales,
const M &  covMatrix 
)

Default constructor.

Definition at line 34 of file ScaledCovMatrixTKGroup.C.

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

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

Destructor.

Definition at line 66 of file ScaledCovMatrixTKGroup.C.

67 {
68 }

Member Function Documentation

template<class V = GslVector, class M = GslMatrix>
virtual void QUESO::ScaledCovMatrixTKGroup< V, M >::cleanCovMatrix ( )
inlinevirtual

Performs whatever cleanup is needed (usually just resetting an internal bool flag) after the covariance matrix was modified.

After this method is called, covMatrixIsDirty should return true.

Implements QUESO::BaseTKGroup< V, M >.

Definition at line 88 of file ScaledCovMatrixTKGroup.h.

88 { }
template<class V , class M >
void QUESO::ScaledCovMatrixTKGroup< V, M >::clearPreComputingPositions ( )
virtual

Clears the pre-computing positions m_preComputingPositions[stageId].

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

Definition at line 214 of file ScaledCovMatrixTKGroup.C.

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

215 {
217 }
virtual void clearPreComputingPositions()
Clears the pre-computing positions m_preComputingPositions[stageId].
Definition: TKGroup.C:111
template<class V = GslVector, class M = GslMatrix>
virtual bool QUESO::ScaledCovMatrixTKGroup< V, M >::covMatrixIsDirty ( )
inlinevirtual

This method determines whether or not the user has 'dirtied' the covariance matrix, thereby necessitating an AM reset.

Should return true if the cov matrix was modified in such a way to affect the Adaptive Metropolis sample covariance calculation.

Implements QUESO::BaseTKGroup< V, M >.

Definition at line 87 of file ScaledCovMatrixTKGroup.h.

87 { return false; }
template<class V , class M >
void QUESO::ScaledCovMatrixTKGroup< 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 249 of file ScaledCovMatrixTKGroup.C.

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

250 {
252 }
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::ScaledCovMatrixTKGroup< V, M >::rv ( unsigned int  stageId) const
virtual

Gaussian increment property to construct a transition kernel.

Implements QUESO::BaseTKGroup< V, M >.

Definition at line 79 of file ScaledCovMatrixTKGroup.C.

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

80 {
81  queso_require_not_equal_to_msg(m_rvs.size(), 0, "m_rvs.size() = 0");
82 
83  queso_require_msg(m_rvs[0], "m_rvs[0] == NULL");
84 
85  queso_require_greater_msg(m_preComputingPositions.size(), stageId, "m_preComputingPositions.size() <= stageId");
86 
87  queso_require_msg(m_preComputingPositions[stageId], "m_preComputingPositions[stageId] == NULL");
88 
89  if ((m_env.subDisplayFile() ) &&
90  (m_env.displayVerbosity() >= 10)) {
91  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::rv1()"
92  << ", stageId = " << stageId
93  << ": about to call m_rvs[0]->updateLawExpVector()"
94  << ", vector = " << *m_preComputingPositions[stageId] // FIX ME: might demand parallelism
95  << std::endl;
96  }
97 
98  GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[0]);
99 
100  gaussian_rv->updateLawExpVector(*m_preComputingPositions[stageId]);
101 
102  return (*gaussian_rv);
103 }
std::vector< const V * > m_preComputingPositions
Definition: TKGroup.h:132
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:133
const BaseEnvironment & m_env
Definition: TKGroup.h:128
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix queso_require_not_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the absence of an options input file"))
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class V , class M >
const GaussianVectorRV< V, M > & QUESO::ScaledCovMatrixTKGroup< 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 107 of file ScaledCovMatrixTKGroup.C.

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

108 {
109  queso_require_greater_equal_msg(m_rvs.size(), stageIds.size(), "m_rvs.size() < stageIds.size()");
110 
111  queso_require_msg(m_rvs[stageIds.size()-1], "m_rvs[stageIds.size()-1] == NULL");
112 
113  queso_require_greater_msg(m_preComputingPositions.size(), stageIds[0], "m_preComputingPositions.size() <= stageIds[0]");
114 
115  queso_require_msg(m_preComputingPositions[stageIds[0]], "m_preComputingPositions[stageIds[0]] == NULL");
116 
117  if ((m_env.subDisplayFile() ) &&
118  (m_env.displayVerbosity() >= 10)) {
119  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::rv2()"
120  << ", stageIds.size() = " << stageIds.size()
121  << ", stageIds[0] = " << stageIds[0]
122  << ": about to call m_rvs[stageIds.size()-1]->updateLawExpVector()"
123  << ", vector = " << *m_preComputingPositions[stageIds[0]] // FIX ME: might demand parallelism
124  << std::endl;
125  }
126 
127  GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[stageIds.size()-1]);
128 
129  gaussian_rv->updateLawExpVector(*m_preComputingPositions[stageIds[0]]);
130 
131  return (*gaussian_rv);
132 }
std::vector< const V * > m_preComputingPositions
Definition: TKGroup.h:132
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:133
const BaseEnvironment & m_env
Definition: TKGroup.h:128
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class V , class M >
const GaussianVectorRV< V, M > & QUESO::ScaledCovMatrixTKGroup< 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 136 of file ScaledCovMatrixTKGroup.C.

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

137 {
138  queso_require_not_equal_to_msg(m_rvs.size(), 0, "m_rvs.size() = 0");
139  queso_require_msg(m_rvs[0], "m_rvs[0] == NULL");
140  //queso_require_greater_msg(m_preComputingPositions.size(), this->m_stageId, "m_preComputingPositions.size() <= stageId");
141  //queso_require_msg(m_preComputingPositions[this->m_stageId], "m_preComputingPositions[stageId] == NULL");
142 
143  GaussianVectorRV<V, M> * gaussian_rv = dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[this->m_stageId]);
144 
145  gaussian_rv->updateLawExpVector(position);
146 
147  return (*gaussian_rv);
148 }
unsigned int m_stageId
Definition: TKGroup.h:134
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:133
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix queso_require_not_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the absence of an options input file"))
template<class V , class M >
unsigned int QUESO::ScaledCovMatrixTKGroup< V, M >::set_dr_stage ( unsigned int  stageId)
virtual

Sets the internal m_stageId varialbe to stageId.

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

Definition at line 221 of file ScaledCovMatrixTKGroup.C.

222 {
223  unsigned int old_stageId = this->m_stageId;
224  this->m_stageId = stageId;
225  return old_stageId;
226 }
unsigned int m_stageId
Definition: TKGroup.h:134
template<class V , class M >
bool QUESO::ScaledCovMatrixTKGroup< 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 175 of file ScaledCovMatrixTKGroup.C.

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

176 {
177  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
178  *m_env.subDisplayFile() << "Entering ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition()"
179  << ": position = " << position
180  << ", stageId = " << stageId
181  << std::endl;
182  }
183 
185  //setRVsWithZeroMean();
186 
187  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
188  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition()"
189  << ", position = " << position
190  << ", stageId = " << stageId
191  << ": preComputingPos = " << *m_preComputingPositions[stageId];
192  if (stageId < m_scales.size()) {
193  *m_env.subDisplayFile() << ", factor = " << 1./m_scales[stageId]/m_scales[stageId];
194  }
195  if (stageId < m_rvs.size()) {
196  const GaussianJointPdf<V,M>* pdfPtr = dynamic_cast< const GaussianJointPdf<V,M>* >(&(m_rvs[stageId]->pdf()));
197  *m_env.subDisplayFile() << ", rvCov = " << pdfPtr->lawCovMatrix(); // FIX ME: might demand parallelism
198  }
199  *m_env.subDisplayFile() << std::endl;
200  }
201 
202  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
203  *m_env.subDisplayFile() << "Leaving ScaledCovMatrixTKGroup<V,M>::setPreComputingPosition()"
204  << ": position = " << position
205  << ", stageId = " << stageId
206  << std::endl;
207  }
208 
209  return true;
210 }
std::vector< const V * > m_preComputingPositions
Definition: TKGroup.h:132
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:133
const BaseEnvironment & m_env
Definition: TKGroup.h:128
std::vector< double > m_scales
Definition: TKGroup.h:131
unsigned int displayVerbosity() const
Definition: Environment.C:450
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
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class V , class M >
void QUESO::ScaledCovMatrixTKGroup< V, M >::setRVsWithZeroMean ( )
private

Sets the mean of the RVs to zero.

Definition at line 231 of file ScaledCovMatrixTKGroup.C.

References QUESO::queso_require_equal_to_msg, and QUESO::queso_require_not_equal_to_msg.

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

232 {
233  queso_require_not_equal_to_msg(m_rvs.size(), 0, "m_rvs.size() = 0");
234 
235  queso_require_equal_to_msg(m_rvs.size(), m_scales.size(), "m_rvs.size() != m_scales.size()");
236 
237  for (unsigned int i = 0; i < m_scales.size(); ++i) {
238  double factor = 1./m_scales[i]/m_scales[i];
239  queso_require_msg(!(m_rvs[i]), "m_rvs[i] != NULL");
240  m_rvs[i] = new GaussianVectorRV<V,M>(m_prefix.c_str(),
241  *m_vectorSpace,
242  m_vectorSpace->zeroVector(),
243  factor*m_originalCovMatrix);
244  }
245 }
std::string m_prefix
Definition: TKGroup.h:129
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:133
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix queso_require_not_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the absence of an options input file"))
const VectorSpace< V, M > * m_vectorSpace
Definition: TKGroup.h:130
std::vector< double > m_scales
Definition: TKGroup.h:131
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"))
template<class V , class M >
bool QUESO::ScaledCovMatrixTKGroup< 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 72 of file ScaledCovMatrixTKGroup.C.

73 {
74  return true;
75 }
template<class V , class M >
void QUESO::ScaledCovMatrixTKGroup< 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 153 of file ScaledCovMatrixTKGroup.C.

154 {
155  for (unsigned int i = 0; i < m_scales.size(); ++i) {
156  double factor = 1./m_scales[i]/m_scales[i];
157  if ((m_env.subDisplayFile() ) &&
158  (m_env.displayVerbosity() >= 10)) {
159  *m_env.subDisplayFile() << "In ScaledCovMatrixTKGroup<V,M>::updateLawCovMatrix()"
160  << ", m_scales.size() = " << m_scales.size()
161  << ", i = " << i
162  << ", m_scales[i] = " << m_scales[i]
163  << ", factor = " << factor
164  << ": about to call m_rvs[i]->updateLawCovMatrix()"
165  << ", covMatrix = \n" << factor*covMatrix // FIX ME: might demand parallelism
166  << std::endl;
167  }
168  dynamic_cast<GaussianVectorRV<V, M> * >(m_rvs[i])->updateLawCovMatrix(factor*covMatrix);
169  }
170 }
std::vector< BaseVectorRV< V, M > * > m_rvs
Definition: TKGroup.h:133
const BaseEnvironment & m_env
Definition: TKGroup.h:128
std::vector< double > m_scales
Definition: TKGroup.h:131
unsigned int displayVerbosity() const
Definition: Environment.C:450
void updateLawCovMatrix(const M &covMatrix)
Scales the covariance matrix.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320

Member Data Documentation

template<class V = GslVector, class M = GslMatrix>
M QUESO::ScaledCovMatrixTKGroup< V, M >::m_originalCovMatrix
private

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

Generated on Tue Jun 5 2018 19:49:36 for queso-0.57.1 by  doxygen 1.8.5