[mlpack-git] master, mlpack-1.0.x: Fix #334 by ensuring vector accesses don't go out of bounds. (bd7aef7)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:49:00 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 bd7aef7910acf070c83acfea3da4568d3e7388b3
Author: Ryan Curtin <ryan at ratml.org>
Date: Thu Jun 12 20:57:22 2014 +0000
Fix #334 by ensuring vector accesses don't go out of bounds.
>---------------------------------------------------------------
bd7aef7910acf070c83acfea3da4568d3e7388b3
src/mlpack/methods/det/dt_utils.cpp | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/mlpack/methods/det/dt_utils.cpp b/src/mlpack/methods/det/dt_utils.cpp
index 2db68e0..273ed98 100644
--- a/src/mlpack/methods/det/dt_utils.cpp
+++ b/src/mlpack/methods/det/dt_utils.cpp
@@ -214,8 +214,10 @@ DTree* mlpack::det::Trainer(arma::mat& dataset,
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 @@ DTree* mlpack::det::Trainer(arma::mat& dataset,
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-git
mailing list