15#ifdef MOOSE_LIBTORCH_ENABLED
25 params.
addClassDescription(
"Generic reporter which decides whether or not to accept a proposed "
26 "sample in Adaptive Monte Carlo type of algorithms.");
28 "Value of the model output from the SubApp.");
32 "Modified value of the model output from this reporter class.");
33 params.
addParam<ReporterValueName>(
"inputs",
"inputs",
"Uncertain inputs to the model.");
35 params.
addParam<UserObjectName>(
"gp_decision",
"The Gaussian Process decision reporter.");
41 _output_value(isParamValid(
"gp_decision") ? getReporterValue<
std::vector<Real>>(
"output_value")
42 : getReporterValue<
std::vector<Real>>(
44 _output_required(declareValue<
std::vector<Real>>(
"output_required")),
45 _inputs(declareValue<
std::vector<
std::vector<Real>>>(
"inputs")),
46 _sampler(getSampler(
"sampler")),
49 _check_step(
std::numeric_limits<
int>::max()),
50 _local_comm(_sampler.getLocalComm()),
51 _gp_used(isParamValid(
"gp_decision")),
52#ifdef MOOSE_LIBTORCH_ENABLED
57 _gp_training_samples(nullptr)
60#ifndef MOOSE_LIBTORCH_ENABLED
62 paramError(
"gp_decision",
"The 'gp_decision' parameter requires libtorch.");
67 paramError(
"sampler",
"The selected sampler is not an adaptive sampler.");
73 _inputs.resize(cols, std::vector<Real>(rows));
74 _prev_val.resize(cols, std::vector<Real>(rows));
97 for (dof_id_type j = 0; j < tmp1.size(); ++j)
130 if (_t_step <= _ais->getNumSamplesTrain() && !restart_gp)
138 if (output_limit_reached)
154 const unsigned int subset =
156 const unsigned int sub_ind =
166 data_in(ss, j) = data[j];
192 if (sub_ind % count_max == 0)
226 if (!output_limit_reached)
registerMooseObject("StochasticToolsApp", AdaptiveMonteCarloDecision)
const ReporterMode REPORTER_MODE_DISTRIBUTED
void ErrorVector unsigned int
A class used to perform Adaptive Importance Sampling using a Markov Chain Monte Carlo algorithm.
const bool & getUseAbsoluteValue() const
const Real & getOutputLimit() const
const int & getNumSamplesTrain() const
const std::vector< Real > & getInitialValues() const
AdaptiveMonteCarloDecision will help make sample accept/reject decisions in adaptive Monte Carlo sche...
std::vector< Real > _output_sorted
Store the sorted output sample values.
std::vector< std::vector< Real > > _prev_val
Storage for previously accepted input values. This helps in making decision on the next proposed inpu...
std::vector< std::vector< Real > > & _inputs
Model input data that is uncertain.
std::vector< Real > & _output_required
Modified value of model output by this reporter class.
virtual void execute() override
const bool _gp_used
Check if a GP is used.
static InputParameters validParams()
const int *const _gp_training_samples
Store the GP training samples.
libMesh::Parallel::Communicator & _local_comm
Communicator that was split based on samples that have rows.
const std::vector< Real > & _output_value
Model output value from SubApp.
Sampler & _sampler
The adaptive Monte Carlo sampler.
AdaptiveMonteCarloDecision(const InputParameters ¶meters)
std::vector< Real > _outputs_sto
Storage for previously accepted sample outputs across all the subsets.
const AdaptiveImportanceSampler *const _ais
Adaptive Importance Sampler.
Real _output_limit
Store the intermediate ouput failure thresholds.
std::vector< Real > _prev_val_out
Storage for previously accepted output value.
int _check_step
Ensure that the MCMC algorithm proceeds in a sequential fashion.
const ParallelSubsetSimulation *const _pss
Parallel Subset Simulation sampler.
std::vector< std::vector< Real > > _inputs_sto
Storage for the previously accepted sample inputs across all the subsets.
void reinitChain()
This reinitializes the Markov chain to the starting value until the Gaussian process training is comp...
std::vector< std::vector< Real > > _inputs_sorted
Store the sorted input samples according to their corresponding outputs.
static InputParameters validParams()
void paramError(const std::string ¶m, Args... args) const
A class used to perform Parallel Subset Simulation Sampling.
const Real & getSubsetProbability() const
Access the subset probability.
const unsigned int & getNumSamplesSub() const
Access the number samples per subset.
const bool & getUseAbsoluteValue() const
Access use absolute value bool.
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
std::vector< Real > sortOutput(const std::vector< Real > &outputs, const unsigned int samplessub, const Real subset_prob)
return the largest po percentile output values.
Real computeMin(const std::vector< Real > &data)
return the minimum value in a vector.
std::vector< std::vector< Real > > sortInput(const std::vector< std::vector< Real > > &inputs, const std::vector< Real > &outputs, const unsigned int samplessub, const Real subset_prob)
return input values corresponding to the largest po percentile output values.
std::vector< Real > computeVectorABS(const std::vector< Real > &data)
return the absolute values in a vector.