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 Types | |
| enum | OptimizerType { OptimizerType::Adam, OptimizerType::LegacyAdam } |
| using | HyperParameterMap = CovarianceFunctionBase::HyperParameterMap |
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 torch::Tensor &training_params, const torch::Tensor &training_data, const GPOptimizerOptions &opts) |
| Sets up the covariance matrix given data and optimization options. More... | |
| void | setupStoredMatrices (const torch::Tensor &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 (torch::Tensor ¶meters, bool keep_moments=false) |
| Standardizes the vector of input parameters (x values). More... | |
| void | standardizeData (torch::Tensor &data, bool keep_moments=false) |
| Standardizes the vector of responses (y values). More... | |
| void | tuneHyperParamsAdam (const torch::Tensor &training_params, const torch::Tensor &training_data, const GPOptimizerOptions &opts) |
| Real | getLoss (torch::Tensor &inputs, torch::Tensor &outputs) |
| std::vector< Real > | getGradient (torch::Tensor &inputs) const |
| void | mapToVec (const std::unordered_map< std::string, std::tuple< unsigned int, unsigned int, Real, Real >> &tuning_data, const HyperParameterMap &hyperparam_map, std::vector< Real > &vec) const |
| Function used to convert the hyperparameter map in this object to a flat vector. More... | |
| void | vecToMap (const std::unordered_map< std::string, std::tuple< unsigned int, unsigned int, Real, Real >> &tuning_data, HyperParameterMap &hyperparam_map, const std::vector< Real > &vec) const |
| Function used to convert the vector back to the hyperparameter map. More... | |
| const StochasticTools::Standardizer & | getParamStandardizer () const |
| Get constant reference to the contained structures. More... | |
| const StochasticTools::Standardizer & | getDataStandardizer () const |
| const torch::Tensor & | getK () const |
| const torch::Tensor & | getKResultsSolve () const |
| const torch::Tensor & | 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 HyperParameterMap & | getHyperParamMap () const |
| const std::vector< Real > & | getLengthScales () 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 () |
| torch::Tensor & | K () |
| torch::Tensor & | KResultsSolve () |
| torch::Tensor & | 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 () |
| HyperParameterMap & | hyperparamMap () |
| std::vector< Real > & | lengthScales () |
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 = 0 |
| 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 = 0 |
| The number of outputs of the GP. More... | |
| HyperParameterMap | _hyperparam_map |
| Hyperparameters. Stored as tensors for use in surrogate reload/reporting. More... | |
| StochasticTools::Standardizer | _param_standardizer |
| Standardizer for use with params (x) More... | |
| StochasticTools::Standardizer | _data_standardizer |
| Standardizer for use with data (y) More... | |
| torch::Tensor | _K |
| An _n_sample by _n_sample covariance matrix constructed from the selected kernel function. More... | |
| torch::Tensor | _K_results_solve |
| A solve of Ax=b via Cholesky. More... | |
| torch::Tensor | _K_cho_decomp |
| Cholesky decomposition libtorch tensor object. More... | |
| unsigned int | _batch_size = 0 |
| The batch size for Adam optimization. More... | |
| std::vector< Real > | _length_scales |
| To return the GP length scales for active learning. 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 27 of file GaussianProcess.h.
| using StochasticTools::GaussianProcess::HyperParameterMap = CovarianceFunctionBase::HyperParameterMap |
Definition at line 30 of file GaussianProcess.h.
|
strong |
| Enumerator | |
|---|---|
| Adam | |
| LegacyAdam | |
Definition at line 34 of file GaussianProcess.h.
| StochasticTools::GaussianProcess::GaussianProcess | ( | ) |
Definition at line 129 of file GaussianProcess.C.
|
inline |
Definition at line 216 of file GaussianProcess.h.
|
inline |
Definition at line 215 of file GaussianProcess.h.
|
inline |
Definition at line 218 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
|
inline |
Definition at line 221 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
|
inline |
Definition at line 217 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
|
inline |
Definition at line 211 of file GaussianProcess.h.
Referenced by dataLoad(), dataStore(), GaussianProcessTrainer::postTrain(), and ActiveLearningGaussianProcess::reTrain().
|
inline |
Definition at line 220 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
|
inline |
Definition at line 219 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 196 of file GaussianProcess.C.
Referenced by initialize().
|
inline |
Definition at line 187 of file GaussianProcess.h.
Referenced by GaussianProcessSurrogate::evaluate(), and GaussianProcessTrainer::GaussianProcessTrainer().
|
inline |
Definition at line 188 of file GaussianProcess.h.
Referenced by GaussianProcessSurrogate::setupCovariance().
|
inline |
Definition at line 190 of file GaussianProcess.h.
|
inline |
Definition at line 199 of file GaussianProcess.h.
|
inline |
Definition at line 189 of file GaussianProcess.h.
|
inline |
Definition at line 183 of file GaussianProcess.h.
Referenced by GaussianProcessSurrogate::evaluate(), and ActiveLearningGaussianProcess::getTrainingStandardizer().
|
inline |
Definition at line 191 of file GaussianProcess.h.
|
inline |
Definition at line 195 of file GaussianProcess.h.
| std::vector< Real > StochasticTools::GaussianProcess::getGradient | ( | torch::Tensor & | inputs | ) | const |
Definition at line 379 of file GaussianProcess.C.
Referenced by tuneHyperParamsAdam().
|
inline |
Definition at line 201 of file GaussianProcess.h.
Referenced by GaussianProcessData::initialize().
|
inline |
Definition at line 184 of file GaussianProcess.h.
|
inline |
Definition at line 186 of file GaussianProcess.h.
Referenced by GaussianProcessSurrogate::evaluate().
|
inline |
Definition at line 185 of file GaussianProcess.h.
Referenced by GaussianProcessSurrogate::evaluate().
|
inline |
Definition at line 202 of file GaussianProcess.h.
Referenced by ActiveLearningGaussianProcess::getLengthScales().
| Real StochasticTools::GaussianProcess::getLoss | ( | torch::Tensor & | inputs, |
| torch::Tensor & | outputs | ||
| ) |
Definition at line 362 of file GaussianProcess.C.
Referenced by tuneHyperParamsAdam().
|
inline |
Definition at line 200 of file GaussianProcess.h.
|
inline |
Get constant reference to the contained structures.
Definition at line 182 of file GaussianProcess.h.
Referenced by GaussianProcessSurrogate::evaluate().
|
inline |
Definition at line 226 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 132 of file GaussianProcess.C.
Referenced by ActiveLearningGaussianProcess::ActiveLearningGaussianProcess(), and GaussianProcessTrainer::GaussianProcessTrainer().
|
inline |
Definition at line 212 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 213 of file GaussianProcess.h.
Referenced by dataLoad(), and dataStore().
|
inline |
Definition at line 227 of file GaussianProcess.h.
| 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 142 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 HyperParameterMap & | hyperparam_map, | ||
| std::vector< Real > & | vec | ||
| ) | const |
Function used to convert the hyperparameter map in this object to a flat vector.
Definition at line 406 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 210 of file GaussianProcess.h.
Referenced by dataLoad(), dataStore(), GaussianProcessTrainer::postTrain(), and ActiveLearningGaussianProcess::reTrain().
| void StochasticTools::GaussianProcess::setupCovarianceMatrix | ( | const torch::Tensor & | training_params, |
| const torch::Tensor & | 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 153 of file GaussianProcess.C.
Referenced by GaussianProcessTrainer::postTrain(), and ActiveLearningGaussianProcess::reTrain().
| void StochasticTools::GaussianProcess::setupStoredMatrices | ( | const torch::Tensor & | 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 189 of file GaussianProcess.C.
Referenced by getLoss(), and setupCovarianceMatrix().
| void StochasticTools::GaussianProcess::standardizeData | ( | torch::Tensor & | 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 238 of file GaussianProcess.C.
Referenced by GaussianProcessTrainer::postTrain(), and ActiveLearningGaussianProcess::reTrain().
| void StochasticTools::GaussianProcess::standardizeParameters | ( | torch::Tensor & | 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 230 of file GaussianProcess.C.
Referenced by GaussianProcessTrainer::postTrain(), and ActiveLearningGaussianProcess::reTrain().
| void StochasticTools::GaussianProcess::tuneHyperParamsAdam | ( | const torch::Tensor & | training_params, |
| const torch::Tensor & | training_data, | ||
| const GPOptimizerOptions & | opts | ||
| ) |
Definition at line 246 of file GaussianProcess.C.
Referenced by setupCovarianceMatrix().
|
inline |
Definition at line 222 of file GaussianProcess.h.
| void StochasticTools::GaussianProcess::vecToMap | ( | const std::unordered_map< std::string, std::tuple< unsigned int, unsigned int, Real, Real >> & | tuning_data, |
| HyperParameterMap & | hyperparam_map, | ||
| const std::vector< Real > & | vec | ||
| ) | const |
Function used to convert the vector back to the hyperparameter map.
Definition at line 429 of file GaussianProcess.C.
Referenced by tuneHyperParamsAdam().
|
protected |
The batch size for Adam optimization.
Definition at line 274 of file GaussianProcess.h.
Referenced by getGradient(), setupCovarianceMatrix(), and tuneHyperParamsAdam().
|
protected |
The name of the covariance function used in this GP.
Definition at line 244 of file GaussianProcess.h.
Referenced by covarName(), getCovarName(), and linkCovarianceFunction().
|
protected |
Type of covariance function used for this GP.
Definition at line 241 of file GaussianProcess.h.
Referenced by covarType(), getCovarType(), and linkCovarianceFunction().
|
protected |
Covariance function object.
Definition at line 232 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 262 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 247 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 250 of file GaussianProcess.h.
Referenced by dependentCovarTypes(), getDependentCovarTypes(), and linkCovarianceFunction().
|
protected |
Hyperparameters. Stored as tensors for use in surrogate reload/reporting.
Definition at line 256 of file GaussianProcess.h.
Referenced by getHyperParamMap(), hyperparamMap(), setupCovarianceMatrix(), and tuneHyperParamsAdam().
|
protected |
An _n_sample by _n_sample covariance matrix constructed from the selected kernel function.
Definition at line 265 of file GaussianProcess.h.
Referenced by getK(), getLoss(), K(), setupCovarianceMatrix(), and setupStoredMatrices().
|
protected |
Cholesky decomposition libtorch tensor object.
Definition at line 271 of file GaussianProcess.h.
Referenced by getGradient(), getKCholeskyDecomp(), getLoss(), KCholeskyDecomp(), and setupStoredMatrices().
|
protected |
A solve of Ax=b via Cholesky.
Definition at line 268 of file GaussianProcess.h.
Referenced by getGradient(), getKResultsSolve(), getLoss(), KResultsSolve(), and setupStoredMatrices().
|
protected |
To return the GP length scales for active learning.
Definition at line 277 of file GaussianProcess.h.
Referenced by getLengthScales(), lengthScales(), and tuneHyperParamsAdam().
|
protected |
The number of outputs of the GP.
Definition at line 253 of file GaussianProcess.h.
Referenced by covarNumOutputs(), getCovarNumOutputs(), getGradient(), linkCovarianceFunction(), and setupCovarianceMatrix().
|
protected |
Number of tunable hyperparameters.
Definition at line 238 of file GaussianProcess.h.
Referenced by generateTuningMap(), getGradient(), getNumTunableParams(), and tuneHyperParamsAdam().
|
protected |
Standardizer for use with params (x)
Definition at line 259 of file GaussianProcess.h.
Referenced by getParamStandardizer(), paramStandardizer(), and standardizeParameters().
|
protected |
Contains tuning inforation. Index of hyperparam, size, and min/max bounds.
Definition at line 235 of file GaussianProcess.h.
Referenced by generateTuningMap(), getGradient(), setupCovarianceMatrix(), tuneHyperParamsAdam(), and tuningData().
1.8.14