[mlpack-svn] r16687 - mlpack/trunk/src/mlpack/methods/det

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Jun 12 16:57:22 EDT 2014


Author: rcurtin
Date: Thu Jun 12 16:57:22 2014
New Revision: 16687

Log:
Fix #334 by ensuring vector accesses don't go out of bounds.


Modified:
   mlpack/trunk/src/mlpack/methods/det/dt_utils.cpp

Modified: mlpack/trunk/src/mlpack/methods/det/dt_utils.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/det/dt_utils.cpp	(original)
+++ mlpack/trunk/src/mlpack/methods/det/dt_utils.cpp	Thu Jun 12 16:57:22 2014
@@ -214,8 +214,10 @@
         minLeafSize);
 
     // Sequentially prune with all the values of available alphas and adding
-    // values for test values.
-    for (size_t i = 0; i < prunedSequence.size() - 2; ++i)
+    // values for test values.  Don't enter this loop if there are less than two
+    // trees in the pruned sequence.
+    for (size_t i = 0;
+         i < ((prunedSequence.size() < 2) ? 0 : prunedSequence.size() - 2); ++i)
     {
       // Compute test values for this state of the tree.
       double cvVal = 0.0;
@@ -242,8 +244,9 @@
       cvVal += cvDTree->ComputeValue(testPoint);
     }
 
-    regularizationConstants[prunedSequence.size() - 2] += 2.0 * cvVal /
-        (double) dataset.n_cols;
+    if (prunedSequence.size() > 2)
+      regularizationConstants[prunedSequence.size() - 2] += 2.0 * cvVal /
+          (double) dataset.n_cols;
 
     test.reset();
     delete cvDTree;



More information about the mlpack-svn mailing list