25 "The distribution names to be sampled, the number of distributions provided defines the "
26 "number of columns per matrix.");
29 "Standard deviations of the proposal distributions");
30 params.
addRequiredParam<Real>(
"output_limit",
"Limiting values of the VPPs");
32 "initial_values",
"Initial input values to get the importance sampler started");
35 "num_samples_train>0",
36 "Number of samples to learn the importance distribution");
38 "num_importance_sampling_steps",
39 "num_importance_sampling_steps>0",
40 "Number of importance sampling steps (after the importance distribution has been trained)");
42 "std_factor",
"Factor to be multiplied to the standard deviation of the importance samples");
43 params.
addParam<
bool>(
"use_absolute_value",
false,
"Use absolute value of the sub app output");
47 "Initialize a certain number of random seeds. Change from the default only if you have to.");
49 "Flag samples if the surrogate prediction was inadequate.");
56 _proposal_std(getParam<
std::vector<Real>>(
"proposal_std")),
57 _initial_values(getParam<
std::vector<Real>>(
"initial_values")),
58 _output_limit(getParam<Real>(
"output_limit")),
59 _num_samples_train(getParam<
int>(
"num_samples_train")),
60 _num_importance_sampling_steps(getParam<
int>(
"num_importance_sampling_steps")),
61 _std_factor(getParam<Real>(
"std_factor")),
62 _use_absolute_value(getParam<bool>(
"use_absolute_value")),
63 _num_random_seeds(getParam<unsigned
int>(
"num_random_seeds")),
64 _is_sampling_completed(declareRecoverableData<bool>(
"is_sampling_completed", false)),
65 _inputs(getReporterValue<
std::vector<
std::vector<Real>>>(
"inputs_reporter")),
66 _prev_value(declareRecoverableData<
std::vector<Real>>(
"prev_value")),
67 _mean_sto(declareRecoverableData<
std::vector<Real>>(
"mean_sto")),
68 _std_sto(declareRecoverableData<
std::vector<Real>>(
"std_sto")),
69 _inputs_sto(declareRecoverableData<
std::vector<
std::vector<Real>>>(
"inputs_sto")),
70 _retraining_steps(declareRecoverableData<
int>(
"retraining_steps", 0)),
71 _gp_flag(isParamValid(
"flag_sample") ? &getReporterValue<
std::vector<bool>>(
"flag_sample")
75 for (
const DistributionName &
name : getParam<std::vector<DistributionName>>(
"distributions"))
114 const bool sample =
_t_step > 1;
115 const bool gp_flag =
_gp_flag ? (*_gp_flag)[0] :
false;
118 mooseError(
"Internal bug: the adaptive sampling is supposed to be completed but another sample "
119 "has been requested.");
129 if (sample && !gp_flag)
133 Real acceptance_ratio = 0.0;
152 else if (sample && !gp_flag)
registerMooseObjectAliased("StochasticToolsApp", AdaptiveImportanceSampler, "AdaptiveImportance")
void ErrorVector unsigned int
A class used to perform Adaptive Importance Sampling using a Markov Chain Monte Carlo algorithm.
std::vector< Real > & _prev_value
For proposing the next sample in the MCMC algorithm.
std::vector< const Distribution * > _distributions
Storage for distribution objects to be utilized.
int & _retraining_steps
Number of retraining performed.
const std::vector< bool > *const _gp_flag
Indicate whether GP prediction is good or bad to influence next proposed sample.
std::vector< Real > & _mean_sto
Storage for means of input values for proposing the next sample.
const unsigned int & _num_random_seeds
Initialize a certain number of random seeds. Change from the default only if you have to.
std::vector< Real > & _std_sto
Storage for standard deviations of input values for proposing the next sample.
bool & _is_sampling_completed
True if the sampling is completed.
virtual Real computeSample(dof_id_type row_index, dof_id_type col_index) const override
Return the sample for the given row (the sample index) and column (the parameter index)
const int & _num_importance_sampling_steps
Number of importance sampling steps (after the importance distribution has been trained)
AdaptiveImportanceSampler(const InputParameters ¶meters)
virtual void executeSetUp() override
static InputParameters validParams()
const int & _num_samples_train
Number of samples to train the importance sampler.
const Real & _std_factor
Factor to be multiplied to the standard deviation of the proposal distribution.
std::vector< std::vector< Real > > & _inputs_sto
Storage for previously accepted samples by the decision reporter system.
const std::vector< Real > & _initial_values
Initial values values vector to start the importance sampler.
const std::vector< std::vector< Real > > & _inputs
Storage for the inputs vector obtained from the reporter.
const std::vector< Real > & _proposal_std
The proposal distribution standard deviations.
const Distribution & getDistributionByName(const DistributionName &name) const
const std::string & name() const
void mooseError(Args &&... args) const
virtual Real cdf(const Real &x) const override
virtual Real pdf(const Real &x) const override
virtual Real quantile(const Real &p) const override
void setNumberOfCols(dof_id_type n_cols)
Real getRand(std::size_t n, unsigned int index=0) const
void setAutoAdvanceGenerators(const bool state)
static InputParameters validParams()
void setNumberOfRows(dof_id_type n_rows)
void setNumberOfRandomSeeds(std::size_t number)
Real computeSTD(const std::vector< Real > &data, const unsigned int &start_index)
compute the standard deviation of a data vector by only considering values from a specific index.
Real computeMean(const std::vector< Real > &data, const unsigned int &start_index)
compute the mean of a data vector by only considering values from a specific index.