[mlpack-svn] r15520 - mlpack/conf/jenkins-conf/benchmark/methods/matlab

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Jul 22 08:31:12 EDT 2013


Author: marcus
Date: Mon Jul 22 08:31:11 2013
New Revision: 15520

Log:
Move the parsing of the xml file into the constructor.

Modified:
   mlpack/conf/jenkins-conf/benchmark/methods/matlab/hmm_generate.py
   mlpack/conf/jenkins-conf/benchmark/methods/matlab/hmm_viterbi.py

Modified: mlpack/conf/jenkins-conf/benchmark/methods/matlab/hmm_generate.py
==============================================================================
--- mlpack/conf/jenkins-conf/benchmark/methods/matlab/hmm_generate.py	(original)
+++ mlpack/conf/jenkins-conf/benchmark/methods/matlab/hmm_generate.py	Mon Jul 22 08:31:11 2013
@@ -40,29 +40,10 @@
     self.verbose = verbose
     self.dataset = dataset
     self.path = path
-
-  '''
-  Destructor to clean up at the end.
-  '''
-  def __del__(self):
-    Log.Info("Clean up.", self.verbose)
-    filelist = ["emis_tmp.csv", "trans_tmp.csv"]
-    for f in filelist:
-      if os.path.isfile(f):
-        os.remove(f) 
-    
-  '''
-  HMM Sequence Generator. If the method has been successfully completed return 
-  the elapsed time in seconds.
-
-  @param options - Extra options for the method.
-  @return - Elapsed time in seconds or -1 if the method was not successful.
-  '''
-  def RunMethod(self, options):
-    Log.Info("Perform HMM GENERATE.", self.verbose)
+    self.error = 0
 
     # Open the HMM xml model file and extract the emis and trans values.
-    fid = open(self.dataset, 'r')
+    fid = open(dataset, 'r')
     line = fid.read()
     fid.close()
 
@@ -81,7 +62,7 @@
     # Write the emis and trans values to a temporary file.
     if not emis or not trans:
       Log.Fatal("Can't parse the HMM model file.")
-      return -1
+      self.error = -1
     else:
       fidEmis = open("emis_tmp.csv", "w")     
       for m in emis:
@@ -95,6 +76,29 @@
         fidTrans.write(m)
       fidTrans.close()
 
+  '''
+  Destructor to clean up at the end.
+  '''
+  def __del__(self):
+    Log.Info("Clean up.", self.verbose)
+    filelist = ["emis_tmp.csv", "trans_tmp.csv"]
+    for f in filelist:
+      if os.path.isfile(f):
+        os.remove(f) 
+    
+  '''
+  HMM Sequence Generator. If the method has been successfully completed return 
+  the elapsed time in seconds.
+
+  @param options - Extra options for the method.
+  @return - Elapsed time in seconds or -1 if the method was not successful.
+  '''
+  def RunMethod(self, options):
+    Log.Info("Perform HMM GENERATE.", self.verbose)
+
+    if (self.error == -1):
+      return -1
+
     inputCmd = "-e emis_tmp.csv -t trans_tmp.csv " + options
     # Split the command using shell-like syntax.
     cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, " +

Modified: mlpack/conf/jenkins-conf/benchmark/methods/matlab/hmm_viterbi.py
==============================================================================
--- mlpack/conf/jenkins-conf/benchmark/methods/matlab/hmm_viterbi.py	(original)
+++ mlpack/conf/jenkins-conf/benchmark/methods/matlab/hmm_viterbi.py	Mon Jul 22 08:31:11 2013
@@ -40,6 +40,45 @@
     self.verbose = verbose
     self.dataset = dataset
     self.path = path
+    self.error = 0
+
+    if len(dataset) != 2:
+      Log.Fatal("This method requires two datasets.")
+      self.error = -1
+    else:
+      # Open the HMM model file and extract the emis and trans values.
+      fid = open(dataset[1], "r")
+      line = fid.read()
+      fid.close()
+
+      patternEmis = re.compile(r"""
+          .*?<hmm_emission_covariance_.*?>(?P<hmm_emission_mean>.*?)
+          </hmm_emission_covariance_
+          """, re.VERBOSE|re.MULTILINE|re.DOTALL)
+
+      patternTrans = re.compile(r"""
+          .*?<hmm_transition>(?P<hmm_transition>.*?)</hmm_transition>
+          """, re.VERBOSE|re.MULTILINE|re.DOTALL)
+
+      emis = patternEmis.findall(line)
+      trans = patternTrans.findall(line)
+
+      # Write the emis and trans values to a temporary file.
+      if not emis or not trans:
+        Log.Fatal("Can't parse the HMM model file.")
+        return -1
+      else:
+        fidEmis = open("emis_tmp.csv", "w")     
+        for m in emis:
+          m = m.split('\n')
+          m = m[0] + "," + m[1] + "\n"
+          fidEmis.write(m)
+        fidEmis.close()
+
+        fidTrans = open("trans_tmp.csv", "w")
+        for m in trans:
+          fidTrans.write(m)
+        fidTrans.close()
 
   '''
   Destructor to clean up at the end.
@@ -61,45 +100,6 @@
   def RunMethod(self, options):
     Log.Info("Perform HMM VITERBI.", self.verbose)
 
-    if len(self.dataset) != 2:
-      Log.Fatal("This method requires two datasets.")
-      return -1
-
-    # Open the HMM model file and extract the emis and trans values.
-    fid = open(self.dataset[1], "r")
-    line = fid.read()
-    fid.close()
-
-    patternEmis = re.compile(r"""
-        .*?<hmm_emission_covariance_.*?>(?P<hmm_emission_mean>.*?)
-        </hmm_emission_covariance_
-        """, re.VERBOSE|re.MULTILINE|re.DOTALL)
-
-    patternTrans = re.compile(r"""
-        .*?<hmm_transition>(?P<hmm_transition>.*?)</hmm_transition>
-        """, re.VERBOSE|re.MULTILINE|re.DOTALL)
-
-    emis = patternEmis.findall(line)
-    trans = patternTrans.findall(line)
-
-    # Write the emis and trans values to a temporary file.
-    if not emis or not trans:
-      Log.Fatal("Can't parse the HMM model file.")
-      return -1
-    else:
-      fidEmis = open("emis_tmp.csv", "w")     
-      for m in emis:
-        m = m.split('\n')
-        m = m[0] + "," + m[1] + "\n"
-        fidEmis.write(m)
-
-      fidEmis.close()
-
-      fidTrans = open("trans_tmp.csv", "w")
-      for m in trans:
-        fidTrans.write(m)
-      fidTrans.close()
-
     inputCmd = "-i " + self.dataset[0] + " -e emis_tmp.csv -t trans_tmp.csv " + options
     # Split the command using shell-like syntax.
     cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, " +



More information about the mlpack-svn mailing list