[mlpack-svn] r15081 - in mlpack/trunk/src/mlpack: core/metrics methods/fastmks

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon May 13 17:29:46 EDT 2013


Author: rcurtin
Date: 2013-05-13 17:29:46 -0400 (Mon, 13 May 2013)
New Revision: 15081

Added:
   mlpack/trunk/src/mlpack/core/metrics/ip_metric.hpp
   mlpack/trunk/src/mlpack/core/metrics/ip_metric_impl.hpp
Removed:
   mlpack/trunk/src/mlpack/methods/fastmks/ip_metric.hpp
   mlpack/trunk/src/mlpack/methods/fastmks/ip_metric_impl.hpp
Modified:
   mlpack/trunk/src/mlpack/core/metrics/CMakeLists.txt
   mlpack/trunk/src/mlpack/methods/fastmks/CMakeLists.txt
   mlpack/trunk/src/mlpack/methods/fastmks/fastmks.hpp
Log:
Move IPMetric to general metrics directory since it will be useful for other
things.


Modified: mlpack/trunk/src/mlpack/core/metrics/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/core/metrics/CMakeLists.txt	2013-05-13 21:24:34 UTC (rev 15080)
+++ mlpack/trunk/src/mlpack/core/metrics/CMakeLists.txt	2013-05-13 21:29:46 UTC (rev 15081)
@@ -1,6 +1,8 @@
 # Define the files we need to compile.
 # Anything not in this list will not be compiled into MLPACK.
 set(SOURCES
+  ip_metric.hpp
+  ip_metric_impl.hpp
   lmetric.hpp
   lmetric_impl.hpp
   mahalanobis_distance.hpp

Copied: mlpack/trunk/src/mlpack/core/metrics/ip_metric.hpp (from rev 15051, mlpack/trunk/src/mlpack/methods/fastmks/ip_metric.hpp)
===================================================================
--- mlpack/trunk/src/mlpack/core/metrics/ip_metric.hpp	                        (rev 0)
+++ mlpack/trunk/src/mlpack/core/metrics/ip_metric.hpp	2013-05-13 21:29:46 UTC (rev 15081)
@@ -0,0 +1,51 @@
+/**
+ * @file ip_metric.hpp
+ * @author Ryan Curtin
+ *
+ * Inner product induced metric.  If given a kernel function, this gives the
+ * complementary metric.
+ */
+#ifndef __MLPACK_METHODS_FASTMKS_IP_METRIC_HPP
+#define __MLPACK_METHODS_FASTMKS_IP_METRIC_HPP
+
+namespace mlpack {
+namespace fastmks /** Fast maximum kernel search. */ {
+
+template<typename KernelType>
+class IPMetric
+{
+ public:
+  //! Create the IPMetric without an instantiated kernel.
+  IPMetric();
+
+  //! Create the IPMetric with an instantiated kernel.
+  IPMetric(KernelType& kernel);
+
+  //! Destroy the IPMetric object.
+  ~IPMetric();
+
+  /**
+   * Evaluate the metric.
+   */
+  template<typename Vec1Type, typename Vec2Type>
+  double Evaluate(const Vec1Type& a, const Vec2Type& b);
+
+  //! Get the kernel.
+  const KernelType& Kernel() const { return kernel; }
+  //! Modify the kernel.
+  KernelType& Kernel() { return kernel; }
+
+ private:
+  //! The locally stored kernel, if it is necessary.
+  KernelType* localKernel;
+  //! The reference to the kernel that is being used.
+  KernelType& kernel;
+};
+
+}; // namespace fastmks
+}; // namespace mlpack
+
+// Include implementation.
+#include "ip_metric_impl.hpp"
+
+#endif

Copied: mlpack/trunk/src/mlpack/core/metrics/ip_metric_impl.hpp (from rev 15051, mlpack/trunk/src/mlpack/methods/fastmks/ip_metric_impl.hpp)
===================================================================
--- mlpack/trunk/src/mlpack/core/metrics/ip_metric_impl.hpp	                        (rev 0)
+++ mlpack/trunk/src/mlpack/core/metrics/ip_metric_impl.hpp	2013-05-13 21:29:46 UTC (rev 15081)
@@ -0,0 +1,69 @@
+/**
+ * @file ip_metric_impl.hpp
+ * @author Ryan Curtin
+ *
+ * Implementation of the IPMetric.
+ */
+#ifndef __MLPACK_METHODS_FASTMKS_IP_METRIC_IMPL_HPP
+#define __MLPACK_METHODS_FASTMKS_IP_METRIC_IMPL_HPP
+
+// In case it hasn't been included yet.
+#include "ip_metric_impl.hpp"
+
+#include <mlpack/core/metrics/lmetric.hpp>
+#include <mlpack/core/kernels/linear_kernel.hpp>
+
+namespace mlpack {
+namespace fastmks {
+
+// Constructor with no instantiated kernel.
+template<typename KernelType>
+IPMetric<KernelType>::IPMetric() :
+    localKernel(new KernelType()),
+    kernel(*localKernel)
+{
+  // Nothing to do.
+}
+
+// Constructor with instantiated kernel.
+template<typename KernelType>
+IPMetric<KernelType>::IPMetric(KernelType& kernel) :
+    localKernel(NULL),
+    kernel(kernel)
+{
+  // Nothing to do.
+}
+
+// Destructor for the IPMetric.
+template<typename KernelType>
+IPMetric<KernelType>::~IPMetric()
+{
+  if (localKernel != NULL)
+    delete localKernel;
+}
+
+template<typename KernelType>
+template<typename Vec1Type, typename Vec2Type>
+inline 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 sqrt(kernel.Evaluate(a, a) + kernel.Evaluate(b, b) -
+      2 * kernel.Evaluate(a, b));
+}
+
+// A specialization for the linear kernel, which actually just turns out to be
+// the Euclidean distance.
+template<>
+template<typename Vec1Type, typename Vec2Type>
+inline double IPMetric<kernel::LinearKernel>::Evaluate(const Vec1Type& a,
+                                                       const Vec2Type& b)
+{
+  return metric::LMetric<2, true>::Evaluate(a, b);
+}
+
+}; // namespace fastmks
+}; // namespace mlpack
+
+#endif

Modified: mlpack/trunk/src/mlpack/methods/fastmks/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/methods/fastmks/CMakeLists.txt	2013-05-13 21:24:34 UTC (rev 15080)
+++ mlpack/trunk/src/mlpack/methods/fastmks/CMakeLists.txt	2013-05-13 21:29:46 UTC (rev 15081)
@@ -1,8 +1,6 @@
 # Define the files we need to compile.
 # Anything not in this list will not be compiled into MLPACK.
 set(SOURCES
-  ip_metric.hpp
-  ip_metric_impl.hpp
   fastmks.hpp
   fastmks_impl.hpp
   fastmks_rules.hpp

Modified: mlpack/trunk/src/mlpack/methods/fastmks/fastmks.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/fastmks/fastmks.hpp	2013-05-13 21:24:34 UTC (rev 15080)
+++ mlpack/trunk/src/mlpack/methods/fastmks/fastmks.hpp	2013-05-13 21:29:46 UTC (rev 15081)
@@ -9,7 +9,7 @@
 #define __MLPACK_METHODS_FASTMKS_FASTMKS_HPP
 
 #include <mlpack/core.hpp>
-#include "ip_metric.hpp"
+#include <mlpack/core/metrics/ip_metric.hpp>
 #include "fastmks_stat.hpp"
 #include <mlpack/core/tree/cover_tree.hpp>
 

Deleted: mlpack/trunk/src/mlpack/methods/fastmks/ip_metric.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/fastmks/ip_metric.hpp	2013-05-13 21:24:34 UTC (rev 15080)
+++ mlpack/trunk/src/mlpack/methods/fastmks/ip_metric.hpp	2013-05-13 21:29:46 UTC (rev 15081)
@@ -1,51 +0,0 @@
-/**
- * @file ip_metric.hpp
- * @author Ryan Curtin
- *
- * Inner product induced metric.  If given a kernel function, this gives the
- * complementary metric.
- */
-#ifndef __MLPACK_METHODS_FASTMKS_IP_METRIC_HPP
-#define __MLPACK_METHODS_FASTMKS_IP_METRIC_HPP
-
-namespace mlpack {
-namespace fastmks /** Fast maximum kernel search. */ {
-
-template<typename KernelType>
-class IPMetric
-{
- public:
-  //! Create the IPMetric without an instantiated kernel.
-  IPMetric();
-
-  //! Create the IPMetric with an instantiated kernel.
-  IPMetric(KernelType& kernel);
-
-  //! Destroy the IPMetric object.
-  ~IPMetric();
-
-  /**
-   * Evaluate the metric.
-   */
-  template<typename Vec1Type, typename Vec2Type>
-  double Evaluate(const Vec1Type& a, const Vec2Type& b);
-
-  //! Get the kernel.
-  const KernelType& Kernel() const { return kernel; }
-  //! Modify the kernel.
-  KernelType& Kernel() { return kernel; }
-
- private:
-  //! The locally stored kernel, if it is necessary.
-  KernelType* localKernel;
-  //! The reference to the kernel that is being used.
-  KernelType& kernel;
-};
-
-}; // namespace fastmks
-}; // namespace mlpack
-
-// Include implementation.
-#include "ip_metric_impl.hpp"
-
-#endif

Deleted: mlpack/trunk/src/mlpack/methods/fastmks/ip_metric_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/fastmks/ip_metric_impl.hpp	2013-05-13 21:24:34 UTC (rev 15080)
+++ mlpack/trunk/src/mlpack/methods/fastmks/ip_metric_impl.hpp	2013-05-13 21:29:46 UTC (rev 15081)
@@ -1,69 +0,0 @@
-/**
- * @file ip_metric_impl.hpp
- * @author Ryan Curtin
- *
- * Implementation of the IPMetric.
- */
-#ifndef __MLPACK_METHODS_FASTMKS_IP_METRIC_IMPL_HPP
-#define __MLPACK_METHODS_FASTMKS_IP_METRIC_IMPL_HPP
-
-// In case it hasn't been included yet.
-#include "ip_metric_impl.hpp"
-
-#include <mlpack/core/metrics/lmetric.hpp>
-#include <mlpack/core/kernels/linear_kernel.hpp>
-
-namespace mlpack {
-namespace fastmks {
-
-// Constructor with no instantiated kernel.
-template<typename KernelType>
-IPMetric<KernelType>::IPMetric() :
-    localKernel(new KernelType()),
-    kernel(*localKernel)
-{
-  // Nothing to do.
-}
-
-// Constructor with instantiated kernel.
-template<typename KernelType>
-IPMetric<KernelType>::IPMetric(KernelType& kernel) :
-    localKernel(NULL),
-    kernel(kernel)
-{
-  // Nothing to do.
-}
-
-// Destructor for the IPMetric.
-template<typename KernelType>
-IPMetric<KernelType>::~IPMetric()
-{
-  if (localKernel != NULL)
-    delete localKernel;
-}
-
-template<typename KernelType>
-template<typename Vec1Type, typename Vec2Type>
-inline 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 sqrt(kernel.Evaluate(a, a) + kernel.Evaluate(b, b) -
-      2 * kernel.Evaluate(a, b));
-}
-
-// A specialization for the linear kernel, which actually just turns out to be
-// the Euclidean distance.
-template<>
-template<typename Vec1Type, typename Vec2Type>
-inline double IPMetric<kernel::LinearKernel>::Evaluate(const Vec1Type& a,
-                                                       const Vec2Type& b)
-{
-  return metric::LMetric<2, true>::Evaluate(a, b);
-}
-
-}; // namespace fastmks
-}; // namespace mlpack
-
-#endif




More information about the mlpack-svn mailing list