[mlpack-git] master: Legacy file converter util (66ed2e4)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:56:37 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

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

commit 66ed2e44003de3c27b6975b6a837d87cd4320f0e
Author: michaelfox99 <michaelfox99 at gmail.com>
Date:   Tue Aug 5 13:36:49 2014 +0000

    Legacy file converter util


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

66ed2e44003de3c27b6975b6a837d87cd4320f0e
 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;
+}



More information about the mlpack-git mailing list