mlpack
dt_utils.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_DET_DT_UTILS_HPP
14 #define MLPACK_METHODS_DET_DT_UTILS_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 #include "dtree.hpp"
18 
19 namespace mlpack {
20 namespace det {
21 
33 template <typename MatType, typename TagType>
35  const MatType& data,
36  const arma::Mat<size_t>& labels,
37  const size_t numClasses,
38  const std::string& leafClassMembershipFile = "");
39 
48 template <typename MatType, typename TagType>
50  const std::string viFile = "");
51 
65 template <typename MatType, typename TagType>
66 DTree<MatType, TagType>* Trainer(MatType& dataset,
67  const size_t folds,
68  const bool useVolumeReg = false,
69  const size_t maxLeafSize = 10,
70  const size_t minLeafSize = 5,
71  const std::string unprunedTreeOutput = "",
72  const bool skipPruning = false);
73 
81 {
82  public:
87  {
94  };
95 
102  template<typename MatType>
104 
108  template<typename MatType>
109  void Enter(const DTree<MatType, int>* node,
110  const DTree<MatType, int>* parent);
111 
115  template<typename MatType>
116  void Leave(const DTree<MatType, int>* node,
117  const DTree<MatType, int>* parent);
118 
122  inline const std::string& PathFor(int tag) const;
123 
127  inline int ParentOf(int tag) const;
128 
132  size_t NumNodes() const { return pathCache.size(); }
133 
134  protected:
135  typedef std::list<std::pair<bool, int>> PathType;
136  typedef std::vector<std::pair<int, std::string>> PathCacheType;
137 
138  PathType path;
139  PathFormat format;
140  PathCacheType pathCache;
141 
142  inline std::string BuildString();
143 };
144 
145 } // namespace det
146 } // namespace mlpack
147 
148 #include "dt_utils_impl.hpp"
149 
150 #endif // MLPACK_METHODS_DET_DT_UTILS_HPP
void Enter(const DTree< MatType, int > *node, const DTree< MatType, int > *parent)
Enter a given node.
Definition: dt_utils_impl.hpp:334
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
This class is responsible for caching the path to each node of the tree.
Definition: dt_utils.hpp:80
The core includes that mlpack expects; standard C++ includes and Armadillo.
DTree< MatType, TagType > * Trainer(MatType &dataset, const size_t folds, const bool useVolumeReg=false, const size_t maxLeafSize=10, const size_t minLeafSize=5, const std::string unprunedTreeOutput="", const bool skipPruning=false)
Train the optimal decision tree using cross-validation with the given number of folds.
Print the direction, then the tag of the node.
Definition: dt_utils.hpp:91
PathCacher(PathFormat fmt, DTree< MatType, int > *tree)
Construct a PathCacher object on the given tree with the given format.
Definition: dt_utils_impl.hpp:323
void PrintLeafMembership(DTree< MatType, TagType > *dtree, const MatType &data, const arma::Mat< size_t > &labels, const size_t numClasses, const std::string &leafClassMembershipFile="")
Print the membership of leaves of a density estimation tree given the labels and number of classes...
const std::string & PathFor(int tag) const
Return the constructed path for a given tag.
Definition: dt_utils_impl.hpp:383
A density estimation tree is similar to both a decision tree and a space partitioning tree (like a kd...
Definition: dtree.hpp:46
void Leave(const DTree< MatType, int > *node, const DTree< MatType, int > *parent)
Leave the given node.
Definition: dt_utils_impl.hpp:349
Print only whether we went left or right.
Definition: dt_utils.hpp:89
Print the tag of the node, then the direction.
Definition: dt_utils.hpp:93
PathFormat
Possible formats to use for output.
Definition: dt_utils.hpp:86
size_t NumNodes() const
Get the number of nodes in the path cache.
Definition: dt_utils.hpp:132
void PrintVariableImportance(const DTree< MatType, TagType > *dtree, const std::string viFile="")
Print the variable importance of each dimension of a density estimation tree.
Definition: dt_utils_impl.hpp:71
int ParentOf(int tag) const
Get the parent tag of a given tag.
Definition: dt_utils_impl.hpp:378