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.");
27 "p",
"Integer p to use for Matern Half Integer Covariance Kernel");
33 _length_factor(addVectorRealHyperParameter(
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 _p(addRealHyperParameter(
"p", getParam<unsigned
int>(
"p"), false))
47 const bool is_self_covariance)
const 50 mooseError(
"length_factor size does not match dimension of trainer input.");
60 const std::vector<Real> & length_factor,
61 const Real sigma_f_squared,
62 const Real sigma_n_squared,
64 const bool is_self_covariance)
66 unsigned int num_samples_x =
x.rows();
67 unsigned int num_samples_xp = xp.rows();
68 unsigned int num_params_x =
x.cols();
70 mooseAssert(num_params_x == xp.cols(),
71 "Number of parameters do not match in covariance kernel calculation");
76 for (
unsigned int ii = 0; ii < num_samples_x; ++ii)
78 for (
unsigned int jj = 0; jj < num_samples_xp; ++jj)
82 for (
unsigned int kk = 0; kk < num_params_x; ++kk)
83 r_scaled +=
pow((
x(ii, kk) - xp(jj, kk)) / length_factor[kk], 2);
84 r_scaled =
sqrt(r_scaled);
88 for (
unsigned int tt = 0; tt < p + 1; ++tt)
89 summation += (tgamma(p + tt + 1) / (tgamma(tt + 1) * tgamma(p - tt + 1))) *
90 pow(2 * factor * r_scaled, p - tt);
91 K(ii, jj) = sigma_f_squared * std::exp(-factor * r_scaled) *
92 (tgamma(p + 1) / (tgamma(2 * p + 1))) * summation;
94 if (is_self_covariance)
95 K(ii, ii) += sigma_n_squared;
102 const std::string & hyper_param_name,
103 unsigned int ind)
const 105 if (
name().length() + 1 > hyper_param_name.length())
108 const std::string name_without_prefix = hyper_param_name.substr(
name().length() + 1);
110 if (name_without_prefix ==
"noise_variance")
116 if (name_without_prefix ==
"signal_variance")
122 if (name_without_prefix ==
"length_factor")
134 const std::vector<Real> & length_factor,
135 const Real sigma_f_squared,
136 const unsigned int p,
139 unsigned int num_samples_x =
x.rows();
140 unsigned int num_params_x =
x.cols();
142 mooseAssert(ind <
x.cols(),
"Incorrect length factor index");
147 for (
unsigned int ii = 0; ii < num_samples_x; ++ii)
149 for (
unsigned int jj = 0; jj < num_samples_x; ++jj)
153 for (
unsigned int kk = 0; kk < num_params_x; ++kk)
154 r_scaled +=
pow((
x(ii, kk) -
x(jj, kk)) / length_factor[kk], 2);
155 r_scaled =
sqrt(r_scaled);
161 for (
unsigned int tt = 0; tt < p + 1; ++tt)
162 summation += (tgamma(p + tt + 1) / (tgamma(tt + 1) * tgamma(p - tt + 1))) *
163 pow(2 * factor * r_scaled, p - tt);
164 K(ii, jj) = -factor * std::exp(-factor * r_scaled) * summation;
168 for (
unsigned int tt = 0; tt < p; ++tt)
169 summation += (tgamma(p + tt + 1) / (tgamma(tt + 1) * tgamma(p - tt + 1))) * 2 * factor *
170 (p - tt) *
pow(2 * factor * r_scaled, p - tt - 1);
171 K(ii, jj) += std::exp(-factor * r_scaled) * summation;
173 K(ii, jj) *= -
std::pow(
x(ii, ind) -
x(jj, ind), 2) /
174 (
std::pow(length_factor[ind], 3) * r_scaled) * sigma_f_squared *
175 (tgamma(p + 1) / (tgamma(2 * p + 1)));
const Real & _sigma_n_squared
noise variance (^2)
static const std::string K
Base class for covariance functions that are used in Gaussian Processes.
static InputParameters validParams()
const std::vector< Real > & _length_factor
lengh factor () for the kernel, in vector form for multiple parameters
bool computedKdhyper(RealEigenMatrix &dKdhp, const RealEigenMatrix &x, const std::string &hyper_param_name, unsigned int ind) const override
Redirect dK/dhp for hyperparameter "hp".
virtual const std::string & name() const
unsigned int _p
non-negative p factor for use in Matern half-int. = p+(1/2) in terms of general Matern ...
registerMooseObject("StochasticToolsApp", MaternHalfIntCovariance)
static void computedKdlf(RealEigenMatrix &K, const RealEigenMatrix &x, const std::vector< Real > &length_factor, const Real sigma_f_squared, const unsigned int p, const int ind)
Computes dK/dlf for individual length factors.
const std::vector< double > x
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.
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealEigenMatrix
static void maternHalfIntFunction(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 unsigned int p, const bool is_self_covariance)
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
void mooseError(Args &&... args) const
MaternHalfIntCovariance(const InputParameters ¶meters)
const Real & _sigma_f_squared
signal variance (^2)
MooseUnits pow(const MooseUnits &, int)
void ErrorVector unsigned int