[mlpack-git] master: Make children pointers, so serialization doesn't copy dimensionMappings and datasetInfo. (e7b0e4e)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed Dec 23 11:46:14 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/de9cc4b05069e1fa4793d9355f2f595af5ff45d2...6070527af14296cd99739de6c62666cc5d2a2125
>---------------------------------------------------------------
commit e7b0e4e608d19ef57921a12acf7e6506076ecbad
Author: Ryan Curtin <ryan at ratml.org>
Date: Thu Nov 12 13:53:25 2015 -0500
Make children pointers, so serialization doesn't copy dimensionMappings and datasetInfo.
>---------------------------------------------------------------
e7b0e4e608d19ef57921a12acf7e6506076ecbad
.../methods/hoeffding_trees/hoeffding_tree.hpp | 6 +++---
.../hoeffding_trees/hoeffding_tree_impl.hpp | 23 +++++++++++-----------
2 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/src/mlpack/methods/hoeffding_trees/hoeffding_tree.hpp b/src/mlpack/methods/hoeffding_trees/hoeffding_tree.hpp
index 55941bc..8e53b50 100644
--- a/src/mlpack/methods/hoeffding_trees/hoeffding_tree.hpp
+++ b/src/mlpack/methods/hoeffding_trees/hoeffding_tree.hpp
@@ -175,9 +175,9 @@ class HoeffdingTree
size_t NumChildren() const { return children.size(); }
//! Get a child.
- const HoeffdingTree& Child(const size_t i) const { return children[i]; }
+ const HoeffdingTree& Child(const size_t i) const { return *children[i]; }
//! Modify a child.
- HoeffdingTree& Child(const size_t i) { return children[i]; }
+ HoeffdingTree& Child(const size_t i) { return *children[i]; }
/**
* Given a point and that this node is not a leaf, calculate the index of the
@@ -293,7 +293,7 @@ class HoeffdingTree
//! If the split is numeric, this holds the splitting information.
typename NumericSplitType<FitnessFunction>::SplitInfo numericSplit;
//! If the split has occurred, these are the children.
- std::vector<HoeffdingTree> children;
+ std::vector<HoeffdingTree*> children;
};
} // namespace tree
diff --git a/src/mlpack/methods/hoeffding_trees/hoeffding_tree_impl.hpp b/src/mlpack/methods/hoeffding_trees/hoeffding_tree_impl.hpp
index e612272..c9bf774 100644
--- a/src/mlpack/methods/hoeffding_trees/hoeffding_tree_impl.hpp
+++ b/src/mlpack/methods/hoeffding_trees/hoeffding_tree_impl.hpp
@@ -157,10 +157,11 @@ HoeffdingTree<FitnessFunction, NumericSplitType, CategoricalSplitType>::
majorityClass(other.majorityClass),
majorityProbability(other.majorityProbability),
categoricalSplit(other.categoricalSplit),
- numericSplit(other.numericSplit),
- children(other.children)
+ numericSplit(other.numericSplit)
{
- // Nothing left to copy.
+ // Copy each of the children.
+ for (size_t i = 0; i < other.children.size(); ++i)
+ children.push_back(new HoeffdingTree(other.children[i]));
}
template<typename FitnessFunction,
@@ -241,7 +242,7 @@ void HoeffdingTree<
// unfortunately, instead, we'll just extract the non-contiguous
// submatrix.
MatType childData = data.cols(indices[i].subvec(0, counts[i] - 1));
- children[i].Train(childData, childLabels, true);
+ children[i]->Train(childData, childLabels, true);
}
}
}
@@ -306,7 +307,7 @@ void HoeffdingTree<
{
// Already split. Pass the training point to the relevant child.
size_t direction = CalculateDirection(point);
- children[direction].Train(point, label);
+ children[direction]->Train(point, label);
}
}
@@ -432,7 +433,7 @@ size_t HoeffdingTree<
else
{
// Otherwise, pass to the right child and let them classify.
- return children[CalculateDirection(point)].Classify(point);
+ return children[CalculateDirection(point)]->Classify(point);
}
}
@@ -459,7 +460,7 @@ void HoeffdingTree<
else
{
// Pass to the right child and let them do the classification.
- children[CalculateDirection(point)].Classify(point, prediction,
+ children[CalculateDirection(point)]->Classify(point, prediction,
probability);
}
}
@@ -532,10 +533,10 @@ void HoeffdingTree<
// We already know what the splitDimension will be.
for (size_t i = 0; i < childMajorities.n_elem; ++i)
{
- children.push_back(HoeffdingTree(*datasetInfo, numClasses,
+ children.push_back(new HoeffdingTree(*datasetInfo, numClasses,
successProbability, maxSamples, checkInterval, minSamples,
dimensionMappings));
- children[i].MajorityClass() = childMajorities[i];
+ children[i]->MajorityClass() = childMajorities[i];
}
// Eliminate now-unnecessary split information.
@@ -643,13 +644,13 @@ void HoeffdingTree<
numChildren = children.size();
ar & CreateNVP(numChildren, "numChildren");
if (Archive::is_loading::value) // If needed, allocate space.
- children.resize(numChildren, HoeffdingTree(data::DatasetInfo(0), 0));
+ children.resize(numChildren, new HoeffdingTree(data::DatasetInfo(0), 0));
for (size_t i = 0; i < numChildren; ++i)
{
std::ostringstream name;
name << "child" << i;
- ar & data::CreateNVP(children[i], name.str());
+ ar & data::CreateNVP(*children[i], name.str());
}
if (Archive::is_loading::value)
More information about the mlpack-git
mailing list