TreeTraits< TreeType > Class Template Reference

The TreeTraits class provides compile-time information on the characteristics of a given tree type. More...

Static Public Attributes

static const bool BinaryTree = false
 This is true if the tree always has only two children. More...

 
static const bool FirstPointIsCentroid = false
 This is true if the first point of each node is the centroid of its bound. More...

 
static const bool HasDuplicatedPoints = false
 This is true if a point can be included in more than one node. More...

 
static const bool HasOverlappingChildren = true
 This is true if the subspaces represented by the children of a node can overlap. More...

 
static const bool HasSelfChildren = false
 This is true if the points contained in the first child of a node (Child(0)) are also contained in that node. More...

 
static const bool RearrangesDataset = false
 This is true if the tree rearranges points in the dataset when it is built. More...

 
static const bool UniqueNumDescendants = true
 This is true if the NumDescendants() method doesn't include duplicated points. More...

 

Detailed Description


template
<
typename
TreeType
>

class mlpack::tree::TreeTraits< TreeType >

The TreeTraits class provides compile-time information on the characteristics of a given tree type.

These include traits such as whether or not a node knows the distance to its parent node, or whether or not the subspaces represented by children can overlap.

These traits can be used for static compile-time optimization:

// This if statement will be optimized out at compile time!
{
// Do a simpler computation because no children overlap.
}
else
{
// Do the full, complex calculation.
}

The traits can also be used in conjunction with SFINAE to write specialized versions of functions:

template<typename TreeType>
void Compute(TreeType& node,
{
// Computation where special dataset-rearranging tree constructor is
// called.
}
template<typename TreeType>
void Compute(TreeType& node,
{
// Computation where normal tree constructor is called.
}

In those two examples, the std::enable_if_t<> class takes a boolean template parameter which allows that function to be called when the boolean is true.

Each trait must be a static const value and not a function; only const values can be used as template parameters (or constexprs can be used too). By default (the unspecialized implementation of TreeTraits), each parameter is set to make as few assumptions about the tree as possible; so, even if TreeTraits is not specialized for a particular tree type, tree-based algorithms should still work.

When you write your own tree, you must specialize the TreeTraits class to your tree type and set the corresponding values appropriately. See mlpack/core/tree/binary_space_tree/traits.hpp for an example.

Definition at line 77 of file tree_traits.hpp.

Member Data Documentation

◆ BinaryTree

const bool BinaryTree = false
static

This is true if the tree always has only two children.

Definition at line 110 of file tree_traits.hpp.

◆ FirstPointIsCentroid

const bool FirstPointIsCentroid = false
static

This is true if the first point of each node is the centroid of its bound.

Definition at line 94 of file tree_traits.hpp.

◆ HasDuplicatedPoints

const bool HasDuplicatedPoints = false
static

This is true if a point can be included in more than one node.

Definition at line 89 of file tree_traits.hpp.

◆ HasOverlappingChildren

const bool HasOverlappingChildren = true
static

This is true if the subspaces represented by the children of a node can overlap.

Definition at line 84 of file tree_traits.hpp.

◆ HasSelfChildren

const bool HasSelfChildren = false
static

This is true if the points contained in the first child of a node (Child(0)) are also contained in that node.

Definition at line 100 of file tree_traits.hpp.

◆ RearrangesDataset

const bool RearrangesDataset = false
static

This is true if the tree rearranges points in the dataset when it is built.

Definition at line 105 of file tree_traits.hpp.

◆ UniqueNumDescendants

const bool UniqueNumDescendants = true
static

This is true if the NumDescendants() method doesn't include duplicated points.

Definition at line 116 of file tree_traits.hpp.


The documentation for this class was generated from the following file:
  • /home/ryan/src/mlpack.org/_src/mlpack-git/src/mlpack/core/tree/tree_traits.hpp