20#define USE_TAYLORMADE_RELAXATIONS
23#ifdef USE_TAYLORMADE_RELAXATIONS
32#ifdef USE_TAYLORMADE_RELAXATIONS
34 using mc::covariance_function;
36 template <
typename T>
inline T
38 return covariance_function(x, 1);
41 template <
typename T>
inline T
44 return covariance_function(x, 2);
47 template <
typename T>
inline T
50 return covariance_function(x, 3);
53 template <
typename T>
inline T
56 return covariance_function(x, 4);
66 std::vector<double>
ell;
73 template <
typename T,
typename V>
77 Matern(std::shared_ptr<const KernelData> data);
82 std::shared_ptr<const KernelData>
_data;
94 for (
size_t i = 0; i < x1.size(); i++) {
108 double const epsilon = 1e-16;
114 auto distance = quadraticDistance + epsilon;
115 distance = sqrt(distance);
125 template <
typename T,
typename V>
140 template <
typename T,
typename V>
155 template <
typename T,
typename V>
170 template <
typename T,
typename V>
185 template<
typename T,
typename V>
188 template<
typename T,
typename V>
198 template<
typename T,
typename V>
201#ifdef USE_TAYLORMADE_RELAXATIONS
204 RET euclidianDistance = sqrt(distance + 1e-16);
209 template<
typename T,
typename V>
211 RET distances = calculate_distance(x1, x2);
212 return evaluate_kernel(distances);
215 template<
typename T,
typename V>
217 return this->_quadratic_distance(x1, x2);
225 template<
typename T,
typename V>
228#ifdef USE_TAYLORMADE_RELAXATIONS
231 RET euclidianDistance = sqrt(distance + 1e-16);
232 RET sqrtK = sqrt(3.0) * euclidianDistance;
240 template<
typename T,
typename V>
242 RET distances = calculate_distance(x1, x2);
243 return evaluate_kernel(distances);
246 template<
typename T,
typename V>
248 return this->_quadratic_distance(x1, x2);
256 template<
typename T,
typename V>
259#ifdef USE_TAYLORMADE_RELAXATIONS
263 RET euclidianDistance = sqrt(distance + 1e-16);
264 RET sqrtK = sqrt(5.0) * euclidianDistance;
265 RET sqrtK2_3 = 5. / 3. * distance;
268 return Matern<T, V>::_data->sf2 * (exp(-sqrtK) + sqrtK * exp(-sqrtK) + sqrtK2_3 * exp(-sqrtK));
273 template<
typename T,
typename V>
275 RET distances = calculate_distance(x1, x2);
276 return evaluate_kernel(distances);
279 template<
typename T,
typename V>
281 return this->_quadratic_distance(x1, x2);
289 template<
typename T,
typename V>
292#ifdef USE_TAYLORMADE_RELAXATIONS
300 template<
typename T,
typename V>
302 RET distances = calculate_distance(x1, x2);
303 return evaluate_kernel(distances);
307 template<
typename T,
typename V>
309 return this->_quadratic_distance(x1, x2);
decltype(std::declval< T >()+std::declval< V >()) RET
Definition kernel.h:33
Class implementation of Matern12 kernel.
Definition matern.h:126
RET evaluate_kernel(std::vector< T > x1, std::vector< V > x2)
Function for evalualting the kernel for the points x1 and x2.
Definition matern.h:210
RET calculate_distance(std::vector< T > x1, std::vector< V > x2)
Function for calculating the distance used in the kernel (type of distance used can vary among kernel...
Definition matern.h:216
Class implementation of Matern32 kernel.
Definition matern.h:141
RET calculate_distance(std::vector< T > x1, std::vector< V > x2)
Function for calculating the distance used in the kernel (type of distance used can vary among kernel...
Definition matern.h:247
RET evaluate_kernel(std::vector< T > x1, std::vector< V > x2)
Function for evalualting the kernel for the points x1 and x2.
Definition matern.h:241
Class implementation of Matern52 kernel.
Definition matern.h:156
RET calculate_distance(std::vector< T > x1, std::vector< V > x2)
Function for calculating the distance used in the kernel (type of distance used can vary among kernel...
Definition matern.h:280
RET evaluate_kernel(std::vector< T > x1, std::vector< V > x2)
Function for evalualting the kernel for the points x1 and x2.
Definition matern.h:274
Abstract parent class for matern kernels.
Definition matern.h:74
RET _quadratic_distance(std::vector< T > x1, std::vector< V > x2) override
Calculates the quadratic distance between two points x1 and x2.
Definition matern.h:91
auto _euclidian_distance(RET quadraticDistance)
Calculates the euclidian distance from the quadratic distance.
Definition matern.h:106
Matern()
Definition matern.h:186
std::shared_ptr< const KernelData > _data
Definition matern.h:82
Class implementation of MaternInf kernel.
Definition matern.h:171
RET evaluate_kernel(std::vector< T > x1, std::vector< V > x2)
Function for evalualting the kernel for the points x1 and x2.
Definition matern.h:301
RET calculate_distance(std::vector< T > x1, std::vector< V > x2)
Function for calculating the distance used in the kernel (type of distance used can vary among kernel...
Definition matern.h:308
T covar_matern_5(const T &x)
Definition matern.h:49
T covar_sqrexp(const T &x)
Definition matern.h:55
T covar_matern_1(const T &x)
Definition matern.h:37
T covar_matern_3(const T &x)
Definition matern.h:43
struct containing kernel parameters
Definition matern.h:64
double sf2
Definition matern.h:65
std::vector< double > ell
Definition matern.h:66