15 #include <petscdmda.h> 17 #include "libmesh/petsc_vector.h" 18 #include "libmesh/petsc_matrix.h" 28 params.
addClassDescription(
"Provides data preperation and training for a single- or multi-output " 29 "Gaussian Process surrogate model.");
31 params.
addRequiredParam<UserObjectName>(
"covariance_function",
"Name of covariance function.");
33 "standardize_params",
true,
"Standardize (center and scale) training parameters (x values)");
35 "standardize_data",
true,
"Standardize (center and scale) training data (y values)");
37 params.
addParam<
unsigned int>(
"num_iters", 1000,
"Tolerance value for Adam optimization");
38 params.
addParam<
unsigned int>(
"batch_size", 0,
"The batch size for Adam optimization");
39 params.
addParam<
Real>(
"learning_rate", 0.001,
"The learning rate for Adam optimization");
41 "show_every_nth_iteration",
43 "Switch to show Adam optimization loss values at every nth step. If 0, nothing is showed.");
44 params.
addParam<std::vector<std::string>>(
"tune_parameters",
45 "Select hyperparameters to be tuned");
46 params.
addParam<std::vector<Real>>(
"tuning_min",
"Minimum allowable tuning value");
47 params.
addParam<std::vector<Real>>(
"tuning_max",
"Maximum allowable tuning value");
54 _predictor_row(getPredictorData()),
56 _training_params(declareModelData<
RealEigenMatrix>(
"_training_params")),
57 _standardize_params(getParam<bool>(
"standardize_params")),
58 _standardize_data(getParam<bool>(
"standardize_data")),
59 _do_tuning(isParamValid(
"tune_parameters")),
60 _optimization_opts(
StochasticTools::GaussianProcess::GPOptimizerOptions(
61 getParam<unsigned
int>(
"show_every_nth_iteration"),
62 getParam<unsigned
int>(
"num_iters"),
63 getParam<unsigned
int>(
"batch_size"),
64 getParam<
Real>(
"learning_rate"))),
65 _sampler_row(getSamplerData())
70 paramError(
"batch_size",
"Batch size cannot be greater than the training data set size.");
72 std::vector<std::string> tune_parameters(
74 : std::vector<std::string>{});
77 (
getParam<std::vector<Real>>(
"tuning_min").size() != tune_parameters.size()))
78 mooseError(
"tuning_min size does not match tune_parameters");
80 (
getParam<std::vector<Real>>(
"tuning_max").size() != tune_parameters.size()))
81 mooseError(
"tuning_max size does not match tune_parameters");
83 std::vector<Real> lower_bounds, upper_bounds;
85 lower_bounds = getParam<std::vector<Real>>(
"tuning_min");
87 upper_bounds =
getParam<std::vector<Real>>(
"tuning_max");
112 mooseError(
"The size of the provided response (",
114 ") does not match the number of expected outputs from the covariance (",
const StochasticTools::GaussianProcess::GPOptimizerOptions _optimization_opts
Struct holding parameters necessary for parameter tuning.
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
virtual void train() override
const Real * _rval
Response value.
unsigned int _n_dims
Dimension of predictor data - either _sampler.getNumberOfCols() or _pvals.size() + _pcols...
const std::vector< Real > * _rvecval
Vector response value.
RealEigenMatrix & _training_params
Paramaters (x) used for training, along with statistics.
const Parallel::Communicator & _communicator
bool _do_tuning
Flag to toggle hyperparameter tuning/optimization.
unsigned int & _n_outputs
The number of outputs.
virtual void postTrain() override
bool isParamValid(const std::string &name) const
GaussianProcessTrainer(const InputParameters ¶meters)
static InputParameters validParams()
registerMooseObject("StochasticToolsApp", GaussianProcessTrainer)
const T & getParam(const std::string &name) const
const std::vector< Real > & _predictor_row
Data from the current predictor row.
void paramError(const std::string ¶m, Args... args) const
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealEigenMatrix
dof_id_type getNumberOfRows() const
virtual void preTrain() override
unsigned int getLocalSampleSize() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This is the main trainer base class.
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
bool _standardize_data
Switch for training data(y) standardization.
std::vector< std::vector< Real > > _data_buffer
Data (y) used for training.
RealEigenMatrix _training_data
Data (y) used for training.
const InputParameters & parameters() const
unsigned int numOutputs() const
Return the number of outputs assumed for this covariance function.
static InputParameters validParams()
StochasticTools::GaussianProcess & _gp
Gaussian process handler responsible for managing training related tasks.
std::vector< std::vector< Real > > _params_buffer
Parameters (x) used for training – we'll allgather these in postTrain().
void ErrorVector unsigned int
bool _standardize_params
Switch for training param (x) standardization.
CovarianceFunctionBase * getCovarianceFunctionByName(const UserObjectName &name) const
Lookup a CovarianceFunction object by name and return pointer.