https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
AdaptiveImportanceSampler Class Reference

A class used to perform Adaptive Importance Sampling using a Markov Chain Monte Carlo algorithm. More...

#include <AdaptiveImportanceSampler.h>

Inheritance diagram for AdaptiveImportanceSampler:
[legend]

Public Types

enum  SampleMode
 
typedef DataFileName DataFileParameterType
 

Public Member Functions

 AdaptiveImportanceSampler (const InputParameters &parameters)
 
const std::vector< Real > & getInitialValues () const
 
const intgetNumSamplesTrain () const
 
const bool & getUseAbsoluteValue () const
 
const Real & getOutputLimit () const
 
const std::vector< Real > & getImportanceVectorMean () const
 
const std::vector< Real > & getImportanceVectorStd () const
 
const std::vector< const Distribution * > & getDistributionNames () const
 
const Real & getStdFactor () const
 
virtual bool isAdaptiveSamplingCompleted () const override
 Returns true if the adaptive sampling is completed.
 
std::vector< Real > getNextLocalRow ()
 
dof_id_type getNumberOfRows () const
 
dof_id_type getNumberOfCols () const
 
dof_id_type getNumberOfLocalRows () const
 
const LocalRankConfiggetRankConfig (bool batch_mode) const
 
libMesh::Parallel::CommunicatorgetLocalComm ()
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
bool isKokkosObject () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParametersparameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const TgetParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const TqueryParam (const std::string &name) const
 
const TgetRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
virtual void initialSetup ()
 
virtual void timestepSetup ()
 
virtual void jacobianSetup ()
 
virtual void residualSetup ()
 
virtual void subdomainSetup ()
 
virtual void customSetup (const ExecFlagType &)
 
const ExecFlagEnumgetExecuteOnEnum () const
 
PerfGraphperfGraph ()
 
TgetSampler (const std::string &name)
 
SamplergetSampler (const std::string &name)
 
TgetSamplerByName (const SamplerName &name)
 
SamplergetSamplerByName (const SamplerName &name)
 
const VectorPostprocessorValuegetVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name, bool needs_broadcast) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
bool hasVectorPostprocessor (const std::string &param_name, const std::string &vector_name) const
 
bool hasVectorPostprocessor (const std::string &param_name) const
 
bool hasVectorPostprocessorByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
bool hasVectorPostprocessorByName (const VectorPostprocessorName &name) const
 
const VectorPostprocessorName & getVectorPostprocessorName (const std::string &param_name) const
 
DenseMatrix< Real > getGlobalSamples ()
 
DenseMatrix< Real > getGlobalSamples ()
 
DenseMatrix< Real > getLocalSamples ()
 
DenseMatrix< Real > getLocalSamples ()
 
dof_id_type getLocalRowBegin () const
 
dof_id_type getLocalRowBegin () const
 
dof_id_type getLocalRowEnd () const
 
dof_id_type getLocalRowEnd () const
 
const DistributiongetDistribution (const std::string &name) const
 
const TgetDistribution (const std::string &name) const
 
const DistributiongetDistribution (const std::string &name) const
 
const TgetDistribution (const std::string &name) const
 
const DistributiongetDistributionByName (const DistributionName &name) const
 
const TgetDistributionByName (const std::string &name) const
 
const DistributiongetDistributionByName (const DistributionName &name) const
 
const TgetDistributionByName (const std::string &name) const
 
bool isVectorPostprocessorDistributed (const std::string &param_name) const
 
bool isVectorPostprocessorDistributed (const std::string &param_name) const
 
bool isVectorPostprocessorDistributedByName (const VectorPostprocessorName &name) const
 
bool isVectorPostprocessorDistributedByName (const VectorPostprocessorName &name) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
bool isImplicit ()
 
Moose::StateArg determineState () const
 

Static Public Member Functions

static InputParameters validParams ()
 
static void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 

Protected Member Functions

virtual void executeSetUp () override
 
virtual Real computeSample (dof_id_type row_index, dof_id_type col_index) override
 Return the sample for the given row (the sample index) and column (the parameter index)
 
void setNumberOfRandomSeeds (std::size_t number)
 
Real getRand (std::size_t n, unsigned int index=0) const
 
unsigned int getRandl (std::size_t n, unsigned int lower, unsigned int upper, unsigned int index=0) const
 
virtual LocalRankConfig constructRankConfig (bool batch_mode) const
 
void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 
std::string timedSectionName (const std::string &section_name) const
 
virtual void addVectorPostprocessorDependencyHelper (const VectorPostprocessorName &) const
 
const ReporterContextBasegetReporterContextBaseByName (const ReporterName &reporter_name) const
 
const ReporterNamegetReporterName (const std::string &param_name) const
 
virtual void addReporterDependencyHelper (const ReporterName &)
 
void setNumberOfRows (dof_id_type n_rows)
 
void setNumberOfRows (dof_id_type n_rows)
 
void setNumberOfCols (dof_id_type n_cols)
 
void setNumberOfCols (dof_id_type n_cols)
 
virtual void computeSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeLocalSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeLocalSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeSampleRow (dof_id_type i, std::vector< Real > &data)
 
virtual void computeSampleRow (dof_id_type i, std::vector< Real > &data)
 
virtual void advanceGenerators (const dof_id_type count)
 
virtual void advanceGenerators (const dof_id_type count)
 
virtual void advanceGenerator (const unsigned int seed_index, const dof_id_type count)
 
virtual void advanceGenerator (const unsigned int seed_index, const dof_id_type count)
 
void setAutoAdvanceGenerators (const bool state)
 
void setAutoAdvanceGenerators (const bool state)
 
virtual void executeTearDown ()
 
virtual void executeTearDown ()
 
const TgetReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const TgetReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const TgetReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const TgetReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 

Protected Attributes

std::vector< const Distribution * > _distributions
 Storage for distribution objects to be utilized.
 
const std::vector< Real > & _proposal_std
 The proposal distribution standard deviations.
 
const std::vector< Real > & _initial_values
 Initial values values vector to start the importance sampler.
 
const Real & _output_limit
 The output limit, exceedance of which indicates failure.
 
const int_num_samples_train
 Number of samples to train the importance sampler.
 
const int_num_importance_sampling_steps
 Number of importance sampling steps (after the importance distribution has been trained)
 
const Real & _std_factor
 Factor to be multiplied to the standard deviation of the proposal distribution.
 
const bool & _use_absolute_value
 Absolute value of the model result. Use this when failure is defined as a non-exceedance rather than an exceedance.
 
const unsigned int_num_random_seeds
 Initialize a certain number of random seeds. Change from the default only if you have to.
 
bool _is_sampling_completed
 True if the sampling is completed.
 
const dof_id_type _min_procs_per_row
 
const dof_id_type _max_procs_per_row
 
libMesh::Parallel::Communicator _local_comm
 
const bool & _enabled
 
MooseApp_app
 
Factory_factory
 
ActionFactory_action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters_pars
 
const ExecFlagEnum_execute_enum
 
const ExecFlagType_current_execute_flag
 
MooseApp_pg_moose_app
 
const std::string _prefix
 
const Parallel::Communicator & _communicator
 
const InputParameters_ti_params
 
FEProblemBase_ti_feproblem
 
bool _is_implicit
 
Real & _t
 
const Real & _t_old
 
int_t_step
 
Real & _dt
 
Real & _dt_old
 
bool _is_transient
 

Private Member Functions

void execute ()
 
void checkReinitStatus () const
 
void advanceGeneratorsInternal (const dof_id_type count)
 
const VectorPostprocessorValuegetVectorPostprocessorByNameHelper (const VectorPostprocessorName &name, const std::string &vector_name, bool broadcast, std::size_t t_index) const
 
const VectorPostprocessorContext< VectorPostprocessorValue > & getVectorPostprocessorContextByNameHelper (const VectorPostprocessorName &name, const std::string &vector_name) const
 
bool vectorPostprocessorsAdded () const
 
bool reportersAdded () const
 
void possiblyCheckHasReporter (const ReporterName &reporter_name, const std::string &param_name="") const
 
void init ()
 
void init ()
 
void reinit ()
 
void reinit ()
 
void possiblyCheckHasVectorPostprocessor (const std::string &param_name, const std::string &vector_name) const
 
void possiblyCheckHasVectorPostprocessor (const std::string &param_name, const std::string &vector_name) const
 
void possiblyCheckHasVectorPostprocessorByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
void possiblyCheckHasVectorPostprocessorByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 

Static Private Member Functions

static const hit::Node * getHitNode (const InputParameters &params)
 
static std::string messagePrefix (const InputParameters &params, const bool hit_prefix)
 

Private Attributes

const std::vector< std::vector< Real > > & _inputs
 Storage for the inputs vector obtained from the reporter.
 
std::vector< Real > _prev_value
 For proposing the next sample in the MCMC algorithm.
 
std::vector< Real > _mean_sto
 Storage for means of input values for proposing the next sample.
 
std::vector< Real > _std_sto
 Storage for standard deviations of input values for proposing the next sample.
 
std::vector< std::vector< Real > > _inputs_sto
 Storage for previously accepted samples by the decision reporter system.
 
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< std::unique_ptr< MooseRandomStateless > > _generators
 
dof_id_type _n_local_rows
 
dof_id_type _local_row_begin
 
dof_id_type _local_row_end
 
dof_id_type _n_rows
 
dof_id_type _n_cols
 
std::size_t _n_seeds
 
dof_id_type _next_local_row
 
bool _next_local_row_requires_state_restore
 
bool _initialized
 
bool _needs_reinit
 
bool _has_executed
 
const dof_id_type _limit_get_global_samples
 
const dof_id_type _limit_get_local_samples
 
const dof_id_type _limit_get_next_local_row
 
std::pair< LocalRankConfig, LocalRankConfig_rank_config
 
bool _auto_advance_generators
 
const ParallelParamObject_parent
 
const MooseBase_si_moose_base
 
const FEProblemBase_si_problem
 
ExecFlagEnum _empty_execute_enum
 
const InputParameters_dni_params
 
FEProblemBase_dni_feproblem
 
const MooseObject *const _dni_moose_object_ptr
 
const InputParameters_si_params
 
FEProblemBase_si_feproblem
 
THREAD_ID _si_tid
 
const bool _broadcast_by_default
 
const MooseObject_vpi_moose_object
 
const FEProblemBase_vpi_feproblem
 
const THREAD_ID _vpi_tid
 
const InputParameters_ri_params
 
FEProblemBase_ri_fe_problem_base
 
const ReporterData_ri_reporter_data
 
const MooseObject_ri_moose_object
 
const std::string _ti_name
 

Detailed Description

A class used to perform Adaptive Importance Sampling using a Markov Chain Monte Carlo algorithm.

Definition at line 18 of file AdaptiveImportanceSampler.h.

Constructor & Destructor Documentation

◆ AdaptiveImportanceSampler()

AdaptiveImportanceSampler::AdaptiveImportanceSampler ( const InputParameters parameters)

Definition at line 53 of file AdaptiveImportanceSampler.C.

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")),
65 _inputs(getReporterValue<std::vector<std::vector<Real>>>("inputs_reporter")),
67 _gp_flag(isParamValid("flag_sample") ? &getReporterValue<std::vector<bool>>("flag_sample")
68 : nullptr)
69{
70 // Filling the `distributions` vector with the user-provided distributions.
71 for (const DistributionName & name : getParam<std::vector<DistributionName>>("distributions"))
73
74 /* Adaptive Importance Sampling (AdaptiveImportanceSampler) relies on a Markov Chain Monte Carlo
75 (MCMC) algorithm. As such, in MOOSE, any use of MCMC algorithms requires that the `num_steps`
76 parameter in the main App's executioner would control the total number of samples. Therefore,
77 the `num_rows` parameter typically used by exisiting non-MCMC samplers to set the total number
78 of samples has no use here and is fixed to 1.*/
80
81 // Setting the number of columns in the sampler matrix (equal to the number of distributions).
83
84 /* `inputs_sto` is a member variable that aids in forming the importance distribution.
85 One dimension of this variable is equal to the number of distributions. The other dimension
86 of the variable, at the last step, is equal to the number of samples the user desires.*/
87 _inputs_sto.resize(_distributions.size());
88
89 // Mapping all the input distributions to a standard normal space
90 for (unsigned int i = 0; i < _distributions.size(); ++i)
91 _inputs_sto[i].push_back(Normal::quantile(_distributions[i]->cdf(_initial_values[i]), 0, 1));
92
93 /* `prev_value` is a member variable for tracking the previously accepted samples in the
94 MCMC algorithm and proposing the next sample.*/
95 _prev_value.resize(_distributions.size());
96
97 // Storage for means of input values for proposing the next sample
98 _mean_sto.resize(_distributions.size());
99
100 // Storage for standard deviations of input values for proposing the next sample
101 _std_sto.resize(_distributions.size());
102
105}
std::vector< Real > _mean_sto
Storage for means of input values for proposing the next sample.
std::vector< const Distribution * > _distributions
Storage for distribution objects to be utilized.
const std::vector< bool > *const _gp_flag
Indicate whether GP prediction is good or bad to influence next proposed sample.
bool _is_sampling_completed
True if the sampling is completed.
const unsigned int & _num_random_seeds
Initialize a certain number of random seeds. Change from the default only if you have to.
const int & _num_importance_sampling_steps
Number of importance sampling steps (after the importance distribution has been trained)
int _retraining_steps
Number of retraining performed.
const Real & _output_limit
The output limit, exceedance of which indicates failure.
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.
std::vector< Real > _std_sto
Storage for standard deviations of input values for proposing the next sample.
std::vector< Real > _prev_value
For proposing the next sample in the MCMC algorithm.
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 bool & _use_absolute_value
Absolute value of the model result. Use this when failure is defined as a non-exceedance rather than ...
const Distribution & getDistributionByName(const DistributionName &name) const
const InputParameters & parameters() const
const std::string & name() const
const T & getParam(const std::string &name) const
bool isParamValid(const std::string &name) const
virtual Real quantile(const Real &p) const override
Definition Normal.C:80
const T & getReporterValue(const std::string &param_name, const std::size_t time_index=0)
void setNumberOfCols(dof_id_type n_cols)
void setAutoAdvanceGenerators(const bool state)
void setNumberOfRows(dof_id_type n_rows)
void setNumberOfRandomSeeds(std::size_t number)

Member Function Documentation

◆ computeSample()

Real AdaptiveImportanceSampler::computeSample ( dof_id_type  row_index,
dof_id_type  col_index 
)
overrideprotectedvirtual

Return the sample for the given row (the sample index) and column (the parameter index)

Implements Sampler.

Definition at line 177 of file AdaptiveImportanceSampler.C.

178{
179 return _distributions[col_index]->quantile(Normal::cdf(_prev_value[col_index], 0.0, 1.0));
180}
virtual Real cdf(const Real &x) const override
Definition Normal.C:74

◆ executeSetUp()

void AdaptiveImportanceSampler::executeSetUp ( )
overrideprotectedvirtual

Reimplemented from Sampler.

Definition at line 108 of file AdaptiveImportanceSampler.C.

109{
110 const bool sample = _t_step > 1;
111 const bool gp_flag = _gp_flag ? (*_gp_flag)[0] : false;
112
113 if (sample && _is_sampling_completed)
114 mooseError("Internal bug: the adaptive sampling is supposed to be completed but another sample "
115 "has been requested.");
116
118 {
119 /* This is the importance distribution training step. Markov Chains are set up
120 to sample from the importance region or the failure region using the Metropolis
121 algorithm. Given that the previous sample resulted in a model failure, the next
122 sample is proposed such that it is very likely to result in a model failure as well.
123 The `initial_values` and `proposal_std` parameters provided by the user affects the
124 formation of the importance distribution. */
125 if (sample && !gp_flag)
126 {
127 for (dof_id_type j = 0; j < _distributions.size(); ++j)
128 _prev_value[j] = Normal::quantile(_distributions[j]->cdf(_inputs[j][0]), 0.0, 1.0);
129 Real acceptance_ratio = 0.0;
130 for (dof_id_type i = 0; i < _distributions.size(); ++i)
131 acceptance_ratio += std::log(Normal::pdf(_prev_value[i], 0.0, 1.0)) -
132 std::log(Normal::pdf(_inputs_sto[i].back(), 0.0, 1.0));
133 if (acceptance_ratio > std::log(getRand(0, _t_step)))
134 {
135 for (dof_id_type i = 0; i < _distributions.size(); ++i)
136 _inputs_sto[i].push_back(_prev_value[i]);
137 }
138 else
139 {
140 for (dof_id_type i = 0; i < _distributions.size(); ++i)
141 _inputs_sto[i].push_back(_inputs_sto[i].back());
142 }
143 for (dof_id_type i = 0; i < _distributions.size(); ++i)
144 _prev_value[i] =
146 }
147 }
148 else if (sample && !gp_flag)
149 {
150 /* This is the importance sampling step using the importance distribution created
151 in the previous step. Once the importance distribution is known, sampling from
152 it is similar to a regular Monte Carlo sampling. */
153 for (dof_id_type i = 0; i < _distributions.size(); ++i)
154 {
155 if (_t_step == _num_samples_train + 1)
156 {
159 }
160 _prev_value[i] =
162 }
163
164 // check if we have performed all the importance sampling steps
167 }
168
169 // When the GP fails, the current time step is 'wasted' and the retraining step doesn't
170 // happen until the next time step. Therefore, keep track of the number of retraining steps
171 // to increase the total number of steps taken.
172 if (sample && gp_flag && _t_step > _num_samples_train)
174}
void mooseError(Args &&... args) const
virtual Real pdf(const Real &x) const override
Definition Normal.C:68
Real getRand(std::size_t n, unsigned int index=0) const
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.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ getDistributionNames()

const std::vector< const Distribution * > & AdaptiveImportanceSampler::getDistributionNames ( ) const
inline

Definition at line 44 of file AdaptiveImportanceSampler.h.

44{ return _distributions; }

Referenced by AdaptiveImportanceStats::AdaptiveImportanceStats().

◆ getImportanceVectorMean()

const std::vector< Real > & AdaptiveImportanceSampler::getImportanceVectorMean ( ) const
inline

Definition at line 38 of file AdaptiveImportanceSampler.h.

38{ return _mean_sto; }

Referenced by AdaptiveImportanceStats::execute().

◆ getImportanceVectorStd()

const std::vector< Real > & AdaptiveImportanceSampler::getImportanceVectorStd ( ) const
inline

Definition at line 41 of file AdaptiveImportanceSampler.h.

41{ return _std_sto; }

Referenced by AdaptiveImportanceStats::execute().

◆ getInitialValues()

const std::vector< Real > & AdaptiveImportanceSampler::getInitialValues ( ) const
inline

◆ getNumSamplesTrain()

const int & AdaptiveImportanceSampler::getNumSamplesTrain ( ) const
inline

◆ getOutputLimit()

const Real & AdaptiveImportanceSampler::getOutputLimit ( ) const
inline

◆ getStdFactor()

const Real & AdaptiveImportanceSampler::getStdFactor ( ) const
inline

Definition at line 47 of file AdaptiveImportanceSampler.h.

47{ return _std_factor; }

Referenced by AdaptiveImportanceStats::AdaptiveImportanceStats().

◆ getUseAbsoluteValue()

const bool & AdaptiveImportanceSampler::getUseAbsoluteValue ( ) const
inline

◆ isAdaptiveSamplingCompleted()

virtual bool AdaptiveImportanceSampler::isAdaptiveSamplingCompleted ( ) const
inlineoverridevirtual

Returns true if the adaptive sampling is completed.

Reimplemented from Sampler.

Definition at line 52 of file AdaptiveImportanceSampler.h.

52{ return _is_sampling_completed; }

◆ validParams()

InputParameters AdaptiveImportanceSampler::validParams ( )
static

Definition at line 19 of file AdaptiveImportanceSampler.C.

20{
22 params.addClassDescription("Adaptive Importance Sampler.");
23 params.addRequiredParam<std::vector<DistributionName>>(
24 "distributions",
25 "The distribution names to be sampled, the number of distributions provided defines the "
26 "number of columns per matrix.");
27 params.addRequiredParam<ReporterName>("inputs_reporter", "Reporter with input parameters.");
28 params.addRequiredParam<std::vector<Real>>("proposal_std",
29 "Standard deviations of the proposal distributions");
30 params.addRequiredParam<Real>("output_limit", "Limiting values of the VPPs");
31 params.addRequiredParam<std::vector<Real>>(
32 "initial_values", "Initial input values to get the importance sampler started");
34 "num_samples_train",
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)");
41 params.addRequiredParam<Real>(
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");
44 params.addParam<unsigned int>(
45 "num_random_seeds",
46 100000,
47 "Initialize a certain number of random seeds. Change from the default only if you have to.");
48 params.addParam<ReporterName>("flag_sample",
49 "Flag samples if the surrogate prediction was inadequate.");
50 return params;
51}
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()

Referenced by AISActiveLearning::validParams().

Member Data Documentation

◆ _distributions

std::vector<const Distribution *> AdaptiveImportanceSampler::_distributions
protected

Storage for distribution objects to be utilized.

Definition at line 60 of file AdaptiveImportanceSampler.h.

Referenced by AdaptiveImportanceSampler(), computeSample(), executeSetUp(), and getDistributionNames().

◆ _gp_flag

const std::vector<bool>* const AdaptiveImportanceSampler::_gp_flag
private

Indicate whether GP prediction is good or bad to influence next proposed sample.

Definition at line 109 of file AdaptiveImportanceSampler.h.

Referenced by executeSetUp().

◆ _initial_values

const std::vector<Real>& AdaptiveImportanceSampler::_initial_values
protected

Initial values values vector to start the importance sampler.

Definition at line 66 of file AdaptiveImportanceSampler.h.

Referenced by AdaptiveImportanceSampler(), and getInitialValues().

◆ _inputs

const std::vector<std::vector<Real> >& AdaptiveImportanceSampler::_inputs
private

Storage for the inputs vector obtained from the reporter.

Definition at line 91 of file AdaptiveImportanceSampler.h.

Referenced by executeSetUp().

◆ _inputs_sto

std::vector<std::vector<Real> > AdaptiveImportanceSampler::_inputs_sto
private

Storage for previously accepted samples by the decision reporter system.

Definition at line 103 of file AdaptiveImportanceSampler.h.

Referenced by AdaptiveImportanceSampler(), and executeSetUp().

◆ _is_sampling_completed

bool AdaptiveImportanceSampler::_is_sampling_completed
protected

True if the sampling is completed.

Definition at line 87 of file AdaptiveImportanceSampler.h.

Referenced by executeSetUp(), and isAdaptiveSamplingCompleted().

◆ _mean_sto

std::vector<Real> AdaptiveImportanceSampler::_mean_sto
private

Storage for means of input values for proposing the next sample.

Definition at line 97 of file AdaptiveImportanceSampler.h.

Referenced by AdaptiveImportanceSampler(), executeSetUp(), and getImportanceVectorMean().

◆ _num_importance_sampling_steps

const int& AdaptiveImportanceSampler::_num_importance_sampling_steps
protected

Number of importance sampling steps (after the importance distribution has been trained)

Definition at line 75 of file AdaptiveImportanceSampler.h.

Referenced by executeSetUp().

◆ _num_random_seeds

const unsigned int& AdaptiveImportanceSampler::_num_random_seeds
protected

Initialize a certain number of random seeds. Change from the default only if you have to.

Definition at line 84 of file AdaptiveImportanceSampler.h.

Referenced by AdaptiveImportanceSampler().

◆ _num_samples_train

const int& AdaptiveImportanceSampler::_num_samples_train
protected

Number of samples to train the importance sampler.

Definition at line 72 of file AdaptiveImportanceSampler.h.

Referenced by executeSetUp(), and getNumSamplesTrain().

◆ _output_limit

const Real& AdaptiveImportanceSampler::_output_limit
protected

The output limit, exceedance of which indicates failure.

Definition at line 69 of file AdaptiveImportanceSampler.h.

Referenced by getOutputLimit().

◆ _prev_value

std::vector<Real> AdaptiveImportanceSampler::_prev_value
private

For proposing the next sample in the MCMC algorithm.

Definition at line 94 of file AdaptiveImportanceSampler.h.

Referenced by AdaptiveImportanceSampler(), computeSample(), and executeSetUp().

◆ _proposal_std

const std::vector<Real>& AdaptiveImportanceSampler::_proposal_std
protected

The proposal distribution standard deviations.

Definition at line 63 of file AdaptiveImportanceSampler.h.

Referenced by executeSetUp().

◆ _retraining_steps

int AdaptiveImportanceSampler::_retraining_steps
private

Number of retraining performed.

Definition at line 106 of file AdaptiveImportanceSampler.h.

Referenced by executeSetUp().

◆ _std_factor

const Real& AdaptiveImportanceSampler::_std_factor
protected

Factor to be multiplied to the standard deviation of the proposal distribution.

Definition at line 78 of file AdaptiveImportanceSampler.h.

Referenced by executeSetUp(), and getStdFactor().

◆ _std_sto

std::vector<Real> AdaptiveImportanceSampler::_std_sto
private

Storage for standard deviations of input values for proposing the next sample.

Definition at line 100 of file AdaptiveImportanceSampler.h.

Referenced by AdaptiveImportanceSampler(), executeSetUp(), and getImportanceVectorStd().

◆ _use_absolute_value

const bool& AdaptiveImportanceSampler::_use_absolute_value
protected

Absolute value of the model result. Use this when failure is defined as a non-exceedance rather than an exceedance.

Definition at line 81 of file AdaptiveImportanceSampler.h.

Referenced by getUseAbsoluteValue().


The documentation for this class was generated from the following files: