https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Private Member Functions | Private Attributes | List of all members
MaternHalfIntCovariance Class Reference

#include <MaternHalfIntCovariance.h>

Inheritance diagram for MaternHalfIntCovariance:
[legend]

Public Types

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

Public Member Functions

 MaternHalfIntCovariance (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.
 
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".
 
void loadHyperParamMap (const HyperParameterMap &map)
 Load some hyperparameters into the local map contained in this object.
 
void buildHyperParamMap (HyperParameterMap &map) const
 Populates the input maps with the owned hyperparameters.
 
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.
 
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 std::vector< UserObjectName > & dependentCovarianceNames () const
 Get the names of the dependent covariances.
 
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 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 maternHalfIntFunction (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 &p, 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 &p, const int ind)
 Computes dK/dlf for individual length factors.
 
static bool isScalarHyperParameter (const torch::Tensor &tensor)
 Return true if a hyperparameter tensor stores one scalar value.
 
static bool isVectorHyperParameter (const torch::Tensor &tensor)
 Return true if a hyperparameter tensor stores a vector of values.
 
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::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.
 
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.
 

Protected Attributes

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 unsigned int _num_outputs
 The number of outputs this covariance function is used to describe.
 
const std::vector< UserObjectName > _dependent_covariance_names
 The names of the dependent covariance functions.
 
std::vector< std::string > _dependent_covariance_types
 The types of the dependent covariance functions.
 
std::vector< CovarianceFunctionBase * > _covariance_functions
 Vector of pointers to the dependent covariance functions.
 
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
 

Static Private Member Functions

static const hit::Node * getHitNode (const InputParameters &params)
 
static std::string messagePrefix (const InputParameters &params, const bool hit_prefix)
 

Private Attributes

const torch::Tensor & _length_factor
 lengh factor (\ell) for the kernel, in vector form for multiple parameters
 
const torch::Tensor & _sigma_f_squared
 signal variance (\sigma_f^2)
 
const torch::Tensor & _sigma_n_squared
 noise variance (\sigma_n^2)
 
const torch::Tensor & _p
 non-negative p factor for use in Matern half-int. \nu = p+(1/2) in terms of general Matern
 
const ParallelParamObject_parent
 
const MooseBase_si_moose_base
 
const FEProblemBase_si_problem
 
FEProblemBase_covar_feproblem
 Reference to FEProblemBase instance.
 

Detailed Description

Definition at line 15 of file MaternHalfIntCovariance.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

◆ MaternHalfIntCovariance()

MaternHalfIntCovariance::MaternHalfIntCovariance ( const InputParameters parameters)

Definition at line 33 of file MaternHalfIntCovariance.C.

36 "length_factor", getParam<std::vector<Real>>("length_factor"), true)),
38 addRealHyperParameter("signal_variance", getParam<Real>("signal_variance"), true)),
40 addRealHyperParameter("noise_variance", getParam<Real>("noise_variance"), true)),
41 _p(addRealHyperParameter("p", getParam<unsigned int>("p"), false))
42{
43}
Base class for covariance functions that are used in Gaussian Processes.
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 & _p
non-negative p factor for use in Matern half-int. \nu = p+(1/2) in terms of general Matern
const torch::Tensor & _sigma_f_squared
signal variance (\sigma_f^2)
const torch::Tensor & _sigma_n_squared
noise variance (\sigma_n^2)
const torch::Tensor & _length_factor
lengh factor (\ell) for the kernel, in vector form for multiple parameters
const InputParameters & parameters() const
const T & getParam(const std::string &name) const

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
const std::string & _name

◆ 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.

108{
109 const auto prefixed_name = _name + ":" + name;
110 return insertHyperParameter(
111 _hyperparameters, _tunable_hp, prefixed_name, makeVectorHyperParameter(value), is_tunable);
112}

Referenced by LMC::LMC().

◆ 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.

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}
unsigned int dim
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.
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.
void mooseError(Args &&... args) const
if(subdm)

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

◆ computeCovarianceMatrix()

void MaternHalfIntCovariance::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 46 of file MaternHalfIntCovariance.C.

50{
51 if ((unsigned)x.sizes()[1] != _length_factor.numel())
52 mooseError("length_factor size does not match dimension of trainer input.");
53
55 K, x, xp, _length_factor, _sigma_f_squared, _sigma_n_squared, _p, is_self_covariance);
56}
const std::vector< double > x
static void maternHalfIntFunction(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 &p, const bool is_self_covariance)

◆ computedKdhyper()

bool MaternHalfIntCovariance::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 91 of file MaternHalfIntCovariance.C.

95{
96 if (name().length() + 1 > hyper_param_name.length())
97 return false;
98
99 const std::string name_without_prefix = hyper_param_name.substr(name().length() + 1);
100
101 if (name_without_prefix == "noise_variance")
102 {
103 const auto options = x.options().dtype(at::kDouble);
105 x,
106 x,
108 torch::tensor(0.0, options),
109 torch::tensor(1.0, options),
110 _p,
111 true);
112 return true;
113 }
114
115 if (name_without_prefix == "signal_variance")
116 {
117 const auto options = x.options().dtype(at::kDouble);
119 x,
120 x,
122 torch::tensor(1.0, options),
123 torch::tensor(0.0, options),
124 _p,
125 false);
126 return true;
127 }
128
129 if (name_without_prefix == "length_factor")
130 {
132 return true;
133 }
134
135 return false;
136}
static void computedKdlf(torch::Tensor &K, const torch::Tensor &x, const torch::Tensor &length_factor, const torch::Tensor &sigma_f_squared, const torch::Tensor &p, const int ind)
Computes dK/dlf for individual length factors.

◆ computedKdlf()

void MaternHalfIntCovariance::computedKdlf ( torch::Tensor &  K,
const torch::Tensor &  x,
const torch::Tensor &  length_factor,
const torch::Tensor &  sigma_f_squared,
const torch::Tensor &  p,
const int  ind 
)
static

Computes dK/dlf for individual length factors.

Definition at line 139 of file MaternHalfIntCovariance.C.

145{
146 const auto p_value = cast_int<unsigned int>(LibtorchUtils::toCPUContiguous(p).item<Real>());
147
148 mooseAssert(ind < x.sizes()[1], "Incorrect length factor index");
149
150 const auto l_factor = length_factor.unsqueeze(0);
151 const auto scaled_distance = torch::cdist(torch::div(x, l_factor), torch::div(x, l_factor), 2.0);
152 const auto nonzero_distance = scaled_distance > 0;
153 const auto safe_scaled_distance =
154 torch::where(nonzero_distance, scaled_distance, torch::ones_like(scaled_distance));
155 const Real factor = std::sqrt(2 * p_value + 1);
156 const Real normalization = std::tgamma(p_value + 1) / std::tgamma(2 * p_value + 1);
157
158 auto summation = torch::zeros_like(safe_scaled_distance);
159 for (const auto tt : make_range(p_value + 1))
160 {
161 const Real coefficient =
162 std::tgamma(p_value + tt + 1) / (std::tgamma(tt + 1) * std::tgamma(p_value - tt + 1));
163 summation = summation +
164 coefficient * torch::pow(2.0 * factor * safe_scaled_distance, Real(p_value - tt));
165 }
166
167 auto summation_derivative = torch::zeros_like(safe_scaled_distance);
168 for (const auto tt : make_range(p_value))
169 {
170 const Real coefficient =
171 std::tgamma(p_value + tt + 1) / (std::tgamma(tt + 1) * std::tgamma(p_value - tt + 1));
172 summation_derivative =
173 summation_derivative +
174 coefficient * 2.0 * factor * (p_value - tt) *
175 torch::pow(2.0 * factor * safe_scaled_distance, Real(p_value - tt - 1));
176 }
177
178 const auto coordinate = x.select(1, ind);
179 const auto coordinate_distance_squared =
180 torch::pow(coordinate.unsqueeze(1) - coordinate.unsqueeze(0), 2);
181 const auto length_factor_ind = length_factor.select(0, ind);
182 const auto dr_dlength_factor =
183 -coordinate_distance_squared / (torch::pow(length_factor_ind, 3) * safe_scaled_distance);
184 const auto dK_dlength_factor = sigma_f_squared * normalization *
185 torch::exp(-factor * safe_scaled_distance) *
186 (summation_derivative - factor * summation) * dr_dlength_factor;
187
188 K = torch::where(nonzero_distance, dK_dlength_factor, torch::zeros_like(dK_dlength_factor));
189}
const Real p
torch::Tensor toCPUContiguous(const torch::Tensor &tensor)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)

Referenced by computedKdhyper().

◆ dependentCovarianceNames()

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

Get the names of the dependent covariances.

Definition at line 67 of file CovarianceFunctionBase.h.

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

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

◆ 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.

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}

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

◆ 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.

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)
const std::string name
Definition Setup.h:21
FEProblemBase & _covar_feproblem
Reference to FEProblemBase instance.
TheWarehouse & theWarehouse() const
Query query()

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

◆ 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.

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}
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.
auto max(const L &left, const R &right)
auto min(const L &left, const R &right)

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

◆ 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.

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

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

◆ 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.

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}
virtual bool isTunable(const std::string &name) const
Check if a given parameter is tunable.

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

◆ 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.

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

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

◆ 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.

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))
146 "Unsupported hyperparameter rank ", map_iter->second.dim(), " for ", iter.first, ".");
147
148 iter.second = map_iter->second.clone();
149 }
150}
void loadHyperParamMap(const HyperParameterMap &map)
Load some hyperparameters into the local map contained in this object.

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

◆ maternHalfIntFunction()

void MaternHalfIntCovariance::maternHalfIntFunction ( 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 &  p,
const bool  is_self_covariance 
)
static

Definition at line 59 of file MaternHalfIntCovariance.C.

67{
68 const auto p_value = cast_int<unsigned int>(LibtorchUtils::toCPUContiguous(p).item<Real>());
69 mooseAssert(x.sizes()[1] == xp.sizes()[1],
70 "Number of parameters do not match in covariance kernel calculation");
71
72 const auto l_factor = length_factor.unsqueeze(0);
73 K = torch::cdist(torch::div(x, l_factor), torch::div(xp, l_factor), 2.0);
74 const Real factor = std::sqrt(2 * p_value + 1);
75 const Real normalization = std::tgamma(p_value + 1) / std::tgamma(2 * p_value + 1);
76
77 auto summation = torch::zeros_like(K);
78 for (const auto tt : make_range(p_value + 1))
79 {
80 const Real coefficient =
81 std::tgamma(p_value + tt + 1) / (std::tgamma(tt + 1) * std::tgamma(p_value - tt + 1));
82 summation = summation + coefficient * torch::pow(2.0 * factor * K, Real(p_value - tt));
83 }
84
85 K = sigma_f_squared * torch::exp(-factor * K) * normalization * summation;
86 if (is_self_covariance)
87 K.diagonal().add_(sigma_n_squared);
88}

Referenced by computeCovarianceMatrix(), and computedKdhyper().

◆ 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.

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

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

◆ validParams()

InputParameters MaternHalfIntCovariance::validParams ( )
static

Definition at line 18 of file MaternHalfIntCovariance.C.

19{
21 params.addClassDescription("Matern half-integer covariance function.");
22 params.addRequiredParam<std::vector<Real>>("length_factor",
23 "Length factors to use for Covariance Kernel");
24 params.addRequiredParam<Real>("signal_variance",
25 "Signal Variance ($\\sigma_f^2$) to use for kernel calculation.");
26 params.addParam<Real>(
27 "noise_variance", 0.0, "Noise Variance ($\\sigma_n^2$) to use for kernel calculation.");
28 params.addRequiredParam<unsigned int>(
29 "p", "Integer p to use for Matern Half Integer Covariance Kernel");
30 return params;
31}
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _covar_feproblem

FEProblemBase& CovarianceInterface::_covar_feproblem
privateinherited

Reference to FEProblemBase instance.

Definition at line 31 of file CovarianceInterface.h.

Referenced by CovarianceInterface::getCovarianceFunctionByName().

◆ _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().

◆ _hyperparameters

HyperParameterMap CovarianceFunctionBase::_hyperparameters
protectedinherited

◆ _length_factor

const torch::Tensor& MaternHalfIntCovariance::_length_factor
private

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

Definition at line 52 of file MaternHalfIntCovariance.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().

◆ _p

const torch::Tensor& MaternHalfIntCovariance::_p
private

non-negative p factor for use in Matern half-int. \nu = p+(1/2) in terms of general Matern

Definition at line 61 of file MaternHalfIntCovariance.h.

Referenced by computeCovarianceMatrix(), and computedKdhyper().

◆ _sigma_f_squared

const torch::Tensor& MaternHalfIntCovariance::_sigma_f_squared
private

signal variance (\sigma_f^2)

Definition at line 55 of file MaternHalfIntCovariance.h.

Referenced by computeCovarianceMatrix(), and computedKdhyper().

◆ _sigma_n_squared

const torch::Tensor& MaternHalfIntCovariance::_sigma_n_squared
private

noise variance (\sigma_n^2)

Definition at line 58 of file MaternHalfIntCovariance.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: