1#ifndef STAN_MATH_REV_FUN_COV_EXP_QUAD_HPP
2#define STAN_MATH_REV_FUN_COV_EXP_QUAD_HPP
21template <
typename T_x,
typename T_sigma,
typename T_l>
54 double inv_half_sq_l_d = 0.5 / (
l_d_ *
l_d_);
56 for (
size_t j = 0; j <
size_ - 1; ++j) {
57 for (
size_t i = j + 1; i <
size_; ++i) {
61 sigma_sq_d_ * std::exp(-dist_sq * inv_half_sq_l_d),
false);
65 for (
size_t i = 0; i <
size_; ++i) {
76 double prod_add = el_low->adj_ * el_low->val_;
77 adjl += prod_add *
dist_[i];
80 for (
size_t i = 0; i <
size_; ++i) {
82 adjsigma += el->adj_ * el->val_;
92template <
typename T_x,
typename T_l>
122 double inv_half_sq_l_d = 0.5 / (
l_d_ *
l_d_);
124 for (
size_t j = 0; j <
size_ - 1; ++j) {
125 for (
size_t i = j + 1; i <
size_; ++i) {
127 dist_[pos] = dist_sq;
129 sigma_sq_d_ * std::exp(-dist_sq * inv_half_sq_l_d),
false);
133 for (
size_t i = 0; i <
size_; ++i) {
143 adjl += el_low->adj_ * el_low->val_ *
dist_[i];
152template <
typename T_x,
155 const var& sigma,
const var& l) {
162template <
typename T_x,
165 double sigma,
const var& l) {
cov_exp_quad_vari(const std::vector< T_x > &x, double sigma, const T_l &l)
cov_exp_quad_vari(const std::vector< T_x > &x, const T_sigma &sigma, const T_l &l)
require_t< std::is_arithmetic< std::decay_t< T > > > require_arithmetic_t
Require type satisfies std::is_arithmetic.
matrix_cl< return_type_t< T1, T2, T3 > > gp_exp_quad_cov(const matrix_cl< T1 > &x, const T2 sigma, const T3 length_scale)
Squared exponential kernel on the GPU.
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
vari_value< double > vari
Eigen::Matrix< return_type_t< T_x, T_sigma, T_l >, Eigen::Dynamic, Eigen::Dynamic > cov_exp_quad(const std::vector< T_x > &x, const T_sigma &sigma, const T_l &length_scale)
auto squared_distance(const T_a &a, const T_b &b)
Returns the squared distance.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
This struct always provides access to the autodiff stack using the singleton pattern.