queso-0.56.1
Private Attributes | List of all members
QUESO::StatisticalInverseProblem< P_V, P_M > Class Template Reference

This templated class represents a Statistical Inverse Problem. More...

#include <StatisticalInverseProblem.h>

Collaboration diagram for QUESO::StatisticalInverseProblem< P_V, P_M >:
Collaboration graph
[legend]

Public Member Functions

Constructor/Destructor methods
 StatisticalInverseProblem (const char *prefix, const SipOptionsValues *alternativeOptionsValues, const BaseVectorRV< P_V, P_M > &priorRv, const BaseScalarFunction< P_V, P_M > &likelihoodFunction, GenericVectorRV< P_V, P_M > &postRv)
 Constructor. More...
 
 StatisticalInverseProblem (const char *prefix, const SipOptionsValues *alternativeOptionsValues, const GPMSAFactory< P_V, P_M > &gpmsaFactory, GenericVectorRV< P_V, P_M > &postRv)
 Constructor for statistical inverse problems to be sovled using GPMSA. More...
 
 ~StatisticalInverseProblem ()
 Destructor. More...
 
Statistical methods
bool computeSolutionFlag () const
 Whether or not compute the solution. More...
 
void solveWithBayesMetropolisHastings (const MhOptionsValues *alternativeOptionsValues, const P_V &initialValues, const P_M *initialProposalCovMatrix)
 Solves the problem via Bayes formula and a Metropolis-Hastings algorithm. More...
 
void seedWithMAPEstimator ()
 Seeds the chain with the result of a deterministic optimisation. More...
 
void solveWithBayesMLSampling ()
 Solves with Bayes Multi-Level (ML) sampling. More...
 
const MetropolisHastingsSG
< P_V, P_M > & 
sequenceGenerator () const
 Return the underlying MetropolisHastingSG object. More...
 
const BaseVectorRV< P_V, P_M > & priorRv () const
 Returns the Prior RV; access to private attribute m_priorRv. More...
 
const GenericVectorRV< P_V, P_M > & postRv () const
 Returns the Posterior RV; access to private attribute m_postrRv. More...
 
const BaseVectorSequence< P_V,
P_M > & 
chain () const
 Returns the MCMC chain; access to private attribute m_chain. More...
 
const ScalarSequence< double > & logLikelihoodValues () const
 Returns log likelihood values; access to private attribute m_logLikelihoodValues. More...
 
const ScalarSequence< double > & logTargetValues () const
 Returns log target values; access to private attribute m_logTargetValues. More...
 
double logEvidence () const
 Returns the logarithm value of the evidence. Related to ML. More...
 
double meanLogLikelihood () const
 Returns the mean of the logarithm value of the likelihood. Related to ML. More...
 
double eig () const
 

Private Attributes

const BaseEnvironmentm_env
 
const BaseVectorRV< P_V, P_M > & m_priorRv
 
const BaseScalarFunction< P_V,
P_M > & 
m_likelihoodFunction
 
GenericVectorRV< P_V, P_M > & m_postRv
 
VectorSet< P_V, P_M > * m_solutionDomain
 
BaseJointPdf< P_V, P_M > * m_solutionPdf
 
BaseVectorMdf< P_V, P_M > * m_subSolutionMdf
 
BaseVectorCdf< P_V, P_M > * m_subSolutionCdf
 
BaseVectorRealizer< P_V, P_M > * m_solutionRealizer
 
MetropolisHastingsSG< P_V, P_M > * m_mhSeqGenerator
 
MLSampling< P_V, P_M > * m_mlSampler
 
BaseVectorSequence< P_V, P_M > * m_chain
 
ScalarSequence< double > * m_logLikelihoodValues
 
ScalarSequence< double > * m_logTargetValues
 
const SipOptionsValuesm_optionsObj
 
bool m_seedWithMAPEstimator
 
bool m_userDidNotProvideOptions
 

I/O methods

void print (std::ostream &os) const
 TODO: Prints the sequence. More...
 
std::ostream & operator<< (std::ostream &os, const StatisticalInverseProblem< P_V, P_M > &obj)
 

Detailed Description

template<class P_V = GslVector, class P_M = GslMatrix>
class QUESO::StatisticalInverseProblem< P_V, P_M >

This templated class represents a Statistical Inverse Problem.

This class is templated on the type 'P_V' of vector and type 'P_M' of matrix, where 'P_' stands for 'parameter'. Some templated classes might also use 'Q_V' and 'Q_M' when referring to a vector type and a matrix type, where 'Q_' stands for 'quantities of interest'. Conceptually, a statistical inverse problem has two input entities and one output entity.
The input entities of a statistical inverse problem are:

  1. the prior RV, an instance of class 'BaseVectorRV<P_V,P_M>', and
  2. the likelihood function, an instance of class 'BaseScalarFunction<P_V,P_M>'.

Let $ \pi()$ denote the mathematical likelihood function and $ x $ denote a vector of parameters. The likelihood function object stores the routine that computes $ \pi(x) $ and whatever data necessary by such routine. The routine in the likelihood function object can compute either the actual value $ \pi(x) $ or the value $ \ln[\pi(x)] $. See files 'basic/inc/ScalarFunction.h' and 'stats/inc/JointPdf.h' for more details.
The output entity of a statistical inverse problem is the posterior RV, another instance of class 'BaseVectorRV<P_V,P_M>', which stores the solution according to the Bayesian approach. Upon return from a solution operation, the posterior RV is available through the operation 'postRv()'. Such posterior RV is able to provide:

  1. a joint pdf (up to a multiplicative constant) through the operation 'postRv().pdf()', which returns an instance of the class 'BaseJointPdf<P_V,P_M>', and
  2. a vector realizer through the operation 'postRv().realizer()', which returns an instance of the class 'BaseVectorRealizer<P_V,P_M>'.

Definition at line 84 of file StatisticalInverseProblem.h.

Constructor & Destructor Documentation

template<class P_V , class P_M >
QUESO::StatisticalInverseProblem< P_V, P_M >::StatisticalInverseProblem ( const char *  prefix,
const SipOptionsValues alternativeOptionsValues,
const BaseVectorRV< P_V, P_M > &  priorRv,
const BaseScalarFunction< P_V, P_M > &  likelihoodFunction,
GenericVectorRV< P_V, P_M > &  postRv 
)

Constructor.

Requirements: 1) the image set of the vector random variable 'priorRv', 2) the domain set of the likelihood function 'likelihoodFunction' and 3) the image set of the vector random variable 'postRv' should belong to vector spaces of equal dimensions. If the requirements are satisfied, the constructor then reads input options that begin with the string '<prefix>ip_'. If no options input file is provided, the construction assigns alternativeOptionsValues to the options of the SIP.

Parameters
prefixThe prefix
alternativeOptionsValuesOptions (if no input file)
priorRvThe prior RV
likelihoodFunctionThe likelihood function
postRvThe posterior RV

Definition at line 37 of file StatisticalInverseProblem.C.

References queso_require_equal_to_msg.

43  :
44  m_env (priorRv.env()),
45  m_priorRv (priorRv),
46  m_likelihoodFunction (likelihoodFunction),
47  m_postRv (postRv),
48  m_solutionDomain (NULL),
49  m_solutionPdf (NULL),
50  m_subSolutionMdf (NULL),
51  m_subSolutionCdf (NULL),
52  m_solutionRealizer (NULL),
53  m_mhSeqGenerator (NULL),
54  m_mlSampler (NULL),
55  m_chain (NULL),
56  m_logLikelihoodValues (NULL),
57  m_logTargetValues (NULL),
58  m_optionsObj (alternativeOptionsValues),
59  m_seedWithMAPEstimator (false),
61 {
62 #ifdef QUESO_MEMORY_DEBUGGING
63  std::cout << "Entering Sip" << std::endl;
64 #endif
65  if (m_env.subDisplayFile()) {
66  *m_env.subDisplayFile() << "Entering StatisticalInverseProblem<P_V,P_M>::constructor()"
67  << ": prefix = " << prefix
68  << ", alternativeOptionsValues = " << alternativeOptionsValues
69  << ", m_env.optionsInputFileName() = " << m_env.optionsInputFileName()
70  << std::endl;
71  }
72 
73  // If NULL, we create one
74  if (m_optionsObj == NULL) {
75  SipOptionsValues * tempOptions = new SipOptionsValues(&m_env, prefix);
76 
77  // We did this dance because scanOptionsValues is not a const method, but
78  // m_optionsObj is a pointer to const
79  m_optionsObj = tempOptions;
80 
81  // We set this flag so we don't delete the user-created object when it
82  // comes time to deconstruct
84  }
85 
86  if (m_optionsObj->m_help != "") {
87  if (m_env.subDisplayFile()) {
88  *m_env.subDisplayFile() << (*m_optionsObj) << std::endl;
89  }
90  }
91 
92 #ifdef QUESO_MEMORY_DEBUGGING
93  std::cout << "In Sip, finished scanning options" << std::endl;
94 #endif
95 
96  queso_require_equal_to_msg(priorRv.imageSet().vectorSpace().dimLocal(), likelihoodFunction.domainSet().vectorSpace().dimLocal(), "'priorRv' and 'likelihoodFunction' are related to vector spaces of different dimensions");
97 
98  queso_require_equal_to_msg(priorRv.imageSet().vectorSpace().dimLocal(), postRv.imageSet().vectorSpace().dimLocal(), "'priorRv' and 'postRv' are related to vector spaces of different dimensions");
99 
100  if (m_env.subDisplayFile()) {
101  *m_env.subDisplayFile() << "Leaving StatisticalInverseProblem<P_V,P_M>::constructor()"
102  << ": prefix = " << m_optionsObj->m_prefix
103  << std::endl;
104  }
105 
106  return;
107 }
ScalarSequence< double > * m_logLikelihoodValues
MetropolisHastingsSG< P_V, P_M > * m_mhSeqGenerator
const BaseScalarFunction< P_V, P_M > & m_likelihoodFunction
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:353
BaseVectorMdf< P_V, P_M > * m_subSolutionMdf
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:73
BaseVectorRealizer< P_V, P_M > * m_solutionRealizer
ScalarSequence< double > * m_logTargetValues
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:82
GenericVectorRV< P_V, P_M > & m_postRv
const BaseEnvironment & env() const
QUESO environment; access to private attribute m_env.
Definition: VectorRV.C:75
BaseVectorSequence< P_V, P_M > * m_chain
BaseVectorCdf< P_V, P_M > * m_subSolutionCdf
BaseJointPdf< P_V, P_M > * m_solutionPdf
const BaseVectorRV< P_V, P_M > & m_priorRv
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
std::string m_help
If this string is non-empty, options are print to the output file.
unsigned int dimLocal() const
Definition: VectorSpace.C:170
template<class P_V , class P_M >
QUESO::StatisticalInverseProblem< P_V, P_M >::StatisticalInverseProblem ( const char *  prefix,
const SipOptionsValues alternativeOptionsValues,
const GPMSAFactory< P_V, P_M > &  gpmsaFactory,
GenericVectorRV< P_V, P_M > &  postRv 
)

Constructor for statistical inverse problems to be sovled using GPMSA.

Requirements: 1) the factory for the GPMSA object 2) the image set of the vector random variable postRv (obtainable via GaussianProcessFactory::prior method) should be equal to the full prior image set (including all the hyperparameters)

If the requirements are satisfied, the constructor then reads input options that begin with the string '<prefix>ip_'. If no options input file is provided, the construction assigns alternativeOptionsValues to the options of the statistical inverse problem.

Definition at line 110 of file StatisticalInverseProblem.C.

References QUESO::VectorSpace< V, M >::dimLocal(), QUESO::BaseScalarFunction< V, M >::domainSet(), QUESO::BaseVectorRV< V, M >::imageSet(), QUESO::StatisticalInverseProblem< P_V, P_M >::m_env, QUESO::SipOptionsValues::m_help, QUESO::StatisticalInverseProblem< P_V, P_M >::m_likelihoodFunction, QUESO::StatisticalInverseProblem< P_V, P_M >::m_optionsObj, QUESO::SipOptionsValues::m_prefix, QUESO::StatisticalInverseProblem< P_V, P_M >::m_priorRv, QUESO::StatisticalInverseProblem< P_V, P_M >::m_userDidNotProvideOptions, QUESO::BaseEnvironment::optionsInputFileName(), queso_require_equal_to_msg, QUESO::BaseEnvironment::subDisplayFile(), and QUESO::VectorSet< V, M >::vectorSpace().

115  :
116  m_env (gpmsaFactory.m_totalPrior->env()),
117  m_priorRv (*(gpmsaFactory.m_totalPrior)),
118  m_likelihoodFunction (gpmsaFactory.getGPMSAEmulator()),
119  m_postRv (postRv),
120  m_solutionDomain (NULL),
121  m_solutionPdf (NULL),
122  m_subSolutionMdf (NULL),
123  m_subSolutionCdf (NULL),
124  m_solutionRealizer (NULL),
125  m_mhSeqGenerator (NULL),
126  m_mlSampler (NULL),
127  m_chain (NULL),
128  m_logLikelihoodValues (NULL),
129  m_logTargetValues (NULL),
130  m_optionsObj (alternativeOptionsValues),
131  m_seedWithMAPEstimator (false),
133 {
134  if (m_env.subDisplayFile()) {
135  *m_env.subDisplayFile() << "Entering StatisticalInverseProblem<P_V,P_M>::constructor()"
136  << ": prefix = " << prefix
137  << ", alternativeOptionsValues = " << alternativeOptionsValues
138  << ", m_env.optionsInputFileName() = " << m_env.optionsInputFileName()
139  << std::endl;
140  }
141 
142  // If NULL, we create one
143  if (m_optionsObj == NULL) {
144  SipOptionsValues * tempOptions = new SipOptionsValues(&m_env, prefix);
145 
146  // We did this dance because scanOptionsValues is not a const method, but
147  // m_optionsObj is a pointer to const
148  m_optionsObj = tempOptions;
149 
151  }
152 
153  if (m_optionsObj->m_help != "") {
154  if (m_env.subDisplayFile()) {
155  *m_env.subDisplayFile() << (*m_optionsObj) << std::endl;
156  }
157  }
158 
159  queso_require_equal_to_msg(m_priorRv.imageSet().vectorSpace().dimLocal(), m_likelihoodFunction.domainSet().vectorSpace().dimLocal(), "'priorRv' and 'likelihoodFunction' are related to vector spaces of different dimensions");
160 
161  queso_require_equal_to_msg(m_priorRv.imageSet().vectorSpace().dimLocal(), postRv.imageSet().vectorSpace().dimLocal(), "'priorRv' and 'postRv' are related to vector spaces of different dimensions");
162 
163  if (m_env.subDisplayFile()) {
164  *m_env.subDisplayFile() << "Leaving StatisticalInverseProblem<P_V,P_M>::constructor()"
165  << ": prefix = " << m_optionsObj->m_prefix
166  << std::endl;
167  }
168 
169  return;
170 }
ScalarSequence< double > * m_logLikelihoodValues
MetropolisHastingsSG< P_V, P_M > * m_mhSeqGenerator
const BaseScalarFunction< P_V, P_M > & m_likelihoodFunction
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:353
BaseVectorMdf< P_V, P_M > * m_subSolutionMdf
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:73
BaseVectorRealizer< P_V, P_M > * m_solutionRealizer
ScalarSequence< double > * m_logTargetValues
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:82
GenericVectorRV< P_V, P_M > & m_postRv
BaseVectorSequence< P_V, P_M > * m_chain
BaseVectorCdf< P_V, P_M > * m_subSolutionCdf
BaseJointPdf< P_V, P_M > * m_solutionPdf
const BaseVectorRV< P_V, P_M > & m_priorRv
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
std::string m_help
If this string is non-empty, options are print to the output file.
unsigned int dimLocal() const
Definition: VectorSpace.C:170
template<class P_V , class P_M >
QUESO::StatisticalInverseProblem< P_V, P_M >::~StatisticalInverseProblem ( )

Destructor.

Definition at line 174 of file StatisticalInverseProblem.C.

175 {
176  if (m_chain) {
177  m_chain->clear();
178  delete m_chain;
179  }
180  if (m_logLikelihoodValues) {
182  delete m_logLikelihoodValues;
183  }
184  if (m_logTargetValues) {
186  delete m_logTargetValues;
187  }
188  if (m_mlSampler ) delete m_mlSampler;
189  if (m_mhSeqGenerator ) delete m_mhSeqGenerator;
191  if (m_subSolutionCdf ) delete m_subSolutionCdf;
192  if (m_subSolutionMdf ) delete m_subSolutionMdf;
193  if (m_solutionPdf ) delete m_solutionPdf;
194  if (m_solutionDomain ) delete m_solutionDomain;
195 
197  delete m_optionsObj;
198  }
199 }
ScalarSequence< double > * m_logLikelihoodValues
MetropolisHastingsSG< P_V, P_M > * m_mhSeqGenerator
void clear()
Clears the sequence of scalars.
BaseVectorMdf< P_V, P_M > * m_subSolutionMdf
BaseVectorRealizer< P_V, P_M > * m_solutionRealizer
ScalarSequence< double > * m_logTargetValues
BaseVectorSequence< P_V, P_M > * m_chain
void clear()
Reset the values and the size of the sequence of vectors.
BaseVectorCdf< P_V, P_M > * m_subSolutionCdf
BaseJointPdf< P_V, P_M > * m_solutionPdf

Member Function Documentation

template<class P_V , class P_M >
const BaseVectorSequence< P_V, P_M > & QUESO::StatisticalInverseProblem< P_V, P_M >::chain ( ) const

Returns the MCMC chain; access to private attribute m_chain.

Only valid after solve has been called.

Definition at line 475 of file StatisticalInverseProblem.C.

References queso_require_msg.

476 {
477  queso_require_msg(m_chain, "m_chain is NULL");
478  return *m_chain;
479 }
BaseVectorSequence< P_V, P_M > * m_chain
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
template<class P_V = GslVector, class P_M = GslMatrix>
bool QUESO::StatisticalInverseProblem< P_V, P_M >::computeSolutionFlag ( ) const

Whether or not compute the solution.

template<class P_V , class P_M >
double QUESO::StatisticalInverseProblem< P_V, P_M >::eig ( ) const

Definition at line 512 of file StatisticalInverseProblem.C.

References queso_require_msg.

513 {
514  queso_require_msg(m_mlSampler, "m_mlSampler is NULL");
515  return m_mlSampler->eig();
516 }
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
template<class P_V , class P_M >
double QUESO::StatisticalInverseProblem< P_V, P_M >::logEvidence ( ) const

Returns the logarithm value of the evidence. Related to ML.

Definition at line 498 of file StatisticalInverseProblem.C.

References queso_require_msg.

499 {
500  queso_require_msg(m_mlSampler, "m_mlSampler is NULL");
501  return m_mlSampler->logEvidence();
502 }
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
template<class P_V , class P_M >
const ScalarSequence< double > & QUESO::StatisticalInverseProblem< P_V, P_M >::logLikelihoodValues ( ) const

Returns log likelihood values; access to private attribute m_logLikelihoodValues.

Only valid for MH and only after solve has been called.

Definition at line 483 of file StatisticalInverseProblem.C.

References queso_require_msg.

484 {
485  queso_require_msg(m_logLikelihoodValues, "m_logLikelihoodValues is NULL");
486  return *m_logLikelihoodValues;
487 }
ScalarSequence< double > * m_logLikelihoodValues
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
template<class P_V , class P_M >
const ScalarSequence< double > & QUESO::StatisticalInverseProblem< P_V, P_M >::logTargetValues ( ) const

Returns log target values; access to private attribute m_logTargetValues.

Only valid for MH and only after solve has been called.

Definition at line 491 of file StatisticalInverseProblem.C.

References queso_require_msg.

492 {
493  queso_require_msg(m_logTargetValues, "m_logTargetValues is NULL");
494  return *m_logTargetValues;
495 }
ScalarSequence< double > * m_logTargetValues
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
template<class P_V , class P_M >
double QUESO::StatisticalInverseProblem< P_V, P_M >::meanLogLikelihood ( ) const

Returns the mean of the logarithm value of the likelihood. Related to ML.

Definition at line 505 of file StatisticalInverseProblem.C.

References queso_require_msg.

506 {
507  queso_require_msg(m_mlSampler, "m_mlSampler is NULL");
508  return m_mlSampler->meanLogLikelihood();
509 }
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
template<class P_V , class P_M >
const GenericVectorRV< P_V, P_M > & QUESO::StatisticalInverseProblem< P_V, P_M >::postRv ( ) const

Returns the Posterior RV; access to private attribute m_postrRv.

The Posterior RV contains the solution of the Bayes problem.

Definition at line 468 of file StatisticalInverseProblem.C.

469 {
470  return m_postRv;
471 }
GenericVectorRV< P_V, P_M > & m_postRv
template<class P_V , class P_M >
void QUESO::StatisticalInverseProblem< P_V, P_M >::print ( std::ostream &  os) const

TODO: Prints the sequence.

Todo:
: implement me!

Definition at line 520 of file StatisticalInverseProblem.C.

521 {
522  return;
523 }
template<class P_V , class P_M >
const BaseVectorRV< P_V, P_M > & QUESO::StatisticalInverseProblem< P_V, P_M >::priorRv ( ) const

Returns the Prior RV; access to private attribute m_priorRv.

Definition at line 461 of file StatisticalInverseProblem.C.

462 {
463  return m_priorRv;
464 }
const BaseVectorRV< P_V, P_M > & m_priorRv
template<class P_V , class P_M >
void QUESO::StatisticalInverseProblem< P_V, P_M >::seedWithMAPEstimator ( )

Seeds the chain with the result of a deterministic optimisation.

This only works for Metropolis-Hastings right now. Multi-level is not currently supported.

Definition at line 375 of file StatisticalInverseProblem.C.

376 {
377  this->m_seedWithMAPEstimator = true;
378 }
template<class P_V , class P_M >
const MetropolisHastingsSG< P_V, P_M > & QUESO::StatisticalInverseProblem< P_V, P_M >::sequenceGenerator ( ) const

Return the underlying MetropolisHastingSG object.

Definition at line 453 of file StatisticalInverseProblem.C.

454 {
455  return *m_mhSeqGenerator;
456 }
MetropolisHastingsSG< P_V, P_M > * m_mhSeqGenerator
template<class P_V , class P_M >
void QUESO::StatisticalInverseProblem< P_V, P_M >::solveWithBayesMetropolisHastings ( const MhOptionsValues alternativeOptionsValues,
const P_V &  initialValues,
const P_M *  initialProposalCovMatrix 
)

Solves the problem via Bayes formula and a Metropolis-Hastings algorithm.

Requirements:

  1. 'initialValues' should have the same number of components as member variable 'm_priorRv'
  2. if 'initialProposalCovMatrix' is not NULL, it should be square and its size should be equal to the size of 'initialValues'.

If the requirements are satisfied, this methods checks the member flag 'm_computeSolution' (one of the options read from the input file during construction). If the flag is 'false', the operation returns immediately, computing nothing; otherwise, the operation sets the member variable 'm_postRv' accordingly. The operation:

  1. sets the pdf of 'm_postRv' equal to an instance of BayesianJointPdf<P_V,P_M>,
  2. instantiates SequenceOfVectors<P_V,P_M> (the chain),
  3. instantiates MetropolisHastingsSG<P_V,P_M> (the Metropolis-Hastings algorithm),
  4. populates the chain with the Metropolis-Hastings algorithm, and
  5. sets the realizer of 'm_postRv' with the contents of the chain.

If seedWithMapEstimator() is called before this method, then initialValues is used as the initial condition for an optimization procedure, the result of which will be used as the seed for the chain.

Definition at line 203 of file StatisticalInverseProblem.C.

References QUESO::InstantiateIntersection(), QUESO::GslOptimizer::minimize(), QUESO::GslOptimizer::minimizer(), queso_require_equal_to_msg, queso_require_msg, QUESO::OptimizerMonitor::set_display_output(), QUESO::GslOptimizer::setInitialPoint(), and UQ_SIP_FILENAME_FOR_NO_FILE.

207 {
208  //grvy_timer_begin("BayesMetropolisHastings"); TODO: revisit timing output
209  //std::cout << "proc " << m_env.fullRank() << ", HERE sip 000" << std::endl;
210  m_env.fullComm().Barrier();
211  //std::cout << "proc " << m_env.fullRank() << ", HERE sip 001" << std::endl;
212  m_env.fullComm().syncPrintDebugMsg("Entering StatisticalInverseProblem<P_V,P_M>::solveWithBayesMetropolisHastings()",1,3000000);
213 
214  if (m_optionsObj->m_computeSolution == false) {
215  if ((m_env.subDisplayFile())) {
216  *m_env.subDisplayFile() << "In StatisticalInverseProblem<P_V,P_M>::solveWithBayesMetropolisHastings()"
217  << ": avoiding solution, as requested by user"
218  << std::endl;
219  }
220  return;
221  }
222  if ((m_env.subDisplayFile())) {
223  *m_env.subDisplayFile() << "In StatisticalInverseProblem<P_V,P_M>::solveWithBayesMetropolisHastings()"
224  << ": computing solution, as requested by user"
225  << std::endl;
226  }
227 
228  queso_require_equal_to_msg(m_priorRv.imageSet().vectorSpace().dimLocal(), initialValues.sizeLocal(), "'m_priorRv' and 'initialValues' should have equal dimensions");
229 
230  if (initialProposalCovMatrix) {
231  queso_require_equal_to_msg(m_priorRv.imageSet().vectorSpace().dimLocal(), initialProposalCovMatrix->numRowsLocal(), "'m_priorRv' and 'initialProposalCovMatrix' should have equal dimensions");
232  queso_require_equal_to_msg(initialProposalCovMatrix->numCols(), initialProposalCovMatrix->numRowsGlobal(), "'initialProposalCovMatrix' should be a square matrix");
233  }
234 
235  if (m_mlSampler ) delete m_mlSampler;
236  if (m_mhSeqGenerator ) delete m_mhSeqGenerator;
238  if (m_subSolutionCdf ) delete m_subSolutionCdf;
239  if (m_subSolutionMdf ) delete m_subSolutionMdf;
240  if (m_solutionPdf ) delete m_solutionPdf;
241  if (m_solutionDomain ) delete m_solutionDomain;
242 
243  P_V numEvaluationPointsVec(m_priorRv.imageSet().vectorSpace().zeroVector());
244  numEvaluationPointsVec.cwSet(250.);
245 
246  // Compute output pdf up to a multiplicative constant: Bayesian approach
248 
249  m_solutionPdf = new BayesianJointPdf<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
250  m_priorRv.pdf(),
252  1.,
254 
255  m_postRv.setPdf(*m_solutionPdf);
256  m_chain = new SequenceOfVectors<P_V,P_M>(m_postRv.imageSet().vectorSpace(),0,m_optionsObj->m_prefix+"chain");
257 
258  // Decide whether or not to create a MetropolisHastingsSG instance from the
259  // user-provided initial seed, or use the user-provided seed for a
260  // deterministic optimisation instead and seed the chain with the result of
261  // the optimisation
262  if (this->m_seedWithMAPEstimator ||
264  // Unfortunately, I didn't have the foresight to make this an input file
265  // option from the beginning, hence needing to check two flags
266 
267  // Read in optimizer options from input file
268  OptimizerOptions optimizer_options(&m_env, "ip_");
269 
270  // Do optimisation before sampling
271  GslOptimizer optimizer(optimizer_options, *m_solutionPdf);
272  optimizer.setInitialPoint(dynamic_cast<const GslVector &>(initialValues));
273 
274  OptimizerMonitor monitor(m_env);
275  monitor.set_display_output(true, true);
276 
277  // If the input file option is set, then use the monitor, otherwise don't
279  optimizer.minimize(&monitor);
280  }
281  else {
282  optimizer.minimize();
283  }
284 
285  // Compute output realizer: Metropolis-Hastings approach
286  m_mhSeqGenerator = new MetropolisHastingsSG<P_V, P_M>(
287  m_optionsObj->m_prefix.c_str(), alternativeOptionsValues,
288  m_postRv, optimizer.minimizer(), initialProposalCovMatrix);
289  }
290  else {
291  // Compute output realizer: Metropolis-Hastings approach
292  m_mhSeqGenerator = new MetropolisHastingsSG<P_V, P_M>(
293  m_optionsObj->m_prefix.c_str(), alternativeOptionsValues, m_postRv,
294  initialValues, initialProposalCovMatrix);
295  }
296 
297 
298  m_logLikelihoodValues = new ScalarSequence<double>(m_env, 0,
300  "logLike");
301 
302  m_logTargetValues = new ScalarSequence<double>(m_env, 0,
304  "logTarget");
305 
306  // m_logLikelihoodValues and m_logTargetValues may be NULL
307  m_mhSeqGenerator->generateSequence(*m_chain, m_logLikelihoodValues,
308  m_logTargetValues);
309 
310  m_solutionRealizer = new SequentialVectorRealizer<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
311  *m_chain);
312 
313  m_postRv.setRealizer(*m_solutionRealizer);
314 
315  m_env.fullComm().syncPrintDebugMsg("In StatisticalInverseProblem<P_V,P_M>::solveWithBayesMetropolisHastings(), code place 1",3,3000000);
316  //m_env.fullComm().Barrier();
317 
318  // Compute output mdf: uniform sampling approach
319 #ifdef UQ_ALSO_COMPUTE_MDFS_WITHOUT_KDE
320  m_subMdfGrids = new ArrayOfOneDGrids <P_V,P_M>((m_optionsObj->m_prefix+"Mdf_").c_str(),m_postRv.imageSet().vectorSpace());
321  m_subMdfValues = new ArrayOfOneDTables<P_V,P_M>((m_optionsObj->m_prefix+"Mdf_").c_str(),m_postRv.imageSet().vectorSpace());
322  m_chain->subUniformlySampledMdf(numEvaluationPointsVec, // input
323  *m_subMdfGrids, // output
324  *m_subMdfValues); // output
325  m_subSolutionMdf = new SampledVectorMdf<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
326  *m_subMdfGrids,
327  *m_subMdfValues);
328  m_postRv.setMdf(*m_subSolutionMdf);
329 
331  (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end())) {
332  if (m_env.subRank() == 0) {
333  // Write data output file
334  if (m_env.subDisplayFile()) {
335  *m_env.subDisplayFile() << "Opening data output file '" << m_optionsObj->m_dataOutputFileName
336  << "' for calibration problem with problem with prefix = " << m_optionsObj->m_prefix
337  << std::endl;
338  }
339 
340  // Open file
341  // Always write at the end of an eventual pre-existing file
342  std::ofstream* ofsvar = new std::ofstream((m_optionsObj->m_dataOutputFileName+"_sub"+m_env.subIdString()+".m").c_str(), std::ofstream::out | std::ofstream::in | std::ofstream::ate);
343  if ((ofsvar == NULL ) ||
344  (ofsvar->is_open() == false)) {
345  delete ofsvar;
346  ofsvar = new std::ofstream((m_optionsObj->m_dataOutputFileName+"_sub"+m_env.subIdString()+".m").c_str(), std::ofstream::out | std::ofstream::trunc);
347  }
348  queso_require_msg((ofsvar && ofsvar->is_open()), "failed to open file");
349 
350  m_postRv.mdf().print(*ofsvar);
351 
352  // Close file
353  //ofsvar->close();
354  delete ofsvar;
355  if (m_env.subDisplayFile()) {
356  *m_env.subDisplayFile() << "Closed data output file '" << m_optionsObj->m_dataOutputFileName
357  << "' for calibration problem with problem with prefix = " << m_optionsObj->m_prefix
358  << std::endl;
359  }
360  }
361  }
362 #endif
363  if (m_env.subDisplayFile()) {
364  *m_env.subDisplayFile() << std::endl;
365  }
366 
367  m_env.fullComm().syncPrintDebugMsg("Leaving StatisticalInverseProblem<P_V,P_M>::solveWithBayesMetropolisHastings()",1,3000000);
368  m_env.fullComm().Barrier();
369  // grvy_timer_end("BayesMetropolisHastings"); TODO: revisit timers
370  return;
371 }
ScalarSequence< double > * m_logLikelihoodValues
MetropolisHastingsSG< P_V, P_M > * m_mhSeqGenerator
const BaseScalarFunction< P_V, P_M > & m_likelihoodFunction
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
Definition: MpiComm.C:164
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
VectorSet< V, M > * InstantiateIntersection(const VectorSet< V, M > &domain1, const VectorSet< V, M > &domain2)
This method calculates the intersection of domain1 and domain2.
const BaseJointPdf< V, M > & pdf() const
Posterior Density Function of the vector RV; access to private attribute m_pdf.
Definition: VectorRV.C:89
BaseVectorMdf< P_V, P_M > * m_subSolutionMdf
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:73
void setPdf(BaseJointPdf< V, M > &pdf)
Sets the PDF of this vector RV to pdf.
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:189
BaseVectorRealizer< P_V, P_M > * m_solutionRealizer
#define UQ_SIP_FILENAME_FOR_NO_FILE
ScalarSequence< double > * m_logTargetValues
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:82
std::set< unsigned int > m_dataOutputAllowedSet
GenericVectorRV< P_V, P_M > & m_postRv
BaseVectorSequence< P_V, P_M > * m_chain
BaseVectorCdf< P_V, P_M > * m_subSolutionCdf
BaseJointPdf< P_V, P_M > * m_solutionPdf
const BaseVectorRV< P_V, P_M > & m_priorRv
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
void syncPrintDebugMsg(const char *msg, unsigned int msgVerbosity, unsigned int numUSecs) const
Synchronizes all the processes and print debug message.
Definition: MpiComm.C:323
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
Definition: Environment.C:274
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
unsigned int dimLocal() const
Definition: VectorSpace.C:170
template<class P_V , class P_M >
void QUESO::StatisticalInverseProblem< P_V, P_M >::solveWithBayesMLSampling ( )

Solves with Bayes Multi-Level (ML) sampling.

Definition at line 382 of file StatisticalInverseProblem.C.

References QUESO::InstantiateIntersection().

383 {
384  m_env.fullComm().Barrier();
385  m_env.fullComm().syncPrintDebugMsg("Entering StatisticalInverseProblem<P_V,P_M>::solveWithBayesMLSampling()",1,3000000);
386 
387  if (m_optionsObj->m_computeSolution == false) {
388  if ((m_env.subDisplayFile())) {
389  *m_env.subDisplayFile() << "In StatisticalInverseProblem<P_V,P_M>::solveWithBayesMLSampling()"
390  << ": avoiding solution, as requested by user"
391  << std::endl;
392  }
393  return;
394  }
395  if ((m_env.subDisplayFile())) {
396  *m_env.subDisplayFile() << "In StatisticalInverseProblem<P_V,P_M>::solveWithBayesMLSampling()"
397  << ": computing solution, as requested by user"
398  << std::endl;
399  }
400 
401  if (m_mlSampler ) delete m_mlSampler;
402  if (m_mhSeqGenerator ) delete m_mhSeqGenerator;
404  if (m_subSolutionCdf ) delete m_subSolutionCdf;
405  if (m_subSolutionMdf ) delete m_subSolutionMdf;
406  if (m_solutionPdf ) delete m_solutionPdf;
407  if (m_solutionDomain ) delete m_solutionDomain;
408 
409  P_V numEvaluationPointsVec(m_priorRv.imageSet().vectorSpace().zeroVector());
410  numEvaluationPointsVec.cwSet(250.);
411 
412  // Compute output pdf up to a multiplicative constant: Bayesian approach
414 
415  m_solutionPdf = new BayesianJointPdf<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
416  m_priorRv.pdf(),
418  1.,
420 
421  m_postRv.setPdf(*m_solutionPdf);
422 
423  // Compute output realizer: ML approach
424  m_chain = new SequenceOfVectors<P_V,P_M>(m_postRv.imageSet().vectorSpace(),0,m_optionsObj->m_prefix+"chain");
425  m_mlSampler = new MLSampling<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
426  //m_postRv,
427  m_priorRv,
429  // initialValues,
430  // initialProposalCovMatrix);
431 
432  m_mlSampler->generateSequence(*m_chain,
433  NULL,
434  NULL);
435 
436  m_solutionRealizer = new SequentialVectorRealizer<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
437  *m_chain);
438 
440 
441  if (m_env.subDisplayFile()) {
442  *m_env.subDisplayFile() << std::endl;
443  }
444 
445  m_env.fullComm().syncPrintDebugMsg("Leaving StatisticalInverseProblem<P_V,P_M>::solveWithBayesMLSampling()",1,3000000);
446  m_env.fullComm().Barrier();
447 
448  return;
449 }
MetropolisHastingsSG< P_V, P_M > * m_mhSeqGenerator
const BaseScalarFunction< P_V, P_M > & m_likelihoodFunction
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
Definition: MpiComm.C:164
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
VectorSet< V, M > * InstantiateIntersection(const VectorSet< V, M > &domain1, const VectorSet< V, M > &domain2)
This method calculates the intersection of domain1 and domain2.
const BaseJointPdf< V, M > & pdf() const
Posterior Density Function of the vector RV; access to private attribute m_pdf.
Definition: VectorRV.C:89
BaseVectorMdf< P_V, P_M > * m_subSolutionMdf
void setPdf(BaseJointPdf< V, M > &pdf)
Sets the PDF of this vector RV to pdf.
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:189
BaseVectorRealizer< P_V, P_M > * m_solutionRealizer
void setRealizer(BaseVectorRealizer< V, M > &realizer)
Sets the realizer of this vector RV to realizer.
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:82
GenericVectorRV< P_V, P_M > & m_postRv
BaseVectorSequence< P_V, P_M > * m_chain
BaseVectorCdf< P_V, P_M > * m_subSolutionCdf
BaseJointPdf< P_V, P_M > * m_solutionPdf
const BaseVectorRV< P_V, P_M > & m_priorRv
void syncPrintDebugMsg(const char *msg, unsigned int msgVerbosity, unsigned int numUSecs) const
Synchronizes all the processes and print debug message.
Definition: MpiComm.C:323
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
Definition: Environment.C:274
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.

Friends And Related Function Documentation

template<class P_V = GslVector, class P_M = GslMatrix>
std::ostream& operator<< ( std::ostream &  os,
const StatisticalInverseProblem< P_V, P_M > &  obj 
)
friend

Definition at line 209 of file StatisticalInverseProblem.h.

210  {
211  obj.print(os);
212  return os;
213  }

Member Data Documentation

template<class P_V = GslVector, class P_M = GslMatrix>
BaseVectorSequence<P_V,P_M>* QUESO::StatisticalInverseProblem< P_V, P_M >::m_chain
private

Definition at line 230 of file StatisticalInverseProblem.h.

template<class P_V = GslVector, class P_M = GslMatrix>
const BaseEnvironment& QUESO::StatisticalInverseProblem< P_V, P_M >::m_env
private
template<class P_V = GslVector, class P_M = GslMatrix>
const BaseScalarFunction<P_V,P_M>& QUESO::StatisticalInverseProblem< P_V, P_M >::m_likelihoodFunction
private
template<class P_V = GslVector, class P_M = GslMatrix>
ScalarSequence<double>* QUESO::StatisticalInverseProblem< P_V, P_M >::m_logLikelihoodValues
private

Definition at line 231 of file StatisticalInverseProblem.h.

template<class P_V = GslVector, class P_M = GslMatrix>
ScalarSequence<double>* QUESO::StatisticalInverseProblem< P_V, P_M >::m_logTargetValues
private

Definition at line 232 of file StatisticalInverseProblem.h.

template<class P_V = GslVector, class P_M = GslMatrix>
MetropolisHastingsSG<P_V,P_M>* QUESO::StatisticalInverseProblem< P_V, P_M >::m_mhSeqGenerator
private

Definition at line 228 of file StatisticalInverseProblem.h.

template<class P_V = GslVector, class P_M = GslMatrix>
MLSampling<P_V,P_M>* QUESO::StatisticalInverseProblem< P_V, P_M >::m_mlSampler
private

Definition at line 229 of file StatisticalInverseProblem.h.

template<class P_V = GslVector, class P_M = GslMatrix>
const SipOptionsValues* QUESO::StatisticalInverseProblem< P_V, P_M >::m_optionsObj
private
template<class P_V = GslVector, class P_M = GslMatrix>
GenericVectorRV<P_V,P_M>& QUESO::StatisticalInverseProblem< P_V, P_M >::m_postRv
private

Definition at line 220 of file StatisticalInverseProblem.h.

template<class P_V = GslVector, class P_M = GslMatrix>
const BaseVectorRV<P_V,P_M>& QUESO::StatisticalInverseProblem< P_V, P_M >::m_priorRv
private
template<class P_V = GslVector, class P_M = GslMatrix>
bool QUESO::StatisticalInverseProblem< P_V, P_M >::m_seedWithMAPEstimator
private

Definition at line 236 of file StatisticalInverseProblem.h.

template<class P_V = GslVector, class P_M = GslMatrix>
VectorSet<P_V,P_M>* QUESO::StatisticalInverseProblem< P_V, P_M >::m_solutionDomain
private

Definition at line 222 of file StatisticalInverseProblem.h.

template<class P_V = GslVector, class P_M = GslMatrix>
BaseJointPdf<P_V,P_M>* QUESO::StatisticalInverseProblem< P_V, P_M >::m_solutionPdf
private

Definition at line 223 of file StatisticalInverseProblem.h.

template<class P_V = GslVector, class P_M = GslMatrix>
BaseVectorRealizer<P_V,P_M>* QUESO::StatisticalInverseProblem< P_V, P_M >::m_solutionRealizer
private

Definition at line 226 of file StatisticalInverseProblem.h.

template<class P_V = GslVector, class P_M = GslMatrix>
BaseVectorCdf<P_V,P_M>* QUESO::StatisticalInverseProblem< P_V, P_M >::m_subSolutionCdf
private

Definition at line 225 of file StatisticalInverseProblem.h.

template<class P_V = GslVector, class P_M = GslMatrix>
BaseVectorMdf<P_V,P_M>* QUESO::StatisticalInverseProblem< P_V, P_M >::m_subSolutionMdf
private

Definition at line 224 of file StatisticalInverseProblem.h.

template<class P_V = GslVector, class P_M = GslMatrix>
bool QUESO::StatisticalInverseProblem< P_V, P_M >::m_userDidNotProvideOptions
private

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

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