[mlpack-git] master: Remove unnecessary method from SortPolicies. (70c67cd)
gitdub at mlpack.org
gitdub at mlpack.org
Tue Jul 26 21:22:08 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/ef51b032f275266f781d42b9bd0aa50aa26a3077...8522b04c3d9a82fb7e964bafd72e70f0cd30bf4b
>---------------------------------------------------------------
commit 70c67cdd3b5d609fc1a075d49d68620a99855741
Author: MarcosPividori <marcos.pividori at gmail.com>
Date: Fri Jul 22 01:44:21 2016 -0300
Remove unnecessary method from SortPolicies.
>---------------------------------------------------------------
70c67cdd3b5d609fc1a075d49d68620a99855741
src/mlpack/methods/neighbor_search/CMakeLists.txt | 2 -
.../sort_policies/furthest_neighbor_sort.cpp | 27 --------
.../sort_policies/furthest_neighbor_sort.hpp | 18 ------
.../sort_policies/nearest_neighbor_sort.cpp | 27 --------
.../sort_policies/nearest_neighbor_sort.hpp | 18 ------
src/mlpack/tests/sort_policy_test.cpp | 72 ----------------------
6 files changed, 164 deletions(-)
diff --git a/src/mlpack/methods/neighbor_search/CMakeLists.txt b/src/mlpack/methods/neighbor_search/CMakeLists.txt
index 4d0d44b..1c51ce4 100644
--- a/src/mlpack/methods/neighbor_search/CMakeLists.txt
+++ b/src/mlpack/methods/neighbor_search/CMakeLists.txt
@@ -9,10 +9,8 @@ set(SOURCES
ns_model.hpp
ns_model_impl.hpp
sort_policies/nearest_neighbor_sort.hpp
- sort_policies/nearest_neighbor_sort.cpp
sort_policies/nearest_neighbor_sort_impl.hpp
sort_policies/furthest_neighbor_sort.hpp
- sort_policies/furthest_neighbor_sort.cpp
sort_policies/furthest_neighbor_sort_impl.hpp
typedef.hpp
unmap.hpp
diff --git a/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.cpp b/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.cpp
deleted file mode 100644
index f58e4d2..0000000
--- a/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-/***
- * @file furthest_neighbor_sort.cpp
- * @author Ryan Curtin
- *
- * Implementation of the simple FurthestNeighborSort policy class.
- */
-#include "furthest_neighbor_sort.hpp"
-
-using namespace mlpack::neighbor;
-
-size_t FurthestNeighborSort::SortDistance(const arma::vec& list,
- const arma::Col<size_t>& indices,
- double newDistance)
-{
- // The first element in the list is the furthest neighbor. We only want to
- // insert if the new distance is greater than the last element in the list.
- if (newDistance < list[list.n_elem - 1])
- return (size_t() - 1); // Do not insert.
-
- // Search from the beginning. This may not be the best way.
- for (size_t i = 0; i < list.n_elem; i++)
- if (newDistance >= list[i] || indices[i] == (size_t() - 1))
- return i;
-
- // Control should never reach here.
- return (size_t() - 1);
-}
diff --git a/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp b/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp
index a69c167..09c3d96 100644
--- a/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp
+++ b/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp
@@ -23,24 +23,6 @@ class FurthestNeighborSort
{
public:
/**
- * Return the index in the vector where the new distance should be inserted,
- * or size_t() - 1 if it should not be inserted (i.e. if it is not any better
- * than any of the existing points in the list). The list should be sorted
- * such that the best point is the first in the list. The actual insertion is
- * not performed.
- *
- * @param list Vector of existing distance points, sorted such that the best
- * point is the first in the list.
- * @param new_distance Distance to try to insert.
- *
- * @return size_t containing the position to insert into, or (size_t() - 1)
- * if the new distance should not be inserted.
- */
- static size_t SortDistance(const arma::vec& list,
- const arma::Col<size_t>& indices,
- double newDistance);
-
- /**
* Return whether or not value is "better" than ref. In this case, that means
* that the value is greater than or equal to the reference.
*
diff --git a/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.cpp b/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.cpp
deleted file mode 100644
index 4a75570..0000000
--- a/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * @file nearest_neighbor_sort.cpp
- * @author Ryan Curtin
- *
- * Implementation of the simple NearestNeighborSort policy class.
- */
-#include "nearest_neighbor_sort.hpp"
-
-using namespace mlpack::neighbor;
-
-size_t NearestNeighborSort::SortDistance(const arma::vec& list,
- const arma::Col<size_t>& indices,
- double newDistance)
-{
- // The first element in the list is the nearest neighbor. We only want to
- // insert if the new distance is less than the last element in the list.
- if (newDistance > list[list.n_elem - 1])
- return (size_t() - 1); // Do not insert.
-
- // Search from the beginning. This may not be the best way.
- for (size_t i = 0; i < list.n_elem; i++)
- if (newDistance <= list[i] || indices[i] == (size_t() - 1))
- return i;
-
- // Control should never reach here.
- return (size_t() - 1);
-}
diff --git a/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp b/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp
index 42a08b0..5ccce6d 100644
--- a/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp
+++ b/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp
@@ -27,24 +27,6 @@ class NearestNeighborSort
{
public:
/**
- * Return the index in the vector where the new distance should be inserted,
- * or (size_t() - 1) if it should not be inserted (i.e. if it is not any
- * better than any of the existing points in the list). The list should be
- * sorted such that the best point is the first in the list. The actual
- * insertion is not performed.
- *
- * @param list Vector of existing distance points, sorted such that the best
- * point is first in the list.
- * @param new_distance Distance to try to insert
- *
- * @return size_t containing the position to insert into, or (size_t() - 1)
- * if the new distance should not be inserted.
- */
- static size_t SortDistance(const arma::vec& list,
- const arma::Col<size_t>& indices,
- double newDistance);
-
- /**
* Return whether or not value is "better" than ref. In this case, that means
* that the value is less than or equal to the reference.
*
diff --git a/src/mlpack/tests/sort_policy_test.cpp b/src/mlpack/tests/sort_policy_test.cpp
index e336a76..5cf4b56 100644
--- a/src/mlpack/tests/sort_policy_test.cpp
+++ b/src/mlpack/tests/sort_policy_test.cpp
@@ -57,42 +57,6 @@ BOOST_AUTO_TEST_CASE(NnsIsBetterNotStrict)
}
/**
- * A simple test case of where to insert when all the values in the list are
- * DBL_MAX.
- */
-BOOST_AUTO_TEST_CASE(NnsSortDistanceAllDblMax)
-{
- arma::vec list(5);
- list.fill(DBL_MAX);
- arma::Col<size_t> indices(5);
- indices.fill(0);
-
- // Should be inserted at the head of the list.
- BOOST_REQUIRE(NearestNeighborSort::SortDistance(list, indices, 5.0) == 0);
-}
-
-/**
- * Another test case, where we are just putting the new value in the middle of
- * the list.
- */
-BOOST_AUTO_TEST_CASE(NnsSortDistance2)
-{
- arma::vec list(3);
- list[0] = 0.66;
- list[1] = 0.89;
- list[2] = 1.14;
- arma::Col<size_t> indices(3);
- indices.fill(0);
-
- // Run a couple possibilities through.
- BOOST_REQUIRE(NearestNeighborSort::SortDistance(list, indices, 0.61) == 0);
- BOOST_REQUIRE(NearestNeighborSort::SortDistance(list, indices, 0.76) == 1);
- BOOST_REQUIRE(NearestNeighborSort::SortDistance(list, indices, 0.99) == 2);
- BOOST_REQUIRE(NearestNeighborSort::SortDistance(list, indices, 1.22) ==
- (size_t() - 1));
-}
-
-/**
* Very simple sanity check to ensure that bounds are working alright. We will
* use a one-dimensional bound for simplicity.
*/
@@ -219,42 +183,6 @@ BOOST_AUTO_TEST_CASE(FnsIsBetterNotStrict)
}
/**
- * A simple test case of where to insert when all the values in the list are
- * 0.
- */
-BOOST_AUTO_TEST_CASE(FnsSortDistanceAllZero)
-{
- arma::vec list(5);
- list.fill(0);
- arma::Col<size_t> indices(5);
- indices.fill(0);
-
- // Should be inserted at the head of the list.
- BOOST_REQUIRE(FurthestNeighborSort::SortDistance(list, indices, 5.0) == 0);
-}
-
-/**
- * Another test case, where we are just putting the new value in the middle of
- * the list.
- */
-BOOST_AUTO_TEST_CASE(FnsSortDistance2)
-{
- arma::vec list(3);
- list[0] = 1.14;
- list[1] = 0.89;
- list[2] = 0.66;
- arma::Col<size_t> indices(3);
- indices.fill(0);
-
- // Run a couple possibilities through.
- BOOST_REQUIRE(FurthestNeighborSort::SortDistance(list, indices, 1.22) == 0);
- BOOST_REQUIRE(FurthestNeighborSort::SortDistance(list, indices, 0.93) == 1);
- BOOST_REQUIRE(FurthestNeighborSort::SortDistance(list, indices, 0.68) == 2);
- BOOST_REQUIRE(FurthestNeighborSort::SortDistance(list, indices, 0.62) ==
- (size_t() - 1));
-}
-
-/**
* Very simple sanity check to ensure that bounds are working alright. We will
* use a one-dimensional bound for simplicity.
*/
More information about the mlpack-git
mailing list