[mlpack-git] master, mlpack-1.0.x: Minor changes to SortDistance(). (8607287)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:42:23 EST 2015
Repository : https://github.com/mlpack/mlpack
On branches: master,mlpack-1.0.x
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit 860728710d18e44c3ae15773f9e197a34dfc51e3
Author: Ryan Curtin <ryan at ratml.org>
Date: Thu Feb 6 20:16:28 2014 +0000
Minor changes to SortDistance().
>---------------------------------------------------------------
860728710d18e44c3ae15773f9e197a34dfc51e3
.../methods/neighbor_search/sort_policies/furthest_neighbor_sort.cpp | 3 ++-
.../methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp | 4 +++-
.../methods/neighbor_search/sort_policies/nearest_neighbor_sort.cpp | 3 ++-
.../methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp | 4 +++-
4 files changed, 10 insertions(+), 4 deletions(-)
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
index e33859f..aee4877 100644
--- a/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.cpp
+++ b/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.cpp
@@ -9,6 +9,7 @@
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 nearest neighbor. We only want to
@@ -18,7 +19,7 @@ size_t FurthestNeighborSort::SortDistance(const arma::vec& list,
// 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])
+ if (newDistance >= list[i] || indices[i] == (size_t() - 1))
return i;
// Control should never reach here.
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 04cf8d2..a267af2 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
@@ -36,7 +36,9 @@ class FurthestNeighborSort
* @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, double newDistance);
+ 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
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
index 8e68db0..4a75570 100644
--- a/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.cpp
+++ b/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.cpp
@@ -9,6 +9,7 @@
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
@@ -18,7 +19,7 @@ size_t NearestNeighborSort::SortDistance(const arma::vec& list,
// 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])
+ if (newDistance <= list[i] || indices[i] == (size_t() - 1))
return i;
// Control should never reach here.
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 b9d9f4d..5bc127b 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
@@ -40,7 +40,9 @@ class NearestNeighborSort
* @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, double newDistance);
+ 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
More information about the mlpack-git
mailing list