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 
64 template <typename MatType, typename TagType>
65 DTree<MatType, TagType>* Trainer(MatType& dataset,
66  const size_t folds,
67  const bool useVolumeReg = false,
68  const size_t maxLeafSize = 10,
69  const size_t minLeafSize = 5,
70  const std::string unprunedTreeOutput = "",
71  const bool skipPruning = false);
72 
80 {
81  public:
86  {
93  };
94 
101  template<typename MatType>
103 
107  template<typename MatType>
108  void Enter(const DTree<MatType, int>* node,
109  const DTree<MatType, int>* parent);
110 
114  template<typename MatType>
115  void Leave(const DTree<MatType, int>* node,
116  const DTree<MatType, int>* parent);
117 
121  const std::string& PathFor(int tag) const;
122 
126  int ParentOf(int tag) const;
127 
131  size_t NumNodes() const { return pathCache.size(); }
132 
133  protected:
134  typedef std::list<std::pair<bool, int>> PathType;
135  typedef std::vector<std::pair<int, std::string>> PathCacheType;
136 
137  PathType path;
139  PathCacheType pathCache;
140 
141  std::string BuildString();
142 };
143 
144 } // namespace det
145 } // namespace mlpack
146 
147 #include "dt_utils_impl.hpp"
148 
149 #endif // MLPACK_METHODS_DET_DT_UTILS_HPP
std::string BuildString()
.hpp
Definition: add_to_po.hpp:21
size_t NumNodes() const
Get the number of nodes in the path cache.
Definition: dt_utils.hpp:131
void Enter(const DTree< MatType, int > *node, const DTree< MatType, int > *parent)
Enter a given node.
int ParentOf(int tag) const
Get the parent tag of a given tag.
PathCacheType pathCache
Definition: dt_utils.hpp:139
This class is responsible for caching the path to each node of the tree.
Definition: dt_utils.hpp:79
The core includes that mlpack expects; standard C++ includes and Armadillo.
std::vector< std::pair< int, std::string > > PathCacheType
Definition: dt_utils.hpp:135
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 only whether we went left or right.
Definition: dt_utils.hpp:88
void Leave(const DTree< MatType, int > *node, const DTree< MatType, int > *parent)
Leave the given node.
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...
PathFormat
Possible formats to use for output.
Definition: dt_utils.hpp:85
A density estimation tree is similar to both a decision tree and a space partitioning tree (like a kd...
Definition: dtree.hpp:46
const std::string & PathFor(int tag) const
Return the constructed path for a given tag.
std::list< std::pair< bool, int > > PathType
Definition: dt_utils.hpp:134
PathCacher(PathFormat fmt, DTree< MatType, int > *tree)
Construct a PathCacher object on the given tree with the given format.
Print the direction, then the tag of the node.
Definition: dt_utils.hpp:90
Print the tag of the node, then the direction.
Definition: dt_utils.hpp:92
void PrintVariableImportance(const DTree< MatType, TagType > *dtree, const std::string viFile="")
Print the variable importance of each dimension of a density estimation tree.