https://mooseframework.inl.gov
ActiveLearningGPDecision.h
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 #ifdef MOOSE_LIBTORCH_ENABLED
10 
11 #pragma once
12 
17 
20 {
21 public:
24 
26  const int & getTrainingSamples() const { return _n_train; }
27 
28 protected:
35  virtual void preNeedSample() override;
36 
47  virtual bool needSample(const std::vector<Real> & row,
48  dof_id_type local_ind,
49  dof_id_type global_ind,
50  Real & val) override;
51 
58  virtual bool facilitateDecision();
59 
66  virtual void setupData(const std::vector<std::vector<Real>> & inputs,
67  const std::vector<Real> & outputs);
68 
77  bool learningFunction(const Real & gp_mean, const Real & gp_std) const;
78 
85 
87  std::vector<std::vector<Real>> _inputs_batch;
89  std::vector<Real> _outputs_batch;
90 
95 
97  std::vector<bool> & _flag_sample;
98 
100  const int _n_train;
101 
103  std::vector<std::vector<Real>> & _inputs;
104 
106  std::vector<Real> & _gp_mean;
108  std::vector<Real> & _gp_std;
109 
111  bool _decision;
112 
114  const std::vector<std::vector<Real>> & _inputs_global;
116  const std::vector<Real> & _outputs_global;
117 };
118 
119 #endif
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.
const Real & _learning_function_threshold
The learning function threshold.
const InputParameters & parameters() const
virtual void preNeedSample() override
This is where most of the computations happen:
const int & getTrainingSamples() const
Access the number of training samples.
const std::vector< Real > & _outputs_global
Reference to global output data requested from base class.
const MooseEnum & _learning_function
The learning function for active learning.
const Real & _learning_function_parameter
The learning function parameter.
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.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Interface for objects that need to use samplers.
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...
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 ...
std::vector< Real > & _gp_mean
Broadcast the GP mean prediciton to JSON.
virtual bool facilitateDecision()
Make decisions whether to call the full model or not based on GP prediction and uncertainty.
const SurrogateModel & _gp_eval
The GP evaluator object that permits re-evaluations.
ActiveLearningGPDecision(const InputParameters &parameters)
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.
This is a base class for performing active learning routines, meant to be used in conjunction with Sa...
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.