MLPACK  1.0.7
Static Public Attributes | List of all members
mlpack::tree::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 FirstPointIsCentroid = false
 This is true if Point(0) is the centroid of the 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 HasParentDistance = false
 This is true if TreeType::ParentDistance() exists and works. 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...
 

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!
* if (TreeTraits<TreeType>::HasOverlappingChildren == false)
* {
* // 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,
* boost::enable_if<
* TreeTraits<TreeType>::HasParentDistance>::type*)
* {
* // Computation with TreeType::ParentDistance().
* }
*
* template<typename TreeType>
* void Compute(TreeType& node,
* boost::enable_if<
* !TreeTraits<TreeType>::HasParentDistance>::type*)
* {
* // Computation without TreeType::ParentDistance().
* }
*

In those two examples, the boost::enable_if<> 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 (with the exception of constexprs, which are a C++11 feature; but MLPACK is not using C++11). 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 87 of file tree_traits.hpp.

Member Data Documentation

template<typename TreeType >
const bool mlpack::tree::TreeTraits< TreeType >::FirstPointIsCentroid = false
static

This is true if Point(0) is the centroid of the node.

Definition at line 106 of file tree_traits.hpp.

template<typename TreeType >
const bool mlpack::tree::TreeTraits< TreeType >::HasOverlappingChildren = true
static

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

Definition at line 101 of file tree_traits.hpp.

template<typename TreeType >
const bool mlpack::tree::TreeTraits< TreeType >::HasParentDistance = false
static

This is true if TreeType::ParentDistance() exists and works.

The ParentDistance() function returns the distance between the center of a node and the center of its parent.

Definition at line 95 of file tree_traits.hpp.

template<typename TreeType >
const bool mlpack::tree::TreeTraits< TreeType >::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 112 of file tree_traits.hpp.


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