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(declareRestartableData<
int>(
"check_step",
std::numeric_limits<
int>::max())),
50 _prev_val(declareRestartableData<
std::vector<
std::vector<Real>>>(
"prev_val")),
51 _prev_val_out(declareRestartableData<
std::vector<Real>>(
"prev_val_out")),
52 _inputs_sto(declareRestartableData<
std::vector<
std::vector<Real>>>(
"inputs_sto")),
53 _inputs_sorted(declareRestartableData<
std::vector<
std::vector<Real>>>(
"inputs_sorted")),
54 _outputs_sto(declareRestartableData<
std::vector<Real>>(
"outputs_sto")),
55 _output_sorted(declareRestartableData<
std::vector<Real>>(
"output_sorted")),
56 _output_limit(declareRestartableData<Real>(
"output_limit", 0.0)),
57 _gp_used(isParamValid(
"gp_decision")),
58#ifdef MOOSE_LIBTORCH_ENABLED
63 _gp_training_samples(nullptr)
66#ifndef MOOSE_LIBTORCH_ENABLED
68 paramError(
"gp_decision",
"The 'gp_decision' parameter requires libtorch.");
73 paramError(
"sampler",
"The selected sampler is not an adaptive sampler.");
79 _inputs.resize(cols, std::vector<Real>(rows));
80 _prev_val.resize(cols, std::vector<Real>(rows));
103 for (dof_id_type j = 0; j < tmp1.size(); ++j)
136 if (_t_step <= _ais->getNumSamplesTrain() && !restart_gp)
144 if (output_limit_reached)
160 const unsigned int subset =
162 const unsigned int sub_ind =
171 "Incorrectly sized outputs.");
194 if (sub_ind % count_max == 0)
228 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< 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()
std::vector< Real > & _prev_val_out
Storage for previously accepted output value.
std::vector< std::vector< Real > > & _inputs_sorted
Store the sorted input samples according to their corresponding outputs.
const int *const _gp_training_samples
Store the GP training samples.
const std::vector< Real > & _output_value
Model output value from SubApp.
int & _check_step
Ensure that the MCMC algorithm proceeds in a sequential fashion.
Sampler & _sampler
The adaptive Monte Carlo sampler.
AdaptiveMonteCarloDecision(const InputParameters ¶meters)
std::vector< std::vector< Real > > & _prev_val
Storage for previously accepted input values. This helps in making decision on the next proposed inpu...
const AdaptiveImportanceSampler *const _ais
Adaptive Importance Sampler.
std::vector< std::vector< Real > > & _inputs_sto
Storage for the previously accepted sample inputs across all the subsets.
Real & _output_limit
Store the intermediate ouput failure thresholds.
std::vector< Real > & _outputs_sto
Storage for previously accepted sample outputs across all the subsets.
const ParallelSubsetSimulation *const _pss
Parallel Subset Simulation sampler.
void reinitChain()
This reinitializes the Markov chain to the starting value until the Gaussian process training is comp...
std::vector< Real > & _output_sorted
Store the sorted output sample values.
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.
dof_id_type getNumberOfLocalRows() const
std::vector< Real > getSampleRow(dof_id_type row_index) const
dof_id_type getNumberOfRows() const
dof_id_type getNumberOfCols() const
DenseMatrix< Real > getGlobalSamples()
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
const Parallel::Communicator & _communicator
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.