21 "Length factors to use for Covariance Kernel");
23 "Signal Variance ($\\sigma_f^2$) to use for kernel calculation.");
25 "noise_variance", 0.0,
"Noise Variance ($\\sigma_n^2$) to use for kernel calculation.");
31 _length_factor(addVectorRealHyperParameter(
32 "length_factor", getParam<
std::vector<
Real>>(
"length_factor"), true)),
34 addRealHyperParameter(
"signal_variance", getParam<
Real>(
"signal_variance"), true)),
36 addRealHyperParameter(
"noise_variance", getParam<
Real>(
"noise_variance"), true))
44 const bool is_self_covariance)
const 47 mooseError(
"length_factor size does not match dimension of trainer input.");
57 const std::vector<Real> & length_factor,
58 const Real sigma_f_squared,
59 const Real sigma_n_squared,
60 const bool is_self_covariance)
62 unsigned int num_samples_x =
x.rows();
63 unsigned int num_samples_xp = xp.rows();
64 unsigned int num_params_x =
x.cols();
66 mooseAssert(num_params_x == xp.cols(),
67 "Number of parameters do not match in covariance kernel calculation");
69 for (
unsigned int ii = 0; ii < num_samples_x; ++ii)
71 for (
unsigned int jj = 0; jj < num_samples_xp; ++jj)
74 Real r_squared_scaled = 0;
75 for (
unsigned int kk = 0; kk < num_params_x; ++kk)
76 r_squared_scaled +=
std::pow((
x(ii, kk) - xp(jj, kk)) / length_factor[kk], 2);
77 K(ii, jj) = sigma_f_squared * std::exp(-r_squared_scaled / 2.0);
79 if (is_self_covariance)
80 K(ii, ii) += sigma_n_squared;
87 const std::string & hyper_param_name,
88 unsigned int ind)
const 90 if (
name().length() + 1 > hyper_param_name.length())
93 const std::string name_without_prefix = hyper_param_name.substr(
name().length() + 1);
95 if (name_without_prefix ==
"noise_variance")
101 if (name_without_prefix ==
"signal_variance")
107 if (name_without_prefix ==
"length_factor")
119 const std::vector<Real> & length_factor,
120 const Real sigma_f_squared,
123 unsigned int num_samples_x =
x.rows();
124 unsigned int num_params_x =
x.cols();
126 mooseAssert(ind <
x.cols(),
"Incorrect length factor index");
128 for (
unsigned int ii = 0; ii < num_samples_x; ++ii)
130 for (
unsigned int jj = 0; jj < num_samples_x; ++jj)
133 Real r_squared_scaled = 0;
134 for (
unsigned int kk = 0; kk < num_params_x; ++kk)
135 r_squared_scaled +=
std::pow((
x(ii, kk) -
x(jj, kk)) / length_factor[kk], 2);
136 K(ii, jj) = sigma_f_squared * std::exp(-r_squared_scaled / 2.0);
const std::vector< Real > & _length_factor
lengh factor () for the kernel, in vector form for multiple parameters
SquaredExponentialCovariance(const InputParameters ¶meters)
static const std::string K
static void computedKdlf(RealEigenMatrix &K, const RealEigenMatrix &x, const std::vector< Real > &length_factor, const Real sigma_f_squared, const int ind)
Computes dK/dlf for individual length factors.
Base class for covariance functions that are used in Gaussian Processes.
static InputParameters validParams()
void computeCovarianceMatrix(RealEigenMatrix &K, const RealEigenMatrix &x, const RealEigenMatrix &xp, const bool is_self_covariance) const override
Generates the Covariance Matrix given two points in the parameter space.
virtual const std::string & name() const
registerMooseObject("StochasticToolsApp", SquaredExponentialCovariance)
const Real & _sigma_f_squared
signal variance (^2)
const std::vector< double > x
const Real & _sigma_n_squared
noise variance (^2)
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealEigenMatrix
bool computedKdhyper(RealEigenMatrix &dKdhp, const RealEigenMatrix &x, const std::string &hyper_param_name, unsigned int ind) const override
Redirect dK/dhp for hyperparameter "hp".
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
static void SquaredExponentialFunction(RealEigenMatrix &K, const RealEigenMatrix &x, const RealEigenMatrix &xp, const std::vector< Real > &length_factor, const Real sigma_f_squared, const Real sigma_n_squared, const bool is_self_covariance)
static InputParameters validParams()
MooseUnits pow(const MooseUnits &, int)