[mlpack] 282/324: Legacy file converter util

Barak A. Pearlmutter barak+git at cs.nuim.ie
Sun Aug 17 08:22:18 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 22bfcd4245613f2944f084e978f12e608c81b1e2
Author: michaelfox99 <michaelfox99 at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Tue Aug 5 13:36:49 2014 +0000

    Legacy file converter util
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16966 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/methods/hmm/hmm_convert_main.cpp | 77 +++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/src/mlpack/methods/hmm/hmm_convert_main.cpp b/src/mlpack/methods/hmm/hmm_convert_main.cpp
new file mode 100644
index 0000000..03fa9d6
--- /dev/null
+++ b/src/mlpack/methods/hmm/hmm_convert_main.cpp
@@ -0,0 +1,77 @@
+/**
+ * @file hmm_convert_main.cpp
+ * @author Ryan Curtin
+ * @author Michael Fox
+ *
+ * Convert an HMM (XML) file from older MLPACK versions to current format.
+ */
+#include <mlpack/core.hpp>
+
+#include "hmm.hpp"
+#include "hmm_util.hpp"
+
+#include <mlpack/methods/gmm/gmm.hpp>
+
+
+PROGRAM_INFO("Hidden Markov Model (HMM) File Converter", "This utility takes "
+    "an already-trained HMM (--model_file) and converts it to the new format "
+    "(--output_file).");
+
+PARAM_STRING_REQ("model_file", "File containing HMM (XML).", "m");
+PARAM_STRING("output_file", "File to save HMM (XML) to.", "o", "output.xml");
+
+using namespace mlpack;
+using namespace mlpack::hmm;
+using namespace mlpack::distribution;
+using namespace mlpack::util;
+using namespace mlpack::gmm;
+using namespace mlpack::math;
+using namespace arma;
+using namespace std;
+
+int main(int argc, char** argv)
+{
+  // Parse command line options.
+  CLI::ParseCommandLine(argc, argv);
+
+  // Load model
+  const string modelFile = CLI::GetParam<string>("model_file");
+
+  // Load model, but first we have to determine its type.
+  SaveRestoreUtility sr, sr2;
+  sr.ReadFile(modelFile);
+  string emissionType;
+  sr.LoadParameter(emissionType, "hmm_type");
+
+  mat observations;
+  Col<size_t> sequence;
+  if (emissionType == "discrete")
+  {
+    HMM<DiscreteDistribution> hmm(1, DiscreteDistribution(1));
+    ConvertHMM(hmm, sr);
+		hmm.Save(sr2);
+  }
+  else if (emissionType == "gaussian")
+  {
+    HMM<GaussianDistribution> hmm(1, GaussianDistribution(1));
+    ConvertHMM(hmm, sr);
+		hmm.Save(sr2);
+  }
+  else if (emissionType == "gmm")
+  {
+    HMM<GMM<> > hmm(1, GMM<>(1, 1));
+    ConvertHMM(hmm, sr);
+		hmm.Save(sr2);
+  }
+  else
+  {
+    Log::Fatal << "Unknown HMM type '" << emissionType << "' in file '" << modelFile
+        << "'!" << endl;
+  }
+
+  // Save the converted model.
+  const string outputFile = CLI::GetParam<string>("output_file");
+  sr2.WriteFile(outputFile);
+  
+	return 0;
+}

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