[mlpack-svn] r15484 - mlpack/trunk/src/mlpack/core/math
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Jul 17 10:33:44 EDT 2013
Author: rcurtin
Date: Wed Jul 17 10:33:43 2013
New Revision: 15484
Log:
Simplify centering code. Maybe it's faster?
Modified:
mlpack/trunk/src/mlpack/core/math/lin_alg.cpp
Modified: mlpack/trunk/src/mlpack/core/math/lin_alg.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/math/lin_alg.cpp (original)
+++ mlpack/trunk/src/mlpack/core/math/lin_alg.cpp Wed Jul 17 10:33:43 2013
@@ -37,13 +37,10 @@
*/
void mlpack::math::Center(const arma::mat& x, arma::mat& xCentered)
{
- // Sum matrix along dimension 0 (that is, sum elements in each row).
- arma::vec rowVectorSum = arma::sum(x, 1);
- rowVectorSum /= x.n_cols; // scale
-
- xCentered.set_size(x.n_rows, x.n_cols);
- for (size_t i = 0; i < x.n_rows; i++)
- xCentered.row(i) = x.row(i) - rowVectorSum(i);
+ // Get the mean of the elements in each row.
+ arma::vec rowMean = arma::sum(x, 1) / x.n_cols;
+
+ xCentered = x - arma::repmat(rowMean, 1, x.n_cols);
}
/**
More information about the mlpack-svn
mailing list