[mlpack-git] master: Add methods for counting distance computations. (66341ba)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Tue May 5 15:38:22 EDT 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/6137e52d32c1338b28853afd059b67cf68a50270...9c34c98c8dad01b4ad659c37367a8b20287b6b5a

>---------------------------------------------------------------

commit 66341ba1d7ba6c24d8754c6614ef987e142f134b
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue May 5 15:15:24 2015 -0400

    Add methods for counting distance computations.


>---------------------------------------------------------------

66341ba1d7ba6c24d8754c6614ef987e142f134b
 src/mlpack/methods/lsh/lsh_search.hpp      | 10 +++++++++-
 src/mlpack/methods/lsh/lsh_search_impl.hpp | 10 ++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/mlpack/methods/lsh/lsh_search.hpp b/src/mlpack/methods/lsh/lsh_search.hpp
index d97c8e0..83c6bd6 100644
--- a/src/mlpack/methods/lsh/lsh_search.hpp
+++ b/src/mlpack/methods/lsh/lsh_search.hpp
@@ -123,9 +123,14 @@ class LSHSearch
               arma::mat& distances,
               const size_t numTablesToSearch = 0);
 
-  // Returns a string representation of this object.
+  //! Returns a string representation of this object.
   std::string ToString() const;
 
+  //! Return the number of distance evaluations performed.
+  size_t DistanceEvaluations() const { return distanceEvaluations; }
+  //! Modify the number of distance evaluations performed.
+  size_t& DistanceEvaluations() { return distanceEvaluations; }
+
  private:
   /**
    * This function builds a hash table with two levels of hashing as presented
@@ -230,6 +235,9 @@ class LSHSearch
 
   //! The pointer to the nearest neighbor indices.
   arma::Mat<size_t>* neighborPtr;
+
+  //! The number of distance evaluations.
+  size_t distanceEvaluations;
 }; // class LSHSearch
 
 }; // namespace neighbor
diff --git a/src/mlpack/methods/lsh/lsh_search_impl.hpp b/src/mlpack/methods/lsh/lsh_search_impl.hpp
index c21aef9..b6110a3 100644
--- a/src/mlpack/methods/lsh/lsh_search_impl.hpp
+++ b/src/mlpack/methods/lsh/lsh_search_impl.hpp
@@ -28,7 +28,8 @@ LSHSearch(const arma::mat& referenceSet,
   numTables(numTables),
   hashWidth(hashWidthIn),
   secondHashSize(secondHashSize),
-  bucketSize(bucketSize)
+  bucketSize(bucketSize),
+  distanceEvaluations(0)
 {
   if (hashWidth == 0.0) // The user has not provided any value.
   {
@@ -64,7 +65,8 @@ LSHSearch(const arma::mat& referenceSet,
   numTables(numTables),
   hashWidth(hashWidthIn),
   secondHashSize(secondHashSize),
-  bucketSize(bucketSize)
+  bucketSize(bucketSize),
+  distanceEvaluations(0)
 {
   if (hashWidth == 0.0) // The user has not provided any value.
   {
@@ -122,6 +124,7 @@ BaseCase(const size_t queryIndex, const size_t referenceIndex)
 
   double distance = metric.Evaluate(querySet.unsafe_col(queryIndex),
                                     referenceSet.unsafe_col(referenceIndex));
+  ++distanceEvaluations;
 
   // If this distance is better than any of the current candidates, the
   // SortDistance() function will give us the position to insert it into.
@@ -247,8 +250,7 @@ Search(const size_t k,
 }
 
 template<typename SortPolicy>
-void LSHSearch<SortPolicy>::
-BuildHash()
+void LSHSearch<SortPolicy>::BuildHash()
 {
   // The first level hash for a single table outputs a 'numProj'-dimensional
   // integer key for each point in the set -- (key, pointID)



More information about the mlpack-git mailing list