MLPACK  1.0.4
Public Member Functions | Private Member Functions | Private Attributes
mlpack::range::RangeSearch< MetricType, TreeType > Class Template Reference

The RangeSearch class is a template class for performing range searches. More...

List of all members.

Public Member Functions

 RangeSearch (const typename TreeType::Mat &referenceSet, const typename TreeType::Mat &querySet, const bool naive=false, const bool singleMode=false, const size_t leafSize=20, const MetricType metric=MetricType())
 Initialize the RangeSearch object with a different reference set and a query set.
 RangeSearch (const typename TreeType::Mat &referenceSet, const bool naive=false, const bool singleMode=false, const size_t leafSize=20, const MetricType metric=MetricType())
 Initialize the RangeSearch object with only a reference set, which will also be used as a query set.
 RangeSearch (TreeType *referenceTree, TreeType *queryTree, const typename TreeType::Mat &referenceSet, const typename TreeType::Mat &querySet, const bool singleMode=false, const MetricType metric=MetricType())
 Initialize the RangeSearch object with the given datasets and pre-constructed trees.
 RangeSearch (TreeType *referenceTree, const typename TreeType::Mat &referenceSet, const bool singleMode=false, const MetricType metric=MetricType())
 Initialize the RangeSearch object with the given reference dataset and pre-constructed tree.
 ~RangeSearch ()
 Destroy the RangeSearch object.
void Search (const math::Range &range, std::vector< std::vector< size_t > > &neighbors, std::vector< std::vector< double > > &distances)
 Search for all points in the given range, returning the results in the neighbors and distances objects.

Private Member Functions

void ComputeBaseCase (const TreeType *referenceNode, const TreeType *queryNode, const math::Range &range, std::vector< std::vector< size_t > > &neighbors, std::vector< std::vector< double > > &distances) const
 Compute the base case, when both referenceNode and queryNode are leaves containing points.
void DualTreeRecursion (const TreeType *referenceNode, const TreeType *queryNode, const math::Range &range, std::vector< std::vector< size_t > > &neighbors, std::vector< std::vector< double > > &distances)
 Perform the dual-tree recursion, which will recurse until the base case is necessary.
template<typename VecType >
void SingleTreeRecursion (const TreeType *referenceNode, const VecType &queryPoint, const size_t queryIndex, const math::Range &range, std::vector< size_t > &neighbors, std::vector< double > &distances)
 Perform the single-tree recursion, which will recurse down the reference tree to get the results for a single point.

Private Attributes

MetricType metric
 Instantiated distance metric.
bool naive
 If true, O(n^2) naive computation is used.
size_t numberOfPrunes
 The number of pruned nodes during computation.
std::vector< size_t > oldFromNewQueries
 Mappings to old query indices (used when this object builds trees).
std::vector< size_t > oldFromNewReferences
 Mappings to old reference indices (used when this object builds trees).
bool ownQueryTree
 Indicates ownership of the query tree (meaning we need to delete it).
bool ownReferenceTree
 Indicates ownership of the reference tree (meaning we need to delete it).
TreeType::Mat queryCopy
 Copy of query matrix; used when a tree is built internally.
const TreeType::Mat & querySet
 Query set (data should be accessed using this).
TreeType * queryTree
 Query tree (may be NULL).
TreeType::Mat referenceCopy
 Copy of reference matrix; used when a tree is built internally.
const TreeType::Mat & referenceSet
 Reference set (data should be accessed using this).
TreeType * referenceTree
 Reference tree.
bool singleMode
 If true, single-tree computation is used.

Detailed Description

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
class mlpack::range::RangeSearch< MetricType, TreeType >

The RangeSearch class is a template class for performing range searches.

Definition at line 41 of file range_search.hpp.


Constructor & Destructor Documentation

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
mlpack::range::RangeSearch< MetricType, TreeType >::RangeSearch ( const typename TreeType::Mat &  referenceSet,
const typename TreeType::Mat &  querySet,
const bool  naive = false,
const bool  singleMode = false,
const size_t  leafSize = 20,
const MetricType  metric = MetricType() 
)

Initialize the RangeSearch object with a different reference set and a query set.

Optionally, perform the computation in naive mode or single-tree mode, and set the leaf size used for tree-building. Additionally, an instantiated metric can be given, for cases where the distance metric holds data.

This method will copy the matrices to internal copies, which are rearranged during tree-building. You can avoid this extra copy by pre-constructing the trees and passing them using a different constructor.

Parameters:
referenceSetReference dataset.
querySetQuery dataset.
naiveWhether the computation should be done in O(n^2) naive mode.
singleModeWhether single-tree computation should be used (as opposed to dual-tree computation).
leafSizeThe leaf size to be used during tree construction.
metricInstantiated distance metric.
template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
mlpack::range::RangeSearch< MetricType, TreeType >::RangeSearch ( const typename TreeType::Mat &  referenceSet,
const bool  naive = false,
const bool  singleMode = false,
const size_t  leafSize = 20,
const MetricType  metric = MetricType() 
)

Initialize the RangeSearch object with only a reference set, which will also be used as a query set.

Optionally, perform the computation in naive mode or single-tree mode, and set the leaf size used for tree-building. Additionally an instantiated metric can be given, for cases where the distance metric holds data.

This method will copy the reference matrix to an internal copy, which is rearranged during tree-building. You can avoid this extra copy by pre-constructing the reference tree and passing it using a different constructor.

Parameters:
referenceSetReference dataset.
naiveWhether the computation should be done in O(n^2) naive mode.
singleModeWhether single-tree computation should be used (as opposed to dual-tree computation).
leafSizeThe leaf size to be used during tree construction.
metricInstantiated distance metric.
template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
mlpack::range::RangeSearch< MetricType, TreeType >::RangeSearch ( TreeType *  referenceTree,
TreeType *  queryTree,
const typename TreeType::Mat &  referenceSet,
const typename TreeType::Mat &  querySet,
const bool  singleMode = false,
const MetricType  metric = MetricType() 
)

Initialize the RangeSearch object with the given datasets and pre-constructed trees.

It is assumed that the points in referenceSet and querySet correspond to the points in referenceTree and queryTree, respectively. Optionally, choose to use single-tree mode. Naive mode is not available as an option for this constructor; instead, to run naive computation, construct a tree with all the points in one leaf (i.e. leafSize = number of points). Additionally, an instantiated distance metric can be given, for cases where the distance metric holds data.

There is no copying of the data matrices in this constructor (because tree-building is not necessary), so this is the constructor to use when copies absolutely must be avoided.

Note:
Because tree-building (at least with BinarySpaceTree) modifies the ordering of a matrix, be sure you pass the modified matrix to this object! In addition, mapping the points of the matrix back to their original indices is not done when this constructor is used.
Parameters:
referenceTreePre-built tree for reference points.
queryTreePre-built tree for query points.
referenceSetSet of reference points corresponding to referenceTree.
querySetSet of query points corresponding to queryTree.
singleModeWhether single-tree computation should be used (as opposed to dual-tree computation).
metricInstantiated distance metric.
template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
mlpack::range::RangeSearch< MetricType, TreeType >::RangeSearch ( TreeType *  referenceTree,
const typename TreeType::Mat &  referenceSet,
const bool  singleMode = false,
const MetricType  metric = MetricType() 
)

Initialize the RangeSearch object with the given reference dataset and pre-constructed tree.

It is assumed that the points in referenceSet correspond to the points in referenceTree. Optionally, choose to use single-tree mode. Naive mode is not available as an option for this constructor; instead, to run naive computation, construct a tree with all the points in one leaf (i.e. leafSize = number of points). Additionally, an instantiated distance metric can be given, for the case where the distance metric holds data.

There is no copying of the data matrices in this constructor (because tree-building is not necessary), so this is the constructor to use when copies absolutely must be avoided.

Note:
Because tree-building (at least with BinarySpaceTree) modifies the ordering of a matrix, be sure you pass the modified matrix to this object! In addition, mapping the points of the matrix back to their original indices is not done when this constructor is used.
Parameters:
referenceTreePre-built tree for reference points.
referenceSetSet of reference points corresponding to referenceTree.
singleModeWhether single-tree computation should be used (as opposed to dual-tree computation).
metricInstantiated distance metric.
template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
mlpack::range::RangeSearch< MetricType, TreeType >::~RangeSearch ( )

Destroy the RangeSearch object.

If trees were created, they will be deleted.


Member Function Documentation

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
void mlpack::range::RangeSearch< MetricType, TreeType >::ComputeBaseCase ( const TreeType *  referenceNode,
const TreeType *  queryNode,
const math::Range range,
std::vector< std::vector< size_t > > &  neighbors,
std::vector< std::vector< double > > &  distances 
) const [private]

Compute the base case, when both referenceNode and queryNode are leaves containing points.

Parameters:
referenceNodeReference node (must be a leaf).
queryNodeQuery node (must be a leaf).
rangeRange of distances to search for.
neighborsObject holding list of neighbors.
distancesObject holding list of distances.
template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
void mlpack::range::RangeSearch< MetricType, TreeType >::DualTreeRecursion ( const TreeType *  referenceNode,
const TreeType *  queryNode,
const math::Range range,
std::vector< std::vector< size_t > > &  neighbors,
std::vector< std::vector< double > > &  distances 
) [private]

Perform the dual-tree recursion, which will recurse until the base case is necessary.

Parameters:
referenceNodeReference node.
queryNodeQuery node.
rangeRange of distances to search for.
neighborsObject holding list of neighbors.
distancesObject holding list of distances.
template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
void mlpack::range::RangeSearch< MetricType, TreeType >::Search ( const math::Range range,
std::vector< std::vector< size_t > > &  neighbors,
std::vector< std::vector< double > > &  distances 
)

Search for all points in the given range, returning the results in the neighbors and distances objects.

Each entry in the external vector corresponds to a query point. Each of these entries holds a vector which contains the indices and distances of the reference points falling into the given range.

That is:

  • neighbors.size() and distances.size() both equal the number of query points.
  • neighbors[i] contains the indices of all the points in the reference set which have distances inside the given range to query point i.
  • distances[i] contains all of the distances corresponding to the indices contained in neighbors[i].
  • neighbors[i] and distances[i] are not sorted in any particular order.
Parameters:
rangeRange of distances in which to search.
neighborsObject which will hold the list of neighbors for each point which fell into the given range, for each query point.
distancesObject which will hold the list of distances for each point which fell into the given range, for each query point.
template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
template<typename VecType >
void mlpack::range::RangeSearch< MetricType, TreeType >::SingleTreeRecursion ( const TreeType *  referenceNode,
const VecType &  queryPoint,
const size_t  queryIndex,
const math::Range range,
std::vector< size_t > &  neighbors,
std::vector< double > &  distances 
) [private]

Perform the single-tree recursion, which will recurse down the reference tree to get the results for a single point.

Parameters:
referenceNodeReference node.
queryPointPoint to query for.
queryIndexIndex of query node.
rangeRange of distances to search for.
neighborsObject holding list of neighbors.
distancesObject holding list of distances.

Member Data Documentation

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
MetricType mlpack::range::RangeSearch< MetricType, TreeType >::metric [private]

Instantiated distance metric.

Definition at line 282 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
bool mlpack::range::RangeSearch< MetricType, TreeType >::naive [private]

If true, O(n^2) naive computation is used.

Definition at line 277 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
size_t mlpack::range::RangeSearch< MetricType, TreeType >::numberOfPrunes [private]

The number of pruned nodes during computation.

Definition at line 285 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
std::vector<size_t> mlpack::range::RangeSearch< MetricType, TreeType >::oldFromNewQueries [private]

Mappings to old query indices (used when this object builds trees).

Definition at line 269 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
std::vector<size_t> mlpack::range::RangeSearch< MetricType, TreeType >::oldFromNewReferences [private]

Mappings to old reference indices (used when this object builds trees).

Definition at line 267 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
bool mlpack::range::RangeSearch< MetricType, TreeType >::ownQueryTree [private]

Indicates ownership of the query tree (meaning we need to delete it).

Definition at line 274 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
bool mlpack::range::RangeSearch< MetricType, TreeType >::ownReferenceTree [private]

Indicates ownership of the reference tree (meaning we need to delete it).

Definition at line 272 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
TreeType::Mat mlpack::range::RangeSearch< MetricType, TreeType >::queryCopy [private]

Copy of query matrix; used when a tree is built internally.

Definition at line 254 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
const TreeType::Mat& mlpack::range::RangeSearch< MetricType, TreeType >::querySet [private]

Query set (data should be accessed using this).

Definition at line 259 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
TreeType* mlpack::range::RangeSearch< MetricType, TreeType >::queryTree [private]

Query tree (may be NULL).

Definition at line 264 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
TreeType::Mat mlpack::range::RangeSearch< MetricType, TreeType >::referenceCopy [private]

Copy of reference matrix; used when a tree is built internally.

Definition at line 252 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
const TreeType::Mat& mlpack::range::RangeSearch< MetricType, TreeType >::referenceSet [private]

Reference set (data should be accessed using this).

Definition at line 257 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
TreeType* mlpack::range::RangeSearch< MetricType, TreeType >::referenceTree [private]

Reference tree.

Definition at line 262 of file range_search.hpp.

template<typename MetricType = mlpack::metric::SquaredEuclideanDistance, typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>, tree::EmptyStatistic>>
bool mlpack::range::RangeSearch< MetricType, TreeType >::singleMode [private]

If true, single-tree computation is used.

Definition at line 279 of file range_search.hpp.


The documentation for this class was generated from the following file: