[mlpack-git] master: unify styles and fix default output problem (775e2a1)

gitdub at mlpack.org gitdub at mlpack.org
Sun Jun 5 05:45:21 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/4fa39b6ab0baa1428116d0406264b5452e716d06...97402b9098d9d72889aa795923cf8fd67a4d87bf

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

commit 775e2a1d1e6968bc9e03990662d3c2bbc5367271
Author: Keon Kim <kwk236 at gmail.com>
Date:   Sun Jun 5 03:34:38 2016 +0900

    unify styles and fix default output problem


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

775e2a1d1e6968bc9e03990662d3c2bbc5367271
 src/mlpack/methods/det/det_main.cpp                |  2 +-
 src/mlpack/methods/emst/emst_main.cpp              |  4 +-
 src/mlpack/methods/gmm/gmm_generate_main.cpp       |  4 +-
 src/mlpack/methods/gmm/gmm_probability_main.cpp    |  4 +-
 src/mlpack/methods/hmm/hmm_generate_main.cpp       |  9 ++--
 src/mlpack/methods/hmm/hmm_train_main.cpp          |  7 ++-
 src/mlpack/methods/hmm/hmm_viterbi_main.cpp        |  4 +-
 .../hoeffding_trees/hoeffding_tree_main.cpp        | 57 ++++++++++++----------
 src/mlpack/methods/lars/lars_main.cpp              | 45 +++++++++--------
 .../linear_regression/linear_regression_main.cpp   | 54 +++++++++++---------
 src/mlpack/methods/mvu/mvu_main.cpp                | 12 ++---
 src/mlpack/methods/perceptron/perceptron_main.cpp  | 16 +++---
 src/mlpack/methods/radical/radical_main.cpp        |  6 +--
 13 files changed, 120 insertions(+), 104 deletions(-)

diff --git a/src/mlpack/methods/det/det_main.cpp b/src/mlpack/methods/det/det_main.cpp
index 87446d5..5b0c506 100644
--- a/src/mlpack/methods/det/det_main.cpp
+++ b/src/mlpack/methods/det/det_main.cpp
@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
     Timer::Stop("det_training");
 
     // Compute training set estimates, if desired.
-    if (CLI::GetParam<string>("training_set_estimates_file") != "")
+    if (CLI::HasParam("training_set_estimates_file"))
     {
       // Compute density estimates for each point in the training set.
       arma::rowvec trainingDensities(trainingData.n_cols);
diff --git a/src/mlpack/methods/emst/emst_main.cpp b/src/mlpack/methods/emst/emst_main.cpp
index 828693e..284c44f 100644
--- a/src/mlpack/methods/emst/emst_main.cpp
+++ b/src/mlpack/methods/emst/emst_main.cpp
@@ -34,8 +34,8 @@ PROGRAM_INFO("Fast Euclidean Minimum Spanning Tree", "This program can compute "
     "column corresponds to the distance between the two points.");
 
 PARAM_STRING_REQ("input_file", "Data input file.", "i");
-PARAM_STRING("output_file", "Data output file.  Stored as an edge list.", "o",
-    "emst_output.csv");
+PARAM_STRING_REQ("output_file", "Data output file.  Stored as an edge list.",
+    "o");
 PARAM_FLAG("naive", "Compute the MST using O(n^2) naive algorithm.", "n");
 PARAM_INT("leaf_size", "Leaf size in the kd-tree.  One-element leaves give the "
     "empirically best performance, but at the cost of greater memory "
diff --git a/src/mlpack/methods/gmm/gmm_generate_main.cpp b/src/mlpack/methods/gmm/gmm_generate_main.cpp
index 7fcf2e1..68e7c99 100644
--- a/src/mlpack/methods/gmm/gmm_generate_main.cpp
+++ b/src/mlpack/methods/gmm/gmm_generate_main.cpp
@@ -21,9 +21,7 @@ PROGRAM_INFO("GMM Sample Generator",
 
 PARAM_STRING_REQ("input_model_file", "File containing input GMM model.", "m");
 PARAM_INT_REQ("samples", "Number of samples to generate.", "n");
-
-PARAM_STRING("output_file", "File to save output samples in.", "o",
-    "output.csv");
+PARAM_STRING_REQ("output_file", "File to save output samples in.", "o");
 
 PARAM_INT("seed", "Random seed.  If 0, 'std::time(NULL)' is used.", "s", 0);
 
diff --git a/src/mlpack/methods/gmm/gmm_probability_main.cpp b/src/mlpack/methods/gmm/gmm_probability_main.cpp
index b771aa2..c8a4388 100644
--- a/src/mlpack/methods/gmm/gmm_probability_main.cpp
+++ b/src/mlpack/methods/gmm/gmm_probability_main.cpp
@@ -20,9 +20,7 @@ PROGRAM_INFO("GMM Probability Calculator",
 
 PARAM_STRING_REQ("input_model_file", "File containing input GMM.", "m");
 PARAM_STRING_REQ("input_file", "File containing points.", "i");
-
-PARAM_STRING("output_file", "File to save calculated probabilities to.", "o",
-    "output.csv");
+PARAM_STRING_REQ("output_file", "File to save calculated probabilities to.", "o");
 
 int main(int argc, char** argv)
 {
diff --git a/src/mlpack/methods/hmm/hmm_generate_main.cpp b/src/mlpack/methods/hmm/hmm_generate_main.cpp
index 5240d55..3068aa6 100644
--- a/src/mlpack/methods/hmm/hmm_generate_main.cpp
+++ b/src/mlpack/methods/hmm/hmm_generate_main.cpp
@@ -21,10 +21,9 @@ PROGRAM_INFO("Hidden Markov Model (HMM) Sequence Generator", "This "
 
 PARAM_STRING_REQ("model_file", "File containing HMM.", "m");
 PARAM_INT_REQ("length", "Length of sequence to generate.", "l");
+PARAM_STRING_REQ("output_file", "File to save observation sequence to.", "o");
 
 PARAM_INT("start_state", "Starting state of sequence.", "t", 0);
-PARAM_STRING("output_file", "File to save observation sequence to.", "o",
-    "output.csv");
 PARAM_STRING("state_file", "File to save hidden state sequence to (may be left "
     "unspecified.", "S", "");
 PARAM_INT("seed", "Random seed.  If 0, 'std::time(NULL)' is used.", "s", 0);
@@ -65,9 +64,11 @@ struct Generate
     data::Save(outputFile, observations, true);
 
     // Do we want to save the hidden sequence?
-    const string sequenceFile = CLI::GetParam<string>("state_file");
-    if (sequenceFile != "")
+    if (CLI::HasParam("state_file"))
+    {
+      const string sequenceFile = CLI::GetParam<string>("state_file");
       data::Save(sequenceFile, sequence, true);
+    }
   }
 };
 
diff --git a/src/mlpack/methods/hmm/hmm_train_main.cpp b/src/mlpack/methods/hmm/hmm_train_main.cpp
index 546fb3c..c56d46a 100644
--- a/src/mlpack/methods/hmm/hmm_train_main.cpp
+++ b/src/mlpack/methods/hmm/hmm_train_main.cpp
@@ -45,8 +45,7 @@ PARAM_INT("gaussians", "Number of gaussians in each GMM (necessary when type is"
 PARAM_STRING("model_file", "Pre-existing HMM model (optional).", "m", "");
 PARAM_STRING("labels_file", "Optional file of hidden states, used for "
     "labeled training.", "l", "");
-PARAM_STRING("output_model_file", "File to save trained HMM to.", "o",
-    "output_hmm.xml");
+PARAM_STRING("output_model_file", "File to save trained HMM to.", "o", "");
 PARAM_INT("seed", "Random seed.  If 0, 'std::time(NULL)' is used.", "s", 0);
 PARAM_DOUBLE("tolerance", "Tolerance of the Baum-Welch algorithm.", "T", 1e-5);
 PARAM_FLAG("random_initialization", "Initialize emissions and transition "
@@ -88,7 +87,7 @@ struct Train
             << endl;
 
     vector<arma::Row<size_t>> labelSeq; // May be empty.
-    if (labelsFile != "")
+    if (CLI::HasParam("labels_file"))
     {
       // Do we have multiple label files to load?
       char lineBuf[1024];
@@ -271,7 +270,7 @@ int main(int argc, char** argv)
   }
 
   // If we have a model file, we can autodetect the type.
-  if (modelFile != "")
+  if (CLI::HasParam("model_file"))
   {
     LoadHMMAndPerformAction<Train>(modelFile, &trainSeq);
   }
diff --git a/src/mlpack/methods/hmm/hmm_viterbi_main.cpp b/src/mlpack/methods/hmm/hmm_viterbi_main.cpp
index 2e6328b..23ecbfa 100644
--- a/src/mlpack/methods/hmm/hmm_viterbi_main.cpp
+++ b/src/mlpack/methods/hmm/hmm_viterbi_main.cpp
@@ -20,8 +20,8 @@ PROGRAM_INFO("Hidden Markov Model (HMM) Viterbi State Prediction", "This "
 
 PARAM_STRING_REQ("input_file", "File containing observations,", "i");
 PARAM_STRING_REQ("model_file", "File containing HMM.", "m");
-PARAM_STRING("output_file", "File to save predicted state sequence to.", "o",
-    "output.csv");
+PARAM_STRING_REQ("output_file", "File to save predicted state sequence to.",
+    "o");
 
 using namespace mlpack;
 using namespace mlpack::hmm;
diff --git a/src/mlpack/methods/hoeffding_trees/hoeffding_tree_main.cpp b/src/mlpack/methods/hoeffding_trees/hoeffding_tree_main.cpp
index 073c00b..609bb64 100644
--- a/src/mlpack/methods/hoeffding_trees/hoeffding_tree_main.cpp
+++ b/src/mlpack/methods/hoeffding_trees/hoeffding_tree_main.cpp
@@ -37,9 +37,9 @@ PROGRAM_INFO("Hoeffding trees",
     "A test file may be specified with the --test_file (-T) option, and if "
     "performance numbers are desired for that test set, labels may be specified"
     " with the --test_labels_file (-L) option.  Predictions for each test point"
-    " will be stored in the file specified by --predictions_file (-p) and "
+    " will be stored in the file specified by --output_predictions_file (-p) and "
     "probabilities for each predictions will be stored in the file specified by"
-    " the --probabilities_file (-P) option.");
+    " the --output_probabilities_file (-P) option.");
 
 PARAM_STRING("training_file", "Training dataset file.", "t", "");
 PARAM_STRING("labels_file", "Labels for training dataset.", "l", "");
@@ -56,10 +56,10 @@ PARAM_STRING("output_model_file", "File to save trained tree to.", "M", "");
 
 PARAM_STRING("test_file", "File of testing data.", "T", "");
 PARAM_STRING("test_labels_file", "Labels of test data.", "L", "");
-PARAM_STRING("predictions_file", "File to output label predictions for test "
-    "data into.", "p", "");
-PARAM_STRING("probabilities_file", "In addition to predicting labels, provide "
-    "prediction probabilities in this file.", "P", "");
+PARAM_STRING("output_predictions_file", "File to output label predictions for"
+    "test data into.", "p", "");
+PARAM_STRING("output_probabilities_file", "In addition to predicting labels, "
+    "provide prediction probabilities in this file.", "P", "");
 
 PARAM_STRING("numeric_split_strategy", "The splitting strategy to use for "
     "numeric features: 'domingos' or 'binary'.", "N", "binary");
@@ -90,25 +90,28 @@ int main(int argc, char** argv)
   const string labelsFile = CLI::GetParam<string>("labels_file");
   const string inputModelFile = CLI::GetParam<string>("input_model_file");
   const string testFile = CLI::GetParam<string>("test_file");
-  const string predictionsFile = CLI::GetParam<string>("predictions_file");
-  const string probabilitiesFile = CLI::GetParam<string>("probabilities_file");
+  const string outputPredictionsFile =
+      CLI::GetParam<string>("output_predictions_file");
+  const string outputProbabilitiesFile =
+      CLI::GetParam<string>("output_probabilities_file");
   const string numericSplitStrategy =
       CLI::GetParam<string>("numeric_split_strategy");
 
-  if ((!predictionsFile.empty() || !probabilitiesFile.empty()) &&
-      testFile.empty())
-    Log::Fatal << "--test_file must be specified if --predictions_file or "
-        << "--probabilities_file is specified." << endl;
+  if ((CLI::HasParam("output_predictions_file") ||
+       CLI::HasParam("output_probabilities_file")) &&
+       !CLI::HasParam("test_file"))
+    Log::Fatal << "--test_file must be specified if --output_predictions_file or "
+        << "--output_probabilities_file is specified." << endl;
 
-  if (trainingFile.empty() && inputModelFile.empty())
+  if (!CLI::HasParam("training_file") && !CLI::HasParam("input_model_file"))
     Log::Fatal << "One of --training_file or --input_model_file must be "
         << "specified!" << endl;
 
-  if (!trainingFile.empty() && labelsFile.empty())
+  if (CLI::HasParam("training_file") && !CLI::HasParam("labels_file"))
     Log::Fatal << "If --training_file is specified, --labels_file must be "
         << "specified too!" << endl;
 
-  if (trainingFile.empty() && CLI::HasParam("batch_mode"))
+  if (!CLI::HasParam("training_file") && CLI::HasParam("batch_mode"))
     Log::Warn << "--batch_mode (-b) ignored; no training set provided." << endl;
 
   if (CLI::HasParam("passes") && CLI::HasParam("batch_mode"))
@@ -177,8 +180,10 @@ void PerformActions(const typename TreeType::NumericSplit& numericSplit)
   const string inputModelFile = CLI::GetParam<string>("input_model_file");
   const string outputModelFile = CLI::GetParam<string>("output_model_file");
   const string testFile = CLI::GetParam<string>("test_file");
-  const string predictionsFile = CLI::GetParam<string>("predictions_file");
-  const string probabilitiesFile = CLI::GetParam<string>("probabilities_file");
+  const string outputPredictionsFile =
+      CLI::GetParam<string>("output_predictions_file");
+  const string outputProbabilitiesFile =
+      CLI::GetParam<string>("output_probabilities_file");
   bool batchTraining = CLI::HasParam("batch_mode");
   const size_t passes = (size_t) CLI::GetParam<int>("passes");
   if (passes > 1)
@@ -186,7 +191,7 @@ void PerformActions(const typename TreeType::NumericSplit& numericSplit)
 
   TreeType* tree = NULL;
   DatasetInfo datasetInfo;
-  if (inputModelFile.empty())
+  if (!CLI::HasParam("input_model_file"))
   {
     arma::mat trainingSet;
     data::Load(trainingFile, trainingSet, datasetInfo, true);
@@ -216,7 +221,7 @@ void PerformActions(const typename TreeType::NumericSplit& numericSplit)
     tree = new TreeType(datasetInfo, 1, 1);
     data::Load(inputModelFile, "streamingDecisionTree", *tree, true);
 
-    if (!trainingFile.empty())
+    if (CLI::HasParam("training_file"))
     {
       arma::mat trainingSet;
       data::Load(trainingFile, trainingSet, datasetInfo, true);
@@ -244,7 +249,7 @@ void PerformActions(const typename TreeType::NumericSplit& numericSplit)
     }
   }
 
-  if (!trainingFile.empty())
+  if (CLI::HasParam("training_file"))
   {
     // Get training error.
     arma::mat trainingSet;
@@ -282,7 +287,7 @@ void PerformActions(const typename TreeType::NumericSplit& numericSplit)
   Log::Info << nodes << " nodes in the tree." << endl;
 
   // The tree is trained or loaded.  Now do any testing if we need.
-  if (!testFile.empty())
+  if (CLI::HasParam("test_file"))
   {
     arma::mat testSet;
     data::Load(testFile, testSet, datasetInfo, true);
@@ -312,15 +317,15 @@ void PerformActions(const typename TreeType::NumericSplit& numericSplit)
           100.0 << ")." << endl;
     }
 
-    if (!predictionsFile.empty())
-      data::Save(predictionsFile, predictions);
+    if (CLI::HasParam("output_predictions_file"))
+      data::Save(outputPredictionsFile, predictions);
 
-    if (!probabilitiesFile.empty())
-      data::Save(probabilitiesFile, probabilities);
+    if (CLI::HasParam("output_probabilities_file"))
+      data::Save(outputProbabilitiesFile, probabilities);
   }
 
   // Check the accuracy on the training set.
-  if (!outputModelFile.empty())
+  if (CLI::HasParam("output_model_file"))
     data::Save(outputModelFile, "streamingDecisionTree", *tree, true);
 
   // Clean up memory.
diff --git a/src/mlpack/methods/lars/lars_main.cpp b/src/mlpack/methods/lars/lars_main.cpp
index 7981ca0..35179e0 100644
--- a/src/mlpack/methods/lars/lars_main.cpp
+++ b/src/mlpack/methods/lars/lars_main.cpp
@@ -40,7 +40,7 @@ PROGRAM_INFO("LARS", "An implementation of LARS: Least Angle Regression "
     " can be saved with the --output_model_file, or, if training is not desired"
     " at all, a model can be loaded with --input_model_file.  Any output "
     "predictions from a test file can be saved into the file specified by the "
-    "--output_predictions option.");
+    "--output_predictions_file option.");
 
 PARAM_STRING("input_file", "File containing covariates (X).", "i", "");
 PARAM_STRING("responses_file", "File containing y (responses/observations).",
@@ -51,8 +51,8 @@ PARAM_STRING("output_model_file", "File to save model to.", "M", "");
 
 PARAM_STRING("test_file", "File containing points to regress on (test points).",
     "t", "");
-PARAM_STRING("output_predictions", "If --test_file is specified, this file is "
-    "where the predicted responses will be saved.", "o", "predictions.csv");
+PARAM_STRING("output_predictions_file", "If --test_file is specified, this "
+    "file is where the predicted responses will be saved.", "o", "");
 
 PARAM_DOUBLE("lambda1", "Regularization parameter for l1-norm penalty.", "l",
     0);
@@ -93,14 +93,18 @@ int main(int argc, char* argv[])
     Log::Fatal << "Both --input_file (-i) and --input_model_file (-m) are "
         << "specified, but only one may be specified!" << endl;
 
-  if (!CLI::HasParam("output_predictions") &&
+  if (!CLI::HasParam("output_predictions_file") &&
       !CLI::HasParam("output_model_file"))
-    Log::Warn << "--output_predictions (-o) and --output_model_file (-M) are "
-        << "not specified; no results will be saved!" << endl;
+    Log::Warn << "--output_predictions_file (-o) and --output_model_file (-M) "
+        << "are not specified; no results will be saved!" << endl;
 
-  if (CLI::HasParam("output_predictions") && !CLI::HasParam("test_file"))
-    Log::Warn << "--output_predictions (-o) specified, but --test_file (-t) is "
-        << "not; no results will be saved." << endl;
+  if (CLI::HasParam("output_predictions_file") && !CLI::HasParam("test_file"))
+    Log::Warn << "--output_predictions_file (-o) specified, but --test_file "
+        << "(-t) is not; no results will be saved." << endl;
+
+  if (CLI::HasParam("test_file") && !CLI::HasParam("output_predictions_file"))
+    Log::Warn << "--test_file (-t) specified, but --output_predictions_file "
+        << "(-o) is not; no results will be saved." << endl;
 
   // Initialize the object.
   LARS lars(useCholesky, lambda1, lambda2);
@@ -109,16 +113,16 @@ int main(int argc, char* argv[])
   {
     // Load covariates.  We can avoid LARS transposing our data by choosing to
     // not transpose this data.
-    const string matXFilename = CLI::GetParam<string>("input_file");
+    const string inputFile = CLI::GetParam<string>("input_file");
     mat matX;
-    data::Load(matXFilename, matX, true, false);
+    data::Load(inputFile, matX, true, false);
 
     // Load responses.  The responses should be a one-dimensional vector, and it
     // seems more likely that these will be stored with one response per line
     // (one per row).  So we should not transpose upon loading.
-    const string yFilename = CLI::GetParam<string>("responses_file");
-    mat matY; // Will be a vector.
-    data::Load(yFilename, matY, true, false);
+    const string responsesFile = CLI::GetParam<string>("responses_file");
+    mat matY; // /yFWill be a vector.
+    data::Load(responsesFile, matY, true, false);
 
     // Make sure y is oriented the right way.
     if (matY.n_rows == 1)
@@ -135,16 +139,14 @@ int main(int argc, char* argv[])
   }
   else // We must have --input_model_file.
   {
-    const string modelFile = CLI::GetParam<string>("input_model_file");
-    data::Load(modelFile, "lars_model", lars, true);
+    const string inputModelFile = CLI::GetParam<string>("input_model_file");
+    data::Load(inputModelFile, "lars_model", lars, true);
   }
 
   if (CLI::HasParam("test_file"))
   {
     Log::Info << "Regressing on test points." << endl;
     const string testFile = CLI::GetParam<string>("test_file");
-    const string outputPredictionsFile =
-        CLI::GetParam<string>("output_predictions");
 
     // Load test points.
     mat testPoints;
@@ -161,7 +163,12 @@ int main(int argc, char* argv[])
     lars.Predict(testPoints.t(), predictions, false);
 
     // Save test predictions.  One per line, so, don't transpose on save.
-    data::Save(outputPredictionsFile, predictions, true, false);
+    if (CLI::HasParam("output_predictions_file"))
+    {
+      const string outputPredictionsFile =
+        CLI::GetParam<string>("output_predictions_file");
+      data::Save(outputPredictionsFile, predictions, true, false);
+    }
   }
 
   if (CLI::HasParam("output_model_file"))
diff --git a/src/mlpack/methods/linear_regression/linear_regression_main.cpp b/src/mlpack/methods/linear_regression/linear_regression_main.cpp
index 9f00850..d96ee17 100644
--- a/src/mlpack/methods/linear_regression/linear_regression_main.cpp
+++ b/src/mlpack/methods/linear_regression/linear_regression_main.cpp
@@ -22,22 +22,23 @@ PROGRAM_INFO("Simple Linear Regression and Prediction",
     " another matrix X' (--test_file):\n\n"
     "   y' = X' * b\n\n"
     "and these predicted responses, y', are saved to a file "
-    "(--output_predictions).  This type of regression is related to least-angle"
-    " regression, which mlpack implements with the 'lars' executable.");
+    "(--output_predictions_file).  This type of regression is related to "
+    "least-angle regression, which mlpack implements with the 'lars' "
+    "executable.");
 
 PARAM_STRING("training_file", "File containing training set X (regressors).",
     "t", "");
-PARAM_STRING("training_responses", "Optional file containing y (responses). If "
-    "not given, the responses are assumed to be the last row of the input "
-    "file.", "r", "");
+PARAM_STRING("training_responses_file", "Optional file containing y "
+    "(responses). If not given, the responses are assumed to be the last row "
+    "of the input file.", "r", "");
 
 PARAM_STRING("input_model_file", "File containing existing model (parameters).",
     "m", "");
 PARAM_STRING("output_model_file", "File to save trained model to.", "M", "");
 
 PARAM_STRING("test_file", "File containing X' (test regressors).", "T", "");
-PARAM_STRING("output_predictions", "If --test_file is specified, this file is "
-    "where the predicted responses will be saved.", "p", "predictions.csv");
+PARAM_STRING("output_predictions_file", "If --test_file is specified, this "
+    "file is where the predicted responses will be saved.", "p", "");
 
 PARAM_DOUBLE("lambda", "Tikhonov regularization for ridge regression.  If 0, "
     "the method reduces to linear regression.", "l", 0.0);
@@ -54,10 +55,12 @@ int main(int argc, char* argv[])
 
   const string inputModelFile = CLI::GetParam<string>("input_model_file");
   const string outputModelFile = CLI::GetParam<string>("output_model_file");
-  const string outputPredictions = CLI::GetParam<string>("output_predictions");
-  const string responseName = CLI::GetParam<string>("training_responses");
-  const string testName = CLI::GetParam<string>("test_file");
-  const string trainName = CLI::GetParam<string>("training_file");
+  const string outputPredictionsFile =
+    CLI::GetParam<string>("output_predictions_file");
+  const string trainingResponsesFile =
+    CLI::GetParam<string>("training_responses_file");
+  const string testFile = CLI::GetParam<string>("test_file");
+  const string trainFile = CLI::GetParam<string>("training_file");
   const double lambda = CLI::GetParam<double>("lambda");
 
   mat regressors;
@@ -69,16 +72,16 @@ int main(int argc, char* argv[])
   bool computeModel = false;
 
   // We want to determine if an input file XOR model file were given.
-  if (trainName.empty()) // The user specified no input file.
+  if (!CLI::HasParam("training_file"))
   {
-    if (inputModelFile.empty()) // The user specified no model file; error.
+    if (!CLI::HasParam("input_model_file"))
       Log::Fatal << "You must specify either --input_file or --model_file."
           << endl;
     else // The model file was specified, no problems.
       computeModel = false;
   }
   // The user specified an input file but no model file, no problems.
-  else if (inputModelFile.empty())
+  else if (!CLI::HasParam("input_model_file"))
     computeModel = true;
   // The user specified both an input file and model file.
   // This is ambiguous -- which model should we use? A generated one or given
@@ -89,9 +92,13 @@ int main(int argc, char* argv[])
         << "both." << endl;
   }
 
+  if (CLI::HasParam("test_file") && !CLI::HasParam("output_predictions_file"))
+    Log::Warn << "--test_file (-t) specified, but --output_predictions_file "
+        << "(-o) is not; no results will be saved." << endl;
+
   // If they specified a model file, we also need a test file or we
   // have nothing to do.
-  if (!computeModel && testName.empty())
+  if (!computeModel && !CLI::HasParam("test_file"))
   {
     Log::Fatal << "When specifying --model_file, you must also specify "
         << "--test_file." << endl;
@@ -106,11 +113,11 @@ int main(int argc, char* argv[])
   if (computeModel)
   {
     Timer::Start("load_regressors");
-    data::Load(trainName, regressors, true);
+    data::Load(trainFile, regressors, true);
     Timer::Stop("load_regressors");
 
     // Are the responses in a separate file?
-    if (responseName.empty())
+    if (!CLI::HasParam("training_responses_file"))
     {
       // The initial predictors for y, Nx1.
       responses = trans(regressors.row(regressors.n_rows - 1));
@@ -120,7 +127,7 @@ int main(int argc, char* argv[])
     {
       // The initial predictors for y, Nx1.
       Timer::Start("load_responses");
-      data::Load(responseName, responses, true);
+      data::Load(trainingResponsesFile, responses, true);
       Timer::Stop("load_responses");
 
       if (responses.n_rows == 1)
@@ -139,12 +146,12 @@ int main(int argc, char* argv[])
     Timer::Stop("regression");
 
     // Save the parameters.
-    if (!outputModelFile.empty())
+    if (CLI::HasParam("output_model_file"))
       data::Save(outputModelFile, "linearRegressionModel", lr);
   }
 
   // Did we want to predict, too?
-  if (!testName.empty())
+  if (CLI::HasParam("test_file"))
   {
     // A model file was passed in, so load it.
     if (!computeModel)
@@ -157,14 +164,14 @@ int main(int argc, char* argv[])
     // Load the test file data.
     arma::mat points;
     Timer::Start("load_test_points");
-    data::Load(testName, points, true);
+    data::Load(testFile, points, true);
     Timer::Stop("load_test_points");
 
     // Ensure that test file data has the right number of features.
     if ((lr.Parameters().n_elem - 1) != points.n_rows)
     {
       Log::Fatal << "The model was trained on " << lr.Parameters().n_elem - 1
-          << "-dimensional data, but the test points in '" << testName
+          << "-dimensional data, but the test points in '" << testFile
           << "' are " << points.n_rows << "-dimensional!" << endl;
     }
 
@@ -175,6 +182,7 @@ int main(int argc, char* argv[])
     Timer::Stop("prediction");
 
     // Save predictions.
-    data::Save(outputPredictions, predictions, true, false);
+    if (CLI::HasParam("output_predictions_file"))
+      data::Save(outputPredictionsFile, predictions, true, false);
   }
 }
diff --git a/src/mlpack/methods/mvu/mvu_main.cpp b/src/mlpack/methods/mvu/mvu_main.cpp
index 1cff076..2324f5e 100644
--- a/src/mlpack/methods/mvu/mvu_main.cpp
+++ b/src/mlpack/methods/mvu/mvu_main.cpp
@@ -16,10 +16,8 @@ PROGRAM_INFO("Maximum Variance Unfolding (MVU)", "This program implements "
     "constant.");
 
 PARAM_STRING_REQ("input_file", "Filename of input dataset.", "i");
+PARAM_STRING_REQ("output_file", "Filename to save unfolded dataset to.", "o");
 PARAM_INT_REQ("new_dim", "New dimensionality of dataset.", "d");
-
-PARAM_STRING("output_file", "Filename to save unfolded dataset to.", "o",
-    "output.csv");
 PARAM_INT("num_neighbors", "Number of nearest neighbors to consider while "
     "unfolding.", "k", 5);
 
@@ -33,16 +31,18 @@ int main(int argc, char **argv)
 {
   // Read from command line.
   CLI::ParseCommandLine(argc, argv);
+  const string inputFile = CLI::GetParam<string>("input_file");
+  const string outputFile = CLI::GetParam<string>("output_file");
+  const int newDim = CLI::GetParam<int>("new_dim");
+  const int numNeighbors = CLI::GetParam<int>("num_neighbors");
 
   RandomSeed(time(NULL));
 
   // Load input dataset.
-  const string inputFile = CLI::GetParam<string>("input_file");
   mat data;
   data::Load(inputFile, data, true);
 
   // Verify that the requested dimensionality is valid.
-  const int newDim = CLI::GetParam<int>("new_dim");
   if (newDim <= 0 || newDim > (int) data.n_rows)
   {
     Log::Fatal << "Invalid new dimensionality (" << newDim << ").  Must be "
@@ -51,7 +51,6 @@ int main(int argc, char **argv)
   }
 
   // Verify that the number of neighbors is valid.
-  const int numNeighbors = CLI::GetParam<int>("num_neighbors");
   if (numNeighbors <= 0 || numNeighbors > (int) data.n_cols)
   {
     Log::Fatal << "Invalid number of neighbors (" << numNeighbors << ").  Must "
@@ -66,6 +65,5 @@ int main(int argc, char **argv)
   mvu.Unfold(newDim, numNeighbors, output);
 
   // Save results to file.
-  const string outputFile = CLI::GetParam<string>("output_file");
   data::Save(outputFile, output, true);
 }
diff --git a/src/mlpack/methods/perceptron/perceptron_main.cpp b/src/mlpack/methods/perceptron/perceptron_main.cpp
index 28a2776..23e6609 100644
--- a/src/mlpack/methods/perceptron/perceptron_main.cpp
+++ b/src/mlpack/methods/perceptron/perceptron_main.cpp
@@ -112,21 +112,25 @@ int main(int argc, char** argv)
   const size_t maxIterations = (size_t) CLI::GetParam<int>("max_iterations");
 
   // We must either load a model or train a model.
-  if (inputModelFile == "" && trainingDataFile == "")
+  if (!CLI::HasParam("input_model_file") && !CLI::HasParam("training_file"))
     Log::Fatal << "Either an input model must be specified with "
         << "--input_model_file or training data must be given "
         << "(--training_file)!" << endl;
 
   // If the user isn't going to save the output model or any predictions, we
   // should issue a warning.
-  if (outputModelFile == "" && testDataFile == "")
+  if (!CLI::HasParam("output_model_file") && !CLI::HasParam("test_file"))
     Log::Warn << "Output will not be saved!  (Neither --test_file nor "
         << "--output_model_file are specified.)" << endl;
 
+  if (CLI::HasParam("test_file") && !CLI::HasParam("output_file"))
+    Log::Fatal << "--output_file must be specified with --test_file" << endl;
+
+
   // Now, load our model, if there is one.
   Perceptron<>* p = NULL;
   Col<size_t> mappings;
-  if (inputModelFile != "")
+  if (CLI::HasParam("input_model_file"))
   {
     Log::Info << "Loading saved perceptron from model file '" << inputModelFile
         << "'." << endl;
@@ -139,7 +143,7 @@ int main(int argc, char** argv)
   }
 
   // Next, load the training data and labels (if they have been given).
-  if (trainingDataFile != "")
+  if (CLI::HasParam("training_file"))
   {
     Log::Info << "Training perceptron on dataset '" << trainingDataFile;
     if (labelsFile != "")
@@ -217,7 +221,7 @@ int main(int argc, char** argv)
   }
 
   // Now, the training procedure is complete.  Do we have any test data?
-  if (testDataFile != "")
+  if (CLI::HasParam("test_file"))
   {
     Log::Info << "Classifying dataset '" << testDataFile << "'." << endl;
     mat testData;
@@ -245,7 +249,7 @@ int main(int argc, char** argv)
   }
 
   // Lastly, do we need to save the output model?
-  if (outputModelFile != "")
+  if (CLI::HasParam("output_model_file"))
   {
     PerceptronModel pm(*p, mappings);
     data::Save(outputModelFile, "perceptron_model", pm);
diff --git a/src/mlpack/methods/radical/radical_main.cpp b/src/mlpack/methods/radical/radical_main.cpp
index 43eac6d..5b9c749 100644
--- a/src/mlpack/methods/radical/radical_main.cpp
+++ b/src/mlpack/methods/radical/radical_main.cpp
@@ -16,10 +16,8 @@ PROGRAM_INFO("RADICAL", "An implementation of RADICAL, a method for independent"
 
 PARAM_STRING_REQ("input_file", "Input dataset filename for ICA.", "i");
 
-PARAM_STRING("output_ic", "File to save independent components to.", "o",
-    "output_ic.csv");
-PARAM_STRING("output_unmixing", "File to save unmixing matrix to.", "u",
-    "output_unmixing.csv");
+PARAM_STRING_REQ("output_ic", "File to save independent components to.", "o");
+PARAM_STRING_REQ("output_unmixing", "File to save unmixing matrix to.", "u");
 
 PARAM_DOUBLE("noise_std_dev", "Standard deviation of Gaussian noise.", "n",
     0.175);




More information about the mlpack-git mailing list