[mlpack] 264/324: utility for converting legacy GMM XML files to new format

Barak A. Pearlmutter barak+git at cs.nuim.ie
Sun Aug 17 08:22:17 UTC 2014


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit f40b87ec8dfe512aa888d8cf4951604098690d13
Author: michaelfox99 <michaelfox99 at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Tue Aug 5 12:57:20 2014 +0000

    utility for converting legacy GMM XML files to new format
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16948 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/methods/gmm/gmm_convert_main.cpp | 63 +++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/src/mlpack/methods/gmm/gmm_convert_main.cpp b/src/mlpack/methods/gmm/gmm_convert_main.cpp
new file mode 100644
index 0000000..e7fb0f9
--- /dev/null
+++ b/src/mlpack/methods/gmm/gmm_convert_main.cpp
@@ -0,0 +1,63 @@
+/**
+ * @author Michael Fox
+ * @file gmm_convert_main.cpp
+ *
+ * This program converts an older GMM XML file to the new format.
+ */
+#include <mlpack/core.hpp>
+#include "gmm.hpp"
+
+
+using namespace mlpack;
+using namespace mlpack::gmm;
+using namespace mlpack::util;
+using namespace std;
+
+PROGRAM_INFO("Gaussian Mixture Model (GMM) file converter",
+    "This program takes a fitted GMM XML file from older MLPACK versions and "
+		"converts it to the current format.");
+
+PARAM_STRING_REQ("input_file", "File containing the fitted model ", "i");
+PARAM_STRING("output_file", "The file to write the model to (as XML).", "o",
+    "gmm.xml");
+
+int main(int argc, char* argv[])
+{
+  CLI::ParseCommandLine(argc, argv);
+	string inputFile = CLI::GetParam<string>("input_file");
+  //data::Load(CLI::GetParam<string>("input_file"), inputFile, true);
+	util::SaveRestoreUtility load;
+
+  if (!load.ReadFile(inputFile))
+    Log::Fatal << " Could not read file '" << inputFile << "'!\n";
+	
+	size_t gaussians, dimensionality;
+	load.LoadParameter(gaussians, "gaussians");
+  load.LoadParameter(dimensionality, "dimensionality");
+	GMM<> gmm(gaussians, dimensionality);
+
+  load.LoadParameter(gmm.Weights(), "weights");
+
+  // We need to do a little error checking here.
+  if (gmm.Weights().n_elem != gmm.Gaussians())
+  {
+    Log::Fatal << "GMM::Load('" << inputFile << "'): file reports "
+				<< gmm.Gaussians() << " gaussians but weights vector only contains "
+				<< gmm.Weights().n_elem << " elements!" << std::endl;
+  }
+
+  
+  for (size_t i = 0; i < gaussians; ++i)
+  {
+    std::stringstream o;
+    o << i;
+    std::string meanName = "mean" + o.str();
+    std::string covName = "covariance" + o.str();
+
+    load.LoadParameter(gmm.Component(i).Mean(), meanName);
+    load.LoadParameter(gmm.Component(i).Covariance(), covName);
+  }
+	
+	gmm.Save(CLI::GetParam<string>("output_file"));
+	
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list