shark::KDTree< InputT > Class Template Reference

KD-tree, a binary space-partitioning tree. More...

#include <shark/Models/Trees/KDTree.h>

+ Inheritance diagram for shark::KDTree< InputT >:

Public Member Functions

 KDTree (Data< InputT > const &dataset, TreeConstruction tc=TreeConstruction())
 
double lower (std::size_t dim) const
 
double upper (std::size_t dim) const
 
double squaredDistanceLowerBound (InputT const &reference) const
 
- Public Member Functions inherited from shark::BinaryTree< InputT >
 BinaryTree (std::size_t size)
 Root node constructor: build the tree from data. More...
 
virtual ~BinaryTree ()
 Destroy the tree and its internal data structures. More...
 
BinaryTreeparent ()
 parent node More...
 
const BinaryTreeparent () const
 parent node More...
 
bool hasChildren () const
 
bool isLeaf () const
 
BinaryTreeleft ()
 "left" sub-node of the binary tree More...
 
const BinaryTreeleft () const
 "left" sub-node of the binary tree More...
 
BinaryTreeright ()
 "right" sub-node of the binary tree More...
 
const BinaryTreeright () const
 "right" sub-node of the binary tree More...
 
std::size_t size () const
 number of points inside the space represented by this node More...
 
std::size_t nodes () const
 number of sub-nodes in this tree (including the node itself) More...
 
std::size_t index (std::size_t point) const
 
double distanceFromPlane (value_type const &point) const
 Function describing the separation of space. More...
 
double threshold () const
 Separation threshold. More...
 
bool isLeft (value_type const &point) const
 
bool isRight (value_type const &point) const
 
virtual AbstractKernelFunction< value_type > const * kernel () const
 If the tree uses a kernel metric, returns a pointer to the kernel object, else NULL. More...
 

Protected Member Functions

 KDTree (KDTree *parent, std::size_t *list, std::size_t size)
 (internal) construction of a non-root node More...
 
template<class Range >
void buildTree (TreeConstruction tc, Range &points)
 
template<class Range >
std::size_t calculateCuttingDimension (Range const &points) const
 Calculate the dimension which should be cut by this node. More...
 
double funct (InputT const &reference) const
 
- Protected Member Functions inherited from shark::BinaryTree< InputT >
 BinaryTree (BinaryTree *parent, std::size_t *list, std::size_t size)
 Sub-node constructor. More...
 
template<class Range1 , class Range2 >
Range2::iterator splitList (Range1 &values, Range2 &points)
 Split the data in the point list and calculate the treshold accordingly. More...
 

Protected Attributes

std::size_t m_cutDim
 split/cut dimension of this node More...
 
- Protected Attributes inherited from shark::BinaryTree< InputT >
BinaryTreemep_parent
 parent node More...
 
BinaryTreemp_left
 "left" child node More...
 
BinaryTreemp_right
 "right" child node More...
 
std::size_t * mp_indexList
 list of indices to points in the dataset More...
 
std::size_t m_size
 number of points in this node More...
 
std::size_t m_nodes
 number of nodes in the sub-tree represented by this node More...
 
double m_threshold
 threshold for the separating function More...
 

Detailed Description

template<class InputT>
class shark::KDTree< InputT >

KD-tree, a binary space-partitioning tree.

KD-tree data structure for efficient nearest neighbor searches in low-dimensional spaces. Low-dimensional means << 10 dimensions.
The tree is constructed from data by splitting the dimension with largest extent (in the data covered, not space represented by the cell), recursively. An approximate median is used as the cutting point, where the maximal number of points used to estimate the median can be controlled with the template parameter MedianAccuracy.
The bucket size for the tree is aleays one, such that there is a unique point in each leaf cell.

Definition at line 70 of file KDTree.h.

Constructor & Destructor Documentation

◆ KDTree() [1/2]

template<class InputT>
shark::KDTree< InputT >::KDTree ( Data< InputT > const &  dataset,
TreeConstruction  tc = TreeConstruction() 
)
inline

Construct the tree from data. It is assumed that the container exceeds the lifetime of the KDTree (which holds only references to the points), and that the memory locations of the points remain unchanged.

Definition at line 82 of file KDTree.h.

References shark::KDTree< InputT >::buildTree(), shark::BinaryTree< InputT >::m_size, and shark::BinaryTree< InputT >::mp_indexList.

◆ KDTree() [2/2]

template<class InputT>
shark::KDTree< InputT >::KDTree ( KDTree< InputT > *  parent,
std::size_t *  list,
std::size_t  size 
)
inlineprotected

(internal) construction of a non-root node

Definition at line 190 of file KDTree.h.

Member Function Documentation

◆ buildTree()

template<class InputT>
template<class Range >
void shark::KDTree< InputT >::buildTree ( TreeConstruction  tc,
Range &  points 
)
inlineprotected

◆ calculateCuttingDimension()

template<class InputT>
template<class Range >
std::size_t shark::KDTree< InputT >::calculateCuttingDimension ( Range const &  points) const
inlineprotected

Calculate the dimension which should be cut by this node.

The KD-Tree calculates the Axis-Aligned-Bounding-Box surrounding the points and splits the longest dimension

Definition at line 243 of file KDTree.h.

References shark::BinaryTree< InputT >::m_size.

Referenced by shark::KDTree< InputT >::buildTree().

◆ funct()

template<class InputT>
double shark::KDTree< InputT >::funct ( InputT const &  reference) const
inlineprotectedvirtual

Function describing the separating hyperplane as its zero set. It is guaranteed that the gradient has norm one, thus the absolute value of the function indicates distance from the hyperplane.

Implements shark::BinaryTree< InputT >.

Definition at line 285 of file KDTree.h.

References shark::KDTree< InputT >::m_cutDim.

◆ lower()

template<class InputT>
double shark::KDTree< InputT >::lower ( std::size_t  dim) const
inline

◆ squaredDistanceLowerBound()

template<class InputT>
double shark::KDTree< InputT >::squaredDistanceLowerBound ( InputT const &  reference) const
inlinevirtual
Compute the squared Euclidean distance of this cell to the given reference point, or alternatively a lower bound on this value.
In the case of the kd-tree the computation is exact, however, only a lower bound is required in general, and other space partitioning trees used in the future may only be able to provide a lower bound, at least with reasonable computational efforts.

Implements shark::BinaryTree< InputT >.

Definition at line 137 of file KDTree.h.

References shark::BinaryTree< InputT >::index(), shark::BinaryTree< InputT >::isLeaf(), shark::KDTree< InputT >::lower(), shark::KDTree< InputT >::m_cutDim, shark::BinaryTree< InputT >::m_nodes, shark::BinaryTree< InputT >::m_size, shark::BinaryTree< InputT >::mep_parent, shark::BinaryTree< InputT >::mp_indexList, shark::BinaryTree< InputT >::mp_left, shark::BinaryTree< InputT >::mp_right, shark::BinaryTree< InputT >::size(), shark::sqr(), shark::BinaryTree< InputT >::threshold(), and shark::KDTree< InputT >::upper().

◆ upper()

template<class InputT>
double shark::KDTree< InputT >::upper ( std::size_t  dim) const
inline

Member Data Documentation

◆ m_cutDim

template<class InputT>
std::size_t shark::KDTree< InputT >::m_cutDim
protected

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