[mlpack-svn] r12705 - mlpack/trunk/src/mlpack/methods/maxip

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu May 17 12:54:54 EDT 2012


Author: rcurtin
Date: 2012-05-17 12:54:53 -0400 (Thu, 17 May 2012)
New Revision: 12705

Added:
   mlpack/trunk/src/mlpack/methods/maxip/ip_metric.hpp
   mlpack/trunk/src/mlpack/methods/maxip/ip_metric_impl.hpp
Log:
Add the IPMetric, which is the "inner product" metric which calculates the
metric induced by a kernel.


Added: mlpack/trunk/src/mlpack/methods/maxip/ip_metric.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/maxip/ip_metric.hpp	                        (rev 0)
+++ mlpack/trunk/src/mlpack/methods/maxip/ip_metric.hpp	2012-05-17 16:54:53 UTC (rev 12705)
@@ -0,0 +1,38 @@
+/**
+ * @file ip_metric.hpp
+ * @author Ryan Curtin
+ *
+ * Inner product induced metric.  If given a kernel function, this gives the
+ * complementary metric.
+ */
+#ifndef __MLPACK_METHODS_MAXIP_IP_METRIC_HPP
+#define __MLPACK_METHODS_MAXIP_IP_METRIC_HPP
+
+namespace mlpack {
+namespace maxip /** The maximum inner product problem. */ {
+
+template<typename KernelType>
+class IPMetric
+{
+ public:
+  typedef KernelType Kernel;
+
+  /**
+   * Create the IPMetric.
+   */
+  IPMetric() { }
+
+  /**
+   * Evaluate the metric.
+   */
+  template<typename Vec1Type, typename Vec2Type>
+  static double Evaluate(const Vec1Type& a, const Vec2Type& b);
+};
+
+}; // namespace maxip
+}; // namespace mlpack
+
+// Include implementation.
+#include "ip_metric_impl.hpp"
+
+#endif

Added: mlpack/trunk/src/mlpack/methods/maxip/ip_metric_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/maxip/ip_metric_impl.hpp	                        (rev 0)
+++ mlpack/trunk/src/mlpack/methods/maxip/ip_metric_impl.hpp	2012-05-17 16:54:53 UTC (rev 12705)
@@ -0,0 +1,29 @@
+/**
+ * @file ip_metric_impl.hpp
+ * @author Ryan Curtin
+ *
+ * Implementation of the IPMetric.
+ */
+#ifndef __MLPACK_METHODS_MAXIP_IP_METRIC_IMPL_HPP
+#define __MLPACK_METHODS_MAXIP_IP_METRIC_IMPL_HPP
+
+// In case it hasn't been included yet.
+#include "ip_metric_impl.hpp"
+
+namespace mlpack {
+namespace maxip {
+
+template<typename KernelType>
+template<typename Vec1Type, typename Vec2Type>
+double IPMetric<KernelType>::Evaluate(const Vec1Type& a, const Vec2Type& b)
+{
+  // This is the metric induced by the kernel function.
+  // Maybe we can do better by caching some of this?
+  return KernelType::Evaluate(a, a) + KernelType::Evaluate(b, b) -
+      2 * KernelType::Evaluate(a, b);
+}
+
+}; // namespace maxip
+}; // namespace mlpack
+
+#endif




More information about the mlpack-svn mailing list