[mlpack-git] mlpack-2.0.x: Fix incorrect conditionals. Thanks to Sergiu Deitsch for pointing these out. (2b3de33)

gitdub at mlpack.org gitdub at mlpack.org
Wed Jul 20 15:44:27 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : mlpack-2.0.x
Link       : https://github.com/mlpack/mlpack/compare/e434bc4ac042534529a2a440a44d86935b4d7164...fc4195d27bb9e642356a384d1fa6fe10cbdf89a6

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

commit 2b3de33bf4c17227472a26865cad606961b0b085
Author: Ryan Curtin <ryan at ratml.org>
Date:   Sat Jul 16 16:21:31 2016 -0400

    Fix incorrect conditionals.  Thanks to Sergiu Deitsch for pointing these out.


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

2b3de33bf4c17227472a26865cad606961b0b085
 src/mlpack/methods/gmm/gmm_generate_main.cpp    |  2 +-
 src/mlpack/methods/gmm/gmm_probability_main.cpp |  2 +-
 src/mlpack/methods/mvu/mvu_main.cpp             | 75 +++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/src/mlpack/methods/gmm/gmm_generate_main.cpp b/src/mlpack/methods/gmm/gmm_generate_main.cpp
index 9bf3f26..2a50bd9 100644
--- a/src/mlpack/methods/gmm/gmm_generate_main.cpp
+++ b/src/mlpack/methods/gmm/gmm_generate_main.cpp
@@ -36,7 +36,7 @@ int main(int argc, char** argv)
 {
   CLI::ParseCommandLine(argc, argv);
 
-  if (CLI::HasParam("output_file"))
+  if (!CLI::HasParam("output_file"))
     Log::Warn << "--output_file (-o) is not specified;"
         << "no results will be saved!" << endl;
 
diff --git a/src/mlpack/methods/gmm/gmm_probability_main.cpp b/src/mlpack/methods/gmm/gmm_probability_main.cpp
index 97dc2e9..ae389cf 100644
--- a/src/mlpack/methods/gmm/gmm_probability_main.cpp
+++ b/src/mlpack/methods/gmm/gmm_probability_main.cpp
@@ -39,7 +39,7 @@ int main(int argc, char** argv)
   const string inputModelFile = CLI::GetParam<string>("input_model_file");
   const string outputFile = CLI::GetParam<string>("output_file");
 
-  if (CLI::HasParam("output_file"))
+  if (!CLI::HasParam("output_file"))
     Log::Warn << "--output_file (-o) is not specified;"
         << "no results will be saved!" << endl;
 
diff --git a/src/mlpack/methods/mvu/mvu_main.cpp b/src/mlpack/methods/mvu/mvu_main.cpp
new file mode 100644
index 0000000..de54048
--- /dev/null
+++ b/src/mlpack/methods/mvu/mvu_main.cpp
@@ -0,0 +1,75 @@
+/**
+ * @file mvu_main.cpp
+ * @author Ryan Curtin
+ *
+ * Executable for MVU.
+ *
+ * Note: this implementation of MVU does not work.  See #189.
+ */
+#include <mlpack/core.hpp>
+#include "mvu.hpp"
+
+PROGRAM_INFO("Maximum Variance Unfolding (MVU)", "This program implements "
+    "Maximum Variance Unfolding, a nonlinear dimensionality reduction "
+    "technique.  The method minimizes dimensionality by unfolding a manifold "
+    "such that the distances to the nearest neighbors of each point are held "
+    "constant.");
+
+PARAM_STRING_IN_REQ("input_file", "Filename of input dataset.", "i");
+PARAM_INT_IN_REQ("new_dim", "New dimensionality of dataset.", "d");
+
+PARAM_STRING_OUT("output_file", "Filename to save unfolded dataset to.", "o");
+PARAM_INT_IN("num_neighbors", "Number of nearest neighbors to consider while "
+    "unfolding.", "k", 5);
+
+using namespace mlpack;
+using namespace mlpack::mvu;
+using namespace mlpack::math;
+using namespace arma;
+using namespace std;
+
+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");
+
+  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.
+  mat data;
+  data::Load(inputFile, data, true);
+
+  // Verify that the requested dimensionality is valid.
+  if (newDim <= 0 || newDim > (int) data.n_rows)
+  {
+    Log::Fatal << "Invalid new dimensionality (" << newDim << ").  Must be "
+      << "between 1 and the input dataset dimensionality (" << data.n_rows
+      << ")." << std::endl;
+  }
+
+  // Verify that the number of neighbors is valid.
+  if (numNeighbors <= 0 || numNeighbors > (int) data.n_cols)
+  {
+    Log::Fatal << "Invalid number of neighbors (" << numNeighbors << ").  Must "
+        << "be between 1 and the number of points in the input dataset ("
+        << data.n_cols << ")." << std::endl;
+  }
+
+  // Now run MVU.
+  MVU mvu(data);
+
+  mat output;
+  mvu.Unfold(newDim, numNeighbors, output);
+
+  // Save results to file.
+  if (CLI::HasParam("output_file"))
+    data::Save(outputFile, output, true);
+}




More information about the mlpack-git mailing list