mlpack  1.0.12
polynomial_kernel.hpp
Go to the documentation of this file.
1 
14 #ifndef __MLPACK_CORE_KERNELS_POLYNOMIAL_KERNEL_HPP
15 #define __MLPACK_CORE_KERNELS_POLYNOMIAL_KERNEL_HPP
16 
17 #include <mlpack/core.hpp>
18 
19 namespace mlpack {
20 namespace kernel {
21 
31 {
32  public:
40  PolynomialKernel(const double degree = 2.0, const double offset = 0.0) :
41  degree(degree),
42  offset(offset)
43  { }
44 
54  template<typename VecType>
55  double Evaluate(const VecType& a, const VecType& 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  std::string ToString() const
72  {
73  std::ostringstream convert;
74  convert << "PolynomialKernel [" << this << "]" << std::endl;
75  convert << " Degree: " << degree << std::endl;
76  convert << " Offset: " << offset << std::endl;
77  return convert.str();
78  }
79 
80  private:
82  double degree;
84  double offset;
85 };
86 
87 }; // namespace kernel
88 }; // namespace mlpack
89 
90 #endif
double degree
The degree of the polynomial.
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: load.hpp:23
double & Offset()
Modify the offset of the dot product of the arguments.
double Evaluate(const VecType &a, const VecType &b) const
Simple evaluation of the dot product.
std::string ToString() const
Return a string representation of the kernel.
const double & Offset() const
Get the offset of the dot product of the arguments.
const double & Degree() const
Get the degree of the polynomial.
double offset
The offset of the dot product of the arguments.
The simple polynomial kernel.
double & Degree()
Modify the degree of the polynomial.