[mlpack-git] master: Performance improvments. BuildWeightMatrix() is probably unnecessary entirely. (c10cc27)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Mon Nov 30 17:24:38 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/10b9d45b806a3e879b0564d78ccb183ebc7051ba...31c557d9cc7e4da57fd8a246085c19e076d12271

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

commit c10cc279c0109880c4e168b5088921c4d45727ca
Author: Ryan Curtin <ryan at ratml.org>
Date:   Mon Nov 30 21:46:01 2015 +0000

    Performance improvments.
    BuildWeightMatrix() is probably unnecessary entirely.


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

c10cc279c0109880c4e168b5088921c4d45727ca
 src/mlpack/methods/adaboost/adaboost_impl.hpp | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/src/mlpack/methods/adaboost/adaboost_impl.hpp b/src/mlpack/methods/adaboost/adaboost_impl.hpp
index 0fb65e1..2a3f53d 100644
--- a/src/mlpack/methods/adaboost/adaboost_impl.hpp
+++ b/src/mlpack/methods/adaboost/adaboost_impl.hpp
@@ -76,8 +76,7 @@ void AdaBoost<MatType, WeakLearner>::Train(
   MatType tempData(data);
 
   // This matrix is a helper matrix used to calculate the final hypothesis.
-  arma::mat sumFinalH(predictedLabels.n_cols, classes);
-  sumFinalH.fill(0.0);
+  arma::mat sumFinalH = arma::zeros<arma::mat>(predictedLabels.n_cols, classes);
 
   // Load the initial weights into a 2-D matrix.
   const double initWeight = 1.0 / double(data.n_cols * classes);
@@ -241,12 +240,7 @@ void AdaBoost<MatType, WeakLearner>::BuildWeightMatrix(
     const arma::mat& D,
     arma::rowvec& weights)
 {
-  size_t i, j;
-  weights.fill(0.0);
-
-  for (i = 0; i < D.n_rows; i++)
-    for (j = 0; j < D.n_cols; j++)
-      weights(i) += D(i, j);
+  weights = arma::sum(D, 1).t();
 }
 
 } // namespace adaboost



More information about the mlpack-git mailing list