[mlpack] 50/149: Yet another instance of me failing to commit all my changes. Add a BaseCases() and Scores() function to NeighborSearch, so that a user (or DTNNKMeans) can obtain how much work was done after the search.

Barak A. Pearlmutter barak+git at pearlmutter.net
Sat May 2 09:11:08 UTC 2015


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit 8fe11f237a8a24ce99b3790f910513d4a7943311
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Mon Oct 13 21:19:59 2014 +0000

    Yet another instance of me failing to commit all my changes.  Add a BaseCases()
    and Scores() function to NeighborSearch, so that a user (or DTNNKMeans) can
    obtain how much work was done after the search.
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17258 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 .../methods/neighbor_search/neighbor_search.hpp    | 19 ++++++++++++-
 .../neighbor_search/neighbor_search_impl.hpp       | 31 +++++++++++++++++-----
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/src/mlpack/methods/neighbor_search/neighbor_search.hpp b/src/mlpack/methods/neighbor_search/neighbor_search.hpp
index 64f71a2..9ae8b6a 100644
--- a/src/mlpack/methods/neighbor_search/neighbor_search.hpp
+++ b/src/mlpack/methods/neighbor_search/neighbor_search.hpp
@@ -192,9 +192,20 @@ class NeighborSearch
               arma::Mat<size_t>& resultingNeighbors,
               arma::mat& distances);
 
-  // Returns a string representation of this object. 
+  //! Returns a string representation of this object.
   std::string ToString() const;
 
+  //! Return the total number of base case evaluations performed during
+  //! searches.
+  size_t BaseCases() const { return baseCases; }
+  //! Modify the total number of base case evaluations.
+  size_t& BaseCases() { return baseCases; }
+
+  //! Return the number of node combination scores during the search.
+  size_t Scores() const { return scores; }
+  //! Modify the number of node combination scores.
+  size_t& Scores() { return scores; }
+
  private:
   //! Copy of reference dataset (if we need it, because tree building modifies
   //! it).
@@ -229,6 +240,12 @@ class NeighborSearch
   std::vector<size_t> oldFromNewReferences;
   //! Permutations of query points during tree building.
   std::vector<size_t> oldFromNewQueries;
+
+  //! The total number of base cases.
+  size_t baseCases;
+  //! The total number of scores (applicable for non-naive search).
+  size_t scores;
+
 }; // class NeighborSearch
 
 }; // namespace neighbor
diff --git a/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp b/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp
index a0f4dc7..60994d6 100644
--- a/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp
+++ b/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp
@@ -57,8 +57,13 @@ NeighborSearch(const typename TreeType::Mat& referenceSetIn,
     hasQuerySet(true),
     naive(naive),
     singleMode(!naive && singleMode), // No single mode if naive.
-    metric(metric)
+    metric(metric),
+    baseCases(0),
+    scores(0)
 {
+  // C++11 will allow us to call out to other constructors so we can avoid this
+  // copypasta problem.
+
   // We'll time tree building, but only if we are building trees.
   Timer::Start("tree_building");
 
@@ -105,7 +110,9 @@ NeighborSearch(const typename TreeType::Mat& referenceSetIn,
     hasQuerySet(false),
     naive(naive),
     singleMode(!naive && singleMode), // No single mode if naive.
-    metric(metric)
+    metric(metric),
+    baseCases(0),
+    scores(0)
 {
   // We'll time tree building, but only if we are building trees.
   Timer::Start("tree_building");
@@ -149,7 +156,9 @@ NeighborSearch<SortPolicy, MetricType, TreeType>::NeighborSearch(
     hasQuerySet(true),
     naive(false),
     singleMode(singleMode),
-    metric(metric)
+    metric(metric),
+    baseCases(0),
+    scores(0)
 {
   // Nothing else to initialize.
 }
@@ -169,7 +178,9 @@ NeighborSearch<SortPolicy, MetricType, TreeType>::NeighborSearch(
     hasQuerySet(false), // In this case we will own a tree, if singleMode.
     naive(false),
     singleMode(singleMode),
-    metric(metric)
+    metric(metric),
+    baseCases(0),
+    scores(0)
 {
   Timer::Start("tree_building");
 
@@ -246,12 +257,14 @@ void NeighborSearch<SortPolicy, MetricType, TreeType>::Search(
     for (size_t i = 0; i < querySet.n_cols; ++i)
       for (size_t j = 0; j < referenceSet.n_cols; ++j)
         rules.BaseCase(i, j);
+
+    baseCases += querySet.n_cols * referenceSet.n_cols;
   }
   else if (singleMode)
   {
     // The search doesn't work if the root node is also a leaf node.
-    // if this is the case, it is suggested that you use the naive method.
-    assert(!(referenceTree->IsLeaf()));
+    // If this is the case, it is suggested that you use the naive method.
+    Log::Assert(!(referenceTree->IsLeaf()));
 
     // Create the traverser.
     typename TreeType::template SingleTreeTraverser<RuleType> traverser(rules);
@@ -260,6 +273,9 @@ void NeighborSearch<SortPolicy, MetricType, TreeType>::Search(
     for (size_t i = 0; i < querySet.n_cols; ++i)
       traverser.Traverse(i, *referenceTree);
 
+    scores += rules.Scores();
+    baseCases += rules.BaseCases();
+
     Log::Info << rules.Scores() << " node combinations were scored.\n";
     Log::Info << rules.BaseCases() << " base cases were calculated.\n";
   }
@@ -270,6 +286,9 @@ void NeighborSearch<SortPolicy, MetricType, TreeType>::Search(
 
     traverser.Traverse(*queryTree, *referenceTree);
 
+    scores += rules.Scores();
+    baseCases += rules.BaseCases();
+
     Log::Info << rules.Scores() << " node combinations were scored.\n";
     Log::Info << rules.BaseCases() << " base cases were calculated.\n";
   }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list