[mlpack-svn] r10125 - in mlpack/trunk/src/mlpack/methods: emst fastica hmm infomax_ica linear_regression mog naive_bayes nca neighbor_search nnsvm regression svm

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Nov 2 21:21:09 EDT 2011


Author: rcurtin
Date: 2011-11-02 21:21:09 -0400 (Wed, 02 Nov 2011)
New Revision: 10125

Modified:
   mlpack/trunk/src/mlpack/methods/emst/emst_main.cpp
   mlpack/trunk/src/mlpack/methods/fastica/fastica_main.cpp
   mlpack/trunk/src/mlpack/methods/fastica/lin_alg_test.cpp
   mlpack/trunk/src/mlpack/methods/hmm/mixtureDST.cpp
   mlpack/trunk/src/mlpack/methods/infomax_ica/infomax_ica_test.cc
   mlpack/trunk/src/mlpack/methods/infomax_ica/main.cc
   mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression.cpp
   mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression_main.cpp
   mlpack/trunk/src/mlpack/methods/mog/mog_em_main.cpp
   mlpack/trunk/src/mlpack/methods/mog/mog_l2e_main.cpp
   mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_main.cc
   mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_test.cc
   mlpack/trunk/src/mlpack/methods/nca/nca_main.cc
   mlpack/trunk/src/mlpack/methods/neighbor_search/allkfn_main.cc
   mlpack/trunk/src/mlpack/methods/neighbor_search/allkfn_test.cc
   mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cc
   mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_test.cc
   mlpack/trunk/src/mlpack/methods/nnsvm/nnsvm_main.cpp
   mlpack/trunk/src/mlpack/methods/regression/ridge_main.cc
   mlpack/trunk/src/mlpack/methods/svm/svm_main.cc
Log:
Use data::Load and data::Save.  This should fix our tests being slow.


Modified: mlpack/trunk/src/mlpack/methods/emst/emst_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/emst/emst_main.cpp	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/emst/emst_main.cpp	2011-11-03 01:21:09 UTC (rev 10125)
@@ -3,10 +3,10 @@
  *
  * Calls the DualTreeBoruvka algorithm from dtb.h
  * Can optionally call Naive Boruvka's method
- * 
- * For algorithm details, see: 
+ *
+ * For algorithm details, see:
  * March, W.B., Ram, P., and Gray, A.G.
- * Fast Euclidean Minimum Spanning Tree: Algorithm, Analysis, Applications. 
+ * Fast Euclidean Minimum Spanning Tree: Algorithm, Analysis, Applications.
  * In KDD, 2010.
  *
  * @author Bill March (march at gatech.edu)
@@ -36,40 +36,38 @@
   std::string data_file_name = CLI::GetParam<std::string>("emst/input_file");
 
   Log::Info << "Reading in data.\n";
-  
+
   arma::mat data_points;
-  data_points.load(data_file_name.c_str());
-  
+  data::Load(data_file_name.c_str(), data_points, true);
+
   // Do naive
   if (CLI::GetParam<bool>("naive/do_naive")) {
-    
+
     Log::Info << "Running naive algorithm.\n";
-    
+
     DualTreeBoruvka naive;
     //CLI::GetParam<bool>("naive/do_naive") = true;
-    
+
     naive.Init(data_points);
-    
+
     arma::mat naive_results;
     naive.ComputeMST(naive_results);
-    
+
     std::string naive_output_filename =
     CLI::GetParam<std::string>("naive/output_file");
-    
-    naive_results.save(naive_output_filename.c_str(), arma::csv_ascii, false,
-                       true);
-    
+
+    data::Save(naive_output_filename.c_str(), naive_results, true);
   }
   else {
-  
+
     Log::Info << "Data read, building tree.\n";
 
     /////////////// Initialize DTB //////////////////////
     DualTreeBoruvka dtb;
     dtb.Init(data_points);
-    
+
     Log::Info << "Tree built, running algorithm.\n\n";
-    
+
     ////////////// Run DTB /////////////////////
     arma::mat results;
 
@@ -81,8 +79,7 @@
     std::string output_filename =
         CLI::GetParam<std::string>("emst/output_file");
 
-    results.save(output_filename.c_str(), arma::csv_ascii, false, true);
-    
+    data::Save(output_filename.c_str(), results, true);
   }
 
   return 0;

Modified: mlpack/trunk/src/mlpack/methods/fastica/fastica_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/fastica/fastica_main.cpp	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/fastica/fastica_main.cpp	2011-11-03 01:21:09 UTC (rev 10125)
@@ -57,7 +57,7 @@
 
   CLI::ParseCommandLine(argc, argv);
   const char* data = CLI::GetParam<std::string>("fastica/input_file").c_str();
-  X.load(data, arma::auto_detect, false, true);
+  data::Load(data, X);
 
   const char* ic_filename = CLI::GetParam<std::string>("fastica/ic_file").c_str();
   const char* unmixing_filename =
@@ -69,9 +69,9 @@
   if(fastica.Init(X) == true) {
     arma::mat W, Y;
     if(fastica.DoFastICA(W, Y) == true) {
-      Y.save(ic_filename, arma::csv_ascii, false, true);
+      data::Save(ic_filename, Y, true);
       arma::mat Z = trans(W);
-      Z.save(unmixing_filename, arma::csv_ascii, false, true);
+      data::Save(unmixing_filename, Z, true);
       success_status = true;
       mlpack::Log::Debug << W << std::endl;
     }

Modified: mlpack/trunk/src/mlpack/methods/fastica/lin_alg_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/fastica/lin_alg_test.cpp	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/fastica/lin_alg_test.cpp	2011-11-03 01:21:09 UTC (rev 10125)
@@ -84,7 +84,7 @@
   // We are loading a matrix from an external file... bad choice.
   mat tmp, tmp_centered, whitened, whitening_matrix;
 
-  tmp.load("trainSet.csv", arma::auto_detect, false, true);
+  data::Load("trainSet.csv", tmp);
   Center(tmp, tmp_centered);
   WhitenUsingEig(tmp_centered, whitened, whitening_matrix);
 
@@ -107,7 +107,7 @@
   // Generate a random matrix; then, orthogonalize it and test if it's
   // orthogonal.
   mat tmp, orth;
-  tmp.load("fake.csv", arma::auto_detect, false, true);
+  data::Load("fake.csv", tmp);
   Orthogonalize(tmp, orth);
 
   // test orthogonality

Modified: mlpack/trunk/src/mlpack/methods/hmm/mixtureDST.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/hmm/mixtureDST.cpp	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/hmm/mixtureDST.cpp	2011-11-03 01:21:09 UTC (rev 10125)
@@ -75,14 +75,14 @@
 
 void MixtureGauss::InitFromFile(const char* mean_fn, const char* covs_fn, const char* prior_fn) {
   arma::mat meansmat;
-  meansmat.load(mean_fn, arma::auto_detect, false, true);
+  data::Load(mean_fn, meansmat);
 
   mat2arrlst(meansmat, means);
   size_t N = means[0].n_elem;
   size_t K = means.size();
   if (covs_fn != NULL) {
     arma::mat covsmat;
-    covsmat.load(covs_fn, arma::auto_detect, false, true);
+    data::Load(covs_fn, covsmat);
 
     mat2arrlstmat(N, covsmat, covs);
     mlpack::Log::Assert(K == covs.size(), "MixtureGauss::InitFromFile(): sizes do not match!");
@@ -100,7 +100,7 @@
 
   if (prior_fn != NULL) {
     arma::mat priormat;
-    priormat.load(prior_fn, arma::auto_detect, false, true);
+    data::Load(prior_fn, priormat);
 
     mlpack::Log::Assert(K == priormat.n_cols, "MixtureGauss::InitFromFile(): sizes do not match!");
 

Modified: mlpack/trunk/src/mlpack/methods/infomax_ica/infomax_ica_test.cc
===================================================================
--- mlpack/trunk/src/mlpack/methods/infomax_ica/infomax_ica_test.cc	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/infomax_ica/infomax_ica_test.cc	2011-11-03 01:21:09 UTC (rev 10125)
@@ -22,7 +22,7 @@
   int bb_ = 5;
   double epsilonb_ = 0.001;
 
-  testdatab_.load("fake.csv", arma::auto_detect, false, true);
+  data::Load("fake.csv", testdatab_);
 
   InfomaxICA icab_(lambdab_, bb_, epsilonb_);
 
@@ -39,7 +39,7 @@
 
   // load some test data that has been verified using the matlab
   // implementation of infomax
-  testdata_.load("fake.csv", arma::auto_detect, false, true);
+  data::Load("fake.csv", testdata_);
 
   InfomaxICA ica_(lambda_, b_, epsilon_);
   ica_.sampleCovariance(testdata_);
@@ -53,7 +53,7 @@
 
   // load some test data that has been verified using the matlab
   // implementation of infomax
-  testdata_.load("fake.csv", arma::auto_detect, false, true);
+  data::Load("fake.csv", testdata_);
 
   InfomaxICA ica_(lambda_, b_, epsilon_);
   arma::mat unmixing;

Modified: mlpack/trunk/src/mlpack/methods/infomax_ica/main.cc
===================================================================
--- mlpack/trunk/src/mlpack/methods/infomax_ica/main.cc	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/infomax_ica/main.cc	2011-11-03 01:21:09 UTC (rev 10125)
@@ -22,7 +22,7 @@
   double epsilon = CLI::GetParam<double>("info/epsilon");
 
   arma::mat dataset;
-  dataset.load(data_file_name, arma::auto_detect, false, true);
+  data::Load(data_file_name, dataset, true);
 
   InfomaxICA ica(lambda, B, epsilon);
   ica.applyICA(dataset);

Modified: mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression.cpp	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression.cpp	2011-11-03 01:21:09 UTC (rev 10125)
@@ -46,7 +46,7 @@
     for(size_t j = 0; j < n_cols; ++j)
     {
       predictions(j) += parameters(i) * points(i-1,j);
-      
+
     }
   }
 }
@@ -59,12 +59,12 @@
 
 bool LinearRegression::load(const std::string& filename)
 {
-  return parameters.load(filename);
+  return data::Load(filename, parameters);
 }
 
 bool LinearRegression::save(const std::string& filename)
 {
-  return parameters.save(filename);
+  return data::Save(filename, parameters);
 }
 
 }; // namespace linear_regression

Modified: mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression_main.cpp	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/linear_regression/linear_regression_main.cpp	2011-11-03 01:21:09 UTC (rev 10125)
@@ -30,7 +30,7 @@
   const std::string response_name =
     CLI::GetParam<std::string>("linear_regression/responses");
 
-  file.load(train_name.c_str(), arma::auto_detect, false, true);
+  data::Load(train_name.c_str(), file, true);
   size_t n_cols = file.n_cols,
          n_rows = file.n_rows;
 
@@ -45,7 +45,7 @@
   {
     predictors = file;
     // The initial predictors for y, Nx1
-    responses.load(response_name.c_str(), arma::auto_detect, false, true);
+    data::Load(response_name.c_str(), responses, true);
     if(responses.n_rows > 1)
     {
       std::cerr << "Error: The responses must have one column.\n";
@@ -59,7 +59,7 @@
     }
   }
 
-  points.load(test_name.c_str(), arma::auto_detect, false, true);
+  data::Load(test_name.c_str(), points, true);
   if(points.n_rows != n_rows)
   {
       std::cerr << "Error: The test data must have the same number of cols as\

Modified: mlpack/trunk/src/mlpack/methods/mog/mog_em_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/mog/mog_em_main.cpp	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/mog/mog_em_main.cpp	2011-11-03 01:21:09 UTC (rev 10125)
@@ -39,8 +39,7 @@
 
   ////// READING PARAMETERS AND LOADING DATA //////
   arma::mat data_points;
-  data_points.load(CLI::GetParam<std::string>("mog/data").c_str(),
-      arma::auto_detect, false, true);
+  data::Load(CLI::GetParam<std::string>("mog/data").c_str(), data_points, true);
 
   ////// MIXTURE OF GAUSSIANS USING EM //////
   MoGEM mog;

Modified: mlpack/trunk/src/mlpack/methods/mog/mog_l2e_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/mog/mog_l2e_main.cpp	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/mog/mog_l2e_main.cpp	2011-11-03 01:21:09 UTC (rev 10125)
@@ -40,8 +40,8 @@
 
   ////// READING PARAMETERS AND LOADING DATA //////
   arma::mat data_points;
-  data_points.load(CLI::GetParam<std::string>("mog_l2e/data").c_str(),
-      arma::auto_detect, false, true);
+  data::Load(CLI::GetParam<std::string>("mog_l2e/data").c_str(), data_points,
+      true);
 
   ////// MIXTURE OF GAUSSIANS USING L2 ESTIMATCLIN //////
   size_t number_of_gaussians = CLI::GetParam<int>("mog_l2e/k");

Modified: mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_main.cc
===================================================================
--- mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_main.cc	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_main.cc	2011-11-03 01:21:09 UTC (rev 10125)
@@ -78,11 +78,11 @@
 
   const char *training_data_filename = CLI::GetParam<std::string>("nbc/train").c_str();
   arma::mat training_data;
-  training_data.load(training_data_filename, arma::auto_detect, false, true);
+  data::Load(training_data_filename, training_data, true);
 
   const char *testing_data_filename = CLI::GetParam<std::string>("nbc/test").c_str();
   arma::mat testing_data;
-  testing_data.load(testing_data_filename, arma::auto_detect, false, true);
+  data::Load(testing_data_filename, testing_data, true);
 
   ////// SIMPLE NAIVE BAYES CLASSIFICATCLIN ASSUMING THE DATA TO BE UNIFORMLY DISTRIBUTED //////
 
@@ -110,7 +110,7 @@
   ////// OUTPUT RESULTS //////
   std::string output_filename = CLI::GetParam<std::string>("nbc/output");
 
-  results.save(output_filename.c_str(), arma::csv_ascii, false, true);
+  data::Save(output_filename.c_str(), results, true);
 
   return 1;
 }

Modified: mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_test.cc
===================================================================
--- mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_test.cc	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_test.cc	2011-11-03 01:21:09 UTC (rev 10125)
@@ -15,8 +15,8 @@
   size_t number_of_classes_ = 2;
 
   arma::mat train_data, train_res, calc_mat;
-  train_data.load(filename_train_, arma::auto_detect, false, true);
-  train_res.load(train_result_, arma::auto_detect, false, true);
+  data::Load(filename_train_, train_data, true);
+  data::Load(train_result_, train_res, true);
 
   CLI::GetParam<int>("nbc/classes") = number_of_classes_;
   SimpleNaiveBayesClassifier nbc_test_(train_data);
@@ -41,8 +41,8 @@
 
   arma::mat test_data, test_res;
   arma::vec test_res_vec, calc_vec;
-  test_data.load(filename_test_, arma::auto_detect, false, true);
-  test_res.load(test_result_, arma::auto_detect, false, true);
+  data::Load(filename_test_, test_data, true);
+  data::Load(test_result_, test_res, true);
 
   nbc_test_.Classify(test_data, calc_vec);
 

Modified: mlpack/trunk/src/mlpack/methods/nca/nca_main.cc
===================================================================
--- mlpack/trunk/src/mlpack/methods/nca/nca_main.cc	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/nca/nca_main.cc	2011-11-03 01:21:09 UTC (rev 10125)
@@ -25,8 +25,7 @@
   CLI::ParseCommandLine(argc, argv);
 
   arma::mat data;
-  data.load(CLI::GetParam<string>("input_file").c_str(), arma::auto_detect,
-      false, true);
+  data::Load(CLI::GetParam<string>("input_file").c_str(), data, true);
 
   arma::uvec labels(data.n_cols);
   for (size_t i = 0; i < data.n_cols; i++)
@@ -40,6 +39,5 @@
 
   nca.LearnDistance(distance);
 
-  distance.save(CLI::GetParam<string>("output_file").c_str(), arma::csv_ascii,
-      false, true);
+  data::Save(CLI::GetParam<string>("output_file").c_str(), distance, true);
 }

Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/allkfn_main.cc
===================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/allkfn_main.cc	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/allkfn_main.cc	2011-11-03 01:21:09 UTC (rev 10125)
@@ -50,8 +50,7 @@
   arma::Mat<size_t> neighbors;
   arma::mat distances;
 
-  if (!reference_data.load(reference_file.c_str(), arma::auto_detect, false,
-      true))
+  if (!data::Load(reference_file.c_str(), reference_data))
     Log::Fatal << "Reference file " << reference_file << "not found." << endl;
 
   Log::Info << "Loaded reference data from " << reference_file << endl;
@@ -67,8 +66,8 @@
 
   // Sanity check on leaf size.
   if (CLI::GetParam<int>("tree/leaf_size") <= 0) {
-    Log::Fatal << "Invalid leaf size: " << CLI::GetParam<int>("allknn/leaf_size")
-        << endl;
+    Log::Fatal << "Invalid leaf size: "
+        << CLI::GetParam<int>("allknn/leaf_size") << endl;
   }
 
   AllkFN* allkfn = NULL;
@@ -77,7 +76,7 @@
     string query_file = CLI::GetParam<string>("query_file");
     arma::mat query_data;
 
-    if(!query_data.load(query_file.c_str(), arma::auto_detect, false, true))
+    if (!data::Load(query_file.c_str(), query_data))
       Log::Fatal << "Query file " << query_file << " not found" << endl;
 
     Log::Info << "Query data loaded from " << query_file << endl;

Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/allkfn_test.cc
===================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/allkfn_test.cc	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/allkfn_test.cc	2011-11-03 01:21:09 UTC (rev 10125)
@@ -323,8 +323,7 @@
   arma::mat data_for_tree_;
 
   // Hard-coded filename: bad!
-  if (!data_for_tree_.load("test_data_3_1000.csv", arma::auto_detect, false,
-      true))
+  if (!data::Load("test_data_3_1000.csv", data_for_tree_))
     BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
 
   // Set up matrices to work with.
@@ -365,8 +364,7 @@
 
   // Hard-coded filename: bad!
   // Code duplication: also bad!
-  if (!data_for_tree_.load("test_data_3_1000.csv", arma::auto_detect, false,
-      true))
+  if (!data::Load("test_data_3_1000.csv", data_for_tree_))
     BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
 
   // Set up matrices to work with (may not be necessary with no ALIAS_MATRIX?).
@@ -405,8 +403,7 @@
 
   // Hard-coded filename: bad!
   // Code duplication: also bad!
-  if (!data_for_tree_.load("test_data_3_1000.csv", arma::auto_detect, false,
-      true))
+  if (!data::Load("test_data_3_1000.csv", data_for_tree_))
     BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
 
   arma::mat single_query(data_for_tree_);

Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cc
===================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cc	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cc	2011-11-03 01:21:09 UTC (rev 10125)
@@ -50,8 +50,7 @@
   arma::Mat<size_t> neighbors;
   arma::mat distances;
 
-  if (!reference_data.load(reference_file.c_str(), arma::auto_detect, false,
-      true))
+  if (!data::Load(reference_file.c_str(), reference_data))
     Log::Fatal << "Reference file " << reference_file << " not found." << endl;
 
   Log::Info << "Loaded reference data from " << reference_file << endl;
@@ -77,7 +76,7 @@
     string query_file = CLI::GetParam<string>("query_file");
     arma::mat query_data;
 
-    if (!query_data.load(query_file.c_str(), arma::auto_detect, false, true))
+    if (!data::Load(query_file.c_str(), query_data))
       Log::Fatal << "Query file " << query_file << " not found" << endl;
 
     Log::Info << "Query data loaded from " << query_file << endl;

Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_test.cc
===================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_test.cc	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_test.cc	2011-11-03 01:21:09 UTC (rev 10125)
@@ -323,8 +323,7 @@
   arma::mat data_for_tree_;
 
   // Hard-coded filename: bad!
-  if (!data_for_tree_.load("test_data_3_1000.csv", arma::auto_detect, false,
-      true))
+  if (!data::Load("test_data_3_1000.csv", data_for_tree_))
     BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
 
   // Set up matrices to work with.
@@ -368,8 +367,7 @@
 
   // Hard-coded filename: bad!
   // Code duplication: also bad!
-  if (!data_for_tree_.load("test_data_3_1000.csv", arma::auto_detect, false,
-      true))
+  if (!data::Load("test_data_3_1000.csv", data_for_tree_))
     BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
 
   // Set up matrices to work with (may not be necessary with no ALIAS_MATRIX?).
@@ -410,8 +408,7 @@
 
   // Hard-coded filename: bad!
   // Code duplication: also bad!
-  if (!data_for_tree_.load("test_data_3_1000.csv", arma::auto_detect, false,
-      true))
+  if (!data::Load("test_data_3_1000.csv", data_for_tree_))
     BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
 
   // Set up matrices to work with (may not be necessary with no ALIAS_MATRIX?).

Modified: mlpack/trunk/src/mlpack/methods/nnsvm/nnsvm_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/nnsvm/nnsvm_main.cpp	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/nnsvm/nnsvm_main.cpp	2011-11-03 01:21:09 UTC (rev 10125)
@@ -47,12 +47,8 @@
     std::string trainFile = CLI::GetParam<std::string>("nnsvm/train_data");
     // Load training data
     arma::mat dataSet;
-    if (!dataSet.load(trainFile.c_str(), arma::auto_detect, false, true))
-    {
-      /* TODO: eventually, we need better exception handling */
-      Log::Debug << "Could not open " << trainFile << " for reading" << std::endl;
+    if (!data::Load(trainFile.c_str(), dataSet))
       return 1;
-    }
 
     // Begin NNSVM Training
     if (kernel == "linear")
@@ -74,13 +70,9 @@
         /* Load testing data */
         std::string testFile = CLI::GetParam<std::string>("nnsvm/test_data");
         arma::mat testset;
-        if (!testset.load(testFile.c_str(), arma::auto_detect, false, true))
-        {
-          /* TODO: eventually, we need better exception handling */
-          Log::Debug << "Could not open " << testFile << " for reading" <<
-            std::endl;
+        if (!data::Load(testFile.c_str(), testset))
           return 1;
-        }
+
         nnsvm.BatchClassify(testset, "testlabels");
       }
     }

Modified: mlpack/trunk/src/mlpack/methods/regression/ridge_main.cc
===================================================================
--- mlpack/trunk/src/mlpack/methods/regression/ridge_main.cc	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/regression/ridge_main.cc	2011-11-03 01:21:09 UTC (rev 10125)
@@ -69,14 +69,14 @@
   std::string predictions_file = CLI::GetParam<std::string>("ridge/predictions");
 
   arma::mat predictors;
-  if (predictors.load(predictors_file.c_str(), arma::auto_detect, false, true)
-      == false) {
+  if (!data::Load(predictors_file.c_str(), predictors))
+  {
     Log::Fatal << "Unable to open file " << predictors_file << std::endl;
   }
 
   arma::mat predictions;
-  if (predictions.load(predictions_file.c_str(), arma::auto_detect, false, true)
-      == false) {
+  if (!data::Load(predictions_file.c_str(), predictions))
+  {
     Log::Fatal << "Unable to open file " << predictions_file << std::endl;
   }
 
@@ -107,14 +107,15 @@
       CLI::GetParam<std::string>("ridge/predictor_indices");
     std::string prune_predictor_indices_file =
       CLI::GetParam<std::string>("ridge/prune_predictor_indices");
-    if (predictor_indices_intermediate.load(predictor_indices_file.c_str(),
-        arma::auto_detect, false, true) == false) {
+    if (!data::Load(predictor_indices_file.c_str(),
+        predictor_indices_intermediate))
+    {
       Log::Fatal << "Unable to open file " << prune_predictor_indices_file
           << std::endl;
     }
-    if (prune_predictor_indices_intermediate.load(
-        prune_predictor_indices_file.c_str(), arma::auto_detect, false, true)
-        == false) {
+    if (!data::Load(prune_predictor_indices_file.c_str(),
+        prune_predictor_indices_intermediate))
+    {
       Log::Fatal << "Unable to open file " << prune_predictor_indices_file << std::endl;
     }
 
@@ -138,7 +139,7 @@
   engine.factors(&factors);
   std::string factors_file = CLI::GetParam<std::string>("ridge/factors");
   Log::Info << "Saving factors..." << std::endl;
-  factors.save(factors_file.c_str(), arma::csv_ascii, false, true);
+  data::Save(factors_file.c_str(), factors, true);
 
   return 0;
 }

Modified: mlpack/trunk/src/mlpack/methods/svm/svm_main.cc
===================================================================
--- mlpack/trunk/src/mlpack/methods/svm/svm_main.cc	2011-11-03 00:16:59 UTC (rev 10124)
+++ mlpack/trunk/src/mlpack/methods/svm/svm_main.cc	2011-11-03 01:21:09 UTC (rev 10125)
@@ -94,7 +94,7 @@
     Log::Info << "Training SVM..." << std::endl;
 
     /* Load training data */
-    if (!dataSet.load(trainFile.c_str(), arma::auto_detect, false, true))
+    if (!data::Load(trainFile.c_str(), dataSet))
       return 1;
 
     /* Begin SVM Training | Training and Testing */
@@ -108,7 +108,7 @@
         /* Load testing data */
         arma::mat dataSet;
         std::string testFile = CLI::GetParam<std::string>("svm/test_data");
-        if (!dataSet.load(testFile.c_str(), arma::auto_detect, false, true))
+        if (!data::Load(testFile.c_str(), dataSet))
           return 1;
 
         svm.BatchPredict(learner_typeid, dataSet, "predicted_values");
@@ -123,7 +123,7 @@
         /* Load testing data */
         arma::mat dataSet;
         std::string testFile = CLI::GetParam<std::string>("svm/test_data");
-        if (!dataSet.load(testFile.c_str(), arma::auto_detect, false, true))
+        if (!data::Load(testFile.c_str(), dataSet))
           return 1;
 
         svm.BatchPredict(learner_typeid, dataSet, "predicted_values"); // TODO:param_req
@@ -138,7 +138,7 @@
     /* Load testing data */
     arma::mat dataSet;
     std::string testFile = CLI::GetParam<std::string>("svm/test_data");
-    if (dataSet.load(testFile.c_str()) == false)
+    if (!data::Load(testFile.c_str(), dataSet))
       return 1;
 
     /* Begin Prediction */




More information about the mlpack-svn mailing list