21 params.
addClassDescription(
"Generic reporter which decides whether or not to accept a proposed " 22 "sample in parallel Markov chain Monte Carlo type of algorithms.");
27 "Modified value of the model output from this reporter class.");
28 params.
addParam<ReporterValueName>(
"inputs",
"inputs",
"Uncertain inputs to the model.");
29 params.
addParam<ReporterValueName>(
"tpm",
"tpm",
"The transition probability matrix.");
30 params.
addParam<ReporterValueName>(
"variance",
"variance",
"Model variance term.");
32 "noise",
"noise",
"Model noise term to pass to Likelihoods object.");
34 params.
addRequiredParam<std::vector<UserObjectName>>(
"likelihoods",
"Names of likelihoods.");
41 _inputs(declareValue<
std::vector<
std::vector<
Real>>>(
"inputs")),
42 _tpm(declareValue<
std::vector<
Real>>(
"tpm")),
43 _variance(declareValue<
std::vector<
Real>>(
"variance")),
44 _noise(declareValue<
Real>(
"noise")),
45 _sampler(getSampler(
"sampler")),
46 _pmcmc(dynamic_cast<const
PMCMCBase *>(&_sampler)),
47 _rnd_vec(_pmcmc->getRandomNumbers()),
48 _new_var_samples(_pmcmc->getVarSamples()),
49 _priors(_pmcmc->getPriors()),
50 _var_prior(_pmcmc->getVarPrior()),
52 isParamValid(
"output_value")
55 _output_value(isParamValid(
"output_value") ? &getReporterValue<
std::vector<
Real>>(
58 _local_comm(_sampler.getLocalComm()),
59 _check_step(
std::numeric_limits<
int>::
max())
62 for (
const UserObjectName &
name :
getParam<std::vector<UserObjectName>>(
"likelihoods"))
67 paramError(
"sampler",
"The selected sampler is not of type MCMC.");
76 for (
unsigned int i = 0; i <
_props; ++i)
88 paramError(
"output_value",
"Value of the model output from the SubApp should be specified.");
96 for (
unsigned int i = 0; i < evidence.size(); ++i)
99 for (
unsigned int j = 0;
j <
_priors.size(); ++
j)
100 evidence[i] += (std::log(
_priors[
j]->pdf(input_matrix(i,
j))) -
104 out1[
j] = (*_outputs_required)[
j *
_props + i];
126 const std::vector<Real> & )
134 const std::vector<Real> & tv,
135 const unsigned int & parallel_index)
137 if (tv[parallel_index] >=
_rnd_vec[parallel_index])
140 req_inputs[
k] = input_matrix(parallel_index,
k);
148 input_matrix(parallel_index,
k) =
_data_prev(parallel_index,
k);
173 data_in(ss,
j) = data[
j];
183 std::vector<Real> evidence(
_props);
194 for (
unsigned int i = 0; i <
_props; ++i)
std::vector< Real > * _outputs_required
Transfer the right outputs to the file.
const std::vector< Real > * _output_value
Current output values.
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
dof_id_type _num_confg_values
Storage for the number of experimental configuration values.
dof_id_type getNumberOfConfigValues() const
Return the number of configuration parameters.
PMCMCDecision will help making sample accept/reject decisions in MCMC schemes (for e...
virtual Real pdf(const Real &x) const=0
dof_id_type getNumberOfConfigParams() const
Return the number of configuration parameters.
void paramError(const std::string ¶m, Args... args) const
const T & getParam(const std::string &name) const
virtual void computeEvidence(std::vector< Real > &evidence, const DenseMatrix< Real > &input_matrix)
Compute the evidence (aka, betterness of the proposed sample vs the previous)
Real & _noise
Model noise term to pass to Likelihoods object.
std::vector< Real > getNextLocalRow()
dof_id_type getLocalRowBegin() const
static InputParameters validParams()
dof_id_type _num_confg_params
Storage for the number of experimental configuration parameters.
virtual void execute() override
dof_id_type getNumberOfLocalRows() const
std::vector< Real > & _variance
Model variance term.
auto max(const L &left, const R &right)
int _check_step
Ensure that the MCMC algorithm proceeds in a sequential fashion.
dof_id_type getNumParallelProposals() const
Return the number of parallel proposals.
libMesh::Parallel::Communicator & _local_comm
Communicator that was split based on samples that have rows.
PMCMCDecision(const InputParameters ¶meters)
const std::string & name() const
virtual bool usingGP() const
Flag to specify if a pre-trained Gaussian process model is used.
DenseMatrix< Real > _data_prev
Storage for previous inputs.
std::vector< Real > _var_prev
Storage for previous variances.
const PMCMCBase *const _pmcmc
MCMC sampler base.
virtual void computeTransitionVector(std::vector< Real > &tv, const std::vector< Real > &evidence)
Compute the transition probability vector (after the computation of evidence)
const ReporterMode REPORTER_MODE_DISTRIBUTED
static InputParameters validParams()
virtual void nextSeeds()
Compute the next set of seeds to facilitate proposals.
dof_id_type getLocalRowEnd() const
const Distribution * _var_prior
Storage for the prior over the variance.
dof_id_type getNumberOfRows() const
const std::vector< const Distribution * > _priors
Storage for the priors.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
registerMooseObject("StochasticToolsApp", PMCMCDecision)
dof_id_type _props
Storage for the number of parallel proposals.
LikelihoodFunctionBase * getLikelihoodFunctionByName(const UserObjectName &name) const
Lookup a LikelihoodFunction object by name and return pointer.
virtual void nextSamples(std::vector< Real > &req_inputs, DenseMatrix< Real > &input_matrix, const std::vector< Real > &tv, const unsigned int ¶llel_index)
Resample inputs given the transition vector (after transition vector computed)
static InputParameters validParams()
virtual int decisionStep() const
Return the step after which decision making can begin.
std::vector< const LikelihoodFunctionBase * > _likelihoods
Storage for the likelihood objects to be utilized.
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
std::vector< Real > _outputs_prev
Storage for previous outputs.
bool isParamValid(const std::string &name) const
Sampler & _sampler
The MCMC sampler.
virtual void initialize() override
const std::vector< Real > & _new_var_samples
Storage for new proposed variance samples.
const std::vector< Real > & _rnd_vec
Storage for the random numbers for decision making.
std::vector< Real > & _tpm
Transition probability matrix.
static const std::string k
void ErrorVector unsigned int
std::vector< std::vector< Real > > & _inputs
Model input data that is uncertain.
dof_id_type getNumberOfCols() const
A base class used to perform Parallel Markov Chain Monte Carlo (MCMC) sampling.