[mlpack-git] master: Refactor to use template template parameters. (06a6879)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed Dec 23 11:44:39 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/de9cc4b05069e1fa4793d9355f2f595af5ff45d2...6070527af14296cd99739de6c62666cc5d2a2125
>---------------------------------------------------------------
commit 06a68796bcb9c19138a4ee3e3b0150c90ae00110
Author: Ryan Curtin <ryan at ratml.org>
Date: Sun Oct 18 07:09:58 2015 -0400
Refactor to use template template parameters.
>---------------------------------------------------------------
06a68796bcb9c19138a4ee3e3b0150c90ae00110
.../hoeffding_trees/binary_numeric_split.hpp | 4 ++
.../hoeffding_trees/hoeffding_numeric_split.hpp | 5 ++
.../methods/hoeffding_trees/hoeffding_split.hpp | 16 ++++--
.../hoeffding_trees/hoeffding_split_impl.hpp | 66 +++++++++++-----------
4 files changed, 53 insertions(+), 38 deletions(-)
diff --git a/src/mlpack/methods/hoeffding_trees/binary_numeric_split.hpp b/src/mlpack/methods/hoeffding_trees/binary_numeric_split.hpp
index fb715f7..755efeb 100644
--- a/src/mlpack/methods/hoeffding_trees/binary_numeric_split.hpp
+++ b/src/mlpack/methods/hoeffding_trees/binary_numeric_split.hpp
@@ -66,6 +66,10 @@ class BinaryNumericSplit
ObservationType bestSplit;
};
+// Convenience typedef.
+template<typename FitnessFunction>
+using BinaryDoubleNumericSplit = BinaryNumericSplit<FitnessFunction, double>;
+
} // namespace tree
} // namespace mlpack
diff --git a/src/mlpack/methods/hoeffding_trees/hoeffding_numeric_split.hpp b/src/mlpack/methods/hoeffding_trees/hoeffding_numeric_split.hpp
index e726c88..2fa40c8 100644
--- a/src/mlpack/methods/hoeffding_trees/hoeffding_numeric_split.hpp
+++ b/src/mlpack/methods/hoeffding_trees/hoeffding_numeric_split.hpp
@@ -83,6 +83,11 @@ class HoeffdingNumericSplit
arma::Mat<size_t> sufficientStatistics;
};
+// Convenience typedef.
+template<typename FitnessFunction>
+using HoeffdingDoubleNumericSplit = HoeffdingNumericSplit<FitnessFunction,
+ double>;
+
} // namespace tree
} // namespace mlpack
diff --git a/src/mlpack/methods/hoeffding_trees/hoeffding_split.hpp b/src/mlpack/methods/hoeffding_trees/hoeffding_split.hpp
index 139099b..2f062fa 100644
--- a/src/mlpack/methods/hoeffding_trees/hoeffding_split.hpp
+++ b/src/mlpack/methods/hoeffding_trees/hoeffding_split.hpp
@@ -17,8 +17,10 @@ namespace mlpack {
namespace tree {
template<typename FitnessFunction = GiniImpurity,
- typename NumericSplitType = HoeffdingNumericSplit<GiniImpurity>,
- typename CategoricalSplitType = HoeffdingCategoricalSplit<GiniImpurity>
+ template<typename> class NumericSplitType =
+ HoeffdingDoubleNumericSplit,
+ template<typename> class CategoricalSplitType =
+ HoeffdingCategoricalSplit
>
class HoeffdingSplit
{
@@ -68,8 +70,8 @@ class HoeffdingSplit
private:
// We need to keep some information for before we have split.
- std::vector<NumericSplitType> numericSplits;
- std::vector<CategoricalSplitType> categoricalSplits;
+ std::vector<NumericSplitType<FitnessFunction>> numericSplits;
+ std::vector<CategoricalSplitType<FitnessFunction>> categoricalSplits;
// This structure is owned by this node only if it is the root of the tree.
std::unordered_map<size_t, std::pair<size_t, size_t>>* dimensionMappings;
@@ -86,8 +88,10 @@ class HoeffdingSplit
size_t splitDimension;
size_t majorityClass;
double majorityProbability;
- typename CategoricalSplitType::SplitInfo categoricalSplit; // In case it's categorical.
- typename NumericSplitType::SplitInfo numericSplit; // In case it's numeric.
+ // In case it's categorical.
+ typename CategoricalSplitType<FitnessFunction>::SplitInfo categoricalSplit;
+ // In case it's numeric.
+ typename NumericSplitType<FitnessFunction>::SplitInfo numericSplit;
};
} // namespace tree
diff --git a/src/mlpack/methods/hoeffding_trees/hoeffding_split_impl.hpp b/src/mlpack/methods/hoeffding_trees/hoeffding_split_impl.hpp
index 80b7548..5f1e29c 100644
--- a/src/mlpack/methods/hoeffding_trees/hoeffding_split_impl.hpp
+++ b/src/mlpack/methods/hoeffding_trees/hoeffding_split_impl.hpp
@@ -11,8 +11,8 @@ namespace mlpack {
namespace tree {
template<typename FitnessFunction,
- typename NumericSplitType,
- typename CategoricalSplitType>
+ template<typename> class NumericSplitType,
+ template<typename> class CategoricalSplitType>
HoeffdingSplit<
FitnessFunction,
NumericSplitType,
@@ -43,14 +43,14 @@ HoeffdingSplit<
{
if (datasetInfo.Type(i) == data::Datatype::categorical)
{
- categoricalSplits.push_back(
- CategoricalSplitType(datasetInfo.NumMappings(i), numClasses));
+ categoricalSplits.push_back(CategoricalSplitType<FitnessFunction>(
+ datasetInfo.NumMappings(i), numClasses));
(*dimensionMappings)[i] = std::make_pair(data::Datatype::categorical,
categoricalSplits.size() - 1);
}
else
{
- numericSplits.push_back(NumericSplitType(numClasses));
+ numericSplits.push_back(NumericSplitType<FitnessFunction>(numClasses));
(*dimensionMappings)[i] = std::make_pair(data::Datatype::numeric,
numericSplits.size() - 1);
}
@@ -62,20 +62,20 @@ HoeffdingSplit<
{
if (datasetInfo.Type(i) == data::Datatype::categorical)
{
- categoricalSplits.push_back(
- CategoricalSplitType(datasetInfo.NumMappings(i), numClasses));
+ categoricalSplits.push_back(CategoricalSplitType<FitnessFunction>(
+ datasetInfo.NumMappings(i), numClasses));
}
else
{
- numericSplits.push_back(NumericSplitType(numClasses));
+ numericSplits.push_back(NumericSplitType<FitnessFunction>(numClasses));
}
}
}
}
template<typename FitnessFunction,
- typename NumericSplitType,
- typename CategoricalSplitType>
+ template<typename> class NumericSplitType,
+ template<typename> class CategoricalSplitType>
HoeffdingSplit<FitnessFunction, NumericSplitType, CategoricalSplitType>::
~HoeffdingSplit()
{
@@ -84,8 +84,8 @@ HoeffdingSplit<FitnessFunction, NumericSplitType, CategoricalSplitType>::
}
template<typename FitnessFunction,
- typename NumericSplitType,
- typename CategoricalSplitType>
+ template<typename> class NumericSplitType,
+ template<typename> class CategoricalSplitType>
template<typename VecType>
void HoeffdingSplit<
FitnessFunction,
@@ -126,8 +126,8 @@ void HoeffdingSplit<
}
template<typename FitnessFunction,
- typename NumericSplitType,
- typename CategoricalSplitType>
+ template<typename> class NumericSplitType,
+ template<typename> class CategoricalSplitType>
size_t HoeffdingSplit<
FitnessFunction,
NumericSplitType,
@@ -200,8 +200,8 @@ size_t HoeffdingSplit<
template<
typename FitnessFunction,
- typename NumericSplitType,
- typename CategoricalSplitType
+ template<typename> class NumericSplitType,
+ template<typename> class CategoricalSplitType
>
size_t HoeffdingSplit<
FitnessFunction,
@@ -214,8 +214,8 @@ size_t HoeffdingSplit<
template<
typename FitnessFunction,
- typename NumericSplitType,
- typename CategoricalSplitType
+ template<typename> class NumericSplitType,
+ template<typename> class CategoricalSplitType
>
size_t& HoeffdingSplit<
FitnessFunction,
@@ -228,8 +228,8 @@ size_t& HoeffdingSplit<
template<
typename FitnessFunction,
- typename NumericSplitType,
- typename CategoricalSplitType
+ template<typename> class NumericSplitType,
+ template<typename> class CategoricalSplitType
>
template<typename VecType>
size_t HoeffdingSplit<
@@ -249,8 +249,8 @@ size_t HoeffdingSplit<
template<
typename FitnessFunction,
- typename NumericSplitType,
- typename CategoricalSplitType
+ template<typename> class NumericSplitType,
+ template<typename> class CategoricalSplitType
>
template<typename VecType>
size_t HoeffdingSplit<
@@ -266,8 +266,8 @@ size_t HoeffdingSplit<
template<
typename FitnessFunction,
- typename NumericSplitType,
- typename CategoricalSplitType
+ template<typename> class NumericSplitType,
+ template<typename> class CategoricalSplitType
>
template<typename VecType>
void HoeffdingSplit<
@@ -284,8 +284,8 @@ void HoeffdingSplit<
template<
typename FitnessFunction,
- typename NumericSplitType,
- typename CategoricalSplitType
+ template<typename> class NumericSplitType,
+ template<typename> class CategoricalSplitType
>
template<typename StreamingDecisionTreeType>
void HoeffdingSplit<
@@ -325,8 +325,8 @@ void HoeffdingSplit<
template<
typename FitnessFunction,
- typename NumericSplitType,
- typename CategoricalSplitType
+ template<typename> class NumericSplitType,
+ template<typename> class CategoricalSplitType
>
template<typename Archive>
void HoeffdingSplit<
@@ -364,15 +364,17 @@ void HoeffdingSplit<
for (size_t i = 0; i < datasetInfo->Dimensionality(); ++i)
{
if (datasetInfo->Type(i) == data::Datatype::categorical)
- categoricalSplits.push_back(CategoricalSplitType(
+ categoricalSplits.push_back(CategoricalSplitType<FitnessFunction>(
datasetInfo->NumMappings(i), numClasses));
else
- numericSplits.push_back(NumericSplitType(numClasses));
+ numericSplits.push_back(
+ NumericSplitType<FitnessFunction>(numClasses));
}
// Clear things we don't need.
- categoricalSplit = typename CategoricalSplitType::SplitInfo(numClasses);
- numericSplit = typename NumericSplitType::SplitInfo();
+ categoricalSplit = typename CategoricalSplitType<FitnessFunction>::
+ SplitInfo(numClasses);
+ numericSplit = typename NumericSplitType<FitnessFunction>::SplitInfo();
}
// There's no need to serialize if there's no information contained in the
More information about the mlpack-git
mailing list