[mlpack-git] master: Hierarchical model support (09a203f)

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


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

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

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

commit 09a203f000ccc9a70d9adea21293af3b9652afb1
Author: michaelfox99 <michaelfox99 at gmail.com>
Date:   Tue Aug 5 13:11:31 2014 +0000

    Hierarchical model support


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

09a203f000ccc9a70d9adea21293af3b9652afb1
 src/mlpack/core/util/save_restore_utility.hpp | 48 ++++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 8 deletions(-)

diff --git a/src/mlpack/core/util/save_restore_utility.hpp b/src/mlpack/core/util/save_restore_utility.hpp
index d27e7f2..f4674ae 100644
--- a/src/mlpack/core/util/save_restore_utility.hpp
+++ b/src/mlpack/core/util/save_restore_utility.hpp
@@ -33,11 +33,18 @@ class SaveRestoreUtility
   std::map<std::string, std::string> parameters;
 
   /**
+   * children contains a list of names in string format and child
+   * models in the model hierarchy in SaveRestoreUtility format
+   */
+  std::map<std::string, SaveRestoreUtility> children;
+
+  /**
    * RecurseOnNodes performs a depth first search of the XML tree.
    */
   void RecurseOnNodes(xmlNode* n);
 
  public:
+    
   SaveRestoreUtility() {}
   ~SaveRestoreUtility() { parameters.clear(); }
 
@@ -45,6 +52,7 @@ class SaveRestoreUtility
    * ReadFile reads an XML tree from a file.
    */
   bool ReadFile(const std::string& filename);
+  void ReadFile(xmlNode* n);
 
   /**
    * WriteFile writes the XML tree to a file.
@@ -55,28 +63,29 @@ class SaveRestoreUtility
    * LoadParameter loads a parameter from the parameters map.
    */
   template<typename T>
-  T& LoadParameter(T& t, const std::string& name);
+  T& LoadParameter(T& t, const std::string& name) const;
 
   /**
    * LoadParameter loads a parameter from the parameters map.
    */
   template<typename T>
-  std::vector<T>& LoadParameter(std::vector<T>& v, const std::string& name);
+  std::vector<T>& LoadParameter(std::vector<T>& v, const std::string& name)
+      const;
 
   /**
    * LoadParameter loads a character from the parameters map.
    */
-  char LoadParameter(char c, const std::string& name);
+  char LoadParameter(char c, const std::string& name) const;
 
   /**
    * LoadParameter loads a string from the parameters map.
    */
-  std::string LoadParameter(std::string& str, const std::string& name);
+  std::string LoadParameter(std::string& str, const std::string& name) const;
 
   /**
    * LoadParameter loads an arma::mat from the parameters map.
    */
-  arma::mat& LoadParameter(arma::mat& matrix, const std::string& name);
+  arma::mat& LoadParameter(arma::mat& matrix, const std::string& name) const;
 
   /**
    * SaveParameter saves a parameter to the parameters map.
@@ -84,8 +93,6 @@ class SaveRestoreUtility
   template<typename T>
   void SaveParameter(const T& t, const std::string& name);
 
-
-
   /**
    * SaveParameter saves a parameter to the parameters map.
    */
@@ -101,18 +108,43 @@ class SaveRestoreUtility
    * SaveParameter saves an arma::mat to the parameters map.
    */
   void SaveParameter(const arma::mat& mat, const std::string& name);
+    
+  /**
+   * SaveSubModel saves a SaveRestoreUtility to the children map.
+   */
+  void AddChild(SaveRestoreUtility& mn, const std::string& name);
+  
+  /**
+   * Return the children.
+   */
+  const std::map<std::string, SaveRestoreUtility> Children() const { return
+    children; }
+  
+  /**
+   * Return modifiable copy of the children.
+   */
+  std::map<std::string, SaveRestoreUtility> Children() { return children; }
+ 
+ private:
+  /**
+  * WriteFile creates XML tree recursively.
+  */
+  void WriteFile(xmlNode* n);
+    
 };
 
 //! Specialization for arma::vec.
 template<>
 arma::vec& SaveRestoreUtility::LoadParameter(arma::vec& t,
-                                             const std::string& name);
+                                             const std::string& name) const;
 
 //! Specialization for arma::vec.
 template<>
 void SaveRestoreUtility::SaveParameter(const arma::vec& t,
                                        const std::string& name);
 
+
+    
 }; /* namespace util */
 }; /* namespace mlpack */
 



More information about the mlpack-git mailing list