[mlpack-git] master, mlpack-1.0.x: IsDistinct() improved. (94be125)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:52:32 EST 2015
Repository : https://github.com/mlpack/mlpack
On branches: master,mlpack-1.0.x
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit 94be1252d8d6ed80145b1d894ba7e228df111cbc
Author: Udit Saxena <saxena.udit at gmail.com>
Date: Wed Jul 9 20:15:45 2014 +0000
IsDistinct() improved.
>---------------------------------------------------------------
94be1252d8d6ed80145b1d894ba7e228df111cbc
src/mlpack/methods/decision_stump/decision_stump.hpp | 2 +-
.../methods/decision_stump/decision_stump_impl.hpp | 15 ++++++++-------
src/mlpack/tests/decision_stump_test.cpp | 18 ------------------
3 files changed, 9 insertions(+), 26 deletions(-)
diff --git a/src/mlpack/methods/decision_stump/decision_stump.hpp b/src/mlpack/methods/decision_stump/decision_stump.hpp
index 2e57d05..fb4d6c9 100644
--- a/src/mlpack/methods/decision_stump/decision_stump.hpp
+++ b/src/mlpack/methods/decision_stump/decision_stump.hpp
@@ -123,7 +123,7 @@ class DecisionStump
*
* @param featureRow The attribute which is checked for identical values.
*/
- template <typename rType> int isDistinct(const arma::Row<rType>& featureRow);
+ template <typename rType> int IsDistinct(const arma::Row<rType>& featureRow);
/**
* Calculate the entropy of the given attribute.
diff --git a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
index cfe4388..7300521 100644
--- a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
+++ b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
@@ -44,13 +44,13 @@ DecisionStump<MatType>::DecisionStump(const MatType& data,
for (int i = 0; i < data.n_rows; i++)
{
// Go through each attribute of the data.
- if (isDistinct<double>(data.row(i)))
+ if (IsDistinct<double>(data.row(i)))
{
// For each attribute with non-identical values, treat it as a potential
// splitting attribute and calculate entropy if split on it.
entropy = SetupSplitAttribute(data.row(i), labels);
- Log::Debug << "Entropy for attribute " << i << " is " << entropy << ".\n";
+ // Log::Debug << "Entropy for attribute " << i << " is " << entropy << ".\n";
gain = rootEntropy - entropy;
// Find the attribute with the best entropy so that the gain is
// maximized.
@@ -351,12 +351,13 @@ rType DecisionStump<MatType>::CountMostFreq(const arma::Row<rType>& subCols)
*/
template <typename MatType>
template <typename rType>
-int DecisionStump<MatType>::isDistinct(const arma::Row<rType>& featureRow)
+int DecisionStump<MatType>::IsDistinct(const arma::Row<rType>& featureRow)
{
- if (featureRow.max() - featureRow.min() > 0)
- return 1;
- else
- return 0;
+ rType val = featureRow(0);
+ for (size_t i = 1; i < featureRow.n_elem; ++i)
+ if (val != featureRow(i))
+ return 1;
+ return 0;
}
/**
diff --git a/src/mlpack/tests/decision_stump_test.cpp b/src/mlpack/tests/decision_stump_test.cpp
index a56dff8..dec4f2c 100644
--- a/src/mlpack/tests/decision_stump_test.cpp
+++ b/src/mlpack/tests/decision_stump_test.cpp
@@ -307,22 +307,4 @@ BOOST_AUTO_TEST_CASE(DimensionSelectionTest)
}
}
-BOOST_AUTO_TEST_CASE(TempAttributeSplit)
-{
- const size_t numClasses = 2;
- const size_t inpBucketSize = 3;
-
- mat trainingData;
- trainingData << 1 << 1 << 1 << 2 << 2 << 2 << endr
- << 0.5 << 0.6 << 0.7 << 0.4 << 0.3 << 0.5 << endr;
-
- Mat<size_t> labelsIn;
- labelsIn << 0 << 0 << 0 << 0 << 1 << 1 << 1;
-
- DecisionStump<> ds(trainingData, labelsIn.row(0), numClasses, inpBucketSize);
-
- // Row<size_t> predictedLabels(testingData.n_cols);
- // ds.Classify(testingData, predictedLabels);
- BOOST_CHECK_EQUAL(ds.SplitAttribute(), 0);
-}
BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-git
mailing list