[mlpack-svn] r10931 - 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 13:15:47 EST 2011


Author: ajinkya
Date: 2011-12-22 13:15:46 -0500 (Thu, 22 Dec 2011)
New Revision: 10931

Added:
   mlpack/trunk/src/mlpack/core/kernels/hyperbolic_tangent_kernel.hpp
Modified:
   mlpack/trunk/src/mlpack/core/kernels/CMakeLists.txt
Log:
hyperbolic tangent kernel


Modified: mlpack/trunk/src/mlpack/core/kernels/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/core/kernels/CMakeLists.txt	2011-12-22 18:10:55 UTC (rev 10930)
+++ mlpack/trunk/src/mlpack/core/kernels/CMakeLists.txt	2011-12-22 18:15:46 UTC (rev 10931)
@@ -10,6 +10,7 @@
   exponential_kernel.hpp
   laplacian_kernel.hpp
   polynomial_kernel.hpp
+  hyperbolic_tangent_kernel.hpp
 )
 
 # add directory name to sources

Added: mlpack/trunk/src/mlpack/core/kernels/hyperbolic_tangent_kernel.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/kernels/hyperbolic_tangent_kernel.hpp	                        (rev 0)
+++ mlpack/trunk/src/mlpack/core/kernels/hyperbolic_tangent_kernel.hpp	2011-12-22 18:15:46 UTC (rev 10931)
@@ -0,0 +1,74 @@
+/**
+ * @file hyperbolic_tangent_kernel.hpp
+ * @author Ajinkya Kale <kaleajinkya at gmail.com>
+ *
+ * Implementation of the hyperbolic tangent kernel
+ */
+#ifndef __MLPACK_CORE_KERNELS_HYPERBOLIC_TANGENT_KERNEL_HPP
+#define __MLPACK_CORE_KERNELS_HYPERBOLIC_TANGENT_KERNEL_HPP
+
+#include <mlpack/core.hpp>
+
+namespace mlpack {
+namespace kernel {
+
+/**
+ * Hyperbolic tangent kernel.  For any two vectors @f$ x @f$,
+ * @f$ y @f$ and @f$ scale @f$ and @f$ offset @f$
+ *
+ * @f[
+ * k(x, y) = \tanh(scale <x, y> + offset)
+ * @f]
+ *
+ */
+class HyperbolicTangentKernel
+{
+ public:
+  /**
+   * This constructor sets default scale to 1.0 and offset to 0.0
+   */
+  HyperbolicTangentKernel() :
+    scale(1.0),
+    offset(0.0)
+  { }
+
+  /**
+   * Construct Hyperbolic Tangent Kernel with custom scale factor and offset
+   *
+   * @param scale scaling factor for <x, y>
+   * @param offset kernel offset
+   */
+  HyperbolicTangentKernel(double scale, double offset) :
+    scale(scale),
+    offset(offset)
+  { }
+
+  /**
+   * Evaluation of Hyperbolic Tangent Kernel.  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 tanh(scale * arma::dot(a, b) + offset);
+  }
+
+  //Get scale factor
+  const double& Scale() const { return scale; }
+  //Get offset for the kernel
+  const double& Offset() const { return offset; }
+
+ private:
+  double scale;
+  double offset;
+};
+
+}; // namespace kernel
+}; // namespace mlpack
+
+#endif




More information about the mlpack-svn mailing list