1#ifndef STAN_MATH_REV_FUN_COV_EXP_QUAD_HPP
2#define STAN_MATH_REV_FUN_COV_EXP_QUAD_HPP
22template <
typename T_x,
typename T_sigma,
typename T_l>
55 double inv_half_sq_l_d = 0.5 / (
l_d_ *
l_d_);
57 for (
size_t j = 0; j <
size_ - 1; ++j) {
58 for (
size_t i = j + 1; i <
size_; ++i) {
62 sigma_sq_d_ * std::exp(-dist_sq * inv_half_sq_l_d),
false);
66 for (
size_t i = 0; i <
size_; ++i) {
77 double prod_add = el_low->adj_ * el_low->val_;
78 adjl += prod_add *
dist_[i];
81 for (
size_t i = 0; i <
size_; ++i) {
83 adjsigma += el->adj_ * el->val_;
93template <
typename T_x,
typename T_l>
123 double inv_half_sq_l_d = 0.5 / (
l_d_ *
l_d_);
125 for (
size_t j = 0; j <
size_ - 1; ++j) {
126 for (
size_t i = j + 1; i <
size_; ++i) {
128 dist_[pos] = dist_sq;
130 sigma_sq_d_ * std::exp(-dist_sq * inv_half_sq_l_d),
false);
134 for (
size_t i = 0; i <
size_; ++i) {
144 adjl += el_low->adj_ * el_low->val_ *
dist_[i];
153template <
typename T_x,
156 const var& sigma,
const var& l) {
163template <
typename T_x,
166 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.