https://mooseframework.inl.gov
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 {
22 public:
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 
92 protected:
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
HyperParameterMap _hyperparameters
Map of hyperparameters stored as rank-0 or rank-1 tensors.
std::vector< std::string > _dependent_covariance_types
The types of the dependent covariance functions.
std::unordered_set< std::string > _tunable_hp
list of tunable hyper-parameters
static bool isVectorHyperParameter(const torch::Tensor &tensor)
Return true if a hyperparameter tensor stores a vector of values.
static const std::string K
Definition: NS.h:174
std::unordered_map< std::string, torch::Tensor > HyperParameterMap
const InputParameters & parameters() const
static bool isScalarHyperParameter(const torch::Tensor &tensor)
Return true if a hyperparameter tensor stores one scalar value.
std::vector< CovarianceFunctionBase * > _covariance_functions
Vector of pointers to the dependent covariance functions.
Base class for covariance functions that are used in Gaussian Processes.
static InputParameters validParams()
CovarianceFunctionBase(const InputParameters &parameters)
void buildHyperParamMap(HyperParameterMap &map) const
Populates the input maps with the owned hyperparameters.
const std::string & name() const
const unsigned int _num_outputs
The number of outputs this covariance function is used to describe.
const std::vector< double > x
const std::vector< UserObjectName > & dependentCovarianceNames() const
Get the names of the dependent covariances.
void loadHyperParamMap(const HyperParameterMap &map)
Load some hyperparameters into the local map contained in this object.
torch::Tensor & addRealHyperParameter(const std::string &name, const Real value, const bool is_tunable)
Register a scalar hyperparameter to this covariance function.
void dependentCovarianceTypes(std::map< UserObjectName, std::string > &name_type_map) const
Populate a map with the names and types of the dependent covariance functions.
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".
const std::vector< UserObjectName > _dependent_covariance_names
The names of the dependent covariance functions.
torch::Tensor & addVectorRealHyperParameter(const std::string &name, const std::vector< Real > &value, const bool is_tunable)
Register a vector hyperparameter to this covariance function.
unsigned int numOutputs() const
Return the number of outputs assumed for this covariance function.
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.
virtual bool isTunable(const std::string &name) const
Check if a given parameter is tunable.
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.