queso-0.51.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...
 
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
 
SipOptionsValues m_alternativeOptionsValues
 
StatisticalInverseProblemOptionsm_optionsObj
 
bool m_seedWithMAPEstimator
 

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, class P_M>
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 81 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 35 of file StatisticalInverseProblem.C.

References UQ_FATAL_TEST_MACRO.

41  :
42  m_env (priorRv.env()),
43  m_priorRv (priorRv),
44  m_likelihoodFunction (likelihoodFunction),
45  m_postRv (postRv),
46  m_solutionDomain (NULL),
47  m_solutionPdf (NULL),
48  m_subSolutionMdf (NULL),
49  m_subSolutionCdf (NULL),
50  m_solutionRealizer (NULL),
51  m_mhSeqGenerator (NULL),
52  m_mlSampler (NULL),
53  m_chain (NULL),
54  m_logLikelihoodValues (NULL),
55  m_logTargetValues (NULL),
57  m_optionsObj (NULL),
59 {
60 #ifdef QUESO_MEMORY_DEBUGGING
61  std::cout << "Entering Sip" << std::endl;
62 #endif
63  if (m_env.subDisplayFile()) {
64  *m_env.subDisplayFile() << "Entering StatisticalInverseProblem<P_V,P_M>::constructor()"
65  << ": prefix = " << prefix
66  << ", alternativeOptionsValues = " << alternativeOptionsValues
67  << ", m_env.optionsInputFileName() = " << m_env.optionsInputFileName()
68  << std::endl;
69  }
70 
71  if (alternativeOptionsValues) m_alternativeOptionsValues = *alternativeOptionsValues;
72  if (m_env.optionsInputFileName() == "") {
73  m_optionsObj = new StatisticalInverseProblemOptions(m_env,prefix,m_alternativeOptionsValues);
74  }
75  else {
76  m_optionsObj = new StatisticalInverseProblemOptions(m_env,prefix);
78  }
79 #ifdef QUESO_MEMORY_DEBUGGING
80  std::cout << "In Sip, finished scanning options" << std::endl;
81 #endif
82 
83  UQ_FATAL_TEST_MACRO(priorRv.imageSet().vectorSpace().dimLocal() != likelihoodFunction.domainSet().vectorSpace().dimLocal(),
84  m_env.worldRank(),
85  "StatisticalInverseProblem<P_V,P_M>::constructor()",
86  "'priorRv' and 'likelihoodFunction' are related to vector spaces of different dimensions");
87 
88  UQ_FATAL_TEST_MACRO(priorRv.imageSet().vectorSpace().dimLocal() != postRv.imageSet().vectorSpace().dimLocal(),
89  m_env.worldRank(),
90  "StatisticalInverseProblem<P_V,P_M>::constructor()",
91  "'priorRv' and 'postRv' are related to vector spaces of different dimensions");
92 
93  if (m_env.subDisplayFile()) {
94  *m_env.subDisplayFile() << "Leaving StatisticalInverseProblem<P_V,P_M>::constructor()"
95  << ": prefix = " << m_optionsObj->m_prefix
96  << std::endl;
97  }
98 
99  return;
100 }
unsigned int dimLocal() const
Definition: VectorSpace.C:199
ScalarSequence< double > * m_logLikelihoodValues
BaseJointPdf< P_V, P_M > * m_solutionPdf
void scanOptionsValues()
It scans the option values from the options input file.
ScalarSequence< double > * m_logTargetValues
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
const BaseVectorRV< P_V, P_M > & m_priorRv
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
BaseVectorMdf< P_V, P_M > * m_subSolutionMdf
BaseVectorSequence< P_V, P_M > * m_chain
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:341
const BaseEnvironment & env() const
QUESO environment; access to private attribute m_env.
Definition: VectorRV.C:72
const BaseScalarFunction< P_V, P_M > & m_likelihoodFunction
BaseVectorCdf< P_V, P_M > * m_subSolutionCdf
GenericVectorRV< P_V, P_M > & m_postRv
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:79
MetropolisHastingsSG< P_V, P_M > * m_mhSeqGenerator
StatisticalInverseProblemOptions * m_optionsObj
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
BaseVectorRealizer< P_V, P_M > * m_solutionRealizer
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 103 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_alternativeOptionsValues, QUESO::StatisticalInverseProblem< P_V, P_M >::m_env, QUESO::StatisticalInverseProblem< P_V, P_M >::m_likelihoodFunction, QUESO::StatisticalInverseProblem< P_V, P_M >::m_optionsObj, QUESO::StatisticalInverseProblemOptions::m_prefix, QUESO::StatisticalInverseProblem< P_V, P_M >::m_priorRv, QUESO::BaseEnvironment::optionsInputFileName(), QUESO::StatisticalInverseProblemOptions::scanOptionsValues(), QUESO::BaseEnvironment::subDisplayFile(), UQ_FATAL_TEST_MACRO, QUESO::VectorSet< V, M >::vectorSpace(), and QUESO::BaseEnvironment::worldRank().

108  :
109  m_env (gpmsaFactory.m_totalPrior->env()),
110  m_priorRv (*(gpmsaFactory.m_totalPrior)),
111  m_likelihoodFunction (gpmsaFactory.getGPMSAEmulator()),
112  m_postRv (postRv),
113  m_solutionDomain (NULL),
114  m_solutionPdf (NULL),
115  m_subSolutionMdf (NULL),
116  m_subSolutionCdf (NULL),
117  m_solutionRealizer (NULL),
118  m_mhSeqGenerator (NULL),
119  m_mlSampler (NULL),
120  m_chain (NULL),
121  m_logLikelihoodValues (NULL),
122  m_logTargetValues (NULL),
124  m_optionsObj (NULL),
125  m_seedWithMAPEstimator (false)
126 {
127  if (m_env.subDisplayFile()) {
128  *m_env.subDisplayFile() << "Entering StatisticalInverseProblem<P_V,P_M>::constructor()"
129  << ": prefix = " << prefix
130  << ", alternativeOptionsValues = " << alternativeOptionsValues
131  << ", m_env.optionsInputFileName() = " << m_env.optionsInputFileName()
132  << std::endl;
133  }
134 
135  if (alternativeOptionsValues) m_alternativeOptionsValues = *alternativeOptionsValues;
136  if (m_env.optionsInputFileName() == "") {
137  m_optionsObj = new StatisticalInverseProblemOptions(m_env,prefix,m_alternativeOptionsValues);
138  }
139  else {
140  m_optionsObj = new StatisticalInverseProblemOptions(m_env,prefix);
142  }
143 
145  m_env.worldRank(),
146  "StatisticalInverseProblem<P_V,P_M>::constructor()",
147  "'priorRv' and 'likelihoodFunction' are related to vector spaces of different dimensions");
148 
149  UQ_FATAL_TEST_MACRO(m_priorRv.imageSet().vectorSpace().dimLocal() != postRv.imageSet().vectorSpace().dimLocal(),
150  m_env.worldRank(),
151  "StatisticalInverseProblem<P_V,P_M>::constructor()",
152  "'priorRv' and 'postRv' are related to vector spaces of different dimensions");
153 
154  if (m_env.subDisplayFile()) {
155  *m_env.subDisplayFile() << "Leaving StatisticalInverseProblem<P_V,P_M>::constructor()"
156  << ": prefix = " << m_optionsObj->m_prefix
157  << std::endl;
158  }
159 
160  return;
161 }
unsigned int dimLocal() const
Definition: VectorSpace.C:199
ScalarSequence< double > * m_logLikelihoodValues
BaseJointPdf< P_V, P_M > * m_solutionPdf
void scanOptionsValues()
It scans the option values from the options input file.
ScalarSequence< double > * m_logTargetValues
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
const BaseVectorRV< P_V, P_M > & m_priorRv
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
BaseVectorMdf< P_V, P_M > * m_subSolutionMdf
BaseVectorSequence< P_V, P_M > * m_chain
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:341
const BaseScalarFunction< P_V, P_M > & m_likelihoodFunction
BaseVectorCdf< P_V, P_M > * m_subSolutionCdf
GenericVectorRV< P_V, P_M > & m_postRv
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:79
MetropolisHastingsSG< P_V, P_M > * m_mhSeqGenerator
StatisticalInverseProblemOptions * m_optionsObj
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
BaseVectorRealizer< P_V, P_M > * m_solutionRealizer
template<class P_V , class P_M >
QUESO::StatisticalInverseProblem< P_V, P_M >::~StatisticalInverseProblem ( )

Destructor.

Definition at line 165 of file StatisticalInverseProblem.C.

166 {
167  if (m_chain) {
168  m_chain->clear();
169  delete m_chain;
170  }
171  if (m_logLikelihoodValues) {
173  delete m_logLikelihoodValues;
174  }
175  if (m_logTargetValues) {
177  delete m_logTargetValues;
178  }
179  if (m_mlSampler ) delete m_mlSampler;
180  if (m_mhSeqGenerator ) delete m_mhSeqGenerator;
182  if (m_subSolutionCdf ) delete m_subSolutionCdf;
183  if (m_subSolutionMdf ) delete m_subSolutionMdf;
184  if (m_solutionPdf ) delete m_solutionPdf;
185  if (m_solutionDomain ) delete m_solutionDomain;
186  if (m_optionsObj ) delete m_optionsObj;
187 }
ScalarSequence< double > * m_logLikelihoodValues
void clear()
Reset the values and the size of the sequence of vectors.
BaseJointPdf< P_V, P_M > * m_solutionPdf
ScalarSequence< double > * m_logTargetValues
BaseVectorMdf< P_V, P_M > * m_subSolutionMdf
BaseVectorSequence< P_V, P_M > * m_chain
BaseVectorCdf< P_V, P_M > * m_subSolutionCdf
MetropolisHastingsSG< P_V, P_M > * m_mhSeqGenerator
StatisticalInverseProblemOptions * m_optionsObj
void clear()
Clears the sequence of scalars.
BaseVectorRealizer< P_V, P_M > * m_solutionRealizer

Member Function Documentation

template<class P_V, class P_M>
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 477 of file StatisticalInverseProblem.C.

References UQ_FATAL_TEST_MACRO.

478 {
480  m_env.worldRank(),
481  "StatisticalInverseProblem<P_V,P_M>::eig()",
482  "m_mlSampler is NULL");
483  return m_mlSampler->eig();
484 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
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 457 of file StatisticalInverseProblem.C.

References UQ_FATAL_TEST_MACRO.

458 {
460  m_env.worldRank(),
461  "StatisticalInverseProblem<P_V,P_M>::logEvidence()",
462  "m_mlSampler is NULL");
463  return m_mlSampler->logEvidence();
464 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
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 467 of file StatisticalInverseProblem.C.

References UQ_FATAL_TEST_MACRO.

468 {
470  m_env.worldRank(),
471  "StatisticalInverseProblem<P_V,P_M>::meanLogLikelihood()",
472  "m_mlSampler is NULL");
473  return m_mlSampler->meanLogLikelihood();
474 }
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
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 451 of file StatisticalInverseProblem.C.

452 {
453  return m_postRv;
454 }
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 488 of file StatisticalInverseProblem.C.

489 {
490  return;
491 }
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 444 of file StatisticalInverseProblem.C.

445 {
446  return m_priorRv;
447 }
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 358 of file StatisticalInverseProblem.C.

359 {
360  this->m_seedWithMAPEstimator = true;
361 }
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 436 of file StatisticalInverseProblem.C.

437 {
438  return *m_mhSeqGenerator;
439 }
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 191 of file StatisticalInverseProblem.C.

References QUESO::InstantiateIntersection(), QUESO::GslOptimizer::minimize(), QUESO::GslOptimizer::minimizer(), QUESO::GslOptimizer::setInitialPoint(), UQ_FATAL_TEST_MACRO, and UQ_SIP_FILENAME_FOR_NO_FILE.

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

References QUESO::InstantiateIntersection().

366 {
367  m_env.fullComm().Barrier();
368  m_env.fullComm().syncPrintDebugMsg("Entering StatisticalInverseProblem<P_V,P_M>::solveWithBayesMLSampling()",1,3000000);
369 
370  if (m_optionsObj->m_ov.m_computeSolution == false) {
371  if ((m_env.subDisplayFile())) {
372  *m_env.subDisplayFile() << "In StatisticalInverseProblem<P_V,P_M>::solveWithBayesMLSampling()"
373  << ": avoiding solution, as requested by user"
374  << std::endl;
375  }
376  return;
377  }
378  if ((m_env.subDisplayFile())) {
379  *m_env.subDisplayFile() << "In StatisticalInverseProblem<P_V,P_M>::solveWithBayesMLSampling()"
380  << ": computing solution, as requested by user"
381  << std::endl;
382  }
383 
384  if (m_mlSampler ) delete m_mlSampler;
385  if (m_mhSeqGenerator ) delete m_mhSeqGenerator;
387  if (m_subSolutionCdf ) delete m_subSolutionCdf;
388  if (m_subSolutionMdf ) delete m_subSolutionMdf;
389  if (m_solutionPdf ) delete m_solutionPdf;
390  if (m_solutionDomain ) delete m_solutionDomain;
391 
392  P_V numEvaluationPointsVec(m_priorRv.imageSet().vectorSpace().zeroVector());
393  numEvaluationPointsVec.cwSet(250.);
394 
395  // Compute output pdf up to a multiplicative constant: Bayesian approach
397 
398  m_solutionPdf = new BayesianJointPdf<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
399  m_priorRv.pdf(),
401  1.,
403 
404  m_postRv.setPdf(*m_solutionPdf);
405 
406  // Compute output realizer: ML approach
407  m_chain = new SequenceOfVectors<P_V,P_M>(m_postRv.imageSet().vectorSpace(),0,m_optionsObj->m_prefix+"chain");
408  m_mlSampler = new MLSampling<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
409  //m_postRv,
410  m_priorRv,
412  // initialValues,
413  // initialProposalCovMatrix);
414 
415  m_mlSampler->generateSequence(*m_chain,
416  NULL,
417  NULL);
418 
419  m_solutionRealizer = new SequentialVectorRealizer<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
420  *m_chain);
421 
423 
424  if (m_env.subDisplayFile()) {
425  *m_env.subDisplayFile() << std::endl;
426  }
427 
428  m_env.fullComm().syncPrintDebugMsg("Leaving StatisticalInverseProblem<P_V,P_M>::solveWithBayesMLSampling()",1,3000000);
429  m_env.fullComm().Barrier();
430 
431  return;
432 }
BaseJointPdf< P_V, P_M > * m_solutionPdf
const BaseJointPdf< V, M > & pdf() const
Posterior Density Function of the vector RV; access to private attribute m_pdf.
Definition: VectorRV.C:86
const BaseVectorRV< P_V, P_M > & m_priorRv
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
Definition: Environment.C:247
BaseVectorMdf< P_V, P_M > * m_subSolutionMdf
BaseVectorSequence< P_V, P_M > * m_chain
void setPdf(BaseJointPdf< V, M > &pdf)
Sets the PDF of this vector RV to pdf.
const VectorSet< V, M > & domainSet() const
Access to the protected attribute m_domainSet: domain set of the scalar function. ...
VectorSet< V, M > * InstantiateIntersection(const VectorSet< V, M > &domain1, const VectorSet< V, M > &domain2)
This method calculates the intersection of domain1 and domain2.
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
Definition: MpiComm.C:143
const BaseScalarFunction< P_V, P_M > & m_likelihoodFunction
BaseVectorCdf< P_V, P_M > * m_subSolutionCdf
GenericVectorRV< P_V, P_M > & m_postRv
void syncPrintDebugMsg(const char *msg, unsigned int msgVerbosity, unsigned int numUSecs) const
Synchronizes all the processes and print debug message.
Definition: MpiComm.C:234
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:79
MetropolisHastingsSG< P_V, P_M > * m_mhSeqGenerator
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:218
StatisticalInverseProblemOptions * m_optionsObj
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
BaseVectorRealizer< P_V, P_M > * m_solutionRealizer
void setRealizer(BaseVectorRealizer< V, M > &realizer)
Sets the realizer of this vector RV to realizer.

Friends And Related Function Documentation

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

Definition at line 194 of file StatisticalInverseProblem.h.

195  {
196  obj.print(os);
197  return os;
198  }

Member Data Documentation

template<class P_V, class P_M>
SipOptionsValues QUESO::StatisticalInverseProblem< P_V, P_M >::m_alternativeOptionsValues
private
template<class P_V, class P_M>
BaseVectorSequence<P_V,P_M>* QUESO::StatisticalInverseProblem< P_V, P_M >::m_chain
private

Definition at line 215 of file StatisticalInverseProblem.h.

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

Definition at line 216 of file StatisticalInverseProblem.h.

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

Definition at line 217 of file StatisticalInverseProblem.h.

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

Definition at line 213 of file StatisticalInverseProblem.h.

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

Definition at line 214 of file StatisticalInverseProblem.h.

template<class P_V, class P_M>
StatisticalInverseProblemOptions* QUESO::StatisticalInverseProblem< P_V, P_M >::m_optionsObj
private
template<class P_V, class P_M>
GenericVectorRV<P_V,P_M>& QUESO::StatisticalInverseProblem< P_V, P_M >::m_postRv
private

Definition at line 205 of file StatisticalInverseProblem.h.

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

Definition at line 222 of file StatisticalInverseProblem.h.

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

Definition at line 207 of file StatisticalInverseProblem.h.

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

Definition at line 208 of file StatisticalInverseProblem.h.

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

Definition at line 211 of file StatisticalInverseProblem.h.

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

Definition at line 210 of file StatisticalInverseProblem.h.

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

Definition at line 209 of file StatisticalInverseProblem.h.


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

Generated on Thu Apr 23 2015 19:26:18 for queso-0.51.1 by  doxygen 1.8.5