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:	 NonDGlobalSingleInterval
10 //- Description: Class for interval bound estimation for epistemic UQ
11 //- Owner:       Laura Swiler
12 //- Checked by:
13 //- Version:
14 
15 #include "NonDGlobalSingleInterval.hpp"
16 #include "dakota_system_defs.hpp"
17 #include "DakotaModel.hpp"
18 #include "DakotaApproximation.hpp"
19 
20 //#define DEBUG
21 
22 
23 namespace Dakota {
24 
25 NonDGlobalSingleInterval::
NonDGlobalSingleInterval(ProblemDescDB & problem_db,Model & model)26 NonDGlobalSingleInterval(ProblemDescDB& problem_db, Model& model):
27   NonDGlobalInterval(problem_db, model)
28 { }
29 
30 
~NonDGlobalSingleInterval()31 NonDGlobalSingleInterval::~NonDGlobalSingleInterval()
32 { }
33 
34 
initialize()35 void NonDGlobalSingleInterval::initialize()
36 { numCells = 1; statCntr = 0; }
37 
38 
get_best_sample(bool maximize,bool eval_approx)39 void NonDGlobalSingleInterval::get_best_sample(bool maximize, bool eval_approx)
40 {
41   // Pull the samples and responses from data used to build latest GP
42   // to determine truthFnStar for use in the expected improvement function
43   const Pecos::SurrogateData& gp_data
44     = fHatModel.approximation_data(respFnCntr);
45   const Pecos::SDVArray& sdv_array = gp_data.variables_data();
46   const Pecos::SDRArray& sdr_array = gp_data.response_data();
47 
48   size_t i, index_star, num_data_pts = gp_data.points();
49   truthFnStar = (maximize) ? -DBL_MAX : DBL_MAX;
50   for (i=0; i<num_data_pts; ++i) {
51     Real truth_fn = sdr_array[i].response_function();
52 #ifdef DEBUG
53     Cout << "GP response function[" << i+1 << "] = " << truth_fn << std::endl;
54 #endif // DEBUG
55     if ( (  maximize && truth_fn > truthFnStar ) ||
56 	 ( !maximize && truth_fn < truthFnStar ) ) {
57       index_star  = i;
58       truthFnStar = truth_fn;
59     }
60   }
61 
62   // If needed, evaluate GP to update approxFnStar
63   if (eval_approx) {
64     const Pecos::SurrogateDataVars& sdv = sdv_array[index_star];
65     if (numContIntervalVars)
66       fHatModel.continuous_variables(sdv.continuous_variables());
67     if (numDiscIntervalVars || numDiscSetIntUncVars)
68       fHatModel.discrete_int_variables(sdv.discrete_int_variables());
69     if (numDiscSetRealUncVars)
70       fHatModel.discrete_real_variables(sdv.discrete_real_variables());
71     ActiveSet set = fHatModel.current_response().active_set();
72     set.request_values(0); set.request_value(1, respFnCntr);
73     fHatModel.evaluate(set);
74     approxFnStar = fHatModel.current_response().function_value(respFnCntr);
75   }
76 }
77 
78 
post_process_cell_results(bool maximize)79 void NonDGlobalSingleInterval::post_process_cell_results(bool maximize)
80 { finalStatistics.function_value(truthFnStar, statCntr++); }
81 
82 } // namespace Dakota
83