https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
PMCMCBase Class Reference

A base class used to perform Parallel Markov Chain Monte Carlo (MCMC) sampling. More...

#include <PMCMCBase.h>

Inheritance diagram for PMCMCBase:
[legend]

Public Types

enum  SampleMode { SampleMode::GLOBAL, SampleMode::LOCAL }
 
typedef DataFileName DataFileParameterType
 

Public Member Functions

 PMCMCBase (const InputParameters &parameters)
 
dof_id_type getNumberOfConfigValues () const
 Return the number of configuration parameters. More...
 
dof_id_type getNumberOfConfigParams () const
 Return the number of configuration parameters. More...
 
dof_id_type getNumParallelProposals () const
 Return the number of parallel proposals. More...
 
const std::vector< Real > & getRandomNumbers () const
 Return the random numbers to facilitate decision making in reporters. More...
 
const std::vector< Real > & getVarSamples () const
 Return the proposed variance samples to facilitate decision making in reporters. More...
 
const std::vector< const Distribution * > getPriors () const
 Return the priors to facilitate decision making in reporters. More...
 
const DistributiongetVarPrior () const
 Return the prior over variance to facilitate decision making in reporters. More...
 
virtual int decisionStep () const
 Return the step after which decision making can begin. More...
 
std::vector< RealgetNextLocalRow ()
 
dof_id_type getNumberOfRows () const
 
dof_id_type getNumberOfCols () const
 
dof_id_type getNumberOfLocalRows () const
 
const LocalRankConfiggetRankConfig (bool batch_mode) const
 
virtual bool isAdaptiveSamplingCompleted () const
 
libMesh::Parallel::CommunicatorgetLocalComm ()
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
virtual const std::string & name () const
 
std::string typeAndName () const
 
std::string errorPrefix (const std::string &error_type) const
 
void callMooseError (std::string msg, const bool with_prefix) const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
const InputParametersparameters () const
 
MooseObjectName uniqueName () const
 
const T & getParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const T * queryParam (const std::string &name) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &nm) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void mooseError (Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
virtual void initialSetup ()
 
virtual void timestepSetup ()
 
virtual void jacobianSetup ()
 
virtual void residualSetup ()
 
virtual void subdomainSetup ()
 
virtual void customSetup (const ExecFlagType &)
 
const ExecFlagEnumgetExecuteOnEnum () const
 
PerfGraphperfGraph ()
 
T & getSampler (const std::string &name)
 
SamplergetSampler (const std::string &name)
 
T & getSamplerByName (const SamplerName &name)
 
SamplergetSamplerByName (const SamplerName &name)
 
const VectorPostprocessorValuegetVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name, bool needs_broadcast) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
bool hasVectorPostprocessor (const std::string &param_name, const std::string &vector_name) const
 
bool hasVectorPostprocessor (const std::string &param_name) const
 
bool hasVectorPostprocessorByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
bool hasVectorPostprocessorByName (const VectorPostprocessorName &name) const
 
const VectorPostprocessorName & getVectorPostprocessorName (const std::string &param_name) const
 
DenseMatrix< RealgetGlobalSamples ()
 
DenseMatrix< RealgetGlobalSamples ()
 
DenseMatrix< RealgetLocalSamples ()
 
DenseMatrix< RealgetLocalSamples ()
 
dof_id_type getLocalRowBegin () const
 
dof_id_type getLocalRowBegin () const
 
dof_id_type getLocalRowEnd () const
 
dof_id_type getLocalRowEnd () const
 
const DistributiongetDistribution (const std::string &name) const
 
const T & getDistribution (const std::string &name) const
 
const DistributiongetDistribution (const std::string &name) const
 
const T & getDistribution (const std::string &name) const
 
const DistributiongetDistributionByName (const DistributionName &name) const
 
const T & getDistributionByName (const std::string &name) const
 
const DistributiongetDistributionByName (const DistributionName &name) const
 
const T & getDistributionByName (const std::string &name) const
 
bool isVectorPostprocessorDistributed (const std::string &param_name) const
 
bool isVectorPostprocessorDistributed (const std::string &param_name) const
 
bool isVectorPostprocessorDistributedByName (const VectorPostprocessorName &name) const
 
bool isVectorPostprocessorDistributedByName (const VectorPostprocessorName &name) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
bool isImplicit ()
 
Moose::StateArg determineState () const
 

Static Public Member Functions

static InputParameters validParams ()
 

Public Attributes

const ConsoleStream _console
 

Protected Types

enum  CommMethod
 

Protected Member Functions

virtual void proposeSamples (const unsigned int seed_value)
 Fill in the _new_samples vector of vectors (happens within sampleSetUp) More...
 
virtual void sampleSetUp (const Sampler::SampleMode mode) override
 
virtual Real computeSample (dof_id_type row_index, dof_id_type col_index) override
 
void randomIndex (const unsigned int &upper_bound, const unsigned int &exclude, const unsigned int &seed, unsigned int &req_index)
 Sample a random index excluding a specified index. More...
 
void randomIndexPair (const unsigned int &upper_bound, const unsigned int &exclude, const unsigned int &seed, unsigned int &req_index1, unsigned int &req_index2)
 Sample two random indices without repitition excluding a specified index. More...
 
void setNumberOfRandomSeeds (std::size_t number)
 
Real getRand (unsigned int index=0)
 
uint32_t getRandl (unsigned int index, uint32_t lower, uint32_t upper)
 
virtual LocalRankConfig constructRankConfig (bool batch_mode) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 
std::string timedSectionName (const std::string &section_name) const
 
virtual void addVectorPostprocessorDependencyHelper (const VectorPostprocessorName &) const
 
const ReporterNamegetReporterName (const std::string &param_name) const
 
virtual void addReporterDependencyHelper (const ReporterName &)
 
void setNumberOfRows (dof_id_type n_rows)
 
void setNumberOfRows (dof_id_type n_rows)
 
void setNumberOfCols (dof_id_type n_cols)
 
void setNumberOfCols (dof_id_type n_cols)
 
virtual void sampleTearDown (const SampleMode)
 
virtual void sampleTearDown (const SampleMode)
 
virtual void computeSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeLocalSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeLocalSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeSampleRow (dof_id_type i, std::vector< Real > &data)
 
virtual void computeSampleRow (dof_id_type i, std::vector< Real > &data)
 
virtual void advanceGenerators (const dof_id_type count)
 
virtual void advanceGenerators (const dof_id_type count)
 
virtual void advanceGenerator (const unsigned int seed_index, const dof_id_type count)
 
virtual void advanceGenerator (const unsigned int seed_index, const dof_id_type count)
 
void setAutoAdvanceGenerators (const bool state)
 
void setAutoAdvanceGenerators (const bool state)
 
void shuffle (std::vector< T > &data, const std::size_t seed_index=0, const CommMethod method=CommMethod::LOCAL)
 
void shuffle (std::vector< T > &data, const std::size_t seed_index=0, const CommMethod method=CommMethod::LOCAL)
 
virtual void executeSetUp ()
 
virtual void executeSetUp ()
 
virtual void executeTearDown ()
 
virtual void executeTearDown ()
 
void saveGeneratorState ()
 
void saveGeneratorState ()
 
void restoreGeneratorState ()
 
void restoreGeneratorState ()
 
const T & getReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const T & getReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const T & getReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const T & getReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 

Protected Attributes

const unsigned int _num_parallel_proposals
 Number of parallel proposals to be made and subApps to be executed. More...
 
std::vector< const Distribution * > _priors
 Storage for prior distribution objects to be utilized. More...
 
const Distribution_var_prior
 Storage for prior distribution object of the variance to be utilized. More...
 
const std::vector< Real > * _lower_bound
 Lower bounds for making the next proposal. More...
 
const std::vector< Real > * _upper_bound
 Upper bounds for making the next proposal. More...
 
int _check_step
 Ensure that the MCMC algorithm proceeds in a sequential fashion. More...
 
const std::vector< Real > & _initial_values
 Initial values of the input params to get the MCMC scheme started. More...
 
std::vector< std::vector< Real > > _new_samples
 Vectors of new proposed samples. More...
 
std::vector< Real_new_var_samples
 Vector of new proposed variance samples. More...
 
std::vector< Real_rnd_vec
 Vector of random numbers for decision making. More...
 
 NONE
 
 LOCAL
 
 SEMI_LOCAL
 
const dof_id_type _min_procs_per_row
 
const dof_id_type _max_procs_per_row
 
libMesh::Parallel::Communicator _local_comm
 
const bool & _enabled
 
MooseApp_app
 
const std::string _type
 
const std::string _name
 
const InputParameters_pars
 
Factory_factory
 
ActionFactory_action_factory
 
const ExecFlagEnum_execute_enum
 
const ExecFlagType_current_execute_flag
 
MooseApp_pg_moose_app
 
const std::string _prefix
 
const Parallel::Communicator & _communicator
 
const InputParameters_ti_params
 
FEProblemBase_ti_feproblem
 
bool _is_implicit
 
Real_t
 
const Real_t_old
 
int_t_step
 
Real_dt
 
Real_dt_old
 
bool _is_transient
 

Private Member Functions

void combineWithExperimentalConfig ()
 Generates combinations of the new samples with the experimental configurations. More...
 

Private Attributes

const unsigned int _num_random_seeds
 Initialize a certain number of random seeds. Change from the default only if you have to. More...
 
std::vector< std::vector< Real > > _confg_values
 Configuration values. More...
 
std::vector< std::vector< Real > > _new_samples_confg
 Vectors of new proposed samples combined with the experimental configuration values. More...
 

Detailed Description

A base class used to perform Parallel Markov Chain Monte Carlo (MCMC) sampling.

Definition at line 19 of file PMCMCBase.h.

Constructor & Destructor Documentation

◆ PMCMCBase()

PMCMCBase::PMCMCBase ( const InputParameters parameters)

Definition at line 46 of file PMCMCBase.C.

48  TransientInterface(this),
49  _num_parallel_proposals(getParam<unsigned int>("num_parallel_proposals")),
50  _lower_bound(isParamValid("lower_bound") ? &getParam<std::vector<Real>>("lower_bound")
51  : nullptr),
52  _upper_bound(isParamValid("upper_bound") ? &getParam<std::vector<Real>>("upper_bound")
53  : nullptr),
54  _check_step(0),
55  _initial_values(getParam<std::vector<Real>>("initial_values")),
56  _num_random_seeds(getParam<unsigned int>("num_random_seeds"))
57 {
58  // Filling the `priors` vector with the user-provided distributions.
59  for (const DistributionName & name :
60  getParam<std::vector<DistributionName>>("prior_distributions"))
61  _priors.push_back(&getDistributionByName(name));
62 
63  // Filling the `var_prior` object with the user-provided distribution for the variance.
64  if (isParamValid("prior_variance"))
65  _var_prior = &getDistributionByName(getParam<DistributionName>("prior_variance"));
66  else
67  _var_prior = nullptr;
68 
69  // Read the experimental configurations from a csv file
70  MooseUtils::DelimitedFileReader reader(getParam<FileName>("file_name"));
71  reader.read();
72  _confg_values.resize(1);
73  if (isParamValid("file_column_name"))
74  _confg_values[0] = reader.getData(getParam<std::string>("file_column_name"));
75  else if (isParamValid("num_columns"))
76  {
77  _confg_values.resize(getParam<unsigned int>("num_columns"));
78  for (unsigned int i = 0; i < _confg_values.size(); ++i)
79  _confg_values[i] = reader.getData(i);
80  }
81  else
82  _confg_values[0] = reader.getData(0);
83 
84  // Setting the number of sampler rows to be equal to the number of parallel proposals
86 
87  // Setting the number of columns in the sampler matrix (equal to the number of distributions).
88  setNumberOfCols(_priors.size() + _confg_values.size());
89 
90  // Resizing the vectors and vector of vectors
91  _new_samples.resize(_num_parallel_proposals, std::vector<Real>(_priors.size(), 0.0));
93  std::vector<Real>(_priors.size() + _confg_values.size(), 0.0));
96 
98 
99  _check_step = 0;
100 
101  // Check whether both the lower and the upper bounds are specified and of same size
102  bool bound_check1 = _lower_bound && !_upper_bound;
103  bool bound_check2 = !_lower_bound && _upper_bound;
104  if (bound_check1 || bound_check2)
105  mooseError("Both lower and upper bounds should be specified.");
106  bool size_check = _lower_bound ? ((*_lower_bound).size() != (*_upper_bound).size()) : 0;
107  if (size_check)
108  mooseError("Lower and upper bounds should be of the same size.");
109 
110  // Check whether the priors, bounds, and initial values are all of the same size
111  if (_priors.size() != _initial_values.size())
112  mooseError("The priors and initial values should be of the same size.");
113 }
void setNumberOfRows(dof_id_type n_rows)
const unsigned int _num_random_seeds
Initialize a certain number of random seeds. Change from the default only if you have to...
Definition: PMCMCBase.h:142
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition: PMCMCBase.h:106
const std::vector< Real > & _initial_values
Initial values of the input params to get the MCMC scheme started.
Definition: PMCMCBase.h:124
std::vector< std::vector< Real > > _new_samples_confg
Vectors of new proposed samples combined with the experimental configuration values.
Definition: PMCMCBase.h:148
const std::vector< Real > * _lower_bound
Lower bounds for making the next proposal.
Definition: PMCMCBase.h:115
std::vector< const Distribution * > _priors
Storage for prior distribution objects to be utilized.
Definition: PMCMCBase.h:109
int _check_step
Ensure that the MCMC algorithm proceeds in a sequential fashion.
Definition: PMCMCBase.h:121
virtual const std::string & name() const
Sampler(const InputParameters &parameters)
bool isParamValid(const std::string &name) const
TransientInterface(const MooseObject *moose_object)
std::vector< Real > _new_var_samples
Vector of new proposed variance samples.
Definition: PMCMCBase.h:130
const T & getParam(const std::string &name) const
std::vector< Real > _rnd_vec
Vector of random numbers for decision making.
Definition: PMCMCBase.h:133
const std::vector< Real > * _upper_bound
Upper bounds for making the next proposal.
Definition: PMCMCBase.h:118
const Distribution & getDistributionByName(const DistributionName &name) const
void setNumberOfCols(dof_id_type n_cols)
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
Definition: PMCMCBase.h:127
const Distribution * _var_prior
Storage for prior distribution object of the variance to be utilized.
Definition: PMCMCBase.h:112
void mooseError(Args &&... args) const
const InputParameters & parameters() const
std::vector< std::vector< Real > > _confg_values
Configuration values.
Definition: PMCMCBase.h:145
void setNumberOfRandomSeeds(std::size_t number)

Member Function Documentation

◆ combineWithExperimentalConfig()

void PMCMCBase::combineWithExperimentalConfig ( )
private

Generates combinations of the new samples with the experimental configurations.

Definition at line 165 of file PMCMCBase.C.

Referenced by computeSample().

166 {
167  unsigned int index1;
168  int index2 = -1;
169  std::vector<Real> tmp;
170  for (unsigned int i = 0; i < _num_parallel_proposals * _confg_values[0].size(); ++i)
171  {
172  index1 = i % _num_parallel_proposals;
173  if (index1 == 0)
174  ++index2;
175  tmp = _new_samples[index1];
176  for (unsigned int j = 0; j < _confg_values.size(); ++j)
177  tmp.push_back(_confg_values[j][index2]);
178  _new_samples_confg[i] = tmp;
179  }
180 }
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition: PMCMCBase.h:106
std::vector< std::vector< Real > > _new_samples_confg
Vectors of new proposed samples combined with the experimental configuration values.
Definition: PMCMCBase.h:148
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
Definition: PMCMCBase.h:127
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
std::vector< std::vector< Real > > _confg_values
Configuration values.
Definition: PMCMCBase.h:145

◆ computeSample()

Real PMCMCBase::computeSample ( dof_id_type  row_index,
dof_id_type  col_index 
)
overrideprotectedvirtual

Implements Sampler.

Definition at line 207 of file PMCMCBase.C.

208 {
209  if (_t_step < 1)
210  for (unsigned int i = 0; i < _num_parallel_proposals; ++i)
212 
213  // Combine the proposed samples with experimental configurations
215 
216  return _new_samples_confg[row_index][col_index];
217 }
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition: PMCMCBase.h:106
const std::vector< Real > & _initial_values
Initial values of the input params to get the MCMC scheme started.
Definition: PMCMCBase.h:124
std::vector< std::vector< Real > > _new_samples_confg
Vectors of new proposed samples combined with the experimental configuration values.
Definition: PMCMCBase.h:148
void combineWithExperimentalConfig()
Generates combinations of the new samples with the experimental configurations.
Definition: PMCMCBase.C:165
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
Definition: PMCMCBase.h:127

◆ decisionStep()

virtual int PMCMCBase::decisionStep ( ) const
inlinevirtual

Return the step after which decision making can begin.

Reimplemented in AffineInvariantDES, AffineInvariantStretchSampler, and IndependentGaussianMH.

Definition at line 64 of file PMCMCBase.h.

Referenced by PMCMCDecision::execute().

64 { return 1; }

◆ getNumberOfConfigParams()

dof_id_type PMCMCBase::getNumberOfConfigParams ( ) const
inline

Return the number of configuration parameters.

Definition at line 34 of file PMCMCBase.h.

Referenced by PMCMCDecision::PMCMCDecision().

34 { return _confg_values.size(); }
std::vector< std::vector< Real > > _confg_values
Configuration values.
Definition: PMCMCBase.h:145

◆ getNumberOfConfigValues()

dof_id_type PMCMCBase::getNumberOfConfigValues ( ) const
inline

Return the number of configuration parameters.

Definition at line 29 of file PMCMCBase.h.

Referenced by PMCMCDecision::PMCMCDecision().

29 { return _confg_values[0].size(); }
std::vector< std::vector< Real > > _confg_values
Configuration values.
Definition: PMCMCBase.h:145

◆ getNumParallelProposals()

dof_id_type PMCMCBase::getNumParallelProposals ( ) const
inline

Return the number of parallel proposals.

Definition at line 39 of file PMCMCBase.h.

Referenced by PMCMCDecision::PMCMCDecision().

39 { return _num_parallel_proposals; }
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition: PMCMCBase.h:106

◆ getPriors()

const std::vector< const Distribution * > PMCMCBase::getPriors ( ) const

Return the priors to facilitate decision making in reporters.

Definition at line 195 of file PMCMCBase.C.

196 {
197  return _priors;
198 }
std::vector< const Distribution * > _priors
Storage for prior distribution objects to be utilized.
Definition: PMCMCBase.h:109

◆ getRandomNumbers()

const std::vector< Real > & PMCMCBase::getRandomNumbers ( ) const

Return the random numbers to facilitate decision making in reporters.

Definition at line 183 of file PMCMCBase.C.

184 {
185  return _rnd_vec;
186 }
std::vector< Real > _rnd_vec
Vector of random numbers for decision making.
Definition: PMCMCBase.h:133

◆ getVarPrior()

const Distribution * PMCMCBase::getVarPrior ( ) const

Return the prior over variance to facilitate decision making in reporters.

Definition at line 201 of file PMCMCBase.C.

202 {
203  return _var_prior;
204 }
const Distribution * _var_prior
Storage for prior distribution object of the variance to be utilized.
Definition: PMCMCBase.h:112

◆ getVarSamples()

const std::vector< Real > & PMCMCBase::getVarSamples ( ) const

Return the proposed variance samples to facilitate decision making in reporters.

Definition at line 189 of file PMCMCBase.C.

190 {
191  return _new_var_samples;
192 }
std::vector< Real > _new_var_samples
Vector of new proposed variance samples.
Definition: PMCMCBase.h:130

◆ proposeSamples()

void PMCMCBase::proposeSamples ( const unsigned int  seed_value)
protectedvirtual

Fill in the _new_samples vector of vectors (happens within sampleSetUp)

Parameters
seed_valueThe seed for the random number generator

Reimplemented in AffineInvariantStretchSampler, AffineInvariantDES, and IndependentGaussianMH.

Definition at line 116 of file PMCMCBase.C.

Referenced by sampleSetUp().

117 {
118  for (unsigned int j = 0; j < _num_parallel_proposals; ++j)
119  for (unsigned int i = 0; i < _priors.size(); ++i)
120  _new_samples[j][i] = _priors[i]->quantile(getRand(seed_value));
121 }
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition: PMCMCBase.h:106
std::vector< const Distribution * > _priors
Storage for prior distribution objects to be utilized.
Definition: PMCMCBase.h:109
Real getRand(unsigned int index=0)
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
Definition: PMCMCBase.h:127
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")

◆ randomIndex()

void PMCMCBase::randomIndex ( const unsigned int upper_bound,
const unsigned int exclude,
const unsigned int seed,
unsigned int req_index 
)
protected

Sample a random index excluding a specified index.

Parameters
upper_boundThe upper bound provided
excludeThe index to be excluded from sampling
seedThe seed of the random number generator
req_indexThe required index to be filled

Definition at line 141 of file PMCMCBase.C.

Referenced by AffineInvariantStretchSampler::proposeSamples(), and randomIndexPair().

145 {
146  req_index = exclude;
147  while (req_index == exclude)
148  req_index = getRandl(seed, 0, upper_bound);
149 }
uint32_t getRandl(unsigned int index, uint32_t lower, uint32_t upper)

◆ randomIndexPair()

void PMCMCBase::randomIndexPair ( const unsigned int upper_bound,
const unsigned int exclude,
const unsigned int seed,
unsigned int req_index1,
unsigned int req_index2 
)
protected

Sample two random indices without repitition excluding a specified index.

Parameters
upper_boundThe upper bound provided
excludeThe index to be excluded from sampling
seedThe seed of the random number generator
req_index1The required index 1 to be filled
req_index2The required index 2 to be filled

Definition at line 152 of file PMCMCBase.C.

Referenced by AffineInvariantDES::proposeSamples().

157 {
158  randomIndex(upper_bound, exclude, seed, req_index1);
159  req_index2 = req_index1;
160  while (req_index1 == req_index2)
161  randomIndex(upper_bound, exclude, seed, req_index2);
162 }
void randomIndex(const unsigned int &upper_bound, const unsigned int &exclude, const unsigned int &seed, unsigned int &req_index)
Sample a random index excluding a specified index.
Definition: PMCMCBase.C:141

◆ sampleSetUp()

void PMCMCBase::sampleSetUp ( const Sampler::SampleMode  mode)
overrideprotectedvirtual

Reimplemented from Sampler.

Definition at line 124 of file PMCMCBase.C.

125 {
126  if (_t_step < 1 || _check_step == _t_step)
127  return;
129 
130  unsigned int seed_value = _t_step > 0 ? (_t_step - 1) : 0;
131 
132  // Filling the new_samples vector of vectors with new proposal samples
133  proposeSamples(seed_value);
134 
135  // Draw random numbers to facilitate decision making later on
136  for (unsigned int j = 0; j < _num_parallel_proposals; ++j)
137  _rnd_vec[j] = getRand(seed_value);
138 }
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition: PMCMCBase.h:106
int _check_step
Ensure that the MCMC algorithm proceeds in a sequential fashion.
Definition: PMCMCBase.h:121
Real getRand(unsigned int index=0)
virtual void proposeSamples(const unsigned int seed_value)
Fill in the _new_samples vector of vectors (happens within sampleSetUp)
Definition: PMCMCBase.C:116
std::vector< Real > _rnd_vec
Vector of random numbers for decision making.
Definition: PMCMCBase.h:133
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")

◆ validParams()

InputParameters PMCMCBase::validParams ( )
static

Definition at line 18 of file PMCMCBase.C.

Referenced by AffineInvariantDES::validParams(), IndependentGaussianMH::validParams(), and AffineInvariantStretchSampler::validParams().

19 {
21  params.addClassDescription("Parallel Markov chain Monte Carlo base.");
22  params.addRequiredParam<std::vector<DistributionName>>(
23  "prior_distributions", "The prior distributions of the parameters to be calibrated.");
24  params.addParam<DistributionName>(
25  "prior_variance", "The prior distribution of the variance parameter to be calibrated.");
26  params.addRequiredParam<unsigned int>(
27  "num_parallel_proposals",
28  "Number of proposals to make and corresponding subApps executed in "
29  "parallel.");
30  params.addRequiredParam<FileName>("file_name", "Name of the CSV file with configuration values.");
31  params.addParam<std::string>(
32  "file_column_name", "Name of column in CSV file to use, by default first column is used.");
33  params.addParam<unsigned int>(
34  "num_columns", "Number of columns to be used in the CSV file with the configuration values.");
35  params.addParam<std::vector<Real>>("lower_bound", "Lower bounds for making the next proposal.");
36  params.addParam<std::vector<Real>>("upper_bound", "Upper bounds for making the next proposal.");
37  params.addRequiredParam<std::vector<Real>>("initial_values",
38  "The starting values of the inputs to be calibrated.");
39  params.addParam<unsigned int>(
40  "num_random_seeds",
41  100000,
42  "Initialize a certain number of random seeds. Change from the default only if you have to.");
43  return params;
44 }
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _check_step

int PMCMCBase::_check_step
protected

Ensure that the MCMC algorithm proceeds in a sequential fashion.

Definition at line 121 of file PMCMCBase.h.

Referenced by PMCMCBase(), and sampleSetUp().

◆ _confg_values

std::vector<std::vector<Real> > PMCMCBase::_confg_values
private

Configuration values.

Definition at line 145 of file PMCMCBase.h.

Referenced by combineWithExperimentalConfig(), getNumberOfConfigParams(), getNumberOfConfigValues(), and PMCMCBase().

◆ _initial_values

const std::vector<Real>& PMCMCBase::_initial_values
protected

Initial values of the input params to get the MCMC scheme started.

Definition at line 124 of file PMCMCBase.h.

Referenced by computeSample(), PMCMCBase(), and IndependentGaussianMH::proposeSamples().

◆ _lower_bound

const std::vector<Real>* PMCMCBase::_lower_bound
protected

Lower bounds for making the next proposal.

Definition at line 115 of file PMCMCBase.h.

Referenced by PMCMCBase(), AffineInvariantDES::proposeSamples(), IndependentGaussianMH::proposeSamples(), and AffineInvariantStretchSampler::proposeSamples().

◆ _new_samples

std::vector<std::vector<Real> > PMCMCBase::_new_samples
protected

◆ _new_samples_confg

std::vector<std::vector<Real> > PMCMCBase::_new_samples_confg
private

Vectors of new proposed samples combined with the experimental configuration values.

Definition at line 148 of file PMCMCBase.h.

Referenced by combineWithExperimentalConfig(), computeSample(), and PMCMCBase().

◆ _new_var_samples

std::vector<Real> PMCMCBase::_new_var_samples
protected

Vector of new proposed variance samples.

Definition at line 130 of file PMCMCBase.h.

Referenced by getVarSamples(), PMCMCBase(), AffineInvariantDES::proposeSamples(), and AffineInvariantStretchSampler::proposeSamples().

◆ _num_parallel_proposals

const unsigned int PMCMCBase::_num_parallel_proposals
protected

◆ _num_random_seeds

const unsigned int PMCMCBase::_num_random_seeds
private

Initialize a certain number of random seeds. Change from the default only if you have to.

Definition at line 142 of file PMCMCBase.h.

Referenced by PMCMCBase().

◆ _priors

std::vector<const Distribution *> PMCMCBase::_priors
protected

◆ _rnd_vec

std::vector<Real> PMCMCBase::_rnd_vec
protected

Vector of random numbers for decision making.

Definition at line 133 of file PMCMCBase.h.

Referenced by getRandomNumbers(), PMCMCBase(), and sampleSetUp().

◆ _upper_bound

const std::vector<Real>* PMCMCBase::_upper_bound
protected

Upper bounds for making the next proposal.

Definition at line 118 of file PMCMCBase.h.

Referenced by PMCMCBase(), and IndependentGaussianMH::proposeSamples().

◆ _var_prior

const Distribution* PMCMCBase::_var_prior
protected

Storage for prior distribution object of the variance to be utilized.

Definition at line 112 of file PMCMCBase.h.

Referenced by getVarPrior(), PMCMCBase(), AffineInvariantDES::proposeSamples(), and AffineInvariantStretchSampler::proposeSamples().


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