diff --git a/src/mlpack/methods/dbscan/dbscan.hpp b/src/mlpack/methods/dbscan/dbscan.hpp index 8618afd512..5dbf1cd8b3 100644 --- a/src/mlpack/methods/dbscan/dbscan.hpp +++ b/src/mlpack/methods/dbscan/dbscan.hpp @@ -47,13 +47,14 @@ namespace mlpack { * with. */ template, - typename PointSelectionPolicy = OrderedPointSelection, - typename MatType = arma::mat> + typename PointSelectionPolicy = OrderedPointSelection> class DBSCAN { public: + //! Easy access to the MatType. + typedef typename RangeSearchType::Mat MatType; //! Easy access to Element Type of the matrix. - typedef typename MatType::elem_type ElemType; + typedef typename RangeSearchType::Mat::elem_type ElemType; /** * Construct the DBSCAN object with the given parameters. The batchMode * parameter should be set to false in the case where RAM issues will be @@ -114,9 +115,6 @@ class DBSCAN //! Maximum distance between two points to be part of same cluster. ElemType epsilon; - //! Zero, just a variable holder for zero value, can be f16, f32 or double. - ElemType zero = 0.0; - //! Minimum number of points to be in the epsilon-neighborhood (including //! itself) for the point to be a core-point. size_t minPoints; diff --git a/src/mlpack/methods/dbscan/dbscan_impl.hpp b/src/mlpack/methods/dbscan/dbscan_impl.hpp index 4db88c76f9..d27de3db08 100644 --- a/src/mlpack/methods/dbscan/dbscan_impl.hpp +++ b/src/mlpack/methods/dbscan/dbscan_impl.hpp @@ -19,9 +19,8 @@ namespace mlpack { /** * Construct the DBSCAN object with the given parameters. */ -template -DBSCAN::DBSCAN( +template +DBSCAN::DBSCAN( const ElemType epsilon, const size_t minPoints, const bool batchMode, @@ -40,9 +39,8 @@ DBSCAN::DBSCAN( * Performs DBSCAN clustering on the data, returning number of clusters * and also the centroid of each cluster. */ -template -size_t DBSCAN::Cluster( +template +size_t DBSCAN::Cluster( const MatType& data, MatType& centroids) { @@ -58,9 +56,8 @@ size_t DBSCAN::Cluster( * Performs DBSCAN clustering on the data, returning number of clusters, * the centroid of each cluster and also the list of cluster assignments. */ -template -size_t DBSCAN::Cluster( +template +size_t DBSCAN::Cluster( const MatType& data, arma::Row& assignments, MatType& centroids) @@ -94,9 +91,8 @@ size_t DBSCAN::Cluster( * Performs DBSCAN clustering on the data, returning the number of clusters and * also the list of cluster assignments. */ -template -size_t DBSCAN::Cluster( +template +size_t DBSCAN::Cluster( const MatType& data, arma::Row& assignments) { @@ -146,9 +142,8 @@ size_t DBSCAN::Cluster( * and can save on RAM usage. It may be slower than the batch search with a * dual-tree algorithm. */ -template -void DBSCAN::PointwiseCluster( +template +void DBSCAN::PointwiseCluster( const MatType& data, UnionFind& uf) { @@ -182,7 +177,7 @@ void DBSCAN::PointwiseCluster( visited[index] = true; // Do the range search for only this point. - rangeSearch.Search(data.col(index), RangeType(zero, epsilon), + rangeSearch.Search(data.col(index), RangeType(ElemType(0.0), epsilon), neighbors, distances); @@ -226,9 +221,8 @@ void DBSCAN::PointwiseCluster( * and also the list of cluster assignments. This can perform search in batch, * naive search). */ -template -void DBSCAN::BatchCluster( +template +void DBSCAN::BatchCluster( const MatType& data, UnionFind& uf) { @@ -237,7 +231,7 @@ void DBSCAN::BatchCluster( std::vector> distances; Log::Info << "Performing range search." << std::endl; rangeSearch.Train(data); - rangeSearch.Search(RangeType(zero, epsilon), neighbors, distances); + rangeSearch.Search(RangeType(ElemType(0.0), epsilon), neighbors, distances); Log::Info << "Range search complete." << std::endl; // See the description of the algorithm in `PointwiseCluster()`. The strategy diff --git a/src/mlpack/methods/range_search/range_search.hpp b/src/mlpack/methods/range_search/range_search.hpp index afd80c8fe1..d02b8705ff 100644 --- a/src/mlpack/methods/range_search/range_search.hpp +++ b/src/mlpack/methods/range_search/range_search.hpp @@ -46,7 +46,8 @@ class RangeSearch public: //! Convenience typedef. typedef TreeType Tree; - + //! The type of Matrix. + typedef MatType Mat; //! The type of element held in MatType. typedef typename MatType::elem_type ElemType; diff --git a/src/mlpack/tests/dbscan_test.cpp b/src/mlpack/tests/dbscan_test.cpp index 758f2870db..99751313da 100644 --- a/src/mlpack/tests/dbscan_test.cpp +++ b/src/mlpack/tests/dbscan_test.cpp @@ -230,8 +230,7 @@ TEST_CASE("Float32OutlierSingleModeTest", "[DBSCANTest]") EuclideanDistance, arma::Mat, FloatKDTree>, - OrderedPointSelection, - arma::Mat> d(0.1, 3, false); + OrderedPointSelection> d(0.1, 3, false); arma::Row assignments; const size_t clusters = d.Cluster(points, assignments);