25 #include <queso/Defines.h>
27 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
28 #include <boost/program_options.hpp>
30 #include <queso/getpot.h>
31 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
33 #include <queso/GPMSAOptions.h>
35 #include <queso/GslVector.h>
39 #define UQ_GPMSA_HELP ""
40 #define UQ_GPMSA_MAX_SIMULATOR_BASIS_VECTORS_ODV 0
41 #define UQ_GPMSA_SIMULATOR_BASIS_VARIANCE_TO_CAPTURE 1.0
42 #define UQ_GPMSA_EMULATOR_PRECISION_SHAPE_ODV 5.0
43 #define UQ_GPMSA_EMULATOR_PRECISION_SCALE_ODV 0.2
44 #define UQ_GPMSA_OBSERVATIONAL_PRECISION_SHAPE_ODV 5.0
45 #define UQ_GPMSA_OBSERVATIONAL_PRECISION_SCALE_ODV 0.2
46 #define UQ_GPMSA_EMULATOR_CORRELATION_STRENGTH_ALPHA_ODV 1.0
47 #define UQ_GPMSA_EMULATOR_CORRELATION_STRENGTH_BETA_ODV 0.1
48 #define UQ_GPMSA_DISCREPANCY_PRECISION_SHAPE_ODV 1.0
49 #define UQ_GPMSA_DISCREPANCY_PRECISION_SCALE_ODV 1e4
50 #define UQ_GPMSA_DISCREPANCY_CORRELATION_STRENGTH_ALPHA_ODV 1.0
51 #define UQ_GPMSA_DISCREPANCY_CORRELATION_STRENGTH_BETA_ODV 0.1
52 #define UQ_GPMSA_EMULATOR_DATA_PRECISION_SHAPE_ODV 3.0
53 #define UQ_GPMSA_EMULATOR_DATA_PRECISION_SCALE_ODV 333.333
58 void min_max_update(V & min, V & max,
const V & new_data)
60 unsigned int dim = min.sizeGlobal();
61 queso_assert_equal_to(dim, max.sizeGlobal());
62 queso_assert_equal_to(dim, new_data.sizeGlobal());
64 for (
unsigned int p=0; p !=
dim; ++p)
66 min[p] = std::min(min[p], new_data[p]);
67 max[p] = std::max(max[p], new_data[p]);
73 void mean_var_update(
unsigned int & n, V & mean, V & var,
const V & new_data)
77 const V delta (new_data - mean);
84 V delta2 (new_data - mean);
101 this->
parse(env, prefix);
108 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
120 m_prefix = std::string(prefix) +
"gpmsa_";
178 queso_error_msg(
"Missing input file is required");
183 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
186 m_parser->registerOption<std::string>
189 "produce help message Gaussian process emulator");
194 "shape hyperprior (Gamma) parameter for emulator precision");
198 "scale hyperprior (Gamma) parameter for emulator precision");
203 "whether to use a calibrated hyperparameter for observational precision");
208 "shape hyperprior (Gamma) parameter for observational precision");
212 "scale hyperprior (Gamma) parameter for observational precision");
217 "alpha hyperprior (Beta) parameter for emulator correlation strength");
221 "beta hyperprior (Beta) parameter for emulator correlation strength");
226 "shape hyperprior (Gamma) parameter for discrepancy precision");
230 "scale hyperprior (Gamma) parameter for discrepancy precision");
235 "alpha hyperprior (Beta) parameter for discrepancy correlation strength");
239 "beta hyperprior (Beta) parameter for discrepancy correlation strength");
244 "shape hyperprior (Gamma) parameter for emulator data precision");
248 "scale hyperprior (Gamma) parameter for emulator data precision");
253 "option to autoscale all parameters and outputs based on data range");
257 "option to autoscale all parameters and outputs based on data statistics");
330 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
412 template <
typename V>
421 if ((m_autoscaleMinMaxAll && m_autoscaleMeanVarAll) ||
422 ((m_autoscaleMinMaxAll || m_autoscaleMeanVarAll) &&
423 (!m_autoscaleMinMaxUncertain.empty() ||
424 !m_autoscaleMeanVarUncertain.empty() ||
425 !m_autoscaleMinMaxScenario.empty() ||
426 !m_autoscaleMeanVarScenario.empty())))
427 queso_error_msg(
"Cannot autoscale based on incompatible criteria");
429 unsigned int dimScenario = m_simulationScenarios.size() ?
430 m_simulationScenarios[0]->sizeGlobal() : 0;
432 unsigned int dimParameter = m_simulationParameters.size() ?
433 m_simulationParameters[0]->sizeGlobal() : 0;
435 if (m_autoscaleMinMaxAll || !m_autoscaleMinMaxScenario.empty())
437 V maxScenario(*m_simulationScenarios[0]);
439 V minScenario(*m_simulationScenarios[0]);
441 for (
unsigned int i=1; i < m_simulationScenarios.size(); ++i)
442 min_max_update(minScenario, maxScenario,
443 (*m_simulationScenarios[i]));
445 for (
unsigned int i=0; i < m_experimentScenarios.size(); ++i)
446 min_max_update(minScenario, maxScenario,
447 (*m_experimentScenarios[i]));
449 for (
unsigned int p=0; p != dimScenario; ++p)
450 if (m_autoscaleMinMaxAll ||
451 m_autoscaleMinMaxScenario.count(p))
453 if ((m_scenarioScaleMin.size() > p) &&
454 ((m_scenarioScaleMin[p] != 0) ||
455 (m_scenarioScaleRange[p] != 1)))
456 queso_error_msg(
"Cannot autoscale and manually scale the same scenario parameter");
458 this->set_scenario_parameter_scaling(p, minScenario[p],
463 if (m_autoscaleMinMaxAll || !m_autoscaleMinMaxUncertain.empty())
465 V maxUncertain(*m_simulationParameters[0]);
467 V minUncertain(*m_simulationParameters[0]);
469 for (
unsigned int i=1; i < m_simulationParameters.size(); ++i)
470 min_max_update(minUncertain, maxUncertain,
471 (*m_simulationParameters[i]));
473 for (
unsigned int p=0; p != dimParameter; ++p)
474 if (m_autoscaleMinMaxAll ||
475 m_autoscaleMinMaxUncertain.count(p))
477 if ((m_uncertainScaleMin.size() > p) &&
478 ((m_uncertainScaleMin[p] != 0) ||
479 (m_uncertainScaleRange[p] != 1)))
480 queso_error_msg(
"Cannot autoscale and manually scale the same uncertain parameter");
482 this->set_uncertain_parameter_scaling(p, minUncertain[p],
488 if (m_autoscaleMeanVarAll || !m_autoscaleMeanVarScenario.empty())
492 V meanScenario(*m_simulationScenarios[0]);
494 V varScenario(m_simulationScenarios[0]->env(),
495 m_simulationScenarios[0]->map());
497 for (
unsigned int i=0; i < m_simulationScenarios.size(); ++i)
498 mean_var_update(n, meanScenario, varScenario,
499 *m_simulationScenarios[i]);
501 for (
unsigned int i=0; i < m_experimentScenarios.size(); ++i)
502 mean_var_update(n, meanScenario, varScenario,
503 *m_experimentScenarios[i]);
507 for (
unsigned int p=0; p != dimScenario; ++p)
508 if (m_autoscaleMeanVarAll ||
509 m_autoscaleMeanVarScenario.count(p))
511 if ((m_scenarioScaleMin.size() > p) &&
512 ((m_scenarioScaleMin[p] != 0) ||
513 (m_scenarioScaleRange[p] != 1)))
514 queso_error_msg(
"Cannot autoscale and manually scale the same scenario parameter");
516 this->set_scenario_parameter_scaling(p, meanScenario[p],
518 std::sqrt(varScenario[p]));
523 if (m_autoscaleMeanVarAll || !m_autoscaleMeanVarUncertain.empty())
527 V meanUncertain(*m_simulationParameters[0]);
529 V varUncertain(m_simulationParameters[0]->env(),
530 m_simulationParameters[0]->map());
532 for (
unsigned int i=0; i < m_simulationParameters.size(); ++i)
533 mean_var_update(n, meanUncertain, varUncertain,
534 *m_simulationParameters[i]);
538 for (
unsigned int p=0; p != dimScenario; ++p)
539 if (m_autoscaleMeanVarAll ||
540 m_autoscaleMeanVarUncertain.count(p))
542 if ((m_uncertainScaleMin.size() > p) &&
543 ((m_uncertainScaleMin[p] != 0) ||
544 (m_uncertainScaleRange[p] != 1)))
545 queso_error_msg(
"Cannot autoscale and manually scale the same uncertain parameter");
547 this->set_uncertain_parameter_scaling(p, meanUncertain[p],
549 std::sqrt(varUncertain[p]));
557 double physical_param)
563 return physical_param;
569 double physical_param)
575 return physical_param;
613 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
614 os << (*(obj.
m_parser)) << std::endl;
615 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
625 GPMSAOptions::set_final_scaling<GslVector>
626 (
const std::vector<SharedPtr<GslVector>::Type> &,
627 const std::vector<SharedPtr<GslVector>::Type> &,
628 const std::vector<SharedPtr<GslVector>::Type> &,
629 const std::vector<SharedPtr<GslVector>::Type> &,
630 const std::vector<SharedPtr<GslVector>::Type> &);
std::shared_ptr< T > Type
std::string m_option_observationalPrecisionShape
std::string m_option_discrepancyPrecisionShape
void print(std::ostream &os) const
Prints this to os.
void set_autoscale_meanvar_scenario_parameter(unsigned int i)
Do automatic normalization, using mean and variance of the.
std::string m_option_emulatorDataPrecisionShape
double m_emulatorDataPrecisionScale
The scale parameter for the Gamma hyperprior for the emulator data precision.
double m_emulatorCorrelationStrengthBeta
The beta paramter for the Beta hyperprior for the emulator correlation strength.
double normalized_uncertain_parameter(unsigned int i, double physical_param) const
Calculate a normalized value from a physical value for the.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
std::vector< double > m_uncertainScaleMin
double m_emulatorPrecisionScale
The scale parameter for the Gamma hyperprior for the emulator precision.
std::string m_option_emulatorBasisVarianceToCapture
std::vector< double > m_scenarioScaleMin
std::string m_option_discrepancyPrecisionScale
void set_autoscale_meanvar_uncertain_parameter(unsigned int i)
Do automatic normalization, using mean and variance of the.
std::string m_option_observationalPrecisionScale
std::string m_option_autoscaleMeanVarAll
std::ostream & operator<<(std::ostream &os, const SequenceStatisticalOptions &obj)
const GetPot & input() const
The GetPot input file parser.
std::string m_option_discrepancyCorrelationStrengthBeta
void set_uncertain_parameter_scaling(unsigned int i, double range_min, double range_max)
Set a value, for uncertain parameter i in simulation inputs, of.
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
void set_prefix(const char *prefix)
Set parameter option names to begin with prefix.
virtual ~GPMSAOptions()
Destructor.
int m_maxEmulatorBasisVectors
The maximum number of basis vectors to use for approximating.
double m_discrepancyCorrelationStrengthBeta
The beta paramter for the Beta hyperprior for the discrepancy correlation strength.
std::string m_option_discrepancyCorrelationStrengthAlpha
std::string m_option_emulatorDataPrecisionScale
std::string m_prefix
The prefix to look for in the input file.
std::string m_option_calibrateObservationalPrecision
QUESO::ScopedPtr< BoostInputOptionsParser >::Type m_parser
const BaseEnvironment * m_env
bool m_autoscaleMinMaxAll
bool m_autoscaleMeanVarAll
std::string m_help
If this string is non-empty, print the options object to the output file.
double m_emulatorCorrelationStrengthAlpha
The alpha paramter for the Beta hyperprior for the emulator correlation strength. ...
void set_scenario_parameter_scaling(unsigned int i, double range_min, double range_max)
Set a value, for scenario parameter i in simulation and.
std::string m_option_emulatorPrecisionShape
std::vector< double > m_scenarioScaleRange
double m_discrepancyPrecisionScale
The scale parameter for the Gamma hyperprior for the discrepancy precision.
double m_emulatorPrecisionShape
The shape parameter for the Gamma hyperprior for the emulator precision.
void parse(const BaseEnvironment &env, const char *prefix)
Given prefix, read the input file for parameters named "prefix"+*.
double normalized_scenario_parameter(unsigned int i, double physical_param) const
Calculate a normalized value from a physical value for the.
std::string m_option_emulatorCorrelationStrengthAlpha
double m_discrepancyPrecisionShape
The shape parameter for the Gamma hyperprior for the discrepancy precision.
std::string m_option_help
double m_emulatorDataPrecisionShape
The shape parameter for the Gamma hyperprior for the emulator data precision.
bool m_calibrateObservationalPrecision
Whether to use an observational error precision hyperparameter.
GPMSAOptions()
Construct with default parameters.
void set_autoscale_minmax_uncertain_parameter(unsigned int i)
Do automatic normalization, using minimum and maximum values in.
std::set< unsigned int > m_autoscaleMinMaxScenario
std::set< unsigned int > m_autoscaleMinMaxUncertain
void set_final_scaling(const std::vector< typename SharedPtr< V >::Type > &m_simulationScenarios, const std::vector< typename SharedPtr< V >::Type > &m_simulationParameters, const std::vector< typename SharedPtr< V >::Type > &m_simulationOutputs, const std::vector< typename SharedPtr< V >::Type > &m_experimentScenarios, const std::vector< typename SharedPtr< V >::Type > &m_experimentOutputs)
Determine the physical parameter ranges (range_min, range_max)
std::set< unsigned int > m_autoscaleMeanVarUncertain
double m_discrepancyCorrelationStrengthAlpha
The alpha paramter for the Beta hyperprior for the discrepancy correlation strength.
const BaseEnvironment & env() const
Returns the QUESO environment.
double m_emulatorBasisVarianceToCapture
The minimum fraction of the variance in simulation output to.
std::string m_option_maxEmulatorBasisVectors
void set_defaults()
Set default values for parameter options.
double m_observationalPrecisionScale
The scale parameter for the Gamma hyperprior for the observational precision.
void set_autoscale_minmax_scenario_parameter(unsigned int i)
Do automatic normalization, using minimum and maximum values in.
std::string m_option_emulatorPrecisionScale
std::string m_option_autoscaleMinMaxAll
void set_autoscale_minmax()
Do automatic normalization, using minimum and maximum values in.
double m_observationalPrecisionShape
The shape parameter for the Gamma hyperprior for the observational precision.
This class defines the options that specify the behaviour of the Gaussian process emulator...
std::string m_option_emulatorCorrelationStrengthBeta
void set_autoscale_meanvar()
Do automatic normalization, using mean and variance of the.
std::set< unsigned int > m_autoscaleMeanVarScenario
std::vector< double > m_uncertainScaleRange
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).