1 /* _______________________________________________________________________ 2 3 DAKOTA: Design Analysis Kit for Optimization and Terascale Applications 4 Copyright 2014-2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 5 This software is distributed under the GNU Lesser General Public License. 6 For more information, see the README file in the top Dakota directory. 7 _______________________________________________________________________ */ 8 9 //- Class: NonDGPMSABayesCalibration 10 //- Description: Wrapper class for the Bayesian calibration capability 11 //- from the LANL GPM/SA library 12 //- Owner: Laura Swiler 13 //- Checked by: 14 //- Version: 15 16 #ifndef NOND_GPMSA_BAYES_CALIBRATION_H 17 #define NOND_GPMSA_BAYES_CALIBRATION_H 18 19 #include "NonDQUESOBayesCalibration.hpp" 20 21 namespace QUESO { 22 // template<class T> class SPType; 23 // // template<typename T> struct SharedPtr; 24 // template<typename T> 25 // struct SharedPtr { typedef SPType<T> Type; } 26 class GPMSAOptions; 27 template<class V, class M> class GPMSAFactory; 28 } 29 30 namespace Dakota { 31 32 /// Generates posterior distribution on model parameters given experiment data 33 34 35 /** This class provides a wrapper for the functionality provided in 36 the Los Alamos National Laboratory code called GPM/SA (Gaussian 37 Process Models for Simulation Analysis). Although this is a 38 code that provides input/output mapping, it DOES NOT provide the 39 mapping that we usually think of in the NonDeterministic class 40 hierarchy in DAKOTA, where uncertainty in parameter inputs are mapped to 41 uncertainty in simulation responses. Instead, this class takes 42 a pre-existing set of simulation data as well as experimental data, and 43 maps priors on input parameters to posterior distributions on those 44 input parameters, according to a likelihood function. The goal of the 45 MCMC sampling is to produce posterior values of parameter estimates 46 which will produce simulation response values that "match well" to the 47 experimental data. The MCMC is an integral part of the calibration. 48 The data structures in GPM/SA are fairly detailed and nested. 49 Part of this prototyping exercise is to determine what data 50 structures need to be specified and initialized in DAKOTA and sent 51 to GPM/SA, and what data structures will be returned. */ 52 53 class NonDGPMSABayesCalibration: public NonDQUESOBayesCalibration 54 { 55 public: 56 57 // 58 //- Heading: Constructors and destructor 59 // 60 61 /// constructor 62 NonDGPMSABayesCalibration(ProblemDescDB& problem_db, Model& model); 63 /// destructor 64 ~NonDGPMSABayesCalibration(); 65 66 protected: 67 68 // 69 //- Heading: Virtual function redefinitions 70 // 71 72 void derived_init_communicators(ParLevLIter pl_iter); 73 void derived_set_communicators(ParLevLIter pl_iter); 74 void derived_free_communicators(ParLevLIter pl_iter); 75 76 /// performs a forward uncertainty propagation by using GPM/SA to 77 /// generate a posterior distribution on parameters given a set of 78 /// simulation parameter/response data, a set of experimental data, and 79 /// additional variables to be specified here. 80 void calibrate(); 81 82 /// specialization to initialize the inverse problem and posterior 83 void init_queso_solver(); 84 85 /// Populate simulation data (run design of experiments or load build data) 86 void acquire_simulation_data(RealMatrix& sim_data); 87 88 /// fill the full proposal covariance, inlcuding hyperparameter 89 /// entries with user-specified or default theta covariance 90 /// information 91 void overlay_proposal_covariance(QUESO::GslMatrix& full_prop_cov) const; 92 93 /// populate the simulation data, calculating and applying scaling if needed 94 void fill_simulation_data(); 95 96 /// populate the experiment data, applying scaling if needed 97 void fill_experiment_data(); 98 99 /// overlay the Dakota user's initial parameters on the full GPMSA 100 /// vector of parameters 101 void overlay_initial_params(QUESO::GslVector& full_param_initials); 102 103 /// retrieve the chain from QUESO and populate acceptanceChain / 104 /// acceptedFnVals 105 void cache_acceptance_chain(); 106 107 // print the final statistics 108 void print_results(std::ostream& s, short results_state = FINAL_RESULTS); 109 110 // 111 //- Heading: Data 112 // 113 114 // 115 //- Heading: Data 116 // 117 118 /// number of samples of the simulation to construct the GP 119 int buildSamples; 120 121 /// name of file from which to import build points to build GP 122 String approxImportFile; 123 124 /// build data import tabular format 125 unsigned short approxImportFormat; 126 127 /// import active variables only 128 bool approxImportActiveOnly; 129 130 /// number of user-specified configuration (scenario) vars 131 unsigned int userConfigVars; 132 133 /// number of config vars presented to GPMSA (minimum 1) 134 unsigned int gpmsaConfigVars; 135 136 /// whether to apply GPMSA-internal variable and data normalization 137 bool gpmsaNormalize; 138 139 /// vector space defining the scenario (configuration) variables 140 std::shared_ptr<QUESO::VectorSpace<QUESO::GslVector, QUESO::GslMatrix> > 141 configSpace; 142 143 /// vector space defining the output (response) space for the simulations 144 std::shared_ptr<QUESO::VectorSpace<QUESO::GslVector, QUESO::GslMatrix> > 145 nEtaSpace; 146 147 /// vector space defining the output (response) space for the experiments 148 std::shared_ptr<QUESO::VectorSpace<QUESO::GslVector, QUESO::GslMatrix> > 149 experimentSpace; 150 151 /// Configuration options for the GPMSA solver 152 std::shared_ptr<QUESO::GPMSAOptions> gpmsaOptions; 153 154 /// core factory that manages a GP-based likelihood 155 std::shared_ptr<QUESO::GPMSAFactory<QUESO::GslVector, QUESO::GslMatrix> > 156 gpmsaFactory; 157 158 159 private: 160 161 // 162 //- Heading: Data 163 // 164 165 //short emulatorType; 166 167 /// Pointer to current class instance for use in static callback functions 168 static NonDGPMSABayesCalibration* nonDGPMSAInstance; 169 /// LHS iterator for generating samples for GP 170 Iterator lhsIter; 171 }; 172 173 } // namespace Dakota 174 175 #endif 176