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
LMC Class Reference

Covariance function for multi-output Gaussian Processes based on the linear model of coregionalization (LMC) More...

#include <LMC.h>

Inheritance diagram for LMC:
[legend]

Public Types

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

Public Member Functions

 LMC (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 sets of 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 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

void computeBMatrix (torch::Tensor &Bmat, const unsigned int exp_i) const
 Computes the covariance matrix for the outputs (using the latent coefficients) We use a $B = \sum_i a_i a_i^T + diag(lambda_i)$ expansion here where $a_i$ and $lambda_i$ are vectors.
 
void computeAGradient (torch::Tensor &grad, const unsigned int exp_i, const unsigned int index) const
 Computes the gradient of $B$ with respect to the entries in $a_i$ in the following expression: $B = \sum_i a_i a_i^T + diag(lambda_i)$.
 
void computeLambdaGradient (torch::Tensor &grad, const unsigned int exp_i, const unsigned int index) const
 Computes the gradient of $B$ with respect to the entries in $lambda_i$ in the following expression: $B = \sum_i a_i a_i^T + diag(lambda_i)$.
 
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

const unsigned int _num_expansion_terms
 The number of expansion terms in the output ovariance matrix.
 
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

std::vector< const torch::Tensor * > _a_coeffs
 The vectors in the $B = \sum_i a_i a_i^T + diag(lambda_i)$ expansion.
 
std::vector< const torch::Tensor * > _lambdas
 
const ParallelParamObject_parent
 
const MooseBase_si_moose_base
 
const FEProblemBase_si_problem
 
FEProblemBase_covar_feproblem
 Reference to FEProblemBase instance.
 

Detailed Description

Covariance function for multi-output Gaussian Processes based on the linear model of coregionalization (LMC)

Definition at line 19 of file LMC.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

◆ LMC()

LMC::LMC ( const InputParameters parameters)

Definition at line 30 of file LMC.C.

32 _num_expansion_terms(getParam<unsigned int>("num_latent_funcs"))
33{
34 // We use a random number generator to obtain the initial guess for the
35 // hyperparams
36 MooseRandom generator_latent;
37 generator_latent.seed(0, 1980);
38
39 // First add and initialize the a A coefficients in the (aa^T+lambda*I) matrix
40 for (const auto exp_i : make_range(_num_expansion_terms))
41 {
42 const std::string a_coeff_name = "acoeff_" + std::to_string(exp_i);
43 std::vector<Real> acoeff_values(_num_outputs);
44 for (const auto out_i : make_range(_num_outputs))
45 acoeff_values[out_i] = 3.0 * generator_latent.rand(0) + 1.0;
46 auto & acoeff_vector = addVectorRealHyperParameter(a_coeff_name, acoeff_values, true);
47 _a_coeffs.push_back(&acoeff_vector);
48 }
49
50 // Then add and initialize the lambda coefficients in the (aa^T+lambda*I) matrix
51 for (const auto exp_i : make_range(_num_expansion_terms))
52 {
53 const std::string lambda_name = "lambda_" + std::to_string(exp_i);
54 std::vector<Real> lambda_values(_num_outputs);
55 for (const auto out_i : make_range(_num_outputs))
56 lambda_values[out_i] = 3.0 * generator_latent.rand(0) + 1.0;
57 auto & lambda_vector = addVectorRealHyperParameter(lambda_name, lambda_values, true);
58 _lambdas.push_back(&lambda_vector);
59 }
60}
Base class for covariance functions that are used in Gaussian Processes.
const unsigned int _num_outputs
The number of outputs this covariance function is used to describe.
torch::Tensor & addVectorRealHyperParameter(const std::string &name, const std::vector< Real > &value, const bool is_tunable)
Register a vector hyperparameter to this covariance function.
std::vector< const torch::Tensor * > _a_coeffs
The vectors in the $B = \sum_i a_i a_i^T + diag(lambda_i)$ expansion.
Definition LMC.h:72
std::vector< const torch::Tensor * > _lambdas
Definition LMC.h:73
const unsigned int _num_expansion_terms
The number of expansion terms in the output ovariance matrix.
Definition LMC.h:67
const InputParameters & parameters() const
void seed(std::size_t i, unsigned int seed)
IntRange< T > make_range(T beg, T end)

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

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

◆ computeAGradient()

void LMC::computeAGradient ( torch::Tensor &  grad,
const unsigned int  exp_i,
const unsigned int  index 
) const
protected

Computes the gradient of $B$ with respect to the entries in $a_i$ in the following expression: $B = \sum_i a_i a_i^T + diag(lambda_i)$.

Parameters
gradThe gradient matrix that should be populated
exp_iThe index of the expansion of B
indexThe index within the vector $a_i$

Definition at line 168 of file LMC.C.

171{
172 const auto & a_coeffs = *_a_coeffs[exp_i];
173 mooseAssert(cast_int<int64_t>(index) < a_coeffs.numel(), "Incorrect LMC coefficient index.");
174 auto basis = torch::zeros_like(a_coeffs);
175 const auto index_tensor =
176 torch::tensor({cast_int<int64_t>(index)},
177 torch::TensorOptions().dtype(torch::kLong).device(a_coeffs.device()));
178 basis.index_fill_(0, index_tensor, 1.0);
179 grad = torch::outer(basis, a_coeffs) + torch::outer(a_coeffs, basis);
180}
std::string grad(const std::string &var)
Definition NS.h:92

Referenced by computedKdhyper().

◆ computeBMatrix()

void LMC::computeBMatrix ( torch::Tensor &  Bmat,
const unsigned int  exp_i 
) const
protected

Computes the covariance matrix for the outputs (using the latent coefficients) We use a $B = \sum_i a_i a_i^T + diag(lambda_i)$ expansion here where $a_i$ and $lambda_i$ are vectors.

Parameters
BmatThe matrix which should be populated by the covariance values
exp_iThe expansion index in the latent space

Definition at line 160 of file LMC.C.

161{
162 const auto & a_coeffs = *_a_coeffs[exp_i];
163 const auto & lambda_coeffs = *_lambdas[exp_i];
164 Bmat = torch::outer(a_coeffs, a_coeffs) + torch::diag(lambda_coeffs);
165}

Referenced by computeCovarianceMatrix(), and computedKdhyper().

◆ computeCovarianceMatrix()

void LMC::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 sets of points in the parameter space.

Parameters
KReference to a matrix which should be populated by the covariance entries
xReference to the first set of points
xpReference to the second set of points
is_self_covarianceSwitch to enable adding the noise variance to the diagonal of the covariance matrix

Implements CovarianceFunctionBase.

Definition at line 63 of file LMC.C.

67{
68 const auto options = x.options().dtype(at::kDouble);
69 // Create temporary vectors for constructing the covariance matrix
70 torch::Tensor K_params = torch::zeros({x.sizes()[0], xp.sizes()[0]}, options);
71 torch::Tensor B = torch::zeros({_num_outputs, _num_outputs}, options);
72 K = torch::zeros({x.sizes()[0] * _num_outputs, xp.sizes()[0] * _num_outputs}, options);
73 torch::Tensor K_working;
74
75 // For every expansion term we add the contribution to the covariance matrix
76 for (const auto exp_i : make_range(_num_expansion_terms))
77 {
78 _covariance_functions[exp_i]->computeCovarianceMatrix(K_params, x, xp, is_self_covariance);
79 computeBMatrix(B, exp_i);
80 K_working = torch::kron(B, K_params);
81 K += K_working;
82 }
83}
const std::vector< double > x
void computeBMatrix(torch::Tensor &Bmat, const unsigned int exp_i) const
Computes the covariance matrix for the outputs (using the latent coefficients) We use a $B = \sum_i a...
Definition LMC.C:160

◆ computedKdhyper()

bool LMC::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".

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

Parameters
dKdhpThe matrix which should be populated with the derivatives
xThe input vector for which the derivatives of the covariance matrix is computed
hyper_param_nameThe name of the hyperparameter
indThe index within the hyperparameter. 0 if it is a scalar parameter. If it is a vector parameter, it should be the index within the vector.

Reimplemented from CovarianceFunctionBase.

Definition at line 86 of file LMC.C.

90{
91 // Early return in the paramter name is longer than the expected [name] prefix.
92 // We prefix the parameter names with the name of the covariance function.
93 if (name().length() + 1 > hyper_param_name.length())
94 return false;
95
96 // Strip the prefix from the given parameter name
97 const std::string name_without_prefix = hyper_param_name.substr(name().length() + 1);
98
99 // Check if the parameter is tunable
100 if (_tunable_hp.find(hyper_param_name) != _tunable_hp.end())
101 {
102 const std::string acoeff_prefix = "acoeff_";
103 const std::string lambda_prefix = "lambda_";
104
105 // Allocate storage for the factors of the total gradient matrix
106 const auto options = x.options().dtype(at::kDouble);
107 torch::Tensor dBdhp = torch::zeros({_num_outputs, _num_outputs}, options);
108 torch::Tensor K_params = torch::zeros({x.sizes()[0], x.sizes()[0]}, options);
109
110 if (name_without_prefix.find(acoeff_prefix) != std::string::npos)
111 {
112 // Automatically grab the expansion index
113 const int number = std::stoi(name_without_prefix.substr(acoeff_prefix.length()));
114 computeAGradient(dBdhp, number, ind);
115 _covariance_functions[number]->computeCovarianceMatrix(K_params, x, x, true);
116 }
117 else if (name_without_prefix.find(lambda_prefix) != std::string::npos)
118 {
119 // Automatically grab the expansion index
120 const int number = std::stoi(name_without_prefix.substr(lambda_prefix.length()));
121 computeLambdaGradient(dBdhp, number, ind);
122 _covariance_functions[number]->computeCovarianceMatrix(K_params, x, x, true);
123 }
124 dKdhp = torch::kron(dBdhp, K_params);
125 return true;
126 }
127 else
128 {
129 // Allocate storage for the matrix factors
130 const auto options = x.options().dtype(at::kDouble);
131 torch::Tensor B_tmp = torch::zeros({_num_outputs, _num_outputs}, options);
132 torch::Tensor B = torch::zeros({_num_outputs, _num_outputs}, options);
133 torch::Tensor dKdhp_sub = torch::zeros({x.sizes()[0], x.sizes()[0]}, options);
134
135 // First, check the dependent covariances
136 bool found = false;
137 for (const auto dependent_covar : _covariance_functions)
138 if (!found)
139 found = dependent_covar->computedKdhyper(dKdhp_sub, x, hyper_param_name, ind);
140
141 if (!found)
142 mooseError("Hyperparameter ", hyper_param_name, "not found!");
143
144 // Then we compute the output covariance
145 for (const auto exp_i : make_range(_num_expansion_terms))
146 {
147 computeBMatrix(B_tmp, exp_i);
148 B += B_tmp;
149 }
150
151 dKdhp = torch::kron(B, dKdhp_sub);
152
153 return true;
154 }
155
156 return false;
157}
void computeAGradient(torch::Tensor &grad, const unsigned int exp_i, const unsigned int index) const
Computes the gradient of $B$ with respect to the entries in $a_i$ in the following expression: $B = \...
Definition LMC.C:168
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".
Definition LMC.C:86
void computeLambdaGradient(torch::Tensor &grad, const unsigned int exp_i, const unsigned int index) const
Computes the gradient of $B$ with respect to the entries in $lambda_i$ in the following expression: $...
Definition LMC.C:183

◆ computeLambdaGradient()

void LMC::computeLambdaGradient ( torch::Tensor &  grad,
const unsigned int  exp_i,
const unsigned int  index 
) const
protected

Computes the gradient of $B$ with respect to the entries in $lambda_i$ in the following expression: $B = \sum_i a_i a_i^T + diag(lambda_i)$.

Parameters
gradThe gradient matrix that should be populated
exp_iThe index of the expansion of B
indexThe index within the vector $lambda_i$

Definition at line 183 of file LMC.C.

186{
187 mooseAssert(index < _num_outputs, "Incorrect LMC lambda index.");
188 auto basis = torch::zeros_like(*_lambdas[exp_i]);
189 const auto index_tensor =
190 torch::tensor({cast_int<int64_t>(index)},
191 torch::TensorOptions().dtype(torch::kLong).device(_lambdas[exp_i]->device()));
192 basis.index_fill_(0, index_tensor, 1.0);
193 grad = torch::diag(basis);
194}

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

◆ 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; }

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

◆ validParams()

InputParameters LMC::validParams ( )
static

Definition at line 18 of file LMC.C.

19{
21 params.addClassDescription("Covariance function for multioutput Gaussian Processes based on the "
22 "Linear Model of Coregionalization (LMC).");
23 params.addParam<unsigned int>(
24 "num_latent_funcs", 1., "The number of latent functions for the expansion of the outputs.");
25 params.makeParamRequired<unsigned int>("num_outputs");
26 params.makeParamRequired<std::vector<UserObjectName>>("covariance_functions");
27 return params;
28}
static InputParameters validParams()
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)
void makeParamRequired(const std::string &name)

Member Data Documentation

◆ _a_coeffs

std::vector<const torch::Tensor *> LMC::_a_coeffs
private

The vectors in the $B = \sum_i a_i a_i^T + diag(lambda_i)$ expansion.

Definition at line 72 of file LMC.h.

Referenced by computeAGradient(), computeBMatrix(), and LMC().

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

◆ _lambdas

std::vector<const torch::Tensor *> LMC::_lambdas
private

Definition at line 73 of file LMC.h.

Referenced by computeBMatrix(), computeLambdaGradient(), and LMC().

◆ _num_expansion_terms

const unsigned int LMC::_num_expansion_terms
protected

The number of expansion terms in the output ovariance matrix.

Definition at line 67 of file LMC.h.

Referenced by computeCovarianceMatrix(), computedKdhyper(), and LMC().

◆ _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 computeCovarianceMatrix(), computedKdhyper(), computeLambdaGradient(), LMC(), and CovarianceFunctionBase::numOutputs().

◆ _tunable_hp

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

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