[mlpack-git] master, mlpack-1.0.x: First pass: comment standardization, fix header guard names, move .cpp to .hpp because it's all templated functions. (92ad00f)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:49:22 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 92ad00f925863e722e3d5192d47ce3616819086d
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Jun 24 00:03:24 2014 +0000

    First pass: comment standardization, fix header guard names, move .cpp to .hpp
    because it's all templated functions.


>---------------------------------------------------------------

92ad00f925863e722e3d5192d47ce3616819086d
 src/mlpack/methods/decision_stump/CMakeLists.txt   |   2 +-
 .../methods/decision_stump/decision_stump.hpp      | 129 ++++++-----
 ...sion_stump_impl.cpp => decision_stump_impl.hpp} | 246 ++++++++++-----------
 .../methods/decision_stump/decision_stump_main.cpp |   2 +-
 4 files changed, 181 insertions(+), 198 deletions(-)

diff --git a/src/mlpack/methods/decision_stump/CMakeLists.txt b/src/mlpack/methods/decision_stump/CMakeLists.txt
index 2e6dfe6..0bc9b8b 100644
--- a/src/mlpack/methods/decision_stump/CMakeLists.txt
+++ b/src/mlpack/methods/decision_stump/CMakeLists.txt
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 2.8)
 # Anything not in this list will not be compiled into MLPACK.
 set(SOURCES
   decision_stump.hpp
-  decision_stump_impl.cpp
+  decision_stump_impl.hpp
 )
 
 # Add directory name to sources.
diff --git a/src/mlpack/methods/decision_stump/decision_stump.hpp b/src/mlpack/methods/decision_stump/decision_stump.hpp
index 8faa977..ed1dbff 100644
--- a/src/mlpack/methods/decision_stump/decision_stump.hpp
+++ b/src/mlpack/methods/decision_stump/decision_stump.hpp
@@ -2,126 +2,123 @@
  * @file decision_stump.hpp
  * @author Udit Saxena
  *
- * Defintion of decision stumps.
+ * Definition of decision stumps.
  */
-
-#ifndef _MLPACK_METHODS_DECISION_STUMP_HPP
-#define _MLPACK_METHODS_DECISION_STUMP_HPP
+#ifndef __MLPACK_METHODS_DECISION_STUMP_DECISION_STUMP_HPP
+#define __MLPACK_METHODS_DECISION_STUMP_DECISION_STUMP_HPP
 
 #include <mlpack/core.hpp>
 
 namespace mlpack {
 namespace decision_stump {
-/*
+
+/**
  * This class implements a decision stump. It constructs a single level
- * decision tree, i.e. a decision stump. It uses entropy to decided splitting
+ * decision tree, i.e., a decision stump. It uses entropy to decide splitting
  * ranges.
- *
  */
 template <typename MatType = arma::mat>
 class DecisionStump
 {
  public:
-  /*
-  Constructor. Train on the provided data. Generate a decision stump
-  from data. 
-
-  @param: data - Input, training data.
-  @param: labels - Labels of data.
-  @param: classes - number of distinct classes in labels.
-  @param: inpBucketSize - minimum size of bucket when splitting.
+  /**
+   * Constructor. Train on the provided data. Generate a decision stump from
+   * data.
+   *
+   * @param data Input, training data.
+   * @param labels Labels of training data.
+   * @param classes Number of distinct classes in labels.
+   * @param inpBucketSize Minimum size of bucket when splitting.
    */
   DecisionStump(const MatType& data,
                 const arma::Row<size_t>& labels,
                 const size_t classes,
                 size_t inpBucketSize);
 
-  /*
-  Classification function. After training, classify test, and put the 
-  predicted classes in predictedLabels.
-
-  @param: test - testing data or data to classify. 
-  @param: predictedLabels - vector to store the predicted classes after
-                            classifying test
+  /**
+   * Classification function. After training, classify test, and put the
+   * predicted classes in predictedLabels.
+   *
+   * @param test Testing data or data to classify.
+   * @param predictedLabels Vector to store the predicted classes after
+   *     classifying test data.
    */
   void Classify(const MatType& test, arma::Row<size_t>& predictedLabels);
 
  private:
-  /* Stores the number of classes.*/
+  //! Stores the number of classes.
   size_t numClass;
 
-  /* Stores the default class. Provided for handling missing attribute values.*/
+  //! Stores the default class. Provided for handling missing attribute values.
   size_t defaultClass;
 
-  /* Stores the value of the attribute on which to split.*/
+  //! Stores the value of the attribute on which to split.
   int splitCol;
 
-  /* Flag value for distinct input class labels.*/
+  //! Flag value for distinct input class labels.
   int oneClass;
 
-  /* Size of bucket while determining splitting criterion.*/
+  //! Size of bucket while determining splitting criterion.
   size_t bucketSize;
 
-  /* Stores the class labels for the input data*/
+  //! Stores the class labels for the input data.
   arma::Row<size_t> classLabels;
 
-  /* Stores the splitting criterion after training.*/
+  //! Stores the splitting criterion after training.
   arma::mat split;
 
-  /* 
-  Sets up attribute as if it were splitting on it and 
-  finds entropy when splitting on attribute.
-
-  @param: attribute - a row from the training data, which might be a
-                      candidate for the splitting attribute.
-  */
+  /**
+   * Sets up attribute as if it were splitting on it and finds entropy when
+   * splitting on attribute.
+   *
+   * @param attribute A row from the training data, which might be a
+   *     candidate for the splitting attribute.
+   */
   double SetupSplitAttribute(const arma::rowvec& attribute);
 
-  /* 
-  After having decided the attribute on which to split, 
-  train on that attribute.
-
-  @param: attribute - attribute is the attribute decided by the constructor
-                      on which we now train the decision stump.
+  /**
+   * After having decided the attribute on which to split, train on that
+   * attribute.
+   *
+   * @param attribute attribute is the attribute decided by the constructor
+   *      on which we now train the decision stump.
    */
   template <typename rType> void TrainOnAtt(const arma::rowvec& attribute);
 
-  /* After the "split" matrix has been set up, 
-     merging ranges with identical class labels.
+  /**
+   * After the "split" matrix has been set up, merge ranges with identical class
+   * labels.
    */
   void MergeRanges();
 
-  /* 
-  Used to count the most frequently occurring element in subCols.
-
-  @param: subCols - the vector in which to find the most frequently 
-                    occurring element.  
+  /**
+   * Count the most frequently occurring element in subCols.
+   *
+   * @param subCols The vector in which to find the most frequently
+   *     occurring element.
    */
   template <typename rType> rType CountMostFreq(const arma::Row<rType>& subCols);
 
-  /* 
-  Returns 1 if all the values of featureRow are not same.
-
-  @param: featureRow - the attribute which is checked so that it 
-                       does not have identical values. 
-  */
+  /**
+   * Returns 1 if all the values of featureRow are not same.
+   *
+   * @param featureRow The attribute which is checked for identical values.
+   */
   template <typename rType> int isDistinct(const arma::Row<rType>& featureRow);
 
-  /* 
-  Calculating Entropy of attribute.
-
-  @param: attribute - the attribute of which we calculate the entropy.
-  @param: labels - corresponding labels of the attribute.
-  */
+  /**
+   * Calculate the entropy of the given attribute.
+   *
+   * @param attribute The attribute of which we calculate the entropy.
+   * @param labels Corresponding labels of the attribute.
+   */
   double CalculateEntropy(const arma::rowvec& attribute,
                           const arma::rowvec& labels);
-
-  
 };
 
-}; //namespace decision_stump
-}; //namespace mlpack
+}; // namespace decision_stump
+}; // namespace mlpack
 
-#include "decision_stump_impl.cpp"
+#include "decision_stump_impl.hpp"
 
 #endif
diff --git a/src/mlpack/methods/decision_stump/decision_stump_impl.cpp b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
similarity index 56%
rename from src/mlpack/methods/decision_stump/decision_stump_impl.cpp
rename to src/mlpack/methods/decision_stump/decision_stump_impl.hpp
index f216987..b3ef678 100644
--- a/src/mlpack/methods/decision_stump/decision_stump_impl.cpp
+++ b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
@@ -1,11 +1,14 @@
 /**
  * @file decision_stump_impl.hpp
  * @author Udit Saxena
-**/
+ *
+ * Implementation of DecisionStump class.
+ */
 
-#ifndef _MLPACK_METHODS_DECISION_STUMP_IMPL_HPP
-#define _MLPACK_METHODS_DECISION_STUMP_IMPL_HPP
+#ifndef __MLPACK_METHODS_DECISION_STUMP_DECISION_STUMP_IMPL_HPP
+#define __MLPACK_METHODS_DECISION_STUMP_DECISION_STUMP_IMPL_HPP
 
+// In case it hasn't been included yet.
 #include "decision_stump.hpp"
 
 #include <set>
@@ -13,14 +16,14 @@
 
 namespace mlpack {
 namespace decision_stump {
-/*
-  Constructor. Train on the provided data. Generate a decision stump
-  from data. 
-
-  @param: data - Input, training data.
-  @param: labels - Labels of data.
-  @param: classes - number of distinct classes in labels.
-  @param: inpBucketSize - minimum size of bucket when splitting.
+
+/**
+ * Constructor. Train on the provided data. Generate a decision stump from data.
+ *
+ * @param data Input, training data.
+ * @param labels Labels of data.
+ * @param classes Number of distinct classes in labels.
+ * @param inpBucketSize Minimum size of bucket when splitting.
  */
 template<typename MatType>
 DecisionStump<MatType>::DecisionStump(const MatType& data,
@@ -36,94 +39,90 @@ DecisionStump<MatType>::DecisionStump(const MatType& data,
   bucketSize = inpBucketSize;
 
   /* Check whether the input labels are not all identical. */
-  if ( !isDistinct<size_t>(classLabels) )
+  if (!isDistinct<size_t>(classLabels))
   {
-    // If the classLabels are all identical, 
-    // the default class is the only class set. 
+    // If the classLabels are all identical, the default class is the only
+    // class.
     oneClass = 1;
     defaultClass = classLabels(0);
   }
 
   else
   {
-    // If classLabels are not all identical
-    // proceed for training
-
+    // If classLabels are not all identical, proceed with training.
     oneClass = 0;
-    int bestAtt=-1,i;
-    double entropy,bestEntropy=DBL_MAX; 
+    int bestAtt = -1;
+    double entropy;
+    double bestEntropy = DBL_MAX;
 
-    // Set the default class to handle attribute values which are 
-    // not present in the training data. 
+    // Set the default class to handle attribute values which are not present in
+    // the training data.
     defaultClass = CountMostFreq<size_t>(classLabels);
 
-    for (i = 0;i < data.n_rows; i++)
+    for (int i = 0; i < data.n_rows; i++)
     {
-      // going through each attribute of data.
+      // Go through each attribute of the data.
       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));
+        // 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));
 
-        // finding the attribute with the bestEntropy
-        // so that the gain is max.
+        // Find the attribute with the bestEntropy so that the gain is
+        // maximized.
         if (entropy < bestEntropy)
         {
           bestAtt = i;
           bestEntropy = entropy;
         }
-
       }
     }
     splitCol = bestAtt;
 
-    // once the splitting column/attribute has been decided, 
-    // train on it.
+    // Once the splitting column/attribute has been decided, train on it.
     TrainOnAtt<double>(data.row(splitCol));
   }
 }
 
-/*
-  Classification function. After training, classify test, and put the 
-  predicted classes in predictedLabels.
-
-  @param: test - testing data or data to classify. 
-  @param: predictedLabels - vector to store the predicted classes after
-                            classifying test
+/**
+ * Classification function. After training, classify test, and put the predicted
+ * classes in predictedLabels.
+ *
+ * @param test Testing data or data to classify.
+ * @param predictedLabels Vector to store the predicted classes after
+ *      classifying test
  */
 template<typename MatType>
 void DecisionStump<MatType>::Classify(const MatType& test,
                                       arma::Row<size_t>& predictedLabels)
 {
-  int i,j,flag;
+  int flag;
   double val;
-  if ( !oneClass )
+  if (!oneClass)
   {
-    for (i = 0; i < test.n_cols; i++)
+    for (int i = 0; i < test.n_cols; i++)
     {
-      j = 0;
+      int j = 0;
       flag = 0;
 
       val = test(splitCol,i);
       while ((j < split.n_rows) && (!flag))
       {
-        if(val < split(j,0) && (!j))
+        if (val < split(j, 0) && (!j))
         {
-          predictedLabels(i) = split(0,1);
+          predictedLabels(i) = split(0, 1);
           flag = 1;
         }
-        else if (val >= split(j,0))
+        else if (val >= split(j, 0))
         {
-          if(j == split.n_rows - 1)
+          if (j == split.n_rows - 1)
           {
             predictedLabels(i) = split(split.n_rows - 1, 1);
             flag = 1;
           }
-          else if (val < split(j+1,0))
+          else if (val < split(j + 1, 0))
           {
-            predictedLabels(i) = split(j,1);
+            predictedLabels(i) = split(j, 1);
             flag = 1;
           }
         }
@@ -133,18 +132,17 @@ void DecisionStump<MatType>::Classify(const MatType& test,
   }
   else
   {
-    for (i = 0;i < test.n_cols;i++)
-      predictedLabels(i)=defaultClass;
+    for (int i = 0; i < test.n_cols; i++)
+      predictedLabels(i) = defaultClass;
   }
-
 }
 
-/* 
-  Sets up attribute as if it were splitting on it and 
-  finds entropy when splitting on attribute.
-
-  @param: attribute - a row from the training data, which might be a
-                      candidate for the splitting attribute.
+/**
+ * Sets up attribute as if it were splitting on it and finds entropy when
+ * splitting on attribute.
+ *
+ * @param attribute A row from the training data, which might be a candidate for
+ *      the splitting attribute.
  */
 template <typename MatType>
 double DecisionStump<MatType>::SetupSplitAttribute(const arma::rowvec& attribute)
@@ -152,15 +150,13 @@ double DecisionStump<MatType>::SetupSplitAttribute(const arma::rowvec& attribute
   int i, count, begin, end;
   double entropy = 0.0;
 
-  // sorting the attribute, for calculating splitting ranges
+  // Sort the attribute in order to calculate splitting ranges.
   arma::rowvec sortedAtt = arma::sort(attribute);
 
-  // storing the indexes of the sorted attribute to build 
-  // a vector of sorted labels.
-  // this sort is stable.
+  // Store the indices of the sorted attribute to build a vector of sorted
+  // labels.  This sort is stable.
   arma::uvec sortedIndexAtt = arma::stable_sort_index(attribute.t());
 
-  // vector of sorted labels
   arma::Row<size_t> sortedLabels(attribute.n_elem);
   sortedLabels.fill(0);
 
@@ -173,7 +169,8 @@ double DecisionStump<MatType>::SetupSplitAttribute(const arma::rowvec& attribute
   i = 0;
   count = 0;
 
-  // this splits the sorted into buckets of size >= inpBucketSize
+  // This splits the sorted into buckets of size greater than or equal to
+  // inpBucketSize.
   while (i < sortedLabels.n_elem)
   {
     count++;
@@ -195,14 +192,14 @@ double DecisionStump<MatType>::SetupSplitAttribute(const arma::rowvec& attribute
       entropy += CalculateEntropy(subColAtts, subColLabels);
       i++;
     }
-    else if( sortedLabels(i) != sortedLabels(i + 1) )
+    else if (sortedLabels(i) != sortedLabels(i + 1))
     {
       if (count < bucketSize)
       {
         begin = i - count + 1;
         end = begin + bucketSize - 1;
 
-        if ( end > sortedLabels.n_elem - 1)
+        if (end > sortedLabels.n_elem - 1)
           end = sortedLabels.n_elem - 1;
       }
       else
@@ -221,12 +218,11 @@ double DecisionStump<MatType>::SetupSplitAttribute(const arma::rowvec& attribute
 
       subColAtts = sortedAtt.cols(begin, end) + zSubColAtts;
 
-      // now using subColLabels and subColAtts to calculate entropuy
+      // Now use subColLabels and subColAtts to calculate entropy.
       entropy += CalculateEntropy(subColAtts, subColLabels);
 
       i = end + 1;
       count = 0;
-
     }
     else
       i++;
@@ -234,12 +230,12 @@ double DecisionStump<MatType>::SetupSplitAttribute(const arma::rowvec& attribute
   return entropy;
 }
 
-/* 
-  After having decided the attribute on which to split, 
-  train on that attribute.
-
-  @param: attribute - attribute is the attribute decided by the constructor
-                      on which we now train the decision stump.
+/**
+ * After having decided the attribute on which to split, train on that
+ * attribute.
+ *
+ * @param attribute Attribute is the attribute decided by the constructor on
+ *      which we now train the decision stump.
  */
 template <typename MatType>
 template <typename rType>
@@ -280,14 +276,15 @@ void DecisionStump<MatType>::TrainOnAtt(const arma::rowvec& attribute)
 
       i++;
     }
-    else if( sortedLabels(i) != sortedLabels(i + 1) )
+    else if (sortedLabels(i) != sortedLabels(i + 1))
     {
-      if (count < bucketSize) // test for differevalues of bucketSize, especially extreme cases. 
+      if (count < bucketSize)
       {
+        // Test for different values of bucketSize, especially extreme cases.
         begin = i - count + 1;
         end = begin + bucketSize - 1;
 
-        if ( end > sortedLabels.n_elem - 1)
+        if (end > sortedLabels.n_elem - 1)
           end = sortedLabels.n_elem - 1;
       }
       else
@@ -300,12 +297,11 @@ void DecisionStump<MatType>::TrainOnAtt(const arma::rowvec& attribute)
 
       subCols = sortedLabels.cols(begin, end) + zSubCols;
 
-      // finding the most freq element in subCols so as to assign a label to the
-      // bucket of subCols
-
+      // Find the most frequent element in subCols so as to assign a label to
+      // the bucket of subCols.
       mostFreq = CountMostFreq<double>(subCols);
 
-      tempSplit << sortedSplitAtt(begin)<< mostFreq << arma::endr;
+      tempSplit << sortedSplitAtt(begin) << mostFreq << arma::endr;
       split = arma::join_cols(split, tempSplit);
 
       i = end + 1;
@@ -315,26 +311,25 @@ void DecisionStump<MatType>::TrainOnAtt(const arma::rowvec& attribute)
       i++;
   }
 
-  // now trimming the split matrix so that buckets one after the after 
-  // which point to the same classLabel are merged as one big bucket.
+  // Now trim the split matrix so that buckets one after the after which point
+  // to the same classLabel are merged as one big bucket.
   MergeRanges();
 }
 
-/* After the "split" matrix has been set up, 
-     merging ranges with identical class labels.
+/**
+ * After the "split" matrix has been set up, merge ranges with identical class
+ * labels.
  */
 template <typename MatType>
 void DecisionStump<MatType>::MergeRanges()
 {
-  int i;
-  for (i = 1;i < split.n_rows; i++)
+  for (int i = 1; i < split.n_rows; i++)
   {
-    if (split(i,1) == split(i-1,1))
+    if (split(i, 1) == split(i - 1, 1))
     {
-      // remove this row, as it has the same label as
-      // the previous bucket.
+      // Remove this row, as it has the same label as the previous bucket.
       split.shed_row(i);
-      // go back to previous row.
+      // Go back to previous row.
       i--;
     }
   }
@@ -344,26 +339,25 @@ template <typename MatType>
 template <typename rType>
 rType DecisionStump<MatType>::CountMostFreq(const arma::Row<rType>& subCols)
 {
-  // sort subCols for easier processing.
+  // Sort subCols for easier processing.
   arma::Row<rType> sortCounts = arma::sort(subCols);
   rType element;
-  int count = 0, localCount = 0,i;
+  int count = 0, localCount = 0;
 
-  // an O(n) loop which counts the most frequent element in sortCounts
-  for (i = 0; i < sortCounts.n_elem ; ++i)
+  // An O(n) loop which counts the most frequent element in sortCounts
+  for (int i = 0; i < sortCounts.n_elem; ++i)
   {
     if (i == sortCounts.n_elem - 1)
     {
-      if (sortCounts(i-1) == sortCounts(i))
+      if (sortCounts(i - 1) == sortCounts(i))
       {
-        // element = sortCounts(i-1);
+        // element = sortCounts(i - 1);
         localCount++;
       }
-      else
-      if (localCount > count)
+      else if (localCount > count)
         count = localCount;
     }
-    else if (sortCounts(i) != sortCounts(i+1))
+    else if (sortCounts(i) != sortCounts(i + 1))
     {
       localCount = 0;
       count++;
@@ -374,7 +368,7 @@ rType DecisionStump<MatType>::CountMostFreq(const arma::Row<rType>& subCols)
       if (localCount > count)
       {
         count = localCount;
-        if(localCount == 1)
+        if (localCount == 1)
           element = sortCounts(i);
       }
     }
@@ -382,34 +376,32 @@ rType DecisionStump<MatType>::CountMostFreq(const arma::Row<rType>& subCols)
   return element;
 }
 
-/* 
-  Returns 1 if all the values of featureRow are not same.
-
-  @param: featureRow - the attribute which is checked so that it 
-                       does not have identical values. 
+/**
+ * Returns 1 if all the values of featureRow are not same.
+ *
+ * @param featureRow The attribute which is checked for identical values.
  */
 template <typename MatType>
 template <typename rType>
 int DecisionStump<MatType>::isDistinct(const arma::Row<rType>& featureRow)
 {
-  if (featureRow.max()-featureRow.min() > 0)
+  if (featureRow.max() - featureRow.min() > 0)
     return 1;
   else
     return 0;
 }
 
-/* 
-  Calculating Entropy of attribute.
-
-  @param: attribute - the attribute of which we calculate the entropy.
-  @param: labels - corresponding labels of the attribute.
+/**
+ * Calculating Entropy of attribute.
+ *
+ * @param attribute The attribute for which we calculate the entropy.
+ * @param labels Corresponding labels of the attribute.
  */
 template<typename MatType>
 double DecisionStump<MatType>::CalculateEntropy(const arma::rowvec& attribute,
                                                 const arma::rowvec& labels)
 {
-  int i,j;
-  double entropy=0.0;
+  double entropy = 0.0;
 
   arma::rowvec uniqueAtt = arma::unique(attribute);
   arma::rowvec uniqueLabel = arma::unique(labels);
@@ -418,11 +410,11 @@ double DecisionStump<MatType>::CalculateEntropy(const arma::rowvec& attribute,
   arma::Mat<size_t> entropyArray(uniqueAtt.n_elem,numClass);
   entropyArray.fill(0);
 
-  // populating entropyArray and numElem, they are to be used as 
-  // helpers to calculate entropy
-  for (j = 0;j < uniqueAtt.n_elem; j++)
+  // Populate entropyArray and numElem; they are used as helpers to calculate
+  // entropy.
+  for (int j = 0; j < uniqueAtt.n_elem; j++)
   {
-    for (i = 0; i < attribute.n_elem; i++)
+    for (int i = 0; i < attribute.n_elem; i++)
     {
       if (uniqueAtt[j] == attribute[i])
       {
@@ -432,28 +424,22 @@ double DecisionStump<MatType>::CalculateEntropy(const arma::rowvec& attribute,
     }
   }
 
-  double p1, p2, p3;
-  for ( j = 0; j < uniqueAtt.size(); j++ )
+  for (int j = 0; j < uniqueAtt.size(); j++)
   {
-    p1 = ((double)numElem(j) / attribute.n_elem);
+    const double p1 = ((double) numElem(j) / attribute.n_elem);
 
-    for ( i = 0; i < numClass; i++)
+    for (int i = 0; i < numClass; i++)
     {
-      p2 = ((double)entropyArray(j,i) / numElem(j));
+      const double p2 = ((double) entropyArray(j, i) / numElem(j));
+      const double p3 = (p2 == 0) ? 0 : p2 * log2(p2);
 
-      if(p2 == 0)
-        p3 = 0;
-      else
-        p3 = (  p2 * log2(p2) );
-
-      entropy+=( p1 * p3 );
+      entropy += p1 * p3;
     }
   }
 
   return entropy;
 }
 
-
 }; // namespace decision_stump
 }; // namespace mlpack
 
diff --git a/src/mlpack/methods/decision_stump/decision_stump_main.cpp b/src/mlpack/methods/decision_stump/decision_stump_main.cpp
index 186a7cb..4c998d5 100644
--- a/src/mlpack/methods/decision_stump/decision_stump_main.cpp
+++ b/src/mlpack/methods/decision_stump/decision_stump_main.cpp
@@ -2,7 +2,7 @@
  * @author: Udit Saxena
  * @file: decision_stump_main.cpp
  *
- *
+ * Main executable for the decision stump.
  */
 
 #include <mlpack/core.hpp>



More information about the mlpack-git mailing list