13 #ifndef MLPACK_METHODS_DET_DTREE_HPP 14 #define MLPACK_METHODS_DET_DTREE_HPP 44 template<
typename MatType = arma::mat,
45 typename TagType =
int>
52 typedef typename MatType::vec_type
VecType;
97 DTree(
const StatType& maxVals,
98 const StatType& minVals,
99 const size_t totalPoints);
109 DTree(MatType& data);
123 DTree(
const StatType& maxVals,
124 const StatType& minVals,
127 const double logNegError);
141 DTree(
const StatType& maxVals,
142 const StatType& minVals,
143 const size_t totalPoints,
160 double Grow(MatType& data,
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);
203 TagType
FindBucket(
const VecType& query)
const;
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; }
324 const StatType&
MaxVals()
const {
return maxVals; }
327 const StatType&
MinVals()
const {
return minVals; }
332 template<
typename Archive>
333 void serialize(Archive& ar,
const uint32_t );
341 bool FindSplit(
const MatType& data,
343 ElemType& splitValue,
346 const size_t minLeafSize = 5)
const;
351 size_t SplitData(MatType& data,
352 const size_t splitDim,
353 const ElemType splitValue,
354 arma::Col<size_t>& oldFromNew)
const;
356 void FillMinMax(
const StatType& mins,
357 const StatType& maxs);
363 #include "dtree_impl.hpp" 365 #endif // MLPACK_METHODS_DET_DTREE_HPP size_t SubtreeLeaves() const
Return the number of leaves which are descendants of this node.
double ComputeValue(const VecType &query) const
Compute the logarithm of the density estimate of a given query point.
DTree & operator=(const DTree &obj)
Copy the given tree.
size_t SplitDim() const
Return the split dimension of this node.
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()
Clean up memory allocated by the tree.
size_t Start() const
Return the starting index of points contained in this node.
Linear algebra utility functions, generally performed on matrices or vectors.
MatType::elem_type ElemType
The actual, underlying type we're working with.
void serialize(Archive &ar, const uint32_t)
Serialize the density estimation tree.
bool WithinRange(const VecType &query) const
Return whether a query point is within the range of this node.
arma::Col< ElemType > StatType
The statistic type we are holding.
double LogNegError() const
Return the log negative error of this node.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Ratio() const
Return the ratio of points in this node to the points in the whole dataset.
DTree * Left() const
Return the left child.
DTree & Child(const size_t child) const
Return the specified child (0 will be left, 1 will be right).
size_t NumChildren() const
Return the number of children in this node.
size_t End() const
Return the first index of a point not contained in this node.
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 ...
ElemType SplitValue() const
Return the split value of this node.
const StatType & MaxVals() const
Return the maximum values.
DTree * Right() const
Return the right child.
double LogVolume() const
Return the inverse of the volume of this node.
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.
MatType::vec_type VecType
The type of vector we are using.
double PruneAndUpdate(const double oldAlpha, const size_t points, const bool useVolReg=false)
Perform alpha pruning on a tree.
void ComputeVariableImportance(arma::vec &importances) const
Compute the variable importance of each dimension in the learned tree.
A density estimation tree is similar to both a decision tree and a space partitioning tree (like a kd...
double LogNegativeError(const size_t totalPoints) const
Compute the log-negative-error for this point, given the total number of points in the dataset...
const StatType & MinVals() const
Return the minimum values.
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.
bool Root() const
Return whether or not this is the root of the tree.
DTree *& ChildPtr(const size_t child)
DTree()
Create an empty density estimation tree.