[mlpack-svn] r10927 - mlpack/trunk/src/mlpack/core/kernels

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Dec 22 08:19:20 EST 2011


Author: ajinkya
Date: 2011-12-22 08:19:20 -0500 (Thu, 22 Dec 2011)
New Revision: 10927

Added:
   mlpack/trunk/src/mlpack/core/kernels/polynomial_kernel.hpp
Modified:
   mlpack/trunk/src/mlpack/core/kernels/CMakeLists.txt
Log:
polynomial kernel

Modified: mlpack/trunk/src/mlpack/core/kernels/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/core/kernels/CMakeLists.txt	2011-12-21 20:46:44 UTC (rev 10926)
+++ mlpack/trunk/src/mlpack/core/kernels/CMakeLists.txt	2011-12-22 13:19:20 UTC (rev 10927)
@@ -9,6 +9,7 @@
   cosine_distance_impl.hpp
   exponential_kernel.hpp
   laplacian_kernel.hpp
+  polynomial_kernel.hpp
 )
 
 # add directory name to sources

Added: mlpack/trunk/src/mlpack/core/kernels/polynomial_kernel.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/kernels/polynomial_kernel.hpp	                        (rev 0)
+++ mlpack/trunk/src/mlpack/core/kernels/polynomial_kernel.hpp	2011-12-22 13:19:20 UTC (rev 10927)
@@ -0,0 +1,74 @@
+/**
+ * @file polynomial_kernel.hpp
+ * @author Ajinkya Kale <kaleajinkya at gmail.com>
+ *
+ * Implementation of the polynomial kernel (just the standard dot product).
+ */
+#ifndef __MLPACK_CORE_KERNELS_POLYNOMIAL_KERNEL_HPP
+#define __MLPACK_CORE_KERNELS_POLYNOMIAL_KERNEL_HPP
+
+#include <mlpack/core.hpp>
+
+namespace mlpack {
+namespace kernel {
+
+/**
+ * The simple polynomial kernel.  For any two vectors @f$ x @f$,
+ * @f$ y @f$, @f$ degree @f$ and @f$ offset @f$
+ *
+ * @f[
+ * K(x, y) = (x^T * y + offset) ^ {degree}
+ * @f]
+ *
+ */
+class PolynomialKernel
+{
+ public:
+  /**
+   * Default constructor; sets offset to 0.0 and degree to 1.0
+   */
+  PolynomialKernel(double offset, double degree) :
+        offset(0.0),
+        degree(1.0)
+  { }
+
+  /* Construct the Polynomial Kernel with custom
+   * offset and degree
+   *
+   * @param offset offset to the polynomial
+   * @param degree degree of the polynomial
+   */
+  PolynomialKernel(double offset, double degree) :
+      offset(offset),
+      degree(degree)
+  { }
+
+  /**
+   * Simple evaluation of the dot product.  This evaluation uses Armadillo's
+   * dot() function.
+   *
+   * @tparam VecType Type of vector (should be arma::vec or arma::spvec).
+   * @param a First vector.
+   * @param b Second vector.
+   * @return K(a, b).
+   */
+  template<typename VecType>
+  static double Evaluate(const VecType& a, const VecType& b)
+  {
+    return pow((arma::dot(a, b) + offset), degree);
+  }
+
+  //! Get the offset
+  const double& Offset() const { return offset; }
+  //! Get the degree of the polynomial
+  const double& Degree() const { return degree; }
+
+ private:
+  double offset;
+  double degree;
+};
+
+}; // namespace kernel
+}; // namespace mlpack
+
+#endif




More information about the mlpack-svn mailing list