[mlpack-svn] r13157 - in mlpack/trunk/src/mlpack/methods: local_coordinate_coding sparse_coding

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Jul 4 13:19:24 EDT 2012


Author: rcurtin
Date: 2012-07-04 13:19:23 -0400 (Wed, 04 Jul 2012)
New Revision: 13157

Modified:
   mlpack/trunk/src/mlpack/methods/local_coordinate_coding/lcc.hpp
   mlpack/trunk/src/mlpack/methods/local_coordinate_coding/lcc_impl.hpp
   mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp
   mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
Log:
Move RemoveRows() out of class definitions.


Modified: mlpack/trunk/src/mlpack/methods/local_coordinate_coding/lcc.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/local_coordinate_coding/lcc.hpp	2012-07-04 17:18:45 UTC (rev 13156)
+++ mlpack/trunk/src/mlpack/methods/local_coordinate_coding/lcc.hpp	2012-07-04 17:19:23 UTC (rev 13157)
@@ -142,11 +142,6 @@
   double lambda;
 };
 
-void RemoveRows(const arma::mat& X,
-                arma::uvec rows_to_remove,
-                arma::mat& X_mod);
-
-
 }; // namespace lcc
 }; // namespace mlpack
 

Modified: mlpack/trunk/src/mlpack/methods/local_coordinate_coding/lcc_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/local_coordinate_coding/lcc_impl.hpp	2012-07-04 17:18:45 UTC (rev 13156)
+++ mlpack/trunk/src/mlpack/methods/local_coordinate_coding/lcc_impl.hpp	2012-07-04 17:19:23 UTC (rev 13157)
@@ -191,9 +191,7 @@
 
     // Create matrix holding only active codes.
     arma::mat activeCodes;
-    arma::uvec inactiveAtomsVec =
-        arma::conv_to<arma::uvec>::from(inactiveAtoms);
-    RemoveRows(codes, inactiveAtomsVec, activeCodes);
+    math::RemoveRows(codes, inactiveAtoms, activeCodes);
 
     // Create reverse atom lookup for active atoms.
     arma::uvec atomReverseLookup(atoms);
@@ -307,57 +305,6 @@
   return std::pow(froNormResidual, 2.0) + lambda * weightedL1NormZ;
 }
 
-void RemoveRows(const arma::mat& X, arma::uvec rows_to_remove, arma::mat& X_mod)
-{
-  arma::uword n_cols = X.n_cols;
-  arma::uword n_rows = X.n_rows;
-  arma::uword n_to_remove = rows_to_remove.n_elem;
-  arma::uword n_to_keep = n_rows - n_to_remove;
-
-  if (n_to_remove == 0)
-  {
-    X_mod = X;
-  }
-  else
-  {
-    X_mod.set_size(n_to_keep, n_cols);
-
-    arma::uword cur_row = 0;
-    arma::uword remove_ind = 0;
-    // first, check 0 to first row to remove
-    if (rows_to_remove(0) > 0)
-    {
-      // note that this implies that n_rows > 1
-      arma::uword height = rows_to_remove(0);
-      X_mod(arma::span(cur_row, cur_row + height - 1), arma::span::all) =
-          X(arma::span(0, rows_to_remove(0) - 1), arma::span::all);
-      cur_row += height;
-    }
-    // now, check i'th row to remove to (i + 1)'th row to remove, until i =
-    // penultimate row
-    while (remove_ind < n_to_remove - 1)
-    {
-      arma::uword height = rows_to_remove[remove_ind + 1] -
-          rows_to_remove[remove_ind] - 1;
-      if (height > 0)
-      {
-        X_mod(arma::span(cur_row, cur_row + height - 1), arma::span::all) =
-            X(arma::span(rows_to_remove[remove_ind] + 1,
-            rows_to_remove[remove_ind + 1] - 1), arma::span::all);
-        cur_row += height;
-      }
-      remove_ind++;
-    }
-    // now that i is last row to remove, check last row to remove to last row
-    if (rows_to_remove[remove_ind] < n_rows - 1)
-    {
-      X_mod(arma::span(cur_row, n_to_keep - 1), arma::span::all) =
-          X(arma::span(rows_to_remove[remove_ind] + 1, n_rows - 1),
-          arma::span::all);
-    }
-  }
-}
-
 }; // namespace lcc
 }; // namespace mlpack
 

Modified: mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp	2012-07-04 17:18:45 UTC (rev 13156)
+++ mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp	2012-07-04 17:19:23 UTC (rev 13157)
@@ -191,10 +191,6 @@
   double lambda2;
 };
 
-void RemoveRows(const arma::mat& X,
-                const arma::uvec& rowsToRemove,
-                arma::mat& modX);
-
 }; // namespace sparse_coding
 }; // namespace mlpack
 

Modified: mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp	2012-07-04 17:18:45 UTC (rev 13156)
+++ mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp	2012-07-04 17:19:23 UTC (rev 13157)
@@ -152,9 +152,7 @@
   arma::mat matActiveZ;
   if (nInactiveAtoms > 0)
   {
-    arma::uvec inactiveAtomsVec =
-        arma::conv_to<arma::uvec>::from(inactiveAtoms);
-    RemoveRows(codes, inactiveAtomsVec, matActiveZ);
+    math::RemoveRows(codes, inactiveAtoms, matActiveZ);
   }
 
   if (nInactiveAtoms > 0)
@@ -321,63 +319,6 @@
   }
 }
 
-void RemoveRows(const arma::mat& X,
-                const arma::uvec& rowsToRemove,
-                arma::mat& modX)
-{
-  const size_t cols = X.n_cols;
-  const size_t rows = X.n_rows;
-  const size_t nRemove = rowsToRemove.n_elem;
-  const size_t nKeep = rows - nRemove;
-
-  if (nRemove == 0)
-  {
-    modX = X;
-  }
-  else
-  {
-    modX.set_size(nKeep, cols);
-
-    size_t curRow = 0;
-    size_t removeInd = 0;
-    // First, check 0 to first row to remove.
-    if (rowsToRemove(0) > 0)
-    {
-      // Note that this implies that n_rows > 1.
-      size_t height = rowsToRemove(0);
-      modX(arma::span(curRow, curRow + height - 1), arma::span::all) =
-          X(arma::span(0, rowsToRemove(0) - 1), arma::span::all);
-      curRow += height;
-    }
-    // Now, check i'th row to remove to (i + 1)'th row to remove, until i is the
-    // penultimate row.
-    while (removeInd < nRemove - 1)
-    {
-      size_t height = rowsToRemove[removeInd + 1] -
-          rowsToRemove[removeInd] - 1;
-
-      if (height > 0)
-      {
-        modX(arma::span(curRow, curRow + height - 1), arma::span::all) =
-            X(arma::span(rowsToRemove[removeInd] + 1,
-            rowsToRemove[removeInd + 1] - 1), arma::span::all);
-        curRow += height;
-      }
-
-      removeInd++;
-    }
-
-    // Now that i is the last row to remove, check last row to remove to last
-    // row.
-    if (rowsToRemove[removeInd] < rows - 1)
-    {
-      modX(arma::span(curRow, nKeep - 1), arma::span::all) =
-          X(arma::span(rowsToRemove[removeInd] + 1, rows - 1),
-          arma::span::all);
-    }
-  }
-}
-
 }; // namespace sparse_coding
 }; // namespace mlpack
 




More information about the mlpack-svn mailing list