[mlpack] 68/207: Don't increment currentCluster when we don't create a cluster.

Barak A. Pearlmutter barak+git at pearlmutter.net
Thu Mar 23 17:53:41 UTC 2017


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

bap pushed a commit to branch master
in repository mlpack.

commit 94d19e304c14116a681ec953d66ce2f8d4ac453d
Author: Ryan Curtin <ryan at ratml.org>
Date:   Wed Aug 3 17:36:30 2016 -0400

    Don't increment currentCluster when we don't create a cluster.
---
 src/mlpack/methods/CMakeLists.txt         |  1 +
 src/mlpack/methods/dbscan/dbscan.hpp      | 16 ++++++++--------
 src/mlpack/methods/dbscan/dbscan_impl.hpp | 10 ++++++----
 src/mlpack/tests/CMakeLists.txt           |  1 +
 4 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/mlpack/methods/CMakeLists.txt b/src/mlpack/methods/CMakeLists.txt
index 6aeed31..2551360 100644
--- a/src/mlpack/methods/CMakeLists.txt
+++ b/src/mlpack/methods/CMakeLists.txt
@@ -22,6 +22,7 @@ set(DIRS
   approx_kfn
   amf
   cf
+  dbscan
   decision_stump
   decision_tree
   det
diff --git a/src/mlpack/methods/dbscan/dbscan.hpp b/src/mlpack/methods/dbscan/dbscan.hpp
index 6d76128..94d7e99 100644
--- a/src/mlpack/methods/dbscan/dbscan.hpp
+++ b/src/mlpack/methods/dbscan/dbscan.hpp
@@ -52,14 +52,14 @@ class DBSCAN
   size_t minPoints;
 
   template<typename MatType>
-  void ProcessPoint(const MatType& data,
-                    boost::dynamic_bitset<>& unvisited,
-                    const size_t index,
-                    arma::Row<size_t>& assignments,
-                    const size_t currentCluster,
-                    const std::vector<std::vector<size_t>>& neighbors,
-                    const std::vector<std::vector<double>>& distances,
-                    const bool topLevel = true);
+  size_t ProcessPoint(const MatType& data,
+                      boost::dynamic_bitset<>& unvisited,
+                      const size_t index,
+                      arma::Row<size_t>& assignments,
+                      const size_t currentCluster,
+                      const std::vector<std::vector<size_t>>& neighbors,
+                      const std::vector<std::vector<double>>& distances,
+                      const bool topLevel = true);
 };
 
 } // namespace dbscan
diff --git a/src/mlpack/methods/dbscan/dbscan_impl.hpp b/src/mlpack/methods/dbscan/dbscan_impl.hpp
index 32e6932..e14a127 100644
--- a/src/mlpack/methods/dbscan/dbscan_impl.hpp
+++ b/src/mlpack/methods/dbscan/dbscan_impl.hpp
@@ -89,9 +89,9 @@ size_t DBSCAN<RangeSearchType, PointSelectionPolicy>::Cluster(
   {
     const size_t nextIndex = pointSelector.Select(unvisited, data);
 
-    ProcessPoint(data, unvisited, nextIndex, assignments, currentCluster,
-        neighbors, distances);
-    ++currentCluster;
+    // currentCluster will only be incremented if a cluster was created.
+    currentCluster = ProcessPoint(data, unvisited, nextIndex, assignments,
+        currentCluster, neighbors, distances);
   }
 
   return currentCluster;
@@ -99,7 +99,7 @@ size_t DBSCAN<RangeSearchType, PointSelectionPolicy>::Cluster(
 
 template<typename RangeSearchType, typename PointSelectionPolicy>
 template<typename MatType>
-void DBSCAN<RangeSearchType, PointSelectionPolicy>::ProcessPoint(
+size_t DBSCAN<RangeSearchType, PointSelectionPolicy>::ProcessPoint(
     const MatType& data,
     boost::dynamic_bitset<>& unvisited,
     const size_t index,
@@ -116,6 +116,7 @@ void DBSCAN<RangeSearchType, PointSelectionPolicy>::ProcessPoint(
   {
     // Mark the point as noise (leave assignments[index] unset) and return.
     unvisited[index] = false;
+    return currentCluster;
   }
   else
   {
@@ -134,6 +135,7 @@ void DBSCAN<RangeSearchType, PointSelectionPolicy>::ProcessPoint(
       ProcessPoint(data, unvisited, neighbors[index][j], assignments,
           currentCluster, neighbors, distances, false);
     }
+    return currentCluster + 1;
   }
 }
 
diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt
index 1b5bf40..8e3c91d 100644
--- a/src/mlpack/tests/CMakeLists.txt
+++ b/src/mlpack/tests/CMakeLists.txt
@@ -10,6 +10,7 @@ add_executable(mlpack_test
   cf_test.cpp
   cli_test.cpp
   cosine_tree_test.cpp
+  dbscan_test.cpp
   decision_stump_test.cpp
   decision_tree_test.cpp
   det_test.cpp

-- 
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