https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
ExponentialCovariance Class Reference

#include <ExponentialCovariance.h>

Inheritance diagram for ExponentialCovariance:
[legend]

Public Types

using HyperParameterMap = std::unordered_map< std::string, torch::Tensor >
 
typedef DataFileName DataFileParameterType
 

Public Member Functions

 ExponentialCovariance (const InputParameters &parameters)
 
void computeCovarianceMatrix (torch::Tensor &K, const torch::Tensor &x, const torch::Tensor &xp, const bool is_self_covariance) const override
 Generates the Covariance Matrix given two points in the parameter space. More...
 
bool computedKdhyper (torch::Tensor &dKdhp, const torch::Tensor &x, const std::string &hyper_param_name, unsigned int ind) const override
 Redirect dK/dhp for hyperparameter "hp". More...
 
void loadHyperParamMap (const HyperParameterMap &map)
 Load some hyperparameters into the local map contained in this object. More...
 
void buildHyperParamMap (HyperParameterMap &map) const
 Populates the input maps with the owned hyperparameters. More...
 
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. More...
 
void dependentCovarianceTypes (std::map< UserObjectName, std::string > &name_type_map) const
 Populate a map with the names and types of the dependent covariance functions. More...
 
const std::vector< UserObjectName > & dependentCovarianceNames () const
 Get the names of the dependent covariances. More...
 
virtual bool isTunable (const std::string &name) const
 Check if a given parameter is tunable. More...
 
unsigned int numOutputs () const
 Return the number of outputs assumed for this covariance function. More...
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
bool isKokkosObject () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParametersparameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const TgetParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const TqueryParam (const std::string &name) const
 
const TgetRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static InputParameters validParams ()
 
static void ExponentialFunction (torch::Tensor &K, const torch::Tensor &x, const torch::Tensor &xp, const torch::Tensor &length_factor, const torch::Tensor &sigma_f_squared, const torch::Tensor &sigma_n_squared, const torch::Tensor &gamma, const bool is_self_covariance)
 
static void computedKdlf (torch::Tensor &K, const torch::Tensor &x, const torch::Tensor &length_factor, const torch::Tensor &sigma_f_squared, const torch::Tensor &gamma, const int ind)
 Computes dK/dlf for individual length factors. More...
 
static bool isScalarHyperParameter (const torch::Tensor &tensor)
 Return true if a hyperparameter tensor stores one scalar value. More...
 
static bool isVectorHyperParameter (const torch::Tensor &tensor)
 Return true if a hyperparameter tensor stores a vector of values. More...
 
static void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 

Protected Member Functions

torch::TensoraddRealHyperParameter (const std::string &name, const Real value, const bool is_tunable)
 Register a scalar hyperparameter to this covariance function. More...
 
torch::TensoraddVectorRealHyperParameter (const std::string &name, const std::vector< Real > &value, const bool is_tunable)
 Register a vector hyperparameter to this covariance function. More...
 
void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) const
 
CovarianceFunctionBasegetCovarianceFunctionByName (const UserObjectName &name) const
 Lookup a CovarianceFunction object by name and return pointer. More...
 

Protected Attributes

HyperParameterMap _hyperparameters
 Map of hyperparameters stored as rank-0 or rank-1 tensors. More...
 
std::unordered_set< std::string > _tunable_hp
 list of tunable hyper-parameters More...
 
const unsigned int _num_outputs
 The number of outputs this covariance function is used to describe. More...
 
const std::vector< UserObjectName > _dependent_covariance_names
 The names of the dependent covariance functions. More...
 
std::vector< std::string > _dependent_covariance_types
 The types of the dependent covariance functions. More...
 
std::vector< CovarianceFunctionBase * > _covariance_functions
 Vector of pointers to the dependent covariance functions. More...
 
const bool & _enabled
 
MooseApp_app
 
Factory_factory
 
ActionFactory_action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters_pars
 
const Parallel::Communicator & _communicator
 

Private Attributes

const torch::Tensor_length_factor
 lengh factor () for the kernel, in vector form for multiple parameters More...
 
const torch::Tensor_sigma_f_squared
 signal variance (^2) More...
 
const torch::Tensor_sigma_n_squared
 noise variance (^2) More...
 
const torch::Tensor_gamma
 gamma exponential factor for use in kernel More...
 

Detailed Description

Definition at line 15 of file ExponentialCovariance.h.

Member Typedef Documentation

◆ HyperParameterMap

using CovarianceFunctionBase::HyperParameterMap = std::unordered_map<std::string, torch::Tensor>
inherited

Definition at line 23 of file CovarianceFunctionBase.h.

Constructor & Destructor Documentation

◆ ExponentialCovariance()

ExponentialCovariance::ExponentialCovariance ( const InputParameters parameters)

Definition at line 31 of file ExponentialCovariance.C.

34  "length_factor", getParam<std::vector<Real>>("length_factor"), true)),
36  addRealHyperParameter("signal_variance", getParam<Real>("signal_variance"), true)),
38  addRealHyperParameter("noise_variance", getParam<Real>("noise_variance"), true)),
39  _gamma(addRealHyperParameter("gamma", getParam<Real>("gamma"), false))
40 {
41 }
const T & getParam(const std::string &name) const
const InputParameters & parameters() const
const torch::Tensor & _gamma
gamma exponential factor for use in kernel
CovarianceFunctionBase(const InputParameters &parameters)
const torch::Tensor & _sigma_n_squared
noise variance (^2)
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 torch::Tensor & _sigma_f_squared
signal variance (^2)
const torch::Tensor & _length_factor
lengh factor () for the kernel, in vector form for multiple parameters

Member Function Documentation

◆ addRealHyperParameter()

torch::Tensor & CovarianceFunctionBase::addRealHyperParameter ( const std::string &  name,
const Real  value,
const bool  is_tunable 
)
protectedinherited

Register a scalar hyperparameter to this covariance function.

Parameters
nameThe name of the parameter
valueThe initial value of the parameter
is_tunableIf the parameter is tunable during optimization

Definition at line 95 of file CovarianceFunctionBase.C.

98 {
99  const auto prefixed_name = _name + ":" + name;
100  return insertHyperParameter(
101  _hyperparameters, _tunable_hp, prefixed_name, makeScalarHyperParameter(value), is_tunable);
102 }
HyperParameterMap _hyperparameters
Map of hyperparameters stored as rank-0 or rank-1 tensors.
std::unordered_set< std::string > _tunable_hp
list of tunable hyper-parameters
const std::string & _name
const std::string & name() const

◆ addVectorRealHyperParameter()

torch::Tensor & CovarianceFunctionBase::addVectorRealHyperParameter ( const std::string &  name,
const std::vector< Real > &  value,
const bool  is_tunable 
)
protectedinherited

Register a vector hyperparameter to this covariance function.

Parameters
nameThe name of the parameter
valueThe initial value of the parameter
is_tunableIf the parameter is tunable during optimization

Definition at line 105 of file CovarianceFunctionBase.C.

Referenced by LMC::LMC().

108 {
109  const auto prefixed_name = _name + ":" + name;
110  return insertHyperParameter(
111  _hyperparameters, _tunable_hp, prefixed_name, makeVectorHyperParameter(value), is_tunable);
112 }
HyperParameterMap _hyperparameters
Map of hyperparameters stored as rank-0 or rank-1 tensors.
std::unordered_set< std::string > _tunable_hp
list of tunable hyper-parameters
const std::string & _name
const std::string & name() const

◆ buildHyperParamMap()

void CovarianceFunctionBase::buildHyperParamMap ( HyperParameterMap map) const
inherited

Populates the input maps with the owned hyperparameters.

Parameters
mapMap of hyperparameters that should be populated

Definition at line 153 of file CovarianceFunctionBase.C.

Referenced by StochasticTools::GaussianProcess::setupCovarianceMatrix().

154 {
155  // First, add the hyperparameters of the dependent covariance functions
156  for (const auto dependent_covar : _covariance_functions)
157  dependent_covar->buildHyperParamMap(map);
158 
159  // At the end we just append the hyperparameters this object owns
160  for (const auto & iter : _hyperparameters)
161  if (!isScalarHyperParameter(iter.second) && !isVectorHyperParameter(iter.second))
162  mooseError("Unsupported hyperparameter rank ", iter.second.dim(), " for ", iter.first, ".");
163  else
164  map[iter.first] = iter.second.clone();
165 }
HyperParameterMap _hyperparameters
Map of hyperparameters stored as rank-0 or rank-1 tensors.
static bool isVectorHyperParameter(const torch::Tensor &tensor)
Return true if a hyperparameter tensor stores a vector of values.
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.
void mooseError(Args &&... args) const

◆ computeCovarianceMatrix()

void ExponentialCovariance::computeCovarianceMatrix ( torch::Tensor K,
const torch::Tensor x,
const torch::Tensor xp,
const bool  is_self_covariance 
) const
overridevirtual

Generates the Covariance Matrix given two points in the parameter space.

Implements CovarianceFunctionBase.

Definition at line 44 of file ExponentialCovariance.C.

48 {
49  if ((unsigned)x.sizes()[1] != _length_factor.numel())
50  mooseError("length_factor size does not match dimension of trainer input.");
51 
53  K, x, xp, _length_factor, _sigma_f_squared, _sigma_n_squared, _gamma, is_self_covariance);
54 }
static const std::string K
Definition: NS.h:174
const torch::Tensor & _gamma
gamma exponential factor for use in kernel
const std::vector< double > x
const torch::Tensor & _sigma_n_squared
noise variance (^2)
static void ExponentialFunction(torch::Tensor &K, const torch::Tensor &x, const torch::Tensor &xp, const torch::Tensor &length_factor, const torch::Tensor &sigma_f_squared, const torch::Tensor &sigma_n_squared, const torch::Tensor &gamma, const bool is_self_covariance)
void mooseError(Args &&... args) const
const torch::Tensor & _sigma_f_squared
signal variance (^2)
const torch::Tensor & _length_factor
lengh factor () for the kernel, in vector form for multiple parameters

◆ computedKdhyper()

bool ExponentialCovariance::computedKdhyper ( torch::Tensor dKdhp,
const torch::Tensor x,
const std::string &  hyper_param_name,
unsigned int  ind 
) const
overridevirtual

Redirect dK/dhp for hyperparameter "hp".

Reimplemented from CovarianceFunctionBase.

Definition at line 77 of file ExponentialCovariance.C.

81 {
82  if (name().length() + 1 > hyper_param_name.length())
83  return false;
84 
85  const std::string name_without_prefix = hyper_param_name.substr(name().length() + 1);
86 
87  if (name_without_prefix == "noise_variance")
88  {
89  const auto options = x.options().dtype(at::kDouble);
90  ExponentialFunction(dKdhp,
91  x,
92  x,
94  torch::tensor(0.0, options),
95  torch::tensor(1.0, options),
96  _gamma,
97  true);
98  return true;
99  }
100 
101  if (name_without_prefix == "signal_variance")
102  {
103  const auto options = x.options().dtype(at::kDouble);
104  ExponentialFunction(dKdhp,
105  x,
106  x,
108  torch::tensor(1.0, options),
109  torch::tensor(0.0, options),
110  _gamma,
111  false);
112  return true;
113  }
114 
115  if (name_without_prefix == "length_factor")
116  {
118  return true;
119  }
120 
121  return false;
122 }
const torch::Tensor & _gamma
gamma exponential factor for use in kernel
const std::string & name() const
const std::vector< double > x
static void ExponentialFunction(torch::Tensor &K, const torch::Tensor &x, const torch::Tensor &xp, const torch::Tensor &length_factor, const torch::Tensor &sigma_f_squared, const torch::Tensor &sigma_n_squared, const torch::Tensor &gamma, const bool is_self_covariance)
const torch::Tensor & _sigma_f_squared
signal variance (^2)
static void computedKdlf(torch::Tensor &K, const torch::Tensor &x, const torch::Tensor &length_factor, const torch::Tensor &sigma_f_squared, const torch::Tensor &gamma, const int ind)
Computes dK/dlf for individual length factors.
const torch::Tensor & _length_factor
lengh factor () for the kernel, in vector form for multiple parameters

◆ computedKdlf()

void ExponentialCovariance::computedKdlf ( torch::Tensor K,
const torch::Tensor x,
const torch::Tensor length_factor,
const torch::Tensor sigma_f_squared,
const torch::Tensor gamma,
const int  ind 
)
static

Computes dK/dlf for individual length factors.

Definition at line 125 of file ExponentialCovariance.C.

Referenced by computedKdhyper().

131 {
132  mooseAssert(ind < x.sizes()[1], "Incorrect length factor index");
133 
134  const auto l_factor = length_factor.unsqueeze(0);
135  const auto scaled_distance = torch::cdist(torch::div(x, l_factor), torch::div(x, l_factor), 2.0);
136  const auto nonzero_distance = scaled_distance > 0;
137  const auto safe_scaled_distance =
138  torch::where(nonzero_distance, scaled_distance, torch::ones_like(scaled_distance));
139  const auto coordinate = x.select(1, ind);
140  const auto coordinate_distance_squared =
141  torch::pow(coordinate.unsqueeze(1) - coordinate.unsqueeze(0), 2);
142  const auto length_factor_ind = length_factor.select(0, ind);
143 
144  const auto dK_dlength_factor = coordinate_distance_squared / torch::pow(length_factor_ind, 3) *
145  gamma * torch::pow(safe_scaled_distance, gamma - 2.0) *
146  sigma_f_squared *
147  torch::exp(-torch::pow(safe_scaled_distance, gamma));
148 
149  K = torch::where(nonzero_distance, dK_dlength_factor, torch::zeros_like(dK_dlength_factor));
150 }
static const std::string K
Definition: NS.h:174
const std::vector< double > x
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)

◆ dependentCovarianceNames()

const std::vector<UserObjectName>& CovarianceFunctionBase::dependentCovarianceNames ( ) const
inlineinherited

Get the names of the dependent covariances.

Definition at line 67 of file CovarianceFunctionBase.h.

Referenced by StochasticTools::GaussianProcess::linkCovarianceFunction().

68  {
70  }
const std::vector< UserObjectName > _dependent_covariance_names
The names of the dependent covariance functions.

◆ dependentCovarianceTypes()

void CovarianceFunctionBase::dependentCovarianceTypes ( std::map< UserObjectName, std::string > &  name_type_map) const
inherited

Populate a map with the names and types of the dependent covariance functions.

Parameters
name_type_mapReference to the map which should be populated

Definition at line 204 of file CovarianceFunctionBase.C.

Referenced by StochasticTools::GaussianProcess::linkCovarianceFunction().

206 {
207  for (const auto dependent_covar : _covariance_functions)
208  {
209  dependent_covar->dependentCovarianceTypes(name_type_map);
210  name_type_map.insert(std::make_pair(dependent_covar->name(), dependent_covar->type()));
211  }
212 }
std::vector< CovarianceFunctionBase * > _covariance_functions
Vector of pointers to the dependent covariance functions.

◆ ExponentialFunction()

void ExponentialCovariance::ExponentialFunction ( torch::Tensor K,
const torch::Tensor x,
const torch::Tensor xp,
const torch::Tensor length_factor,
const torch::Tensor sigma_f_squared,
const torch::Tensor sigma_n_squared,
const torch::Tensor gamma,
const bool  is_self_covariance 
)
static

Definition at line 57 of file ExponentialCovariance.C.

Referenced by computeCovarianceMatrix(), and computedKdhyper().

65 {
66  mooseAssert(x.sizes()[1] == xp.sizes()[1],
67  "Number of parameters do not match in covariance kernel calculation");
68 
69  const auto l_factor = length_factor.unsqueeze(0);
70  K = torch::cdist(torch::div(x, l_factor), torch::div(xp, l_factor), 2.0);
71  K = sigma_f_squared * torch::exp(-torch::pow(K, gamma));
72  if (is_self_covariance)
73  K.diagonal().add_(sigma_n_squared);
74 }
static const std::string K
Definition: NS.h:174
const std::vector< double > x
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)

◆ getCovarianceFunctionByName()

CovarianceFunctionBase * CovarianceInterface::getCovarianceFunctionByName ( const UserObjectName &  name) const
protectedinherited

Lookup a CovarianceFunction object by name and return pointer.

Definition at line 26 of file CovarianceInterface.C.

Referenced by ActiveLearningGaussianProcess::ActiveLearningGaussianProcess(), CovarianceFunctionBase::CovarianceFunctionBase(), GaussianProcessTrainer::GaussianProcessTrainer(), and GaussianProcessSurrogate::setupCovariance().

27 {
28  std::vector<CovarianceFunctionBase *> models;
30  .query()
31  .condition<AttribName>(name)
32  .condition<AttribSystem>("CovarianceFunction")
33  .queryInto(models);
34  if (models.empty())
35  mooseError("Unable to find a CovarianceFunction object with the name '" + name + "'");
36  return models[0];
37 }
void mooseError(Args &&... args)
TheWarehouse & theWarehouse() const
const std::string name
Definition: Setup.h:21
Query query()
FEProblemBase & _covar_feproblem
Reference to FEProblemBase instance.

◆ getTuningData()

bool CovarianceFunctionBase::getTuningData ( const std::string &  name,
unsigned int size,
Real min,
Real max 
) const
virtualinherited

Get the default minimum and maximum and size of a hyperparameter.

Returns false is the parameter has not been found in this covariance object.

Parameters
nameThe name of the hyperparameter
sizeReference to an unsigned int that will contain the size of the hyperparameter (will be populated with 1 if it is scalar)
minReference to a number which will be populated by the maximum allowed value of the hyperparameter
maxReference to a number which will be populated by the minimum allowed value of the hyperparameter

Definition at line 168 of file CovarianceFunctionBase.C.

Referenced by StochasticTools::GaussianProcess::generateTuningMap().

172 {
173  // First, check the dependent covariances
174  for (const auto dependent_covar : _covariance_functions)
175  if (dependent_covar->getTuningData(name, size, min, max))
176  return true;
177 
178  min = 1e-9;
179  max = 1e9;
180 
181  const auto tensor_value = _hyperparameters.find(name);
182  if (tensor_value == _hyperparameters.end())
183  {
184  size = 0;
185  return false;
186  }
187 
188  if (isScalarHyperParameter(tensor_value->second))
189  {
190  size = 1;
191  return true;
192  }
193 
194  if (isVectorHyperParameter(tensor_value->second))
195  {
196  size = tensor_value->second.numel();
197  return true;
198  }
199 
200  mooseError("Unsupported hyperparameter rank ", tensor_value->second.dim(), " for ", name, ".");
201 }
HyperParameterMap _hyperparameters
Map of hyperparameters stored as rank-0 or rank-1 tensors.
static bool isVectorHyperParameter(const torch::Tensor &tensor)
Return true if a hyperparameter tensor stores a vector of values.
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.
auto max(const L &left, const R &right)
const std::string & name() const
void mooseError(Args &&... args) const
auto min(const L &left, const R &right)

◆ isScalarHyperParameter()

bool CovarianceFunctionBase::isScalarHyperParameter ( const torch::Tensor tensor)
staticinherited

Return true if a hyperparameter tensor stores one scalar value.

Definition at line 44 of file CovarianceFunctionBase.C.

Referenced by CovarianceFunctionBase::buildHyperParamMap(), CovarianceFunctionBase::getTuningData(), GaussianProcessData::initialize(), and CovarianceFunctionBase::loadHyperParamMap().

45 {
46  return tensor.dim() == 0;
47 }

◆ isTunable()

bool CovarianceFunctionBase::isTunable ( const std::string &  name) const
virtualinherited

Check if a given parameter is tunable.

Parameters
Thename of the hyperparameter

Definition at line 115 of file CovarianceFunctionBase.C.

Referenced by StochasticTools::GaussianProcess::generateTuningMap().

116 {
117  // First, we check if the dependent covariances have the parameter
118  for (const auto dependent_covar : _covariance_functions)
119  if (dependent_covar->isTunable(name))
120  return true;
121 
122  if (_tunable_hp.find(name) != _tunable_hp.end())
123  return true;
124  else if (_hyperparameters.find(name) != _hyperparameters.end())
125  mooseError("We found hyperparameter ", name, " but it was not declared tunable!");
126 
127  return false;
128 }
HyperParameterMap _hyperparameters
Map of hyperparameters stored as rank-0 or rank-1 tensors.
std::unordered_set< std::string > _tunable_hp
list of tunable hyper-parameters
std::vector< CovarianceFunctionBase * > _covariance_functions
Vector of pointers to the dependent covariance functions.
const std::string & name() const
void mooseError(Args &&... args) const

◆ isVectorHyperParameter()

bool CovarianceFunctionBase::isVectorHyperParameter ( const torch::Tensor tensor)
staticinherited

Return true if a hyperparameter tensor stores a vector of values.

Definition at line 50 of file CovarianceFunctionBase.C.

Referenced by CovarianceFunctionBase::buildHyperParamMap(), CovarianceFunctionBase::getTuningData(), GaussianProcessData::initialize(), and CovarianceFunctionBase::loadHyperParamMap().

51 {
52  return tensor.dim() == 1;
53 }

◆ loadHyperParamMap()

void CovarianceFunctionBase::loadHyperParamMap ( const HyperParameterMap map)
inherited

Load some hyperparameters into the local map contained in this object.

Parameters
mapInput map of hyperparameters

Definition at line 131 of file CovarianceFunctionBase.C.

Referenced by LoadCovarianceDataAction::load(), StochasticTools::GaussianProcess::setupCovarianceMatrix(), and StochasticTools::GaussianProcess::tuneHyperParamsAdam().

132 {
133  // First, load the hyperparameters of the dependent covariance functions
134  for (const auto dependent_covar : _covariance_functions)
135  dependent_covar->loadHyperParamMap(map);
136 
137  // Then we load the hyperparameters of this object
138  for (auto & iter : _hyperparameters)
139  {
140  const auto map_iter = map.find(iter.first);
141  if (map_iter == map.end())
142  continue;
143 
144  if (!isScalarHyperParameter(map_iter->second) && !isVectorHyperParameter(map_iter->second))
145  mooseError(
146  "Unsupported hyperparameter rank ", map_iter->second.dim(), " for ", iter.first, ".");
147 
148  iter.second = map_iter->second.clone();
149  }
150 }
HyperParameterMap _hyperparameters
Map of hyperparameters stored as rank-0 or rank-1 tensors.
static bool isVectorHyperParameter(const torch::Tensor &tensor)
Return true if a hyperparameter tensor stores a vector of values.
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.
void mooseError(Args &&... args) const

◆ numOutputs()

unsigned int CovarianceFunctionBase::numOutputs ( ) const
inlineinherited

Return the number of outputs assumed for this covariance function.

Definition at line 90 of file CovarianceFunctionBase.h.

Referenced by GaussianProcessSurrogate::evaluate(), GaussianProcessTrainer::GaussianProcessTrainer(), and StochasticTools::GaussianProcess::linkCovarianceFunction().

90 { return _num_outputs; }
const unsigned int _num_outputs
The number of outputs this covariance function is used to describe.

◆ validParams()

InputParameters ExponentialCovariance::validParams ( )
static

Definition at line 17 of file ExponentialCovariance.C.

18 {
20  params.addClassDescription("Exponential covariance function.");
21  params.addRequiredParam<std::vector<Real>>("length_factor",
22  "Length factors to use for Covariance Kernel");
23  params.addRequiredParam<Real>("signal_variance",
24  "Signal Variance ($\\sigma_f^2$) to use for kernel calculation.");
25  params.addParam<Real>(
26  "noise_variance", 0.0, "Noise Variance ($\\sigma_n^2$) to use for kernel calculation.");
27  params.addRequiredParam<Real>("gamma", "Gamma to use for Exponential Covariance Kernel");
28  return params;
29 }
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _covariance_functions

std::vector<CovarianceFunctionBase *> CovarianceFunctionBase::_covariance_functions
protectedinherited

◆ _dependent_covariance_names

const std::vector<UserObjectName> CovarianceFunctionBase::_dependent_covariance_names
protectedinherited

The names of the dependent covariance functions.

Definition at line 118 of file CovarianceFunctionBase.h.

Referenced by CovarianceFunctionBase::CovarianceFunctionBase(), and CovarianceFunctionBase::dependentCovarianceNames().

◆ _dependent_covariance_types

std::vector<std::string> CovarianceFunctionBase::_dependent_covariance_types
protectedinherited

The types of the dependent covariance functions.

Definition at line 121 of file CovarianceFunctionBase.h.

Referenced by CovarianceFunctionBase::CovarianceFunctionBase().

◆ _gamma

const torch::Tensor& ExponentialCovariance::_gamma
private

gamma exponential factor for use in kernel

Definition at line 61 of file ExponentialCovariance.h.

Referenced by computeCovarianceMatrix(), and computedKdhyper().

◆ _hyperparameters

HyperParameterMap CovarianceFunctionBase::_hyperparameters
protectedinherited

◆ _length_factor

const torch::Tensor& ExponentialCovariance::_length_factor
private

lengh factor () for the kernel, in vector form for multiple parameters

Definition at line 52 of file ExponentialCovariance.h.

Referenced by computeCovarianceMatrix(), and computedKdhyper().

◆ _num_outputs

const unsigned int CovarianceFunctionBase::_num_outputs
protectedinherited

The number of outputs this covariance function is used to describe.

Definition at line 115 of file CovarianceFunctionBase.h.

Referenced by LMC::computeCovarianceMatrix(), LMC::computedKdhyper(), LMC::computeLambdaGradient(), LMC::LMC(), and CovarianceFunctionBase::numOutputs().

◆ _sigma_f_squared

const torch::Tensor& ExponentialCovariance::_sigma_f_squared
private

signal variance (^2)

Definition at line 55 of file ExponentialCovariance.h.

Referenced by computeCovarianceMatrix(), and computedKdhyper().

◆ _sigma_n_squared

const torch::Tensor& ExponentialCovariance::_sigma_n_squared
private

noise variance (^2)

Definition at line 58 of file ExponentialCovariance.h.

Referenced by computeCovarianceMatrix().

◆ _tunable_hp

std::unordered_set<std::string> CovarianceFunctionBase::_tunable_hp
protectedinherited

The documentation for this class was generated from the following files: