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> & )
133 DenseMatrix<Real> & input_matrix,
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);
147 req_inputs[k] =
_data_prev(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)
registerMooseObject("StochasticToolsApp", PMCMCDecision)
const ReporterMode REPORTER_MODE_DISTRIBUTED
void ErrorVector unsigned int
virtual Real pdf(const Real &x) const=0
static InputParameters validParams()
static InputParameters validParams()
LikelihoodFunctionBase * getLikelihoodFunctionByName(const UserObjectName &name) const
Lookup a LikelihoodFunction object by name and return pointer.
const std::string & name() const
void paramError(const std::string ¶m, Args... args) const
bool isParamValid(const std::string &name) const
A base class used to perform Parallel Markov Chain Monte Carlo (MCMC) sampling.
dof_id_type getNumberOfConfigParams() const
Return the number of configuration parameters.
virtual int decisionStep() const
Return the step after which decision making can begin.
dof_id_type getNumberOfConfigValues() const
Return the number of configuration parameters.
dof_id_type getNumParallelProposals() const
Return the number of parallel proposals.
PMCMCDecision will help making sample accept/reject decisions in MCMC schemes (for e....
const std::vector< Real > & _rnd_vec
Storage for the random numbers for decision making.
std::vector< Real > & _tpm
Transition probability matrix.
int _check_step
Ensure that the MCMC algorithm proceeds in a sequential fashion.
dof_id_type _num_confg_values
Storage for the number of experimental configuration values.
libMesh::Parallel::Communicator & _local_comm
Communicator that was split based on samples that have rows.
std::vector< const LikelihoodFunctionBase * > _likelihoods
Storage for the likelihood objects to be utilized.
std::vector< Real > & _variance
Model variance term.
virtual void execute() override
virtual void nextSeeds()
Compute the next set of seeds to facilitate proposals.
std::vector< std::vector< Real > > & _inputs
Model input data that is uncertain.
const std::vector< const Distribution * > _priors
Storage for the priors.
virtual void initialize() override
dof_id_type _num_confg_params
Storage for the number of experimental configuration parameters.
Sampler & _sampler
The MCMC sampler.
virtual bool usingGP() const
Flag to specify if a pre-trained Gaussian process model is used.
static InputParameters validParams()
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)
const std::vector< Real > * _output_value
Current output values.
std::vector< Real > _var_prev
Storage for previous variances.
DenseMatrix< Real > _data_prev
Storage for previous inputs.
const PMCMCBase *const _pmcmc
MCMC sampler base.
const Distribution * _var_prior
Storage for the prior over the variance.
PMCMCDecision(const InputParameters ¶meters)
Real & _noise
Model noise term to pass to Likelihoods object.
const std::vector< Real > & _new_var_samples
Storage for new proposed variance samples.
std::vector< Real > _outputs_prev
Storage for previous outputs.
virtual void computeTransitionVector(std::vector< Real > &tv, const std::vector< Real > &evidence)
Compute the transition probability vector (after the computation of evidence)
dof_id_type _props
Storage for the number of parallel proposals.
virtual void computeEvidence(std::vector< Real > &evidence, const DenseMatrix< Real > &input_matrix)
Compute the evidence (aka, betterness of the proposed sample vs the previous)
std::vector< Real > * _outputs_required
Transfer the right outputs to the file.
std::vector< Real > getNextLocalRow()
dof_id_type getNumberOfLocalRows() const
dof_id_type getLocalRowEnd() const
dof_id_type getLocalRowBegin() const
dof_id_type getNumberOfRows() const
dof_id_type getNumberOfCols() const
void allgather(const T &send_data, std::vector< T, A > &recv_data) const