Utility class dedicated to hold structures and functions commont to Gaussian Processes. More...
#include <GaussianProcess.h>
Classes | |
struct | GPOptimizerOptions |
Structure containing the optimization options for hyperparameter-tuning. More... | |
Public Member Functions | |
GaussianProcess () | |
void | initialize (CovarianceFunctionBase *covariance_function, const std::vector< std::string > ¶ms_to_tune, const std::vector< Real > &min=std::vector< Real >(), const std::vector< Real > &max=std::vector< Real >()) |
Initializes the most important structures in the Gaussian Process: the covariance function and a tuning map which is used if the user requires parameter tuning. More... | |
void | setupCovarianceMatrix (const RealEigenMatrix &training_params, const RealEigenMatrix &training_data, const GPOptimizerOptions &opts) |
Sets up the covariance matrix given data and optimization options. More... | |
void | setupStoredMatrices (const RealEigenMatrix &input) |
Sets up the Cholesky decomposition and inverse action of the covariance matrix. More... | |
void | linkCovarianceFunction (CovarianceFunctionBase *covariance_function) |
Finds and links the covariance function to this object. More... | |
void | generateTuningMap (const std::vector< std::string > ¶ms_to_tune, const std::vector< Real > &min=std::vector< Real >(), const std::vector< Real > &max=std::vector< Real >()) |
Sets up the tuning map which is used if the user requires parameter tuning. More... | |
void | standardizeParameters (RealEigenMatrix ¶meters, bool keep_moments=false) |
Standardizes the vector of input parameters (x values). More... | |
void | standardizeData (RealEigenMatrix &data, bool keep_moments=false) |
Standardizes the vector of responses (y values). More... | |
void | tuneHyperParamsAdam (const RealEigenMatrix &training_params, const RealEigenMatrix &training_data, const GPOptimizerOptions &opts) |
Real | getLoss (RealEigenMatrix &inputs, RealEigenMatrix &outputs) |
std::vector< Real > | getGradient (RealEigenMatrix &inputs) const |
void | mapToVec (const std::unordered_map< std::string, std::tuple< unsigned int, unsigned int, Real, Real >> &tuning_data, const std::unordered_map< std::string, Real > &scalar_map, const std::unordered_map< std::string, std::vector< Real >> &vector_map, std::vector< Real > &vec) const |
Function used to convert the hyperparameter maps in this object to vectors. More... | |
void | vecToMap (const std::unordered_map< std::string, std::tuple< unsigned int, unsigned int, Real, Real >> &tuning_data, std::unordered_map< std::string, Real > &scalar_map, std::unordered_map< std::string, std::vector< Real >> &vector_map, const std::vector< Real > &vec) const |
Function used to convert the vectors back to hyperparameter maps. More... | |
const StochasticTools::Standardizer & | getParamStandardizer () const |
Get constant reference to the contained structures. More... | |
const StochasticTools::Standardizer & | getDataStandardizer () const |
const RealEigenMatrix & | getK () const |
const RealEigenMatrix & | getKResultsSolve () const |
const Eigen::LLT< RealEigenMatrix > & | getKCholeskyDecomp () const |
const CovarianceFunctionBase & | getCovarFunction () const |
const CovarianceFunctionBase * | getCovarFunctionPtr () const |
const std::string & | getCovarType () const |
const std::string & | getCovarName () const |
const std::vector< UserObjectName > & | getDependentCovarNames () const |
const std::map< UserObjectName, std::string > & | getDependentCovarTypes () const |
const unsigned int & | getCovarNumOutputs () const |
const unsigned int & | getNumTunableParams () const |
const std::unordered_map< std::string, Real > & | getHyperParamMap () const |
const std::unordered_map< std::string, std::vector< Real > > & | getHyperParamVectorMap () const |
StochasticTools::Standardizer & | paramStandardizer () |
Get non-constant reference to the contained structures (if they need to be modified from the utside) More... | |
StochasticTools::Standardizer & | dataStandardizer () |
RealEigenMatrix & | K () |
RealEigenMatrix & | KResultsSolve () |
Eigen::LLT< RealEigenMatrix > & | KCholeskyDecomp () |
CovarianceFunctionBase * | covarFunctionPtr () |
CovarianceFunctionBase & | covarFunction () |
std::string & | covarType () |
std::string & | covarName () |
std::map< UserObjectName, std::string > & | dependentCovarTypes () |
std::vector< UserObjectName > & | dependentCovarNames () |
unsigned int & | covarNumOutputs () |
std::unordered_map< std::string, std::tuple< unsigned int, unsigned int, Real, Real > > & | tuningData () |
std::unordered_map< std::string, Real > & | hyperparamMap () |
std::unordered_map< std::string, std::vector< Real > > & | hyperparamVectorMap () |
Protected Attributes | |
CovarianceFunctionBase * | _covariance_function = nullptr |
Covariance function object. More... | |
std::unordered_map< std::string, std::tuple< unsigned int, unsigned int, Real, Real > > | _tuning_data |
Contains tuning inforation. Index of hyperparam, size, and min/max bounds. More... | |
unsigned int | _num_tunable |
Number of tunable hyperparameters. More... | |
std::string | _covar_type |
Type of covariance function used for this GP. More... | |
std::string | _covar_name |
The name of the covariance function used in this GP. More... | |
std::vector< UserObjectName > | _dependent_covar_names |
The names of the covariance functions the used covariance function depends on. More... | |
std::map< UserObjectName, std::string > | _dependent_covar_types |
The types of the covariance functions the used covariance function depends on. More... | |
unsigned int | _num_outputs |
The number of outputs of the GP. More... | |
std::unordered_map< std::string, Real > | _hyperparam_map |
Scalar hyperparameters. Stored for use in surrogate. More... | |
std::unordered_map< std::string, std::vector< Real > > | _hyperparam_vec_map |
Vector hyperparameters. Stored for use in surrogate. More... | |
StochasticTools::Standardizer | _param_standardizer |
Standardizer for use with params (x) More... | |
StochasticTools::Standardizer | _data_standardizer |
Standardizer for use with data (y) More... | |
RealEigenMatrix | _K |
An _n_sample by _n_sample covariance matrix constructed from the selected kernel function. More... | |
RealEigenMatrix | _K_results_solve |
A solve of Ax=b via Cholesky. More... | |
Eigen::LLT< RealEigenMatrix > | _K_cho_decomp |
Cholesky decomposition Eigen object. More... | |
const RealEigenMatrix * | _training_params |
Paramaters (x) used for training, along with statistics. More... | |
const RealEigenMatrix * | _training_data |
Data (y) used for training. More... | |
unsigned int | _batch_size |
The batch size for Adam optimization. More... | |
Utility class dedicated to hold structures and functions commont to Gaussian Processes.
It can be used to standardize parameters, manipulate covariance data and compute additional stored matrices.
Definition at line 25 of file GaussianProcess.h.
StochasticTools::GaussianProcess::GaussianProcess | ( | ) |
Definition at line 46 of file GaussianProcess.C.
|
inline |
Definition at line 209 of file GaussianProcess.h.
|
inline |
Definition at line 208 of file GaussianProcess.h.
|
inline |
Definition at line 211 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
|
inline |
Definition at line 214 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
|
inline |
Definition at line 210 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
|
inline |
Definition at line 204 of file GaussianProcess.h.
Referenced by dataLoad(), dataStore(), GaussianProcessTrainer::postTrain(), and ActiveLearningGaussianProcess::reTrain().
|
inline |
Definition at line 213 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
|
inline |
Definition at line 212 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
void StochasticTools::GaussianProcess::generateTuningMap | ( | const std::vector< std::string > & | params_to_tune, |
const std::vector< Real > & | min = std::vector<Real>() , |
||
const std::vector< Real > & | max = std::vector<Real>() |
||
) |
Sets up the tuning map which is used if the user requires parameter tuning.
params_to_tune | List of parameters which need to be tuned. |
min | List of lower bounds for the parameter tuning. |
max | List of upper bounds for parameter tuning. |
Definition at line 102 of file GaussianProcess.C.
Referenced by initialize().
|
inline |
Definition at line 177 of file GaussianProcess.h.
Referenced by GaussianProcessSurrogate::evaluate(), and GaussianProcessTrainer::GaussianProcessTrainer().
|
inline |
Definition at line 178 of file GaussianProcess.h.
Referenced by GaussianProcessSurrogate::setupCovariance().
|
inline |
Definition at line 180 of file GaussianProcess.h.
|
inline |
Definition at line 189 of file GaussianProcess.h.
|
inline |
Definition at line 179 of file GaussianProcess.h.
|
inline |
Definition at line 173 of file GaussianProcess.h.
Referenced by GaussianProcessSurrogate::evaluate().
|
inline |
Definition at line 181 of file GaussianProcess.h.
|
inline |
Definition at line 185 of file GaussianProcess.h.
std::vector< Real > StochasticTools::GaussianProcess::getGradient | ( | RealEigenMatrix & | inputs | ) | const |
Definition at line 251 of file GaussianProcess.C.
Referenced by tuneHyperParamsAdam().
|
inline |
Definition at line 191 of file GaussianProcess.h.
Referenced by GaussianProcessData::initialize().
|
inline |
Definition at line 192 of file GaussianProcess.h.
Referenced by GaussianProcessData::initialize().
|
inline |
Definition at line 174 of file GaussianProcess.h.
|
inline |
Definition at line 176 of file GaussianProcess.h.
Referenced by GaussianProcessSurrogate::evaluate().
|
inline |
Definition at line 175 of file GaussianProcess.h.
Referenced by GaussianProcessSurrogate::evaluate().
Real StochasticTools::GaussianProcess::getLoss | ( | RealEigenMatrix & | inputs, |
RealEigenMatrix & | outputs | ||
) |
Definition at line 234 of file GaussianProcess.C.
Referenced by tuneHyperParamsAdam().
|
inline |
Definition at line 190 of file GaussianProcess.h.
|
inline |
Get constant reference to the contained structures.
Definition at line 172 of file GaussianProcess.h.
Referenced by GaussianProcessSurrogate::evaluate().
|
inline |
Definition at line 219 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
|
inline |
Definition at line 220 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
void StochasticTools::GaussianProcess::initialize | ( | CovarianceFunctionBase * | covariance_function, |
const std::vector< std::string > & | params_to_tune, | ||
const std::vector< Real > & | min = std::vector<Real>() , |
||
const std::vector< Real > & | max = std::vector<Real>() |
||
) |
Initializes the most important structures in the Gaussian Process: the covariance function and a tuning map which is used if the user requires parameter tuning.
covariance_function | Pointer to the covariance function that needs to be used for the Gaussian Process. |
params_to_tune | List of parameters which need to be tuned. |
min | List of lower bounds for the parameter tuning. |
max | List of upper bounds for parameter tuning. |
Definition at line 49 of file GaussianProcess.C.
Referenced by ActiveLearningGaussianProcess::ActiveLearningGaussianProcess(), and GaussianProcessTrainer::GaussianProcessTrainer().
|
inline |
Definition at line 205 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
|
inline |
Definition at line 207 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
|
inline |
Definition at line 206 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
void StochasticTools::GaussianProcess::linkCovarianceFunction | ( | CovarianceFunctionBase * | covariance_function | ) |
Finds and links the covariance function to this object.
Used mainly in the covariance data action.
covariance_function | Pointer to the covariance function that needs to be used for the Gaussian Process. |
Definition at line 59 of file GaussianProcess.C.
Referenced by initialize(), and GaussianProcessSurrogate::setupCovariance().
void StochasticTools::GaussianProcess::mapToVec | ( | const std::unordered_map< std::string, std::tuple< unsigned int, unsigned int, Real, Real >> & | tuning_data, |
const std::unordered_map< std::string, Real > & | scalar_map, | ||
const std::unordered_map< std::string, std::vector< Real >> & | vector_map, | ||
std::vector< Real > & | vec | ||
) | const |
Function used to convert the hyperparameter maps in this object to vectors.
Definition at line 274 of file GaussianProcess.C.
Referenced by tuneHyperParamsAdam().
|
inline |
Get non-constant reference to the contained structures (if they need to be modified from the utside)
Definition at line 203 of file GaussianProcess.h.
Referenced by dataLoad(), dataStore(), GaussianProcessTrainer::postTrain(), and ActiveLearningGaussianProcess::reTrain().
void StochasticTools::GaussianProcess::setupCovarianceMatrix | ( | const RealEigenMatrix & | training_params, |
const RealEigenMatrix & | training_data, | ||
const GPOptimizerOptions & | opts | ||
) |
Sets up the covariance matrix given data and optimization options.
training_params | The training parameter values (x values) for the covariance matrix. |
training_data | The training data (y values) for the inversion of the covariance matrix. |
opts | The optimizer options. |
Definition at line 70 of file GaussianProcess.C.
Referenced by GaussianProcessTrainer::postTrain(), and ActiveLearningGaussianProcess::reTrain().
void StochasticTools::GaussianProcess::setupStoredMatrices | ( | const RealEigenMatrix & | input | ) |
Sets up the Cholesky decomposition and inverse action of the covariance matrix.
input | The vector/matrix which right multiples the inverse of the covariance matrix. |
Definition at line 95 of file GaussianProcess.C.
Referenced by getLoss(), and setupCovarianceMatrix().
void StochasticTools::GaussianProcess::standardizeData | ( | RealEigenMatrix & | data, |
bool | keep_moments = false |
||
) |
Standardizes the vector of responses (y values).
data | The vector/matrix of input data. |
keep_moments | If previously computed or new moments are to be used. |
Definition at line 144 of file GaussianProcess.C.
Referenced by GaussianProcessTrainer::postTrain(), and ActiveLearningGaussianProcess::reTrain().
void StochasticTools::GaussianProcess::standardizeParameters | ( | RealEigenMatrix & | parameters, |
bool | keep_moments = false |
||
) |
Standardizes the vector of input parameters (x values).
parameters | The vector/matrix of input data. |
keep_moments | If previously computed or new moments are to be used. |
Definition at line 136 of file GaussianProcess.C.
Referenced by GaussianProcessTrainer::postTrain(), and ActiveLearningGaussianProcess::reTrain().
void StochasticTools::GaussianProcess::tuneHyperParamsAdam | ( | const RealEigenMatrix & | training_params, |
const RealEigenMatrix & | training_data, | ||
const GPOptimizerOptions & | opts | ||
) |
Definition at line 152 of file GaussianProcess.C.
Referenced by setupCovarianceMatrix().
|
inline |
Definition at line 215 of file GaussianProcess.h.
void StochasticTools::GaussianProcess::vecToMap | ( | const std::unordered_map< std::string, std::tuple< unsigned int, unsigned int, Real, Real >> & | tuning_data, |
std::unordered_map< std::string, Real > & | scalar_map, | ||
std::unordered_map< std::string, std::vector< Real >> & | vector_map, | ||
const std::vector< Real > & | vec | ||
) | const |
Function used to convert the vectors back to hyperparameter maps.
Definition at line 298 of file GaussianProcess.C.
Referenced by tuneHyperParamsAdam().
|
protected |
The batch size for Adam optimization.
Definition at line 279 of file GaussianProcess.h.
Referenced by getGradient(), getLoss(), setupCovarianceMatrix(), and tuneHyperParamsAdam().
|
protected |
The name of the covariance function used in this GP.
Definition at line 240 of file GaussianProcess.h.
Referenced by covarName(), getCovarName(), and linkCovarianceFunction().
|
protected |
Type of covariance function used for this GP.
Definition at line 237 of file GaussianProcess.h.
Referenced by covarType(), getCovarType(), and linkCovarianceFunction().
|
protected |
Covariance function object.
Definition at line 228 of file GaussianProcess.h.
Referenced by covarFunction(), covarFunctionPtr(), generateTuningMap(), getCovarFunction(), getCovarFunctionPtr(), getGradient(), getLoss(), linkCovarianceFunction(), setupCovarianceMatrix(), and tuneHyperParamsAdam().
|
protected |
Standardizer for use with data (y)
Definition at line 261 of file GaussianProcess.h.
Referenced by dataStandardizer(), getDataStandardizer(), and standardizeData().
|
protected |
The names of the covariance functions the used covariance function depends on.
Definition at line 243 of file GaussianProcess.h.
Referenced by dependentCovarNames(), getDependentCovarNames(), and linkCovarianceFunction().
|
protected |
The types of the covariance functions the used covariance function depends on.
Definition at line 246 of file GaussianProcess.h.
Referenced by dependentCovarTypes(), getDependentCovarTypes(), and linkCovarianceFunction().
|
protected |
Scalar hyperparameters. Stored for use in surrogate.
Definition at line 252 of file GaussianProcess.h.
Referenced by getHyperParamMap(), hyperparamMap(), setupCovarianceMatrix(), and tuneHyperParamsAdam().
|
protected |
Vector hyperparameters. Stored for use in surrogate.
Definition at line 255 of file GaussianProcess.h.
Referenced by getHyperParamVectorMap(), hyperparamVectorMap(), setupCovarianceMatrix(), and tuneHyperParamsAdam().
|
protected |
An _n_sample by _n_sample covariance matrix constructed from the selected kernel function.
Definition at line 264 of file GaussianProcess.h.
Referenced by getK(), getLoss(), K(), setupCovarianceMatrix(), and setupStoredMatrices().
|
protected |
Cholesky decomposition Eigen object.
Definition at line 270 of file GaussianProcess.h.
Referenced by getGradient(), getKCholeskyDecomp(), KCholeskyDecomp(), and setupStoredMatrices().
|
protected |
A solve of Ax=b via Cholesky.
Definition at line 267 of file GaussianProcess.h.
Referenced by getGradient(), getKResultsSolve(), getLoss(), KResultsSolve(), and setupStoredMatrices().
|
protected |
The number of outputs of the GP.
Definition at line 249 of file GaussianProcess.h.
Referenced by covarNumOutputs(), getCovarNumOutputs(), linkCovarianceFunction(), and setupCovarianceMatrix().
|
protected |
Number of tunable hyperparameters.
Definition at line 234 of file GaussianProcess.h.
Referenced by generateTuningMap(), getGradient(), getNumTunableParams(), and tuneHyperParamsAdam().
|
protected |
Standardizer for use with params (x)
Definition at line 258 of file GaussianProcess.h.
Referenced by getParamStandardizer(), paramStandardizer(), and standardizeParameters().
|
protected |
Data (y) used for training.
Definition at line 276 of file GaussianProcess.h.
|
protected |
Paramaters (x) used for training, along with statistics.
Definition at line 273 of file GaussianProcess.h.
|
protected |
Contains tuning inforation. Index of hyperparam, size, and min/max bounds.
Definition at line 231 of file GaussianProcess.h.
Referenced by generateTuningMap(), getGradient(), setupCovarianceMatrix(), tuneHyperParamsAdam(), and tuningData().