mlpack 3.4.2
polynomial_kernel.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_CORE_KERNELS_POLYNOMIAL_KERNEL_HPP
13#define MLPACK_CORE_KERNELS_POLYNOMIAL_KERNEL_HPP
14
15#include <mlpack/prereqs.hpp>
16
17namespace mlpack {
18namespace kernel {
19
29{
30 public:
38 PolynomialKernel(const double degree = 2.0, const double offset = 0.0) :
39 degree(degree),
40 offset(offset)
41 { }
42
54 template<typename VecTypeA, typename VecTypeB>
55 double Evaluate(const VecTypeA& a, const VecTypeB& b) const
56 {
57 return pow((arma::dot(a, b) + offset), degree);
58 }
59
61 const double& Degree() const { return degree; }
63 double& Degree() { return degree; }
64
66 const double& Offset() const { return offset; }
68 double& Offset() { return offset; }
69
71 template<typename Archive>
72 void serialize(Archive& ar, const unsigned int /* version */)
73 {
74 ar & BOOST_SERIALIZATION_NVP(degree);
75 ar & BOOST_SERIALIZATION_NVP(offset);
76 }
77
78 private:
80 double degree;
82 double offset;
83};
84
85} // namespace kernel
86} // namespace mlpack
87
88#endif
The simple polynomial kernel.
const double & Offset() const
Get the offset of the dot product of the arguments.
double & Offset()
Modify the offset of the dot product of the arguments.
double Evaluate(const VecTypeA &a, const VecTypeB &b) const
Simple evaluation of the dot product.
const double & Degree() const
Get the degree of the polynomial.
double & Degree()
Modify the degree of the polynomial.
void serialize(Archive &ar, const unsigned int)
Serialize the kernel.
PolynomialKernel(const double degree=2.0, const double offset=0.0)
Construct the Polynomial Kernel with the given offset and degree.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.