neighbor_search.hpp
Go to the documentation of this file.00001
00023 #ifndef __MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP
00024 #define __MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP
00025
00026 #include <mlpack/core.hpp>
00027 #include <vector>
00028 #include <string>
00029
00030 #include <mlpack/core/tree/binary_space_tree.hpp>
00031
00032 #include <mlpack/core/metrics/lmetric.hpp>
00033 #include "neighbor_search_stat.hpp"
00034 #include "sort_policies/nearest_neighbor_sort.hpp"
00035
00036 namespace mlpack {
00037 namespace neighbor {
00040
00059 template<typename SortPolicy = NearestNeighborSort,
00060 typename MetricType = mlpack::metric::SquaredEuclideanDistance,
00061 typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>,
00062 NeighborSearchStat<SortPolicy> > >
00063 class NeighborSearch
00064 {
00065 public:
00086 NeighborSearch(const typename TreeType::Mat& referenceSet,
00087 const typename TreeType::Mat& querySet,
00088 const bool naive = false,
00089 const bool singleMode = false,
00090 const size_t leafSize = 20,
00091 const MetricType metric = MetricType());
00092
00114 NeighborSearch(const typename TreeType::Mat& referenceSet,
00115 const bool naive = false,
00116 const bool singleMode = false,
00117 const size_t leafSize = 20,
00118 const MetricType metric = MetricType());
00119
00149 NeighborSearch(TreeType* referenceTree,
00150 TreeType* queryTree,
00151 const typename TreeType::Mat& referenceSet,
00152 const typename TreeType::Mat& querySet,
00153 const bool singleMode = false,
00154 const MetricType metric = MetricType());
00155
00183 NeighborSearch(TreeType* referenceTree,
00184 const typename TreeType::Mat& referenceSet,
00185 const bool singleMode = false,
00186 const MetricType metric = MetricType());
00187
00188
00193 ~NeighborSearch();
00194
00207 void Search(const size_t k,
00208 arma::Mat<size_t>& resultingNeighbors,
00209 arma::mat& distances);
00210
00211 private:
00214 arma::mat referenceCopy;
00216 arma::mat queryCopy;
00217
00219 const arma::mat& referenceSet;
00221 const arma::mat& querySet;
00222
00224 TreeType* referenceTree;
00226 TreeType* queryTree;
00227
00229 bool treeOwner;
00231 bool hasQuerySet;
00232
00234 bool naive;
00236 bool singleMode;
00237
00239 MetricType metric;
00240
00242 std::vector<size_t> oldFromNewReferences;
00244 std::vector<size_t> oldFromNewQueries;
00245
00247 size_t numberOfPrunes;
00248 };
00249
00250 };
00251 };
00252
00253
00254 #include "neighbor_search_impl.hpp"
00255
00256
00257 #include "typedef.hpp"
00258
00259 #endif