Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : #include "Sampler.h" 13 : #include "TransientInterface.h" 14 : 15 : /** 16 : * A class used to perform Adaptive Importance Sampling using a Markov Chain Monte Carlo algorithm 17 : */ 18 : class AdaptiveImportanceSampler : public Sampler, public TransientInterface 19 : { 20 : public: 21 : static InputParameters validParams(); 22 : 23 : AdaptiveImportanceSampler(const InputParameters & parameters); 24 : 25 : // Access the initial values vector 26 33 : const std::vector<Real> & getInitialValues() const { return _initial_values; } 27 : 28 : // Access the number of training samples 29 985 : const int & getNumSamplesTrain() const { return _num_samples_train; } 30 : 31 : // Access use absolute value bool 32 580 : const bool & getUseAbsoluteValue() const { return _use_absolute_value; } 33 : 34 : // Access the output limit 35 189 : const Real & getOutputLimit() const { return _output_limit; } 36 : 37 : // Access the mean vector of the importance distribution 38 175 : const std::vector<Real> & getImportanceVectorMean() const { return _mean_sto; } 39 : 40 : // Access the std vector of the importance distribution 41 175 : const std::vector<Real> & getImportanceVectorStd() const { return _std_sto; } 42 : 43 : // Access the std vector of the importance distribution 44 14 : const std::vector<const Distribution *> & getDistributionNames() const { return _distributions; } 45 : 46 : // Access the output limit 47 14 : const Real & getStdFactor() const { return _std_factor; } 48 : 49 : /** 50 : * Returns true if the adaptive sampling is completed 51 : */ 52 567 : virtual bool isAdaptiveSamplingCompleted() const override { return _is_sampling_completed; } 53 : 54 : protected: 55 : virtual void executeSetUp() override; 56 : /// Return the sample for the given row (the sample index) and column (the parameter index) 57 : virtual Real computeSample(dof_id_type row_index, dof_id_type col_index) override; 58 : 59 : /// Storage for distribution objects to be utilized 60 : std::vector<const Distribution *> _distributions; 61 : 62 : /// The proposal distribution standard deviations 63 : const std::vector<Real> & _proposal_std; 64 : 65 : /// Initial values values vector to start the importance sampler 66 : const std::vector<Real> & _initial_values; 67 : 68 : /// The output limit, exceedance of which indicates failure 69 : const Real & _output_limit; 70 : 71 : /// Number of samples to train the importance sampler 72 : const int & _num_samples_train; 73 : 74 : /// Number of importance sampling steps (after the importance distribution has been trained) 75 : const int & _num_importance_sampling_steps; 76 : 77 : /// Factor to be multiplied to the standard deviation of the proposal distribution 78 : const Real & _std_factor; 79 : 80 : /// Absolute value of the model result. Use this when failure is defined as a non-exceedance rather than an exceedance. 81 : const bool & _use_absolute_value; 82 : 83 : /// Initialize a certain number of random seeds. Change from the default only if you have to. 84 : const unsigned int & _num_random_seeds; 85 : 86 : /// True if the sampling is completed 87 : bool _is_sampling_completed; 88 : 89 : private: 90 : /// Storage for the inputs vector obtained from the reporter 91 : const std::vector<std::vector<Real>> & _inputs; 92 : 93 : /// For proposing the next sample in the MCMC algorithm 94 : std::vector<Real> _prev_value; 95 : 96 : /// Storage for means of input values for proposing the next sample 97 : std::vector<Real> _mean_sto; 98 : 99 : /// Storage for standard deviations of input values for proposing the next sample 100 : std::vector<Real> _std_sto; 101 : 102 : /// Storage for previously accepted samples by the decision reporter system 103 : std::vector<std::vector<Real>> _inputs_sto; 104 : 105 : /// Number of retraining performed 106 : int _retraining_steps; 107 : 108 : /// Indicate whether GP prediction is good or bad to influence next proposed sample 109 : const std::vector<bool> * const _gp_flag; 110 : };