[mlpack-git] master: warn when output file is not specified (d79dd3f)
gitdub at mlpack.org
gitdub at mlpack.org
Wed Jun 8 07:31:57 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/4fa39b6ab0baa1428116d0406264b5452e716d06...97402b9098d9d72889aa795923cf8fd67a4d87bf
>---------------------------------------------------------------
commit d79dd3fbc55c1492c517b64a7b5d6ecc758adee6
Author: Keon Kim <kwk236 at gmail.com>
Date: Wed Jun 8 20:31:57 2016 +0900
warn when output file is not specified
>---------------------------------------------------------------
d79dd3fbc55c1492c517b64a7b5d6ecc758adee6
src/mlpack/core/util/cli_impl.hpp | 2 +-
src/mlpack/methods/emst/emst_main.cpp | 25 ++++++++++++++-----------
src/mlpack/methods/gmm/gmm_generate_main.cpp | 9 +++++++--
src/mlpack/methods/gmm/gmm_probability_main.cpp | 18 ++++++++++++++----
src/mlpack/methods/hmm/hmm_generate_main.cpp | 15 +++++++++------
src/mlpack/methods/hmm/hmm_viterbi_main.cpp | 13 +++++++++----
src/mlpack/methods/lars/lars_main.cpp | 2 +-
src/mlpack/methods/mvu/mvu_main.cpp | 10 ++++++++--
8 files changed, 63 insertions(+), 31 deletions(-)
diff --git a/src/mlpack/core/util/cli_impl.hpp b/src/mlpack/core/util/cli_impl.hpp
index 882382e..607bfb2 100644
--- a/src/mlpack/core/util/cli_impl.hpp
+++ b/src/mlpack/core/util/cli_impl.hpp
@@ -51,7 +51,7 @@ void CLI::Add(const std::string& identifier,
gmap_t& gmap = GetSingleton().globalValues;
amap_t& amap = GetSingleton().aliasValues;
- // if found in current map, print fatal error and terminat program.
+ // if found in current map, print fatal error and terminate the program.
if (gmap.count(identifier))
outstr << "Parameter --" << identifier << "(-" << alias << ") "
<< "is defined multiple times with same identifiers." << std::endl;
diff --git a/src/mlpack/methods/emst/emst_main.cpp b/src/mlpack/methods/emst/emst_main.cpp
index 284c44f..7efea0a 100644
--- a/src/mlpack/methods/emst/emst_main.cpp
+++ b/src/mlpack/methods/emst/emst_main.cpp
@@ -34,8 +34,9 @@ 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_REQ("output_file", "Data output file. Stored as an edge list.",
- "o");
+
+PARAM_STRING("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 "
@@ -51,10 +52,15 @@ int main(int argc, char* argv[])
{
CLI::ParseCommandLine(argc, argv);
- const string dataFilename = CLI::GetParam<string>("input_file");
+ const string inputFile = CLI::GetParam<string>("input_file");
+ const string outputFile= CLI::GetParam<string>("output_file");
+
+ if (CLI::HasParam("output_file"))
+ Log::Warn << "--output_file (-o) is not specified;"
+ << "no results will be saved!" << endl;
arma::mat dataPoints;
- data::Load(dataFilename, dataPoints, true);
+ data::Load(inputFile, dataPoints, true);
// Do naive computation if necessary.
if (CLI::GetParam<bool>("naive"))
@@ -66,9 +72,8 @@ int main(int argc, char* argv[])
arma::mat naiveResults;
naive.ComputeMST(naiveResults);
- const string outputFilename = CLI::GetParam<string>("output_file");
-
- data::Save(outputFilename, naiveResults, true);
+ if (CLI::HasParam("output_file"))
+ data::Save(outputFile, naiveResults, true);
}
else
{
@@ -120,9 +125,7 @@ int main(int argc, char* argv[])
unmappedResults(2, i) = results(2, i);
}
- // Output the results.
- const string outputFilename = CLI::GetParam<string>("output_file");
-
- data::Save(outputFilename, unmappedResults, true);
+ if (CLI::HasParam("output_file"))
+ data::Save(outputFile, unmappedResults, true);
}
}
diff --git a/src/mlpack/methods/gmm/gmm_generate_main.cpp b/src/mlpack/methods/gmm/gmm_generate_main.cpp
index 68e7c99..38508f7 100644
--- a/src/mlpack/methods/gmm/gmm_generate_main.cpp
+++ b/src/mlpack/methods/gmm/gmm_generate_main.cpp
@@ -21,14 +21,18 @@ 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_REQ("output_file", "File to save output samples in.", "o");
+PARAM_STRING("output_file", "File to save output samples in.", "o", "");
PARAM_INT("seed", "Random seed. If 0, 'std::time(NULL)' is used.", "s", 0);
int main(int argc, char** argv)
{
CLI::ParseCommandLine(argc, argv);
+ if (CLI::HasParam("output_file"))
+ Log::Warn << "--output_file (-o) is not specified;"
+ << "no results will be saved!" << endl;
+
if (CLI::GetParam<int>("seed") == 0)
mlpack::math::RandomSeed(time(NULL));
else
@@ -46,5 +50,6 @@ int main(int argc, char** argv)
for (size_t i = 0; i < length; ++i)
samples.col(i) = gmm.Random();
- data::Save(CLI::GetParam<string>("output_file"), samples);
+ if(CLI::HasParam("output_file"))
+ data::Save(CLI::GetParam<string>("output_file"), samples);
}
diff --git a/src/mlpack/methods/gmm/gmm_probability_main.cpp b/src/mlpack/methods/gmm/gmm_probability_main.cpp
index c8a4388..5a740cd 100644
--- a/src/mlpack/methods/gmm/gmm_probability_main.cpp
+++ b/src/mlpack/methods/gmm/gmm_probability_main.cpp
@@ -20,18 +20,27 @@ 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_REQ("output_file", "File to save calculated probabilities to.", "o");
+
+PARAM_STRING("output_file", "File to save calculated probabilities to.", "o", "");
int main(int argc, char** argv)
{
CLI::ParseCommandLine(argc, argv);
+ const string inputFile = CLI::GetParam<string>("input_file");
+ const string inputModelFile = CLI::GetParam<string>("input_model_file");
+ const string outputFile = CLI::GetParam<string>("input_model_file");
+
+ if (CLI::HasParam("output_file"))
+ Log::Warn << "--output_file (-o) is not specified;"
+ << "no results will be saved!" << endl;
+
// Get the GMM and the points.
GMM gmm;
- data::Load(CLI::GetParam<string>("input_model_file"), "gmm", gmm);
+ data::Load(inputFile, "gmm", gmm);
arma::mat dataset;
- data::Load(CLI::GetParam<string>("input_file"), dataset);
+ data::Load(inputModelFile, dataset);
// Now calculate the probabilities.
arma::rowvec probabilities(dataset.n_cols);
@@ -39,5 +48,6 @@ int main(int argc, char** argv)
probabilities[i] = gmm.Probability(dataset.unsafe_col(i));
// And save the result.
- data::Save(CLI::GetParam<string>("output_file"), probabilities);
+ if (CLI::HasParam("output_file"))
+ data::Save(outputFile, probabilities);
}
diff --git a/src/mlpack/methods/hmm/hmm_generate_main.cpp b/src/mlpack/methods/hmm/hmm_generate_main.cpp
index 3068aa6..49dd646 100644
--- a/src/mlpack/methods/hmm/hmm_generate_main.cpp
+++ b/src/mlpack/methods/hmm/hmm_generate_main.cpp
@@ -21,8 +21,8 @@ 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_STRING("output_file", "File to save observation sequence to.", "o" ,"");
PARAM_INT("start_state", "Starting state of sequence.", "t", 0);
PARAM_STRING("state_file", "File to save hidden state sequence to (may be left "
"unspecified.", "S", "");
@@ -50,6 +50,8 @@ struct Generate
// Load the parameters.
const size_t startState = (size_t) CLI::GetParam<int>("start_state");
const size_t length = (size_t) CLI::GetParam<int>("length");
+ const string outputFile = CLI::GetParam<string>("output_file");
+ const string sequenceFile = CLI::GetParam<string>("state_file");
Log::Info << "Generating sequence of length " << length << "..." << endl;
if (startState >= hmm.Transition().n_rows)
@@ -60,15 +62,12 @@ struct Generate
hmm.Generate(length, observations, sequence, startState);
// Now save the output.
- const string outputFile = CLI::GetParam<string>("output_file");
- data::Save(outputFile, observations, true);
+ if (CLI::HasParam("output_file"))
+ data::Save(outputFile, observations, true);
// Do we want to save the hidden sequence?
if (CLI::HasParam("state_file"))
- {
- const string sequenceFile = CLI::GetParam<string>("state_file");
data::Save(sequenceFile, sequence, true);
- }
}
};
@@ -77,6 +76,10 @@ int main(int argc, char** argv)
// Parse command line options.
CLI::ParseCommandLine(argc, argv);
+ if (CLI::HasParam("output_file"))
+ Log::Warn << "--output_file (-o) is not specified;"
+ << "no results will be saved!" << endl;
+
// Set random seed.
if (CLI::GetParam<int>("seed") != 0)
RandomSeed((size_t) CLI::GetParam<int>("seed"));
diff --git a/src/mlpack/methods/hmm/hmm_viterbi_main.cpp b/src/mlpack/methods/hmm/hmm_viterbi_main.cpp
index 23ecbfa..31275a0 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_REQ("output_file", "File to save predicted state sequence to.",
- "o");
+PARAM_STRING("output_file", "File to save predicted state sequence to.",
+ "o", "");
using namespace mlpack;
using namespace mlpack::hmm;
@@ -40,6 +40,7 @@ struct Viterbi
{
// Load observations.
const string inputFile = CLI::GetParam<string>("input_file");
+ const string outputFile = CLI::GetParam<string>("output_file");
mat dataSeq;
data::Load(inputFile, dataSeq, true);
@@ -62,8 +63,8 @@ struct Viterbi
hmm.Predict(dataSeq, sequence);
// Save output.
- const string outputFile = CLI::GetParam<string>("output_file");
- data::Save(outputFile, sequence, true);
+ if (CLI::HasParam("output_file"))
+ data::Save(outputFile, sequence, true);
}
};
@@ -72,6 +73,10 @@ int main(int argc, char** argv)
// Parse command line options.
CLI::ParseCommandLine(argc, argv);
+ if (CLI::HasParam("output_file"))
+ Log::Warn << "--output_file (-o) is not specified;"
+ << "no results will be saved!" << endl;
+
const string modelFile = CLI::GetParam<string>("model_file");
LoadHMMAndPerformAction<Viterbi>(modelFile);
}
diff --git a/src/mlpack/methods/lars/lars_main.cpp b/src/mlpack/methods/lars/lars_main.cpp
index 35179e0..d053772 100644
--- a/src/mlpack/methods/lars/lars_main.cpp
+++ b/src/mlpack/methods/lars/lars_main.cpp
@@ -121,7 +121,7 @@ int main(int argc, char* argv[])
// 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 responsesFile = CLI::GetParam<string>("responses_file");
- mat matY; // /yFWill be a vector.
+ mat matY; // Will be a vector.
data::Load(responsesFile, matY, true, false);
// Make sure y is oriented the right way.
diff --git a/src/mlpack/methods/mvu/mvu_main.cpp b/src/mlpack/methods/mvu/mvu_main.cpp
index 2324f5e..976b0d3 100644
--- a/src/mlpack/methods/mvu/mvu_main.cpp
+++ b/src/mlpack/methods/mvu/mvu_main.cpp
@@ -16,8 +16,9 @@ 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", "");
PARAM_INT("num_neighbors", "Number of nearest neighbors to consider while "
"unfolding.", "k", 5);
@@ -36,6 +37,10 @@ int main(int argc, char **argv)
const int newDim = CLI::GetParam<int>("new_dim");
const int numNeighbors = CLI::GetParam<int>("num_neighbors");
+ if (CLI::HasParam("output_file"))
+ Log::Warn << "--output_file (-o) is not specified;"
+ << "no results will be saved!" << endl;
+
RandomSeed(time(NULL));
// Load input dataset.
@@ -65,5 +70,6 @@ int main(int argc, char **argv)
mvu.Unfold(newDim, numNeighbors, output);
// Save results to file.
- data::Save(outputFile, output, true);
+ if (CLI::HasParam("output_file"))
+ data::Save(outputFile, output, true);
}
More information about the mlpack-git
mailing list