https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | 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< std::vector< Real > > & getSamples () const
 Return the proposed 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
 
bool isKokkosObject () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParametersparameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const TgetParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const TqueryParam (const std::string &name) const
 
const TgetRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool haveParameter (const std::string &name) const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (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
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) 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 ()
 
TgetSampler (const std::string &name)
 
SamplergetSampler (const std::string &name)
 
TgetSamplerByName (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 TgetDistribution (const std::string &name) const
 
const DistributiongetDistribution (const std::string &name) const
 
const TgetDistribution (const std::string &name) const
 
const DistributiongetDistributionByName (const DistributionName &name) const
 
const TgetDistributionByName (const std::string &name) const
 
const DistributiongetDistributionByName (const DistributionName &name) const
 
const TgetDistributionByName (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 ()
 
static void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 

Protected Member Functions

virtual void proposeSamples ()
 Fill in the _new_samples vector of vectors (happens within sampleSetUp) More...
 
virtual void executeSetUp () override
 
virtual Real computeSample (dof_id_type row_index, dof_id_type col_index) override
 
Real random ()
 Sample a random number between 0 and 1. More...
 
unsigned int randomIndex (const unsigned int &upper_bound, const unsigned int &exclude)
 Sample a random index excluding a specified index. More...
 
std::pair< unsigned int, unsigned intrandomIndexPair (const unsigned int &upper_bound, const unsigned int &exclude)
 Sample two random indices without repitition excluding a specified index. More...
 
void setNumberOfRandomSeeds (std::size_t number)
 
Real getRand (std::size_t n, unsigned int index=0) const
 
unsigned int getRandl (std::size_t n, unsigned int lower, unsigned int upper, unsigned int index=0) const
 
virtual LocalRankConfig constructRankConfig (bool batch_mode) const
 
void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) 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 ReporterContextBasegetReporterContextBaseByName (const ReporterName &reporter_name) 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 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)
 
virtual void executeTearDown ()
 
virtual void executeTearDown ()
 
const TgetReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const TgetReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const TgetReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const TgetReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const TgetReporterValueByName (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...
 
const Real_variance_bound
 Upper bound for variance for making the next proposal. 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...
 
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
 
Factory_factory
 
ActionFactory_action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters_pars
 
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...
 
unsigned int _seed_index
 Generator index when requesting random numbers. More...
 
std::size_t _rand_index
 Running index for the random number generators. 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 49 of file PMCMCBase.C.

51  TransientInterface(this),
52  _num_parallel_proposals(getParam<unsigned int>("num_parallel_proposals")),
53  _lower_bound(isParamValid("lower_bound") ? &getParam<std::vector<Real>>("lower_bound")
54  : nullptr),
55  _upper_bound(isParamValid("upper_bound") ? &getParam<std::vector<Real>>("upper_bound")
56  : nullptr),
57  _variance_bound(getParam<Real>("variance_bound")),
58  _initial_values(getParam<std::vector<Real>>("initial_values")),
59  _num_random_seeds(getParam<unsigned int>("num_random_seeds")),
60  _seed_index(0),
61  _rand_index(0)
62 {
63  // Filling the `priors` vector with the user-provided distributions.
64  for (const DistributionName & name :
65  getParam<std::vector<DistributionName>>("prior_distributions"))
66  _priors.push_back(&getDistributionByName(name));
67 
68  // Filling the `var_prior` object with the user-provided distribution for the variance.
69  if (isParamValid("prior_variance"))
70  _var_prior = &getDistributionByName(getParam<DistributionName>("prior_variance"));
71  else
72  _var_prior = nullptr;
73 
74  // Read the experimental configurations from a csv file
75  MooseUtils::DelimitedFileReader reader(getParam<FileName>("file_name"));
76  reader.read();
77  _confg_values.resize(1);
78  if (isParamValid("file_column_name"))
79  _confg_values[0] = reader.getData(getParam<std::string>("file_column_name"));
80  else if (isParamValid("num_columns"))
81  {
82  _confg_values.resize(getParam<unsigned int>("num_columns"));
83  for (unsigned int i = 0; i < _confg_values.size(); ++i)
84  _confg_values[i] = reader.getData(i);
85  }
86  else
87  _confg_values[0] = reader.getData(0);
88 
89  // Setting the number of sampler rows to be equal to the number of parallel proposals
91 
92  // Setting the number of columns in the sampler matrix (equal to the number of distributions).
93  setNumberOfCols(_priors.size() + _confg_values.size());
94 
95  // Resizing the vectors and vector of vectors
98  std::vector<Real>(_priors.size() + _confg_values.size(), 0.0));
101 
104 
105  // Check whether both the lower and the upper bounds are specified and of same size
106  bool bound_check1 = _lower_bound && !_upper_bound;
107  bool bound_check2 = !_lower_bound && _upper_bound;
108  if (bound_check1 || bound_check2)
109  mooseError("Both lower and upper bounds should be specified.");
110  bool size_check = _lower_bound ? ((*_lower_bound).size() != (*_upper_bound).size()) : 0;
111  if (size_check)
112  mooseError("Lower and upper bounds should be of the same size.");
113 
114  // Check whether the priors, bounds, and initial values are all of the same size
115  if (_priors.size() != _initial_values.size())
116  mooseError("The priors and initial values should be of the same size.");
117 }
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:148
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition: PMCMCBase.h:112
const std::vector< Real > & _initial_values
Initial values of the input params to get the MCMC scheme started.
Definition: PMCMCBase.h:130
std::size_t _rand_index
Running index for the random number generators.
Definition: PMCMCBase.h:154
const T & getParam(const std::string &name) const
std::vector< std::vector< Real > > _new_samples_confg
Vectors of new proposed samples combined with the experimental configuration values.
Definition: PMCMCBase.h:160
const std::vector< Real > * _lower_bound
Lower bounds for making the next proposal.
Definition: PMCMCBase.h:121
const InputParameters & parameters() const
std::vector< const Distribution * > _priors
Storage for prior distribution objects to be utilized.
Definition: PMCMCBase.h:115
Sampler(const InputParameters &parameters)
const Real & _variance_bound
Upper bound for variance for making the next proposal.
Definition: PMCMCBase.h:127
TransientInterface(const MooseObject *moose_object)
const std::string & name() const
std::vector< Real > _new_var_samples
Vector of new proposed variance samples.
Definition: PMCMCBase.h:136
unsigned int _seed_index
Generator index when requesting random numbers.
Definition: PMCMCBase.h:151
std::vector< Real > _rnd_vec
Vector of random numbers for decision making.
Definition: PMCMCBase.h:139
const std::vector< Real > * _upper_bound
Upper bounds for making the next proposal.
Definition: PMCMCBase.h:124
const Distribution & getDistributionByName(const DistributionName &name) const
void setAutoAdvanceGenerators(const bool state)
void setNumberOfCols(dof_id_type n_cols)
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
Definition: PMCMCBase.h:133
const Distribution * _var_prior
Storage for prior distribution object of the variance to be utilized.
Definition: PMCMCBase.h:118
void mooseError(Args &&... args) const
bool isParamValid(const std::string &name) const
std::vector< std::vector< Real > > _confg_values
Configuration values.
Definition: PMCMCBase.h:157
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 167 of file PMCMCBase.C.

Referenced by computeSample().

168 {
169  unsigned int index1;
170  int index2 = -1;
171  std::vector<Real> tmp;
172  for (unsigned int i = 0; i < _num_parallel_proposals * _confg_values[0].size(); ++i)
173  {
174  index1 = i % _num_parallel_proposals;
175  if (index1 == 0)
176  ++index2;
177  tmp = _new_samples[index1];
178  for (unsigned int j = 0; j < _confg_values.size(); ++j)
179  tmp.push_back(_confg_values[j][index2]);
180  _new_samples_confg[i] = tmp;
181  }
182 }
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition: PMCMCBase.h:112
std::vector< std::vector< Real > > _new_samples_confg
Vectors of new proposed samples combined with the experimental configuration values.
Definition: PMCMCBase.h:160
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
Definition: PMCMCBase.h:133
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:157

◆ computeSample()

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

Implements Sampler.

Definition at line 215 of file PMCMCBase.C.

216 {
217  if (_t_step < 1)
218  for (unsigned int i = 0; i < _num_parallel_proposals; ++i)
220 
221  // Combine the proposed samples with experimental configurations
223 
224  return _new_samples_confg[row_index][col_index];
225 }
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition: PMCMCBase.h:112
const std::vector< Real > & _initial_values
Initial values of the input params to get the MCMC scheme started.
Definition: PMCMCBase.h:130
std::vector< std::vector< Real > > _new_samples_confg
Vectors of new proposed samples combined with the experimental configuration values.
Definition: PMCMCBase.h:160
void combineWithExperimentalConfig()
Generates combinations of the new samples with the experimental configurations.
Definition: PMCMCBase.C:167
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
Definition: PMCMCBase.h:133

◆ 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 73 of file PMCMCBase.h.

Referenced by PMCMCDecision::execute().

73 { return 1; }

◆ executeSetUp()

void PMCMCBase::executeSetUp ( )
overrideprotectedvirtual

Reimplemented from Sampler.

Definition at line 128 of file PMCMCBase.C.

129 {
131  _rand_index = 0;
132 
133  // Filling the new_samples vector of vectors with new proposal samples
134  proposeSamples();
135 
136  // Draw random numbers to facilitate decision making later on
137  for (unsigned int j = 0; j < _num_parallel_proposals; ++j)
138  _rnd_vec[j] = random();
139 }
Real random()
Sample a random number between 0 and 1.
Definition: PMCMCBase.C:142
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition: PMCMCBase.h:112
std::size_t _rand_index
Running index for the random number generators.
Definition: PMCMCBase.h:154
virtual void proposeSamples()
Fill in the _new_samples vector of vectors (happens within sampleSetUp)
Definition: PMCMCBase.C:120
unsigned int _seed_index
Generator index when requesting random numbers.
Definition: PMCMCBase.h:151
std::vector< Real > _rnd_vec
Vector of random numbers for decision making.
Definition: PMCMCBase.h:139
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")

◆ getNumberOfConfigParams()

dof_id_type PMCMCBase::getNumberOfConfigParams ( ) const
inline

Return the number of configuration parameters.

Definition at line 34 of file PMCMCBase.h.

Referenced by BayesianActiveLearner::BayesianActiveLearner(), and PMCMCDecision::PMCMCDecision().

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

◆ getNumberOfConfigValues()

dof_id_type PMCMCBase::getNumberOfConfigValues ( ) const
inline

Return the number of configuration parameters.

Definition at line 29 of file PMCMCBase.h.

Referenced by BayesianActiveLearner::BayesianActiveLearner(), and PMCMCDecision::PMCMCDecision().

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

◆ 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:112

◆ getPriors()

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

Return the priors to facilitate decision making in reporters.

Definition at line 203 of file PMCMCBase.C.

204 {
205  return _priors;
206 }
std::vector< const Distribution * > _priors
Storage for prior distribution objects to be utilized.
Definition: PMCMCBase.h:115

◆ getRandomNumbers()

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

Return the random numbers to facilitate decision making in reporters.

Definition at line 185 of file PMCMCBase.C.

186 {
187  return _rnd_vec;
188 }
std::vector< Real > _rnd_vec
Vector of random numbers for decision making.
Definition: PMCMCBase.h:139

◆ getSamples()

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

Return the proposed samples to facilitate decision making in reporters.

In MCMC schemes, there is a decision-making step after evaluating the computational model on whether or not to accept the proposed samples. To facilitate this decision-making, which happens in the Reporter, we have to provide it the proposed samples.

Definition at line 197 of file PMCMCBase.C.

198 {
199  return _new_samples;
200 }
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
Definition: PMCMCBase.h:133

◆ getVarPrior()

const Distribution * PMCMCBase::getVarPrior ( ) const

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

Definition at line 209 of file PMCMCBase.C.

210 {
211  return _var_prior;
212 }
const Distribution * _var_prior
Storage for prior distribution object of the variance to be utilized.
Definition: PMCMCBase.h:118

◆ getVarSamples()

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

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

Definition at line 191 of file PMCMCBase.C.

192 {
193  return _new_var_samples;
194 }
std::vector< Real > _new_var_samples
Vector of new proposed variance samples.
Definition: PMCMCBase.h:136

◆ proposeSamples()

void PMCMCBase::proposeSamples ( )
protectedvirtual

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

Parameters
seed_valueThe seed for the random number generator

Reimplemented in BayesianActiveLearningSampler, AffineInvariantStretchSampler, AffineInvariantDES, and IndependentGaussianMH.

Definition at line 120 of file PMCMCBase.C.

Referenced by executeSetUp().

121 {
122  for (unsigned int j = 0; j < _num_parallel_proposals; ++j)
123  for (unsigned int i = 0; i < _priors.size(); ++i)
124  _new_samples[j][i] = _priors[i]->quantile(random());
125 }
Real random()
Sample a random number between 0 and 1.
Definition: PMCMCBase.C:142
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
Definition: PMCMCBase.h:112
std::vector< const Distribution * > _priors
Storage for prior distribution objects to be utilized.
Definition: PMCMCBase.h:115
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
Definition: PMCMCBase.h:133
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")

◆ random()

Real PMCMCBase::random ( )
protected

Sample a random number between 0 and 1.

Parameters
upper_boundThe upper bound provided
Returns
The required index

Definition at line 142 of file PMCMCBase.C.

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

143 {
144  return getRand(_rand_index++, _seed_index);
145 }
std::size_t _rand_index
Running index for the random number generators.
Definition: PMCMCBase.h:154
Real getRand(std::size_t n, unsigned int index=0) const
unsigned int _seed_index
Generator index when requesting random numbers.
Definition: PMCMCBase.h:151

◆ randomIndex()

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

Sample a random index excluding a specified index.

Parameters
upper_boundThe upper bound provided
Returns
The required index

Definition at line 148 of file PMCMCBase.C.

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

149 {
150  auto req_index = exclude;
151  while (req_index == exclude)
152  req_index = getRandl(_rand_index++, 0, upper_bound, _seed_index);
153  return req_index;
154 }
std::size_t _rand_index
Running index for the random number generators.
Definition: PMCMCBase.h:154
unsigned int getRandl(std::size_t n, unsigned int lower, unsigned int upper, unsigned int index=0) const
unsigned int _seed_index
Generator index when requesting random numbers.
Definition: PMCMCBase.h:151

◆ randomIndexPair()

std::pair< unsigned int, unsigned int > PMCMCBase::randomIndexPair ( const unsigned int upper_bound,
const unsigned int exclude 
)
protected

Sample two random indices without repitition excluding a specified index.

Parameters
upper_boundThe upper bound provided
excludeThe index to be excluded from sampling
Returns
Pair of required indices

Definition at line 157 of file PMCMCBase.C.

Referenced by AffineInvariantDES::proposeSamples().

158 {
159  auto req_index1 = randomIndex(upper_bound, exclude);
160  auto req_index2 = req_index1;
161  while (req_index1 == req_index2)
162  req_index2 = randomIndex(upper_bound, exclude);
163  return {req_index1, req_index2};
164 }
unsigned int randomIndex(const unsigned int &upper_bound, const unsigned int &exclude)
Sample a random index excluding a specified index.
Definition: PMCMCBase.C:148

◆ validParams()

InputParameters PMCMCBase::validParams ( )
static

Definition at line 18 of file PMCMCBase.C.

Referenced by AffineInvariantDES::validParams(), IndependentGaussianMH::validParams(), AffineInvariantStretchSampler::validParams(), and BayesianActiveLearningSampler::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.addParam<Real>("variance_bound",
38  std::numeric_limits<Real>::max(),
39  "Upper bound for variance for making the next proposal.");
40  params.addRequiredParam<std::vector<Real>>("initial_values",
41  "The starting values of the inputs to be calibrated.");
42  params.addParam<unsigned int>(
43  "num_random_seeds",
44  100000,
45  "Initialize a certain number of random seeds. Change from the default only if you have to.");
46  return params;
47 }
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)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _confg_values

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

Configuration values.

Definition at line 157 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 130 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 121 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 160 of file PMCMCBase.h.

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

◆ _new_var_samples

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

◆ _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 148 of file PMCMCBase.h.

Referenced by PMCMCBase().

◆ _priors

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

◆ _rand_index

std::size_t PMCMCBase::_rand_index
private

Running index for the random number generators.

Definition at line 154 of file PMCMCBase.h.

Referenced by executeSetUp(), random(), and randomIndex().

◆ _rnd_vec

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

Vector of random numbers for decision making.

Definition at line 139 of file PMCMCBase.h.

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

◆ _seed_index

unsigned int PMCMCBase::_seed_index
private

Generator index when requesting random numbers.

Definition at line 151 of file PMCMCBase.h.

Referenced by executeSetUp(), random(), and randomIndex().

◆ _upper_bound

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

Upper bounds for making the next proposal.

Definition at line 124 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 118 of file PMCMCBase.h.

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

◆ _variance_bound

const Real& PMCMCBase::_variance_bound
protected

Upper bound for variance for making the next proposal.

Definition at line 127 of file PMCMCBase.h.

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


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