[mlpack] 279/324: Implemented Save, Load for hierarchical model support

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 7a6be9e9cbb9e6b0bb95169b5b87d35a5406fc78
Author: michaelfox99 <michaelfox99 at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Tue Aug 5 13:32:56 2014 +0000

    Implemented Save, Load for hierarchical model support
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16963 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/methods/hmm/hmm_impl.hpp | 42 +++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/src/mlpack/methods/hmm/hmm_impl.hpp b/src/mlpack/methods/hmm/hmm_impl.hpp
index a8644f2..8d70346 100644
--- a/src/mlpack/methods/hmm/hmm_impl.hpp
+++ b/src/mlpack/methods/hmm/hmm_impl.hpp
@@ -2,6 +2,7 @@
  * @file hmm_impl.hpp
  * @author Ryan Curtin
  * @author Tran Quoc Long
+ * @author Michael Fox
  *
  * Implementation of HMM class.
  */
@@ -522,6 +523,47 @@ std::string HMM<Distribution>::ToString() const
   return convert.str();
 }
 
+//! Save to SaveRestoreUtility
+template<typename Distribution>
+void HMM<Distribution>::Save(util::SaveRestoreUtility& sr) const
+{
+  //  Save parameters.
+  sr.SaveParameter(Type(), "type");
+  sr.SaveParameter(Emission()[0].Type(), "emission_type");
+  sr.SaveParameter(dimensionality, "dimensionality");
+  sr.SaveParameter(transition.n_rows, "states");
+  sr.SaveParameter(transition, "transition");
+  
+  // Now the emissions.
+  util::SaveRestoreUtility mn;
+  for (size_t i = 0; i < transition.n_rows; ++i)
+  {
+    // Generate name.
+    std::stringstream s;
+    s << "emission_distribution_" << i;
+    Emission()[i].Save(mn);
+    sr.AddChild(mn, s.str());
+  }
+}
+
+//! Load from SaveRestoreUtility
+template<typename Distribution>
+void HMM<Distribution>::Load(const util::SaveRestoreUtility& sr)
+{
+  // Load parameters.
+  sr.LoadParameter(dimensionality, "dimensionality");
+  sr.LoadParameter(transition, "transition");
+
+  // Now each emission distribution.
+  Emission().resize(transition.n_rows);
+  for (size_t i = 0; i < transition.n_rows; ++i)
+  {
+    std::stringstream s;
+    s << "emission_distribution_" << i;
+    Emission()[i].Load(sr.Children().at(s.str()));
+  }
+}
+
 }; // namespace hmm
 }; // namespace mlpack
 

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