[mlpack-svn] r14965 - mlpack/trunk/src/mlpack/methods/fastmks

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Apr 26 23:05:40 EDT 2013


Author: rcurtin
Date: 2013-04-26 23:05:40 -0400 (Fri, 26 Apr 2013)
New Revision: 14965

Modified:
   mlpack/trunk/src/mlpack/methods/fastmks/ip_metric.hpp
   mlpack/trunk/src/mlpack/methods/fastmks/ip_metric_impl.hpp
Log:
Update IPMetric API and document it.


Modified: mlpack/trunk/src/mlpack/methods/fastmks/ip_metric.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/fastmks/ip_metric.hpp	2013-04-26 18:54:17 UTC (rev 14964)
+++ mlpack/trunk/src/mlpack/methods/fastmks/ip_metric.hpp	2013-04-27 03:05:40 UTC (rev 14965)
@@ -9,29 +9,36 @@
 #define __MLPACK_METHODS_FASTMKS_IP_METRIC_HPP
 
 namespace mlpack {
-namespace fastmks /** The fast maximum kernel search problem. */ {
+namespace fastmks /** Fast maximum kernel search. */ {
 
 template<typename KernelType>
 class IPMetric
 {
  public:
-  IPMetric() : kernel(localKernel) { }
+  //! Create the IPMetric without an instantiated kernel.
+  IPMetric();
 
-  /**
-   * Create the IPMetric.
-   */
-  IPMetric(KernelType& kernel) : kernel(kernel) { }
+  //! 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; }
 
-  KernelType localKernel;
+ private:
+  //! The locally stored kernel, if it is necessary.
+  KernelType* localKernel;
+  //! The reference to the kernel that is being used.
   KernelType& kernel;
 };
 

Modified: mlpack/trunk/src/mlpack/methods/fastmks/ip_metric_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/fastmks/ip_metric_impl.hpp	2013-04-26 18:54:17 UTC (rev 14964)
+++ mlpack/trunk/src/mlpack/methods/fastmks/ip_metric_impl.hpp	2013-04-27 03:05:40 UTC (rev 14965)
@@ -16,24 +16,50 @@
 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?
-  ++distanceEvaluations;
   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)
 {
-  ++distanceEvaluations;
   return metric::LMetric<2, true>::Evaluate(a, b);
 }
 




More information about the mlpack-svn mailing list