mlpack  2.2.4

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

Public Member Functions

 DTree ()
 Create an empty density estimation tree. More...

 
 DTree (const arma::vec &maxVals, const arma::vec &minVals, const size_t totalPoints)
 Create a density estimation tree with the given bounds and the given number of total points. More...

 
 DTree (arma::mat &data)
 Create a density estimation tree on the given data. More...

 
 DTree (const arma::vec &maxVals, const arma::vec &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 arma::vec &maxVals, const arma::vec &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. More...

 
double AlphaUpper () const
 Return the upper part of the alpha sum. More...

 
double ComputeValue (const arma::vec &query) const
 Compute the logarithm of the density estimate of a given query point. More...

 
void ComputeVariableImportance (arma::vec &importances) const
 Compute the variable importance of each dimension in the learned tree. More...

 
size_t End () const
 Return the first index of a point not contained in this node. More...

 
int FindBucket (const arma::vec &query) const
 Return the tag of the leaf containing the query. More...

 
double Grow (arma::mat &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...

 
DTreeLeft () const
 Return the left child. 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...

 
double LogNegError () const
 Return the log negative error of this node. More...

 
double LogVolume () const
 Return the inverse of the volume of this node. More...

 
const arma::vec & MaxVals () const
 Return the maximum values. More...

 
arma::vec & MaxVals ()
 Modify the maximum values. More...

 
const arma::vec & MinVals () const
 Return the minimum values. More...

 
arma::vec & MinVals ()
 Modify the minimum values. More...

 
double PruneAndUpdate (const double oldAlpha, const size_t points, const bool useVolReg=false)
 Perform alpha pruning on a tree. More...

 
double Ratio () const
 Return the ratio of points in this node to the points in the whole dataset. More...

 
DTreeRight () const
 Return the right child. More...

 
bool Root () const
 Return whether or not this is the root of the tree. More...

 
template
<
typename
Archive
>
void Serialize (Archive &ar, const unsigned int)
 Serialize the density estimation tree. More...

 
size_t SplitDim () const
 Return the split dimension of this node. More...

 
double SplitValue () const
 Return the split value of this node. More...

 
size_t Start () const
 Return the starting index of points contained in this node. More...

 
size_t SubtreeLeaves () const
 Return the number of leaves which are descendants of this node. More...

 
double SubtreeLeavesLogNegError () const
 Return the log negative error of all descendants of this node. More...

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

 
bool WithinRange (const arma::vec &query) const
 Return whether a query point is within the range of this node. More...

 
void WriteTree (FILE *fp, const size_t level=0) const
 Print the tree in a depth-first manner (this function is called recursively). More...

 

Private Member Functions

bool FindSplit (const arma::mat &data, size_t &splitDim, double &splitValue, double &leftError, double &rightError, const size_t minLeafSize=5) const
 Find the dimension to split on. More...

 
size_t SplitData (arma::mat &data, const size_t splitDim, const double splitValue, arma::Col< size_t > &oldFromNew) const
 Split the data, returning the number of points left of the split. More...

 

Private Attributes

double alphaUpper
 Upper part of alpha sum; used for pruning. More...

 
int bucketTag
 The tag for the leaf, used for hashing points. More...

 
size_t end
 The index of the last point in the dataset contained in this node (and its children). More...

 
DTreeleft
 The left child. More...

 
double logNegError
 log-negative-L2-error of the node. More...

 
double logVolume
 The logarithm of the volume of the node. More...

 
arma::vec maxVals
 Upper half of bounding box for this node. More...

 
arma::vec minVals
 Lower half of bounding box for this node. More...

 
double ratio
 Ratio of the number of points in the node to the total number of points. More...

 
DTreeright
 The right child. More...

 
bool root
 If true, this node is the root of the tree. More...

 
size_t splitDim
 The splitting dimension for this node. More...

 
double splitValue
 The split value on the splitting dimension for this node. More...

 
size_t start
 The index of the first point in the dataset contained in this node (and its children). More...

 
size_t subtreeLeaves
 Number of leaves of the subtree. More...

 
double subtreeLeavesLogNegError
 Sum of the error of the leaves of the subtree. More...

 

Detailed Description

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}
}

Definition at line 44 of file dtree.hpp.

Constructor & Destructor Documentation

◆ DTree() [1/5]

mlpack::det::DTree::DTree ( )

Create an empty density estimation tree.

◆ DTree() [2/5]

mlpack::det::DTree::DTree ( const arma::vec &  maxVals,
const arma::vec &  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() [3/5]

mlpack::det::DTree::DTree ( arma::mat &  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() [4/5]

mlpack::det::DTree::DTree ( const arma::vec &  maxVals,
const arma::vec &  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.
errorlog-negative error of this node.

◆ DTree() [5/5]

mlpack::det::DTree::DTree ( const arma::vec &  maxVals,
const arma::vec &  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.
startStart of points represented by this node in the data matrix.
endEnd of points represented by this node in the data matrix.

◆ ~DTree()

mlpack::det::DTree::~DTree ( )

Clean up memory allocated by the tree.

Member Function Documentation

◆ AlphaUpper()

double mlpack::det::DTree::AlphaUpper ( ) const
inline

Return the upper part of the alpha sum.

Definition at line 274 of file dtree.hpp.

References alphaUpper.

◆ ComputeValue()

double mlpack::det::DTree::ComputeValue ( const arma::vec &  query) const

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

Parameters
queryPoint to estimate density of.

◆ ComputeVariableImportance()

void mlpack::det::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.

◆ End()

size_t mlpack::det::DTree::End ( ) const
inline

Return the first index of a point not contained in this node.

Definition at line 251 of file dtree.hpp.

References end.

◆ FindBucket()

int mlpack::det::DTree::FindBucket ( const arma::vec &  query) const

Return the tag of the leaf containing the query.

This is useful for generating class memberships.

Parameters
queryQuery to search for.

◆ FindSplit()

bool mlpack::det::DTree::FindSplit ( const arma::mat &  data,
size_t &  splitDim,
double &  splitValue,
double &  leftError,
double &  rightError,
const size_t  minLeafSize = 5 
) const
private

Find the dimension to split on.

Referenced by Serialize().

◆ Grow()

double mlpack::det::DTree::Grow ( arma::mat &  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.

◆ Left()

DTree* mlpack::det::DTree::Left ( ) const
inline

Return the left child.

Definition at line 268 of file dtree.hpp.

References left.

◆ LogNegativeError()

double mlpack::det::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.

◆ LogNegError()

double mlpack::det::DTree::LogNegError ( ) const
inline

Return the log negative error of this node.

Definition at line 257 of file dtree.hpp.

References logNegError.

◆ LogVolume()

double mlpack::det::DTree::LogVolume ( ) const
inline

Return the inverse of the volume of this node.

Definition at line 266 of file dtree.hpp.

References logVolume.

◆ MaxVals() [1/2]

const arma::vec& mlpack::det::DTree::MaxVals ( ) const
inline

Return the maximum values.

Definition at line 277 of file dtree.hpp.

References maxVals.

◆ MaxVals() [2/2]

arma::vec& mlpack::det::DTree::MaxVals ( )
inline

Modify the maximum values.

Definition at line 279 of file dtree.hpp.

References maxVals.

◆ MinVals() [1/2]

const arma::vec& mlpack::det::DTree::MinVals ( ) const
inline

Return the minimum values.

Definition at line 282 of file dtree.hpp.

References minVals.

◆ MinVals() [2/2]

arma::vec& mlpack::det::DTree::MinVals ( )
inline

Modify the minimum values.

Definition at line 284 of file dtree.hpp.

References minVals.

◆ PruneAndUpdate()

double mlpack::det::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()

double mlpack::det::DTree::Ratio ( ) const
inline

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

Definition at line 264 of file dtree.hpp.

References ratio.

◆ Right()

DTree* mlpack::det::DTree::Right ( ) const
inline

Return the right child.

Definition at line 270 of file dtree.hpp.

References right.

◆ Root()

bool mlpack::det::DTree::Root ( ) const
inline

Return whether or not this is the root of the tree.

Definition at line 272 of file dtree.hpp.

References root.

◆ Serialize()

template
<
typename
Archive
>
void mlpack::det::DTree::Serialize ( Archive &  ar,
const unsigned  int 
)
inline

Serialize the density estimation tree.

Definition at line 290 of file dtree.hpp.

References mlpack::data::CreateNVP(), FindSplit(), left, right, and SplitData().

◆ SplitData()

size_t mlpack::det::DTree::SplitData ( arma::mat &  data,
const size_t  splitDim,
const double  splitValue,
arma::Col< size_t > &  oldFromNew 
) const
private

Split the data, returning the number of points left of the split.

Referenced by Serialize().

◆ SplitDim()

size_t mlpack::det::DTree::SplitDim ( ) const
inline

Return the split dimension of this node.

Definition at line 253 of file dtree.hpp.

References splitDim.

◆ SplitValue()

double mlpack::det::DTree::SplitValue ( ) const
inline

Return the split value of this node.

Definition at line 255 of file dtree.hpp.

References splitValue.

◆ Start()

size_t mlpack::det::DTree::Start ( ) const
inline

Return the starting index of points contained in this node.

Definition at line 249 of file dtree.hpp.

References start.

◆ SubtreeLeaves()

size_t mlpack::det::DTree::SubtreeLeaves ( ) const
inline

Return the number of leaves which are descendants of this node.

Definition at line 261 of file dtree.hpp.

References subtreeLeaves.

◆ SubtreeLeavesLogNegError()

double mlpack::det::DTree::SubtreeLeavesLogNegError ( ) const
inline

Return the log negative error of all descendants of this node.

Definition at line 259 of file dtree.hpp.

References subtreeLeavesLogNegError.

◆ TagTree()

int mlpack::det::DTree::TagTree ( const int  tag = 0)

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.

Parameters
tagTag for the next leaf; leave at 0 for the initial call.

◆ WithinRange()

bool mlpack::det::DTree::WithinRange ( const arma::vec &  query) const

Return whether a query point is within the range of this node.

◆ WriteTree()

void mlpack::det::DTree::WriteTree ( FILE *  fp,
const size_t  level = 0 
) const

Print the tree in a depth-first manner (this function is called recursively).

Parameters
fpFile to write the tree to.
levelLevel of the tree (should start at 0).

Member Data Documentation

◆ alphaUpper

double mlpack::det::DTree::alphaUpper
private

Upper part of alpha sum; used for pruning.

Definition at line 240 of file dtree.hpp.

Referenced by AlphaUpper().

◆ bucketTag

int mlpack::det::DTree::bucketTag
private

The tag for the leaf, used for hashing points.

Definition at line 237 of file dtree.hpp.

◆ end

size_t mlpack::det::DTree::end
private

The index of the last point in the dataset contained in this node (and its children).

Definition at line 205 of file dtree.hpp.

Referenced by End().

◆ left

DTree* mlpack::det::DTree::left
private

The left child.

Definition at line 243 of file dtree.hpp.

Referenced by Left(), and Serialize().

◆ logNegError

double mlpack::det::DTree::logNegError
private

log-negative-L2-error of the node.

Definition at line 219 of file dtree.hpp.

Referenced by LogNegError().

◆ logVolume

double mlpack::det::DTree::logVolume
private

The logarithm of the volume of the node.

Definition at line 234 of file dtree.hpp.

Referenced by LogVolume().

◆ maxVals

arma::vec mlpack::det::DTree::maxVals
private

Upper half of bounding box for this node.

Definition at line 208 of file dtree.hpp.

Referenced by MaxVals().

◆ minVals

arma::vec mlpack::det::DTree::minVals
private

Lower half of bounding box for this node.

Definition at line 210 of file dtree.hpp.

Referenced by MinVals().

◆ ratio

double mlpack::det::DTree::ratio
private

Ratio of the number of points in the node to the total number of points.

Definition at line 231 of file dtree.hpp.

Referenced by Ratio().

◆ right

DTree* mlpack::det::DTree::right
private

The right child.

Definition at line 245 of file dtree.hpp.

Referenced by Right(), and Serialize().

◆ root

bool mlpack::det::DTree::root
private

If true, this node is the root of the tree.

Definition at line 228 of file dtree.hpp.

Referenced by Root().

◆ splitDim

size_t mlpack::det::DTree::splitDim
private

The splitting dimension for this node.

Definition at line 213 of file dtree.hpp.

Referenced by SplitDim().

◆ splitValue

double mlpack::det::DTree::splitValue
private

The split value on the splitting dimension for this node.

Definition at line 216 of file dtree.hpp.

Referenced by SplitValue().

◆ start

size_t mlpack::det::DTree::start
private

The index of the first point in the dataset contained in this node (and its children).

Definition at line 202 of file dtree.hpp.

Referenced by Start().

◆ subtreeLeaves

size_t mlpack::det::DTree::subtreeLeaves
private

Number of leaves of the subtree.

Definition at line 225 of file dtree.hpp.

Referenced by SubtreeLeaves().

◆ subtreeLeavesLogNegError

double mlpack::det::DTree::subtreeLeavesLogNegError
private

Sum of the error of the leaves of the subtree.

Definition at line 222 of file dtree.hpp.

Referenced by SubtreeLeavesLogNegError().


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