Skip to content

Commit

Permalink
warn when output file is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
keon committed Jun 8, 2016
1 parent 92f3cd1 commit d79dd3f
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/mlpack/core/util/cli_impl.hpp
Expand Up @@ -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;
Expand Down
25 changes: 14 additions & 11 deletions src/mlpack/methods/emst/emst_main.cpp
Expand Up @@ -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 "
Expand All @@ -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"))

This comment has been minimized.

Copy link
@sergiud

sergiud Jul 16, 2016

This statement must be inverted.

This comment has been minimized.

Copy link
@rcurtin

rcurtin Jul 16, 2016

Member

Fized by #723, should be merged soon. Thanks for taking the time to point this out---I'll go through and check that each of the comments have been addressed in #723 and if not I will make the changes.

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"))
Expand All @@ -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
{
Expand Down Expand Up @@ -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);
}
}
9 changes: 7 additions & 2 deletions src/mlpack/methods/gmm/gmm_generate_main.cpp
Expand Up @@ -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"))

This comment has been minimized.

Copy link
@sergiud

sergiud Jul 16, 2016

The statement must be inverted.

This comment has been minimized.

Copy link
@rcurtin

rcurtin Jul 16, 2016

Member

Fixed in #723 by the commit I just pushed (95ee836). Thanks again for pointing out each of these issues; please post if you find any more. :)

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
Expand All @@ -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);
}
18 changes: 14 additions & 4 deletions src/mlpack/methods/gmm/gmm_probability_main.cpp
Expand Up @@ -20,24 +20,34 @@ 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");

This comment has been minimized.

Copy link
@sergiud

sergiud Jul 16, 2016

Copy-and-paste error. The literal input_model_file must actually be output_file.

This comment has been minimized.

Copy link
@rcurtin

rcurtin Jul 16, 2016

Member

Fixed in #723.


if (CLI::HasParam("output_file"))

This comment has been minimized.

Copy link
@sergiud

sergiud Jul 16, 2016

The statement must be inverted.

This comment has been minimized.

Copy link
@rcurtin

rcurtin Jul 16, 2016

Member

Fixed in #723 by the commit I just pushed (95ee836).

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);

This comment has been minimized.

Copy link
@sergiud

sergiud Jul 16, 2016

Must be actually inputModelFile instead of inputFile.

This comment has been minimized.

Copy link
@rcurtin

rcurtin Jul 16, 2016

Member

Fixed in #723.


arma::mat dataset;
data::Load(CLI::GetParam<string>("input_file"), dataset);
data::Load(inputModelFile, dataset);

This comment has been minimized.

Copy link
@sergiud

sergiud Jul 16, 2016

Must be actually inputFile instead of inputModelFile.

This comment has been minimized.

Copy link
@rcurtin

rcurtin Jul 16, 2016

Member

Fixed in #723.


// Now calculate the probabilities.
arma::rowvec probabilities(dataset.n_cols);
for (size_t i = 0; i < dataset.n_cols; ++i)
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);
}
15 changes: 9 additions & 6 deletions src/mlpack/methods/hmm/hmm_generate_main.cpp
Expand Up @@ -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", "");
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
}
};

Expand All @@ -77,6 +76,10 @@ int main(int argc, char** argv)
// Parse command line options.
CLI::ParseCommandLine(argc, argv);

if (CLI::HasParam("output_file"))

This comment has been minimized.

Copy link
@sergiud

sergiud Jul 16, 2016

The statement must be inverted.

This comment has been minimized.

Copy link
@rcurtin

rcurtin Jul 16, 2016

Member

Fixed in #723.

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"));
Expand Down
13 changes: 9 additions & 4 deletions src/mlpack/methods/hmm/hmm_viterbi_main.cpp
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}
};

Expand All @@ -72,6 +73,10 @@ int main(int argc, char** argv)
// Parse command line options.
CLI::ParseCommandLine(argc, argv);

if (CLI::HasParam("output_file"))

This comment has been minimized.

Copy link
@sergiud

sergiud Jul 16, 2016

The statement must be inverted.

This comment has been minimized.

Copy link
@rcurtin

rcurtin Jul 16, 2016

Member

Fixed in #723.

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);
}
2 changes: 1 addition & 1 deletion src/mlpack/methods/lars/lars_main.cpp
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions src/mlpack/methods/mvu/mvu_main.cpp
Expand Up @@ -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);

Expand All @@ -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"))

This comment has been minimized.

Copy link
@sergiud

sergiud Jul 16, 2016

The statement must be inverted.

This comment has been minimized.

Copy link
@rcurtin

rcurtin Jul 16, 2016

Member

Fixed in #723 (by the commit I just pushed, 95ee836).

Log::Warn << "--output_file (-o) is not specified;"
<< "no results will be saved!" << endl;

RandomSeed(time(NULL));

// Load input dataset.
Expand Down Expand Up @@ -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);
}

1 comment on commit d79dd3f

@keon
Copy link
Member Author

@keon keon commented on d79dd3f Jul 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow sorry for the huge mistakes I've made :(
And thanks for pointing those out.
I failed to check the output when I mindlessly changed variable.empty() to CLI::HasParam("variable")

Please sign in to comment.