13#ifndef MLPACK_METHODS_DET_DTREE_HPP
14#define MLPACK_METHODS_DET_DTREE_HPP
44template<
typename MatType = arma::mat,
45 typename TagType =
int>
52 typedef typename MatType::vec_type
VecType;
99 const size_t totalPoints);
127 const double logNegError);
143 const size_t totalPoints,
161 arma::Col<size_t>& oldFromNew,
162 const bool useVolReg =
false,
163 const size_t maxLeafSize = 10,
164 const size_t minLeafSize = 5);
176 const bool useVolReg =
false);
194 TagType
TagTree(
const TagType& tag = 0,
bool everyNode =
false);
255 double subtreeLeavesLogNegError;
258 size_t subtreeLeaves;
282 size_t Start()
const {
return start; }
284 size_t End()
const {
return end; }
297 double Ratio()
const {
return ratio; }
305 bool Root()
const {
return root; }
319 DTree&
Child(
const size_t child)
const {
return !child ? *left : *right; }
332 template<
typename Archive>
341 bool FindSplit(
const MatType& data,
346 const size_t minLeafSize = 5)
const;
351 size_t SplitData(MatType& data,
352 const size_t splitDim,
354 arma::Col<size_t>& oldFromNew)
const;
356 void FillMinMax(
const StatType& mins,
363#include "dtree_impl.hpp"
A density estimation tree is similar to both a decision tree and a space partitioning tree (like a kd...
double Ratio() const
Return the ratio of points in this node to the points in the whole dataset.
DTree & operator=(const DTree &obj)
Copy the given tree.
const StatType & MinVals() const
Return the minimum values.
double LogNegativeError(const size_t totalPoints) const
Compute the log-negative-error for this point, given the total number of points in the dataset.
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 minV...
DTree *& ChildPtr(const size_t child)
void ComputeVariableImportance(arma::vec &importances) const
Compute the variable importance of each dimension in the learned tree.
size_t NumChildren() const
Return the number of children in this node.
DTree(const DTree &obj)
Create a tree that is the copy of the given tree.
MatType::elem_type ElemType
The actual, underlying type we're working with.
size_t SubtreeLeaves() const
Return the number of leaves which are descendants of this node.
TagType BucketTag() const
Return the current bucket's ID, if leaf, or -1 otherwise.
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.
DTree(DTree &&obj)
Create a tree by taking ownership of another tree (move constructor).
ElemType SplitValue() const
Return the split value of this node.
DTree * Left() const
Return the left child.
double LogNegError() const
Return the log negative error of this node.
DTree * Right() const
Return the right child.
double ComputeValue(const VecType &query) const
Compute the logarithm of the density estimate of a given query point.
size_t SplitDim() const
Return the split dimension of this node.
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 minV...
MatType::vec_type VecType
The type of vector we are using.
arma::Col< ElemType > StatType
The statistic type we are holding.
DTree & operator=(DTree &&obj)
Take ownership of the given tree (move operator).
bool WithinRange(const VecType &query) const
Return whether a query point is within the range of this node.
double LogVolume() const
Return the inverse of the volume of this node.
DTree & Child(const size_t child) const
Return the specified child (0 will be left, 1 will be right).
size_t End() const
Return the first index of a point not contained in this node.
const StatType & MaxVals() const
Return the maximum values.
double AlphaUpper() const
Return the upper part of the alpha sum.
double PruneAndUpdate(const double oldAlpha, const size_t points, const bool useVolReg=false)
Perform alpha pruning on a tree.
TagType FindBucket(const VecType &query) const
Return the tag of the leaf containing the query.
double SubtreeLeavesLogNegError() const
Return the log negative error of all descendants of this node.
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.
bool Root() const
Return whether or not this is the root of the tree.
DTree()
Create an empty density estimation tree.
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 ...
size_t Start() const
Return the starting index of points contained in this node.
void serialize(Archive &ar, const unsigned int)
Serialize the density estimation tree.
DTree(MatType &data)
Create a density estimation tree on the given data.
~DTree()
Clean up memory allocated by the tree.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.