https://mooseframework.inl.gov
BiFidelityActiveLearningGPDecision.C
Go to the documentation of this file.
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 
11 #include "Sampler.h"
12 
14 
17 {
19  params.addClassDescription("Perform active learning decision making in bi-fidelity modeling.");
20  params.addRequiredParam<SamplerName>("sampler", "The sampler object.");
21  params.addRequiredParam<ReporterName>("outputs_lf",
22  "Value of the LF model output from the SubApp.");
23  params.addParam<ReporterValueName>("lf_corrected", "lf_corrected", "GP-corrected LF prediciton.");
24  return params;
25 }
26 
28  const InputParameters & parameters)
29  : ActiveLearningGPDecision(parameters),
30  _sampler(getSampler("sampler")),
31  _outputs_lf(getReporterValue<std::vector<Real>>("outputs_lf", REPORTER_MODE_DISTRIBUTED)),
32  _lf_corrected(declareValue<std::vector<Real>>("lf_corrected",
33  std::vector<Real>(sampler().getNumberOfRows()))),
34  _local_comm(_sampler.getLocalComm())
35 {
36 }
37 
38 bool
40 {
41  for (dof_id_type i = 0; i < _inputs.size(); ++i)
42  {
46  }
47 
48  for (const auto & fs : _flag_sample)
49  if (!fs)
50  return false;
51  return true;
52 }
53 
54 void
56 {
59  // Accumulate inputs and outputs if we previously decided we needed a sample
60  if (_t_step > 1 && _decision)
61  {
62  std::vector<Real> differences(_outputs_global.size());
63  for (dof_id_type i = 0; i < _outputs_global.size(); ++i)
64  differences[i] = _outputs_global[i] - _outputs_lf_batch[i];
65 
66  // Accumulate data into _batch members
67  setupData(_inputs, differences);
68 
69  // Retrain if we are outside the training phase
70  if (_t_step >= _n_train)
72  }
73 
74  // Gather inputs for the current step
76 
77  // Evaluate GP and decide if we need more data if outside training phase
78  if (_t_step >= _n_train)
80 }
81 
82 bool
85  dof_id_type global_ind,
86  Real & val)
87 {
88  if (!_decision)
89  val = _outputs_lf_batch[global_ind] + _gp_mean[global_ind];
90  return _decision;
91 }
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
virtual void setupData(const std::vector< std::vector< Real >> &inputs, const std::vector< Real > &outputs)
This sets up data for re-training the GP.
std::vector< Real > _outputs_batch
Store all the outputs used for training.
const int _n_train
Number of initial training points for GP.
static InputParameters validParams()
bool _decision
GP pass/fail decision.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
virtual void reTrain(const std::vector< std::vector< Real >> &inputs, const std::vector< Real > &outputs) const final
const std::vector< Real > & _outputs_global
Reference to global output data requested from base class.
const std::vector< Real > & _outputs_lf
Store all the outputs used for training from the LF model.
void addRequiredParam(const std::string &name, const std::string &doc_string)
BiFidelityActiveLearningGPDecision(const InputParameters &parameters)
libMesh::Parallel::Communicator & _local_comm
Communicator that was split based on samples that have rows.
std::vector< Real > & _lf_corrected
Broadcast the GP-corrected LF prediciton to JSON.
virtual Real evaluate(const std::vector< Real > &x) const
Evaluate surrogate model given a row of parameters.
const ReporterMode REPORTER_MODE_DISTRIBUTED
virtual bool needSample(const std::vector< Real > &row, dof_id_type local_ind, dof_id_type global_ind, Real &val) override
Based on the computations in preNeedSample, the decision to get more data is passed and results from ...
virtual bool facilitateDecision() override
This makes decisions whether to call the full model or not based on GP prediction and uncertainty...
std::vector< std::vector< Real > > _inputs_batch
Store all the input vectors used for training.
const ActiveLearningGaussianProcess & _al_gp
The active learning GP trainer that permits re-training.
std::vector< Real > _outputs_lf_batch
Store all the outputs used for training from the LF model.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void preNeedSample() override
This is where most of the computations happen:
registerMooseObject("StochasticToolsApp", BiFidelityActiveLearningGPDecision)
bool learningFunction(const Real &gp_mean, const Real &gp_std) const
This method evaluates the active learning acquisition function and returns bool that indicates whethe...
void addClassDescription(const std::string &doc_string)
std::vector< Real > & _gp_mean
Broadcast the GP mean prediciton to JSON.
A class for performing active learning decision making in bi-fidelity modeling.
const SurrogateModel & _gp_eval
The GP evaluator object that permits re-evaluations.
std::vector< std::vector< Real > > & _inputs
Storage for the input vectors to be transferred to the output file.
std::vector< Real > & _gp_std
Broadcast the GP standard deviation to JSON.
const std::vector< std::vector< Real > > & _inputs_global
Reference to global input data requested from base class.
uint8_t dof_id_type
std::vector< bool > & _flag_sample
Flag samples when the GP fails.