https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CovarianceFunctionBase.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
13#include "StochasticToolsApp.h"
14#include "MooseObject.h"
15#include "CovarianceInterface.h"
16
21{
22public:
23 using HyperParameterMap = std::unordered_map<std::string, torch::Tensor>;
24
26 static bool isScalarHyperParameter(const torch::Tensor & tensor);
27
29 static bool isVectorHyperParameter(const torch::Tensor & tensor);
30
33
39 virtual void computeCovarianceMatrix(torch::Tensor & K,
40 const torch::Tensor & x,
41 const torch::Tensor & xp,
42 const bool is_self_covariance) const = 0;
43
46 void loadHyperParamMap(const HyperParameterMap & map);
47
50 void buildHyperParamMap(HyperParameterMap & map) const;
51
59 virtual bool
60 getTuningData(const std::string & name, unsigned int & size, Real & min, Real & max) const;
61
64 void dependentCovarianceTypes(std::map<UserObjectName, std::string> & name_type_map) const;
65
67 const std::vector<UserObjectName> & dependentCovarianceNames() const
68 {
70 }
71
80 virtual bool computedKdhyper(torch::Tensor & dKdhp,
81 const torch::Tensor & x,
82 const std::string & hyper_param_name,
83 unsigned int ind) const;
84
87 virtual bool isTunable(const std::string & name) const;
88
90 unsigned int numOutputs() const { return _num_outputs; }
91
92protected:
97 torch::Tensor &
98 addRealHyperParameter(const std::string & name, const Real value, const bool is_tunable);
99
104 torch::Tensor & addVectorRealHyperParameter(const std::string & name,
105 const std::vector<Real> & value,
106 const bool is_tunable);
107
110
112 std::unordered_set<std::string> _tunable_hp;
113
115 const unsigned int _num_outputs;
116
118 const std::vector<UserObjectName> _dependent_covariance_names;
119
121 std::vector<std::string> _dependent_covariance_types;
122
124 std::vector<CovarianceFunctionBase *> _covariance_functions;
125};
126
127#endif
const std::vector< double > x
Base class for covariance functions that are used in Gaussian Processes.
virtual bool getTuningData(const std::string &name, unsigned int &size, Real &min, Real &max) const
Get the default minimum and maximum and size of a hyperparameter.
std::vector< std::string > _dependent_covariance_types
The types of the dependent covariance functions.
virtual void computeCovarianceMatrix(torch::Tensor &K, const torch::Tensor &x, const torch::Tensor &xp, const bool is_self_covariance) const =0
Generates the Covariance Matrix given two sets of points in the parameter space.
std::vector< CovarianceFunctionBase * > _covariance_functions
Vector of pointers to the dependent covariance functions.
void buildHyperParamMap(HyperParameterMap &map) const
Populates the input maps with the owned hyperparameters.
HyperParameterMap _hyperparameters
Map of hyperparameters stored as rank-0 or rank-1 tensors.
const std::vector< UserObjectName > _dependent_covariance_names
The names of the dependent covariance functions.
void dependentCovarianceTypes(std::map< UserObjectName, std::string > &name_type_map) const
Populate a map with the names and types of the dependent covariance functions.
const unsigned int _num_outputs
The number of outputs this covariance function is used to describe.
void loadHyperParamMap(const HyperParameterMap &map)
Load some hyperparameters into the local map contained in this object.
static bool isVectorHyperParameter(const torch::Tensor &tensor)
Return true if a hyperparameter tensor stores a vector of values.
virtual bool isTunable(const std::string &name) const
Check if a given parameter is tunable.
unsigned int numOutputs() const
Return the number of outputs assumed for this covariance function.
virtual bool computedKdhyper(torch::Tensor &dKdhp, const torch::Tensor &x, const std::string &hyper_param_name, unsigned int ind) const
Redirect dK/dhp for hyperparameter "hp".
static bool isScalarHyperParameter(const torch::Tensor &tensor)
Return true if a hyperparameter tensor stores one scalar value.
static InputParameters validParams()
const std::vector< UserObjectName > & dependentCovarianceNames() const
Get the names of the dependent covariances.
std::unordered_map< std::string, torch::Tensor > HyperParameterMap
std::unordered_set< std::string > _tunable_hp
list of tunable hyper-parameters
torch::Tensor & addRealHyperParameter(const std::string &name, const Real value, const bool is_tunable)
Register a scalar hyperparameter to this covariance function.
torch::Tensor & addVectorRealHyperParameter(const std::string &name, const std::vector< Real > &value, const bool is_tunable)
Register a vector hyperparameter to this covariance function.
const InputParameters & parameters() const
const std::string & name() const