[mlpack-git] master: Take ownership of DatasetInfo struct when needed. (6622778)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed Dec 23 11:45:43 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/de9cc4b05069e1fa4793d9355f2f595af5ff45d2...6070527af14296cd99739de6c62666cc5d2a2125
>---------------------------------------------------------------
commit 66227787398861a057b826841c7bbdc2b4ffdb50
Author: Ryan Curtin <ryan at ratml.org>
Date: Sun Nov 1 17:46:12 2015 +0000
Take ownership of DatasetInfo struct when needed.
>---------------------------------------------------------------
66227787398861a057b826841c7bbdc2b4ffdb50
src/mlpack/methods/hoeffding_trees/hoeffding_tree.hpp | 4 +++-
src/mlpack/methods/hoeffding_trees/hoeffding_tree_impl.hpp | 8 ++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/mlpack/methods/hoeffding_trees/hoeffding_tree.hpp b/src/mlpack/methods/hoeffding_trees/hoeffding_tree.hpp
index 27101a5..a97f1e5 100644
--- a/src/mlpack/methods/hoeffding_trees/hoeffding_tree.hpp
+++ b/src/mlpack/methods/hoeffding_trees/hoeffding_tree.hpp
@@ -264,8 +264,10 @@ class HoeffdingTree
size_t maxSamples;
//! The number of samples that should be seen before checking for a split.
size_t checkInterval;
- //! The dataset information. (We don't own this.)
+ //! The dataset information.
const data::DatasetInfo* datasetInfo;
+ //! Whether or not we own the dataset information.
+ bool ownsInfo;
//! The required probability of success for a split to be performed.
double successProbability;
diff --git a/src/mlpack/methods/hoeffding_trees/hoeffding_tree_impl.hpp b/src/mlpack/methods/hoeffding_trees/hoeffding_tree_impl.hpp
index bed0237..badd55a 100644
--- a/src/mlpack/methods/hoeffding_trees/hoeffding_tree_impl.hpp
+++ b/src/mlpack/methods/hoeffding_trees/hoeffding_tree_impl.hpp
@@ -37,6 +37,7 @@ HoeffdingTree<
maxSamples(maxSamples),
checkInterval(checkInterval),
datasetInfo(&datasetInfo),
+ ownsInfo(false),
successProbability(successProbability),
splitDimension(size_t(-1)),
categoricalSplit(0),
@@ -86,6 +87,7 @@ HoeffdingTree<
maxSamples(maxSamples),
checkInterval(checkInterval),
datasetInfo(&datasetInfo),
+ ownsInfo(false),
successProbability(successProbability),
splitDimension(size_t(-1)),
categoricalSplit(0),
@@ -144,6 +146,7 @@ HoeffdingTree<FitnessFunction, NumericSplitType, CategoricalSplitType>::
maxSamples(other.maxSamples),
checkInterval(other.checkInterval),
datasetInfo(new data::DatasetInfo(*other.datasetInfo)),
+ ownsInfo(true),
successProbability(other.successProbability),
splitDimension(other.splitDimension),
majorityClass(other.majorityClass),
@@ -163,6 +166,8 @@ HoeffdingTree<FitnessFunction, NumericSplitType, CategoricalSplitType>::
{
if (ownsMappings)
delete dimensionMappings;
+ if (ownsInfo)
+ delete datasetInfo;
}
//! Train on a set of points.
@@ -499,7 +504,10 @@ void HoeffdingTree<
d = const_cast<data::DatasetInfo*>(datasetInfo);
ar & CreateNVP(d, "datasetInfo");
if (Archive::is_loading::value)
+ {
datasetInfo = d;
+ ownsInfo = true;
+ }
ar & CreateNVP(majorityClass, "majorityClass");
ar & CreateNVP(majorityProbability, "majorityProbability");
More information about the mlpack-git
mailing list