[mlpack-svn] r16936 - mlpack/trunk/src/mlpack/methods/decision_stump

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Aug 4 11:18:31 EDT 2014


Author: rcurtin
Date: Mon Aug  4 11:18:30 2014
New Revision: 16936

Log:
Minor code cleanups.


Modified:
   mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump.hpp
   mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump_impl.hpp

Modified: mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump.hpp	Mon Aug  4 11:18:30 2014
@@ -54,23 +54,21 @@
   void Classify(const MatType& test, arma::Row<size_t>& predictedLabels);
 
   /**
-   *  Alternate constructor which copies parameters bucketSize and numClass
-   *  from an already initiated decision stump, other. It appropriately 
-   *  sets the Weight vector.
-   *
-   *  @param other The other initiated Decision Stump object from 
-   *               which we copy the values from.
-   *  @param data The data on which to train this object on.
-   *  @param D Weight vector to use while training. For boosting purposes.
-   *  @param labels The labels of data.
-   */
-  DecisionStump(
-    const DecisionStump<>& other, 
-    const MatType& data, 
-    const arma::rowvec& weights, 
-    const arma::Row<size_t>& labels
-    );
-  
+   * Alternate constructor which copies parameters bucketSize and numClass from
+   * an already initiated decision stump, other. It appropriately sets the
+   * weight vector.
+   *
+   * @param other The other initiated Decision Stump object from
+   *      which we copy the values from.
+   * @param data The data on which to train this object on.
+   * @param D Weight vector to use while training. For boosting purposes.
+   * @param labels The labels of data.
+   */
+  DecisionStump(const DecisionStump<>& other,
+                const MatType& data,
+                const arma::rowvec& weights,
+                const arma::Row<size_t>& labels);
+
   //! Access the splitting attribute.
   int SplitAttribute() const { return splitAttribute; }
   //! Modify the splitting attribute (be careful!).
@@ -134,7 +132,8 @@
    * @param subCols The vector in which to find the most frequently
    *     occurring element.
    */
-  template <typename rType> rType CountMostFreq(const arma::Row<rType>& subCols);
+  template <typename rType> rType CountMostFreq(const arma::Row<rType>&
+      subCols);
 
   /**
    * Returns 1 if all the values of featureRow are not same.
@@ -153,8 +152,10 @@
   double CalculateEntropy(arma::subview_row<LabelType> labels, int begin);
 
   /**
+   * Train the decision stump on the given data and labels.
    *
-   *
+   * @param data Dataset to train on.
+   * @param labels Labels for dataset.
    */
   void Train(const MatType& data, const arma::Row<size_t>& labels);
 

Modified: mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump_impl.hpp	Mon Aug  4 11:18:30 2014
@@ -60,7 +60,6 @@
       // splitting attribute and calculate entropy if split on it.
       entropy = SetupSplitAttribute(data.row(i), labels);
 
-      // 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.
@@ -114,21 +113,21 @@
 }
 
 /**
- *  Alternate constructor which copies parameters bucketSize and numClass
- *  from an already initiated decision stump, other. It appropriately 
- *  sets the Weight vector.
+ * Alternate constructor which copies parameters bucketSize and numClass
+ * from an already initiated decision stump, other. It appropriately
+ * sets the Weight vector.
  *
- *  @param other The other initiated Decision Stump object from 
- *               which we copy the values from.
- *  @param data The data on which to train this object on.
- *  @param D Weight vector to use while training. For boosting purposes.
- *  @param labels The labels of data.
+ * @param other The other initiated Decision Stump object from
+ *      which we copy the values from.
+ * @param data The data on which to train this object on.
+ * @param D Weight vector to use while training. For boosting purposes.
+ * @param labels The labels of data.
  */
 template <typename MatType>
 DecisionStump<MatType>::DecisionStump(
-                        const DecisionStump<>& other, 
-                        const MatType& data, 
-                        const arma::rowvec& weights, 
+                        const DecisionStump<>& other,
+                        const MatType& data,
+                        const arma::rowvec& weights,
                         const arma::Row<size_t>& labels
                         )
 {
@@ -173,7 +172,7 @@
     sortedLabels(i) = labels(sortedIndexAtt(i));
     tempD(i) = weightD(sortedIndexAtt(i));
   }
-  
+
   i = 0;
   count = 0;
 
@@ -411,7 +410,9 @@
  */
 template<typename MatType>
 template<typename LabelType>
-double DecisionStump<MatType>::CalculateEntropy(arma::subview_row<LabelType> labels, int begin)
+double DecisionStump<MatType>::CalculateEntropy(
+    arma::subview_row<LabelType> labels,
+    int begin)
 {
   double entropy = 0.0;
   size_t j;
@@ -419,21 +420,20 @@
   arma::Row<size_t> numElem(numClass);
   numElem.fill(0);
 
-  // variable to accumulate the weight in this subview_row
+  // Variable to accumulate the weight in this subview_row.
   double accWeight = 0.0;
-  // Populate numElem; they are used as helpers to calculate
-  // entropy.
-  
+  // Populate numElem; they are used as helpers to calculate entropy.
+
   for (j = 0; j < labels.n_elem; j++)
   {
     numElem(labels(j)) += tempD(j + begin);
     accWeight += tempD(j + begin);
-  }  
+  }
     // numElem(labels(j))++;
 
   for (j = 0; j < numClass; j++)
   {
-    const double p1 = ((double) numElem(j) / accWeight); 
+    const double p1 = ((double) numElem(j) / accWeight);
 
     entropy += (p1 == 0) ? 0 : p1 * log2(p1);
   }



More information about the mlpack-svn mailing list