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

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Apr 30 15:04:04 EDT 2013


Author: rcurtin
Date: 2013-04-30 15:04:04 -0400 (Tue, 30 Apr 2013)
New Revision: 14980

Modified:
   mlpack/trunk/src/mlpack/core/kernels/polynomial_kernel.hpp
Log:
Clean up polynomial kernel and reverse input arguments so they are now in line
with what FastMKS actually implements.


Modified: mlpack/trunk/src/mlpack/core/kernels/polynomial_kernel.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/kernels/polynomial_kernel.hpp	2013-04-30 18:54:52 UTC (rev 14979)
+++ mlpack/trunk/src/mlpack/core/kernels/polynomial_kernel.hpp	2013-04-30 19:04:04 UTC (rev 14980)
@@ -13,34 +13,26 @@
 namespace kernel {
 
 /**
- * The simple polynomial kernel.  For any two vectors @f$ x @f$,
- * @f$ y @f$, @f$ degree @f$ and @f$ offset @f$
+ * 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}
+ * 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() :
-    offset(0.0),
-    degree(1.0)
-  { }
-
-  /* Construct the Polynomial Kernel with custom
-   * offset and degree
+   * Construct the Polynomial Kernel with the given offset and degree.  If the
+   * arguments are omitted, the default degree is 2 and the default offset is 0.
    *
-   * @param offset offset to the polynomial
-   * @param degree degree of the polynomial
+   * @param offset Offset of the dot product of the arguments.
+   * @param degree Degree of the polynomial.
    */
-  PolynomialKernel(double offset, double degree) :
-    offset(offset),
-    degree(degree)
+  PolynomialKernel(const double degree = 2.0, const double offset = 0.0) :
+      degree(degree),
+      offset(offset)
   { }
 
   /**
@@ -53,19 +45,26 @@
    * @return K(a, b).
    */
   template<typename VecType>
-  double Evaluate(const VecType& a, const VecType& b)
+  double Evaluate(const VecType& a, const VecType& b) const
   {
     return pow((arma::dot(a, b) + offset), degree);
   }
 
-  //! Get the offset
-  const double& Offset() const { return offset; }
-  //! Get the degree of the polynomial
+  //! Get the degree of the polynomial.
   const double& Degree() const { return degree; }
+  //! Modify the degree of the polynomial.
+  double& Degree() { return degree; }
 
+  //! Get the offset of the dot product of the arguments.
+  const double& Offset() const { return offset; }
+  //! Modify the offset of the dot product of the arguments.
+  double& Offset() { return offset; }
+
  private:
-  double offset;
+  //! The degree of the polynomial.
   double degree;
+  //! The offset of the dot product of the arguments.
+  double offset;
 };
 
 }; // namespace kernel




More information about the mlpack-svn mailing list