[mlpack-git] master: Print the number of nodes in the tree. (92ade97)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed Dec 23 11:46:48 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/de9cc4b05069e1fa4793d9355f2f595af5ff45d2...6070527af14296cd99739de6c62666cc5d2a2125
>---------------------------------------------------------------
commit 92ade97b3617d55b0de5d2d01aa440d6c216eb76
Author: Ryan Curtin <ryan at ratml.org>
Date: Wed Dec 9 19:35:35 2015 -0800
Print the number of nodes in the tree.
>---------------------------------------------------------------
92ade97b3617d55b0de5d2d01aa440d6c216eb76
.../methods/hoeffding_trees/hoeffding_tree_main.cpp | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/mlpack/methods/hoeffding_trees/hoeffding_tree_main.cpp b/src/mlpack/methods/hoeffding_trees/hoeffding_tree_main.cpp
index 0be4623..31aa326 100644
--- a/src/mlpack/methods/hoeffding_trees/hoeffding_tree_main.cpp
+++ b/src/mlpack/methods/hoeffding_trees/hoeffding_tree_main.cpp
@@ -8,6 +8,7 @@
#include <mlpack/methods/hoeffding_trees/hoeffding_tree.hpp>
#include <mlpack/methods/hoeffding_trees/binary_numeric_split.hpp>
#include <mlpack/methods/hoeffding_trees/information_gain.hpp>
+#include <queue>
using namespace std;
using namespace mlpack;
@@ -237,8 +238,22 @@ void PerformActions(const typename TreeType::NumericSplit& numericSplit)
Log::Info << correct << " out of " << labels.n_elem << " correct "
<< "on training set (" << double(correct) / double(labels.n_elem) *
100.0 << ")." << endl;
+ }
+
+ // Get the number of nods in the tree.
+ std::queue<TreeType*> queue;
+ queue.push(tree);
+ size_t nodes = 0;
+ while (!queue.empty())
+ {
+ TreeType* node = queue.front();
+ queue.pop();
+ ++nodes;
+ for (size_t i = 0; i < node->NumChildren(); ++i)
+ queue.push(&node->Child(i));
}
+ Log::Info << nodes << " nodes in the tree." << endl;
// The tree is trained or loaded. Now do any testing if we need.
if (!testFile.empty())
More information about the mlpack-git
mailing list