[mlpack] 162/324: IsDistinct() improved.
Barak A. Pearlmutter
barak+git at cs.nuim.ie
Sun Aug 17 08:22:06 UTC 2014
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch svn-trunk
in repository mlpack.
commit 2a648152b43850275a667c6c6abddb2b78b3a8ff
Author: saxena.udit <saxena.udit at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date: Wed Jul 9 20:15:45 2014 +0000
IsDistinct() improved.
git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16801 9d5b8971-822b-0410-80eb-d18c1038ef23
---
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();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git
More information about the debian-science-commits
mailing list