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 74 : const std::vector<Real> & getInitialValues() const { return _initial_values; } 27 : 28 : // Access the number of training samples 29 1970 : const int & getNumSamplesTrain() const { return _num_samples_train; } 30 : 31 : // Access use absolute value bool 32 1160 : const bool & getUseAbsoluteValue() const { return _use_absolute_value; } 33 : 34 : // Access the output limit 35 382 : const Real & getOutputLimit() const { return _output_limit; } 36 : 37 : // Access the mean vector of the importance distribution 38 350 : const std::vector<Real> & getImportanceVectorMean() const { return _mean_sto; } 39 : 40 : // Access the std vector of the importance distribution 41 350 : const std::vector<Real> & getImportanceVectorStd() const { return _std_sto; } 42 : 43 : // Access the std vector of the importance distribution 44 32 : const std::vector<const Distribution *> & getDistributionNames() const { return _distributions; } 45 : 46 : // Access the output limit 47 32 : const Real & getStdFactor() const { return _std_factor; } 48 : 49 : /** 50 : * Returns true if the adaptive sampling is completed 51 : */ 52 1296 : virtual bool isAdaptiveSamplingCompleted() const override { return _is_sampling_completed; } 53 : 54 : protected: 55 : /// Return the sample for the given row (the sample index) and column (the parameter index) 56 : virtual Real computeSample(dof_id_type row_index, dof_id_type col_index) override; 57 : 58 : /// Storage for distribution objects to be utilized 59 : std::vector<const Distribution *> _distributions; 60 : 61 : /// The proposal distribution standard deviations 62 : const std::vector<Real> & _proposal_std; 63 : 64 : /// Initial values values vector to start the importance sampler 65 : const std::vector<Real> & _initial_values; 66 : 67 : /// The output limit, exceedance of which indicates failure 68 : const Real & _output_limit; 69 : 70 : /// Number of samples to train the importance sampler 71 : const int & _num_samples_train; 72 : 73 : /// Number of importance sampling steps (after the importance distribution has been trained) 74 : const int & _num_importance_sampling_steps; 75 : 76 : /// Factor to be multiplied to the standard deviation of the proposal distribution 77 : const Real & _std_factor; 78 : 79 : /// Absolute value of the model result. Use this when failure is defined as a non-exceedance rather than an exceedance. 80 : const bool & _use_absolute_value; 81 : 82 : /// Initialize a certain number of random seeds. Change from the default only if you have to. 83 : const unsigned int & _num_random_seeds; 84 : 85 : /// True if the sampling is completed 86 : bool _is_sampling_completed; 87 : 88 : private: 89 : /// Storage for the inputs vector obtained from the reporter 90 : const std::vector<std::vector<Real>> & _inputs; 91 : 92 : /// Ensure that the MCMC algorithm proceeds in a sequential fashion 93 : int _check_step; 94 : 95 : /// For proposing the next sample in the MCMC algorithm 96 : std::vector<Real> _prev_value; 97 : 98 : /// Storage for means of input values for proposing the next sample 99 : std::vector<Real> _mean_sto; 100 : 101 : /// Storage for standard deviations of input values for proposing the next sample 102 : std::vector<Real> _std_sto; 103 : 104 : /// Storage for previously accepted samples by the decision reporter system 105 : std::vector<std::vector<Real>> _inputs_sto; 106 : 107 : /// Number of retraining performed 108 : int _retraining_steps; 109 : 110 : /// Indicate whether GP prediction is good or bad to influence next proposed sample 111 : const std::vector<bool> * const _gp_flag; 112 : };