mlpack
Public Types | Public Member Functions | List of all members
mlpack::det::DTree< MatType, TagType > Class Template Reference

A density estimation tree is similar to both a decision tree and a space partitioning tree (like a kd-tree). More...

#include <dtree.hpp>

Public Types

typedef MatType::elem_type ElemType
 The actual, underlying type we're working with.
 
typedef MatType::vec_type VecType
 The type of vector we are using.
 
typedef arma::Col< ElemTypeStatType
 The statistic type we are holding.
 

Public Member Functions

 DTree ()
 Create an empty density estimation tree.
 
 DTree (const DTree &obj)
 Create a tree that is the copy of the given tree. More...
 
DTreeoperator= (const DTree &obj)
 Copy the given tree. More...
 
 DTree (DTree &&obj)
 Create a tree by taking ownership of another tree (move constructor). More...
 
DTreeoperator= (DTree &&obj)
 Take ownership of the given tree (move operator). More...
 
 DTree (const StatType &maxVals, const StatType &minVals, const size_t totalPoints)
 Create a density estimation tree with the given bounds and the given number of total points. More...
 
 DTree (MatType &data)
 Create a density estimation tree on the given data. More...
 
 DTree (const StatType &maxVals, const StatType &minVals, const size_t start, const size_t end, const double logNegError)
 Create a child node of a density estimation tree given the bounding box specified by maxVals and minVals, using the size given in start and end and the specified error. More...
 
 DTree (const StatType &maxVals, const StatType &minVals, const size_t totalPoints, const size_t start, const size_t end)
 Create a child node of a density estimation tree given the bounding box specified by maxVals and minVals, using the size given in start and end, and calculating the error with the total number of points given. More...
 
 ~DTree ()
 Clean up memory allocated by the tree.
 
double Grow (MatType &data, arma::Col< size_t > &oldFromNew, const bool useVolReg=false, const size_t maxLeafSize=10, const size_t minLeafSize=5)
 Greedily expand the tree. More...
 
double PruneAndUpdate (const double oldAlpha, const size_t points, const bool useVolReg=false)
 Perform alpha pruning on a tree. More...
 
double ComputeValue (const VecType &query) const
 Compute the logarithm of the density estimate of a given query point. More...
 
TagType TagTree (const TagType &tag=0, bool everyNode=false)
 Index the buckets for possible usage later; this results in every leaf in the tree having a specific tag (accessible with BucketTag()). More...
 
TagType FindBucket (const VecType &query) const
 Return the tag of the leaf containing the query. More...
 
void ComputeVariableImportance (arma::vec &importances) const
 Compute the variable importance of each dimension in the learned tree. More...
 
double LogNegativeError (const size_t totalPoints) const
 Compute the log-negative-error for this point, given the total number of points in the dataset. More...
 
bool WithinRange (const VecType &query) const
 Return whether a query point is within the range of this node.
 
size_t Start () const
 Return the starting index of points contained in this node.
 
size_t End () const
 Return the first index of a point not contained in this node.
 
size_t SplitDim () const
 Return the split dimension of this node.
 
ElemType SplitValue () const
 Return the split value of this node.
 
double LogNegError () const
 Return the log negative error of this node.
 
double SubtreeLeavesLogNegError () const
 Return the log negative error of all descendants of this node.
 
size_t SubtreeLeaves () const
 Return the number of leaves which are descendants of this node.
 
double Ratio () const
 Return the ratio of points in this node to the points in the whole dataset. More...
 
double LogVolume () const
 Return the inverse of the volume of this node.
 
DTreeLeft () const
 Return the left child.
 
DTreeRight () const
 Return the right child.
 
bool Root () const
 Return whether or not this is the root of the tree.
 
double AlphaUpper () const
 Return the upper part of the alpha sum.
 
TagType BucketTag () const
 Return the current bucket's ID, if leaf, or -1 otherwise.
 
size_t NumChildren () const
 Return the number of children in this node.
 
DTreeChild (const size_t child) const
 Return the specified child (0 will be left, 1 will be right). More...
 
DTree *& ChildPtr (const size_t child)
 
const StatTypeMaxVals () const
 Return the maximum values.
 
const StatTypeMinVals () const
 Return the minimum values.
 
template<typename Archive >
void serialize (Archive &ar, const uint32_t)
 Serialize the density estimation tree.
 

Detailed Description

template<typename MatType = arma::mat, typename TagType = int>
class mlpack::det::DTree< MatType, TagType >

A density estimation tree is similar to both a decision tree and a space partitioning tree (like a kd-tree).

Each leaf represents a constant-density hyper-rectangle. The tree is constructed in such a way as to minimize the integrated square error between the probability distribution of the tree and the observed probability distribution of the data. Because the tree is similar to a decision tree, the density estimation tree can provide very fast density estimates for a given point.

For more information, see the following paper:

@incollection{ram2011,
author = {Ram, Parikshit and Gray, Alexander G.},
title = {Density estimation trees},
booktitle = {{Proceedings of the 17th ACM SIGKDD International Conference
on Knowledge Discovery and Data Mining}},
series = {KDD '11},
year = {2011},
pages = {627--635}
}

Constructor & Destructor Documentation

◆ DTree() [1/6]

template<typename MatType , typename TagType >
DTree::DTree ( const DTree< MatType, TagType > &  obj)

Create a tree that is the copy of the given tree.

Parameters
objTree to copy.

◆ DTree() [2/6]

template<typename MatType , typename TagType >
DTree::DTree ( DTree< MatType, TagType > &&  obj)

Create a tree by taking ownership of another tree (move constructor).

Parameters
objTree to take ownership of.

◆ DTree() [3/6]

template<typename MatType , typename TagType >
DTree::DTree ( const StatType maxVals,
const StatType minVals,
const size_t  totalPoints 
)

Create a density estimation tree with the given bounds and the given number of total points.

Children will not be created.

Parameters
maxValsMaximum values of the bounding box.
minValsMinimum values of the bounding box.
totalPointsTotal number of points in the dataset.

◆ DTree() [4/6]

template<typename MatType , typename TagType >
DTree::DTree ( MatType &  data)

Create a density estimation tree on the given data.

Children will be created following the procedure outlined in the paper. The data will be modified; it will be reordered similar to the way BinarySpaceTree modifies datasets.

Parameters
dataDataset to build tree on.

◆ DTree() [5/6]

template<typename MatType , typename TagType >
DTree::DTree ( const StatType maxVals,
const StatType minVals,
const size_t  start,
const size_t  end,
const double  logNegError 
)

Create a child node of a density estimation tree given the bounding box specified by maxVals and minVals, using the size given in start and end and the specified error.

Children of this node will not be created recursively.

Parameters
maxValsUpper bound of bounding box.
minValsLower bound of bounding box.
startStart of points represented by this node in the data matrix.
endEnd of points represented by this node in the data matrix.
logNegErrorlog-negative error of this node.

◆ DTree() [6/6]

template<typename MatType , typename TagType >
DTree::DTree ( const StatType maxVals,
const StatType minVals,
const size_t  totalPoints,
const size_t  start,
const size_t  end 
)

Create a child node of a density estimation tree given the bounding box specified by maxVals and minVals, using the size given in start and end, and calculating the error with the total number of points given.

Children of this node will not be created recursively.

Parameters
maxValsUpper bound of bounding box.
minValsLower bound of bounding box.
totalPointsTotal number of points.
startStart of points represented by this node in the data matrix.
endEnd of points represented by this node in the data matrix.

Member Function Documentation

◆ Child()

template<typename MatType = arma::mat, typename TagType = int>
DTree& mlpack::det::DTree< MatType, TagType >::Child ( const size_t  child) const
inline

Return the specified child (0 will be left, 1 will be right).

If the index is greater than 1, this will return the right child.

Parameters
childIndex of child to return.

◆ ComputeValue()

template<typename MatType , typename TagType >
double DTree::ComputeValue ( const VecType query) const

Compute the logarithm of the density estimate of a given query point.

Parameters
queryPoint to estimate density of.

◆ ComputeVariableImportance()

template<typename MatType , typename TagType >
void DTree::ComputeVariableImportance ( arma::vec &  importances) const

Compute the variable importance of each dimension in the learned tree.

Parameters
importancesVector to store the calculated importances in.

◆ FindBucket()

template<typename MatType , typename TagType >
TagType DTree::FindBucket ( const VecType query) const

Return the tag of the leaf containing the query.

This is useful for generating class memberships.

Parameters
queryQuery to search for.

◆ Grow()

template<typename MatType , typename TagType >
double DTree::Grow ( MatType &  data,
arma::Col< size_t > &  oldFromNew,
const bool  useVolReg = false,
const size_t  maxLeafSize = 10,
const size_t  minLeafSize = 5 
)

Greedily expand the tree.

The points in the dataset will be reordered during tree growth.

Parameters
dataDataset to build tree on.
oldFromNewMappings from old points to new points.
useVolRegIf true, volume regularization is used.
maxLeafSizeMaximum size of a leaf.
minLeafSizeMinimum size of a leaf.

◆ LogNegativeError()

template<typename MatType , typename TagType >
double DTree::LogNegativeError ( const size_t  totalPoints) const

Compute the log-negative-error for this point, given the total number of points in the dataset.

Parameters
totalPointsTotal number of points in the dataset.

◆ operator=() [1/2]

template<typename MatType , typename TagType >
DTree< MatType, TagType > & DTree::operator= ( const DTree< MatType, TagType > &  obj)

Copy the given tree.

Parameters
objTree to copy.

◆ operator=() [2/2]

template<typename MatType , typename TagType >
DTree< MatType, TagType > & DTree::operator= ( DTree< MatType, TagType > &&  obj)

Take ownership of the given tree (move operator).

Parameters
objTree to take ownership of.

◆ PruneAndUpdate()

template<typename MatType , typename TagType >
double DTree::PruneAndUpdate ( const double  oldAlpha,
const size_t  points,
const bool  useVolReg = false 
)

Perform alpha pruning on a tree.

Returns the new value of alpha.

Parameters
oldAlphaOld value of alpha.
pointsTotal number of points in dataset.
useVolRegIf true, volume regularization is used.
Returns
New value of alpha.

◆ Ratio()

template<typename MatType = arma::mat, typename TagType = int>
double mlpack::det::DTree< MatType, TagType >::Ratio ( ) const
inline

Return the ratio of points in this node to the points in the whole dataset.

◆ TagTree()

template<typename MatType , typename TagType >
TagType DTree::TagTree ( const TagType &  tag = 0,
bool  everyNode = false 
)

Index the buckets for possible usage later; this results in every leaf in the tree having a specific tag (accessible with BucketTag()).

This function calls itself recursively. The tag is incremented with operator++(), so any TagType overriding it will do.

Parameters
tagTag for the next leaf; leave at 0 for the initial call.
everyNodeWhether to increment on every node, not just leaves.

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