[mlpack-svn] r15545 - mlpack/conf/jenkins-conf/benchmark/methods/matlab
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Jul 25 16:27:01 EDT 2013
Author: marcus
Date: Thu Jul 25 16:27:01 2013
New Revision: 15545
Log:
Clean matlab scripts and make the code compatible with python 3.
Modified:
mlpack/conf/jenkins-conf/benchmark/methods/matlab/allknn.py
mlpack/conf/jenkins-conf/benchmark/methods/matlab/hmm_generate.py
mlpack/conf/jenkins-conf/benchmark/methods/matlab/hmm_viterbi.py
mlpack/conf/jenkins-conf/benchmark/methods/matlab/kmeans.py
mlpack/conf/jenkins-conf/benchmark/methods/matlab/linear_regression.py
mlpack/conf/jenkins-conf/benchmark/methods/matlab/nbc.py
mlpack/conf/jenkins-conf/benchmark/methods/matlab/nmf.py
mlpack/conf/jenkins-conf/benchmark/methods/matlab/pca.py
mlpack/conf/jenkins-conf/benchmark/methods/matlab/range_search.py
Modified: mlpack/conf/jenkins-conf/benchmark/methods/matlab/allknn.py
==============================================================================
--- mlpack/conf/jenkins-conf/benchmark/methods/matlab/allknn.py (original)
+++ mlpack/conf/jenkins-conf/benchmark/methods/matlab/allknn.py Thu Jul 25 16:27:01 2013
@@ -12,9 +12,9 @@
# Import the util path, this method even works if the path contains symlinks to
# modules.
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(
- os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
+ os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
if cmd_subfolder not in sys.path:
- sys.path.insert(0, cmd_subfolder)
+ sys.path.insert(0, cmd_subfolder)
from log import *
from profiler import *
@@ -29,86 +29,86 @@
'''
class ALLKNN(object):
- '''
- Create the All K-Nearest-Neighbors benchmark instance.
+ '''
+ Create the All K-Nearest-Neighbors benchmark instance.
@param dataset - Input dataset to perform ALLKNN on.
@param path - Path to the matlab binary.
@param verbose - Display informational messages.
- '''
- def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
- self.verbose = verbose
- self.dataset = dataset
- self.path = path
-
- '''
+ '''
+ def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
+ self.verbose = verbose
+ self.dataset = dataset
+ self.path = path
+
+ '''
All K-Nearest-Neighbors. 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 ALLKNN.", self.verbose)
+ def RunMethod(self, options):
+ Log.Info("Perform ALLKNN.", self.verbose)
+
+ # If the dataset contains two files then the second file is the query file.
+ # In this case we add this to the command line.
+ if len(self.dataset) == 2:
+ inputCmd = "-r " + self.dataset[0] + " -q " + self.dataset[1] + " " + options
+ else:
+ inputCmd = "-r " + self.dataset + " " + options
+
+ # Split the command using shell-like syntax.
+ cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, " +
+ "ALLKNN('" + inputCmd + "'), catch, exit(1), end, exit(0)\"")
+
+ # Run command with the nessecary arguments and return its output as a byte
+ # string. We have untrusted input so we disables all shell based features.
+ try:
+ s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
+ except Exception:
+ Log.Fatal("Could not execute command: " + str(cmd))
+ return -1
+
+ # Return the elapsed time.
+ timer = self.parseTimer(s)
+ if not timer:
+ Log.Fatal("Can't parse the timer")
+ return -1
+ else:
+ time = self.GetTime(timer)
+ Log.Info(("total time: %fs" % time), self.verbose)
+
+ return time
+
+ '''
+ Parse the timer data form a given string.
- # If the dataset contains two files then the second file is the query file.
- # In this case we add this to the command line.
- if len(self.dataset) == 2:
- inputCmd = "-r " + self.dataset[0] + " -q " + self.dataset[1] + " " + options
- else:
- inputCmd = "-r " + self.dataset + " " + options
-
- # Split the command using shell-like syntax.
- cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, " +
- "ALLKNN('" + inputCmd + "'), catch, exit(1), end, exit(0)\"")
-
- # Run command with the nessecary arguments and return its output as a byte
- # string. We have untrusted input so we disables all shell based features.
- try:
- s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
- except Exception:
- Log.Fatal("Could not execute command: " + str(cmd))
- return -1
-
- # Return the elapsed time.
- timer = self.parseTimer(s)
- if not timer:
- Log.Fatal("Can't parse the timer")
- return -1
- else:
- time = self.GetTime(timer)
- Log.Info(("total time: %fs" % time), self.verbose)
-
- return time
-
- '''
- Parse the timer data form a given string.
-
- @param data - String to parse timer data from.
- @return - Namedtuple that contains the timer data.
- '''
- def parseTimer(self, data):
- # Compile the regular expression pattern into a regular expression object to
- # parse the timer data.
- pattern = re.compile(r"""
- .*?total_time: (?P<total_time>.*?)s.*?
- """, re.VERBOSE|re.MULTILINE|re.DOTALL)
-
- match = pattern.match(data)
- if not match:
- Log.Fatal("Can't parse the data: wrong format")
- return -1
- else:
- # Create a namedtuple and return the timer data.
- timer = collections.namedtuple("timer", ["total_time"])
-
- return timer(float(match.group("total_time")))
-
- '''
- Return the elapsed time in seconds.
-
- @param timer - Namedtuple that contains the timer data.
- @return Elapsed time in seconds.
- '''
- def GetTime(self, timer):
- return timer.total_time
+ @param data - String to parse timer data from.
+ @return - Namedtuple that contains the timer data.
+ '''
+ def parseTimer(self, data):
+ # Compile the regular expression pattern into a regular expression object to
+ # parse the timer data.
+ pattern = re.compile(br"""
+ .*?total_time: (?P<total_time>.*?)s.*?
+ """, re.VERBOSE|re.MULTILINE|re.DOTALL)
+
+ match = pattern.match(data)
+ if not match:
+ Log.Fatal("Can't parse the data: wrong format")
+ return -1
+ else:
+ # Create a namedtuple and return the timer data.
+ timer = collections.namedtuple("timer", ["total_time"])
+
+ return timer(float(match.group("total_time")))
+
+ '''
+ Return the elapsed time in seconds.
+
+ @param timer - Namedtuple that contains the timer data.
+ @return Elapsed time in seconds.
+ '''
+ def GetTime(self, timer):
+ return timer.total_time
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 Thu Jul 25 16:27:01 2013
@@ -132,7 +132,7 @@
def parseTimer(self, data):
# Compile the regular expression pattern into a regular expression object to
# parse the timer data.
- pattern = re.compile(r"""
+ pattern = re.compile(br"""
.*?total_time: (?P<total_time>.*?)s.*?
""", re.VERBOSE|re.MULTILINE|re.DOTALL)
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 Thu Jul 25 16:27:01 2013
@@ -51,12 +51,12 @@
line = fid.read()
fid.close()
- patternEmis = re.compile(r"""
+ patternEmis = re.compile(br"""
.*?<hmm_emission_covariance_.*?>(?P<hmm_emission_mean>.*?)
</hmm_emission_covariance_
""", re.VERBOSE|re.MULTILINE|re.DOTALL)
- patternTrans = re.compile(r"""
+ patternTrans = re.compile(br"""
.*?<hmm_transition>(?P<hmm_transition>.*?)</hmm_transition>
""", re.VERBOSE|re.MULTILINE|re.DOTALL)
@@ -133,7 +133,7 @@
def parseTimer(self, data):
# Compile the regular expression pattern into a regular expression object to
# parse the timer data.
- pattern = re.compile(r"""
+ pattern = re.compile(br"""
.*?total_time: (?P<total_time>.*?)s.*?
""", re.VERBOSE|re.MULTILINE|re.DOTALL)
Modified: mlpack/conf/jenkins-conf/benchmark/methods/matlab/kmeans.py
==============================================================================
--- mlpack/conf/jenkins-conf/benchmark/methods/matlab/kmeans.py (original)
+++ mlpack/conf/jenkins-conf/benchmark/methods/matlab/kmeans.py Thu Jul 25 16:27:01 2013
@@ -12,9 +12,9 @@
# Import the util path, this method even works if the path contains symlinks to
# modules.
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(
- os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
+ os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
if cmd_subfolder not in sys.path:
- sys.path.insert(0, cmd_subfolder)
+ sys.path.insert(0, cmd_subfolder)
from log import *
from profiler import *
@@ -29,86 +29,86 @@
'''
class KMEANS(object):
- '''
- Create the K-Means Clustering benchmark instance.
+ '''
+ Create the K-Means Clustering benchmark instance.
@param dataset - Input dataset to perform K-Means on.
@param path - Path to the matlab binary.
@param verbose - Display informational messages.
- '''
- def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
- self.verbose = verbose
- self.dataset = dataset
- self.path = path
-
- '''
+ '''
+ def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
+ self.verbose = verbose
+ self.dataset = dataset
+ self.path = path
+
+ '''
K-Means Clustering benchmark instance. 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 K-Means.", self.verbose)
+ def RunMethod(self, options):
+ Log.Info("Perform K-Means.", self.verbose)
+
+ # If the dataset contains two files then the second file is the centroids
+ # file. In this case we add this to the command line.
+ if len(self.dataset) == 2:
+ inputCmd = "-i " + self.dataset[0] + " -I " + self.dataset[1] + " " + options
+ else:
+ inputCmd = "-i " + self.dataset + " " + options
+
+ # Split the command using shell-like syntax.
+ cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, " +
+ "KMEANS('" + inputCmd + "'), catch, exit(1), end, exit(0)\"")
+
+ # Run command with the nessecary arguments and return its output as a byte
+ # string. We have untrusted input so we disables all shell based features.
+ try:
+ s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
+ except Exception:
+ Log.Fatal("Could not execute command: " + str(cmd))
+ return -1
+
+ # Return the elapsed time.
+ timer = self.parseTimer(s)
+ if not timer:
+ Log.Fatal("Can't parse the timer")
+ return -1
+ else:
+ time = self.GetTime(timer)
+ Log.Info(("total time: %fs" % time), self.verbose)
+
+ return time
+
+ '''
+ Parse the timer data form a given string.
- # If the dataset contains two files then the second file is the centroids
- # file. In this case we add this to the command line.
- if len(self.dataset) == 2:
- inputCmd = "-i " + self.dataset[0] + " -I " + self.dataset[1] + " " + options
- else:
- inputCmd = "-i " + self.dataset + " " + options
-
- # Split the command using shell-like syntax.
- cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, " +
- "KMEANS('" + inputCmd + "'), catch, exit(1), end, exit(0)\"")
-
- # Run command with the nessecary arguments and return its output as a byte
- # string. We have untrusted input so we disables all shell based features.
- try:
- s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
- except Exception:
- Log.Fatal("Could not execute command: " + str(cmd))
- return -1
-
- # Return the elapsed time.
- timer = self.parseTimer(s)
- if not timer:
- Log.Fatal("Can't parse the timer")
- return -1
- else:
- time = self.GetTime(timer)
- Log.Info(("total time: %fs" % time), self.verbose)
-
- return time
-
- '''
- Parse the timer data form a given string.
-
- @param data - String to parse timer data from.
- @return - Namedtuple that contains the timer data.
- '''
- def parseTimer(self, data):
- # Compile the regular expression pattern into a regular expression object to
- # parse the timer data.
- pattern = re.compile(r"""
- .*?total_time: (?P<total_time>.*?)s.*?
- """, re.VERBOSE|re.MULTILINE|re.DOTALL)
-
- match = pattern.match(data)
- if not match:
- Log.Fatal("Can't parse the data: wrong format")
- return -1
- else:
- # Create a namedtuple and return the timer data.
- timer = collections.namedtuple("timer", ["total_time"])
-
- return timer(float(match.group("total_time")))
-
- '''
- Return the elapsed time in seconds.
-
- @param timer - Namedtuple that contains the timer data.
- @return Elapsed time in seconds.
- '''
- def GetTime(self, timer):
- return timer.total_time
+ @param data - String to parse timer data from.
+ @return - Namedtuple that contains the timer data.
+ '''
+ def parseTimer(self, data):
+ # Compile the regular expression pattern into a regular expression object to
+ # parse the timer data.
+ pattern = re.compile(br"""
+ .*?total_time: (?P<total_time>.*?)s.*?
+ """, re.VERBOSE|re.MULTILINE|re.DOTALL)
+
+ match = pattern.match(data)
+ if not match:
+ Log.Fatal("Can't parse the data: wrong format")
+ return -1
+ else:
+ # Create a namedtuple and return the timer data.
+ timer = collections.namedtuple("timer", ["total_time"])
+
+ return timer(float(match.group("total_time")))
+
+ '''
+ Return the elapsed time in seconds.
+
+ @param timer - Namedtuple that contains the timer data.
+ @return Elapsed time in seconds.
+ '''
+ def GetTime(self, timer):
+ return timer.total_time
Modified: mlpack/conf/jenkins-conf/benchmark/methods/matlab/linear_regression.py
==============================================================================
--- mlpack/conf/jenkins-conf/benchmark/methods/matlab/linear_regression.py (original)
+++ mlpack/conf/jenkins-conf/benchmark/methods/matlab/linear_regression.py Thu Jul 25 16:27:01 2013
@@ -12,9 +12,9 @@
# Import the util path, this method even works if the path contains symlinks to
# modules.
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(
- os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
+ os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
if cmd_subfolder not in sys.path:
- sys.path.insert(0, cmd_subfolder)
+ sys.path.insert(0, cmd_subfolder)
from log import *
from profiler import *
@@ -29,86 +29,86 @@
'''
class LinearRegression(object):
- '''
- Create the Linear Regression benchmark instance.
+ '''
+ Create the Linear Regression benchmark instance.
@param dataset - Input dataset to perform Linear Regression on.
@param path - Path to the matlab binary.
@param verbose - Display informational messages.
- '''
- def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
- self.verbose = verbose
- self.dataset = dataset
- self.path = path
-
- '''
+ '''
+ def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
+ self.verbose = verbose
+ self.dataset = dataset
+ self.path = path
+
+ '''
Linear Regression benchmark instance. 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 Linear Regression.", self.verbose)
+ def RunMethod(self, options):
+ Log.Info("Perform Linear Regression.", self.verbose)
+
+ # If the dataset contains two files then the second file is the responses
+ # file. In this case we add this to the command line.
+ if len(self.dataset) == 2:
+ inputCmd = "-i " + self.dataset[0] + " -r " + self.dataset[1] + " " + options
+ else:
+ inputCmd = "-i " + self.dataset + " " + options
+
+ # Split the command using shell-like syntax.
+ cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, " +
+ "LINEAR_REGRESSION('" + inputCmd + "'), catch, exit(1), end, exit(0)\"")
+
+ # Run command with the nessecary arguments and return its output as a byte
+ # string. We have untrusted input so we disables all shell based features.
+ try:
+ s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
+ except Exception:
+ Log.Fatal("Could not execute command: " + str(cmd))
+ return -1
+
+ # Return the elapsed time.
+ timer = self.parseTimer(s)
+ if not timer:
+ Log.Fatal("Can't parse the timer")
+ return -1
+ else:
+ time = self.GetTime(timer)
+ Log.Info(("total time: %fs" % time), self.verbose)
+
+ return time
+
+ '''
+ Parse the timer data form a given string.
- # If the dataset contains two files then the second file is the responses
- # file. In this case we add this to the command line.
- if len(self.dataset) == 2:
- inputCmd = "-i " + self.dataset[0] + " -r " + self.dataset[1] + " " + options
- else:
- inputCmd = "-i " + self.dataset + " " + options
-
- # Split the command using shell-like syntax.
- cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, " +
- "LINEAR_REGRESSION('" + inputCmd + "'), catch, exit(1), end, exit(0)\"")
-
- # Run command with the nessecary arguments and return its output as a byte
- # string. We have untrusted input so we disables all shell based features.
- try:
- s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
- except Exception:
- Log.Fatal("Could not execute command: " + str(cmd))
- return -1
-
- # Return the elapsed time.
- timer = self.parseTimer(s)
- if not timer:
- Log.Fatal("Can't parse the timer")
- return -1
- else:
- time = self.GetTime(timer)
- Log.Info(("total time: %fs" % time), self.verbose)
-
- return time
-
- '''
- Parse the timer data form a given string.
-
- @param data - String to parse timer data from.
- @return - Namedtuple that contains the timer data.
- '''
- def parseTimer(self, data):
- # Compile the regular expression pattern into a regular expression object to
- # parse the timer data.
- pattern = re.compile(r"""
- .*?total_time: (?P<total_time>.*?)s.*?
- """, re.VERBOSE|re.MULTILINE|re.DOTALL)
-
- match = pattern.match(data)
- if not match:
- Log.Fatal("Can't parse the data: wrong format")
- return -1
- else:
- # Create a namedtuple and return the timer data.
- timer = collections.namedtuple("timer", ["total_time"])
-
- return timer(float(match.group("total_time")))
-
- '''
- Return the elapsed time in seconds.
-
- @param timer - Namedtuple that contains the timer data.
- @return Elapsed time in seconds.
- '''
- def GetTime(self, timer):
- return timer.total_time
+ @param data - String to parse timer data from.
+ @return - Namedtuple that contains the timer data.
+ '''
+ def parseTimer(self, data):
+ # Compile the regular expression pattern into a regular expression object to
+ # parse the timer data.
+ pattern = re.compile(br"""
+ .*?total_time: (?P<total_time>.*?)s.*?
+ """, re.VERBOSE|re.MULTILINE|re.DOTALL)
+
+ match = pattern.match(data)
+ if not match:
+ Log.Fatal("Can't parse the data: wrong format")
+ return -1
+ else:
+ # Create a namedtuple and return the timer data.
+ timer = collections.namedtuple("timer", ["total_time"])
+
+ return timer(float(match.group("total_time")))
+
+ '''
+ Return the elapsed time in seconds.
+
+ @param timer - Namedtuple that contains the timer data.
+ @return Elapsed time in seconds.
+ '''
+ def GetTime(self, timer):
+ return timer.total_time
Modified: mlpack/conf/jenkins-conf/benchmark/methods/matlab/nbc.py
==============================================================================
--- mlpack/conf/jenkins-conf/benchmark/methods/matlab/nbc.py (original)
+++ mlpack/conf/jenkins-conf/benchmark/methods/matlab/nbc.py Thu Jul 25 16:27:01 2013
@@ -12,9 +12,9 @@
# Import the util path, this method even works if the path contains symlinks to
# modules.
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(
- os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
+ os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
if cmd_subfolder not in sys.path:
- sys.path.insert(0, cmd_subfolder)
+ sys.path.insert(0, cmd_subfolder)
from log import *
from profiler import *
@@ -29,80 +29,80 @@
'''
class NBC(object):
- '''
- Create the Naive Bayes Classifier benchmark instance.
+ '''
+ Create the Naive Bayes Classifier benchmark instance.
@param dataset - Input dataset to perform NBC on.
@param path - Path to the matlab binary.
@param verbose - Display informational messages.
- '''
- def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
- self.verbose = verbose
- self.dataset = dataset
- self.path = path
-
- '''
+ '''
+ def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
+ self.verbose = verbose
+ self.dataset = dataset
+ self.path = path
+
+ '''
Naive Bayes Classifier. 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 NBC.", self.verbose)
+ def RunMethod(self, options):
+ Log.Info("Perform NBC.", self.verbose)
+
+ inputCmd = "-t " + self.dataset[0] + " -T " + self.dataset[1] + " " + options
+ # Split the command using shell-like syntax.
+ cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, NBC('"
+ + inputCmd + "'), catch, exit(1), end, exit(0)\"")
+
+ # Run command with the nessecary arguments and return its output as a byte
+ # string. We have untrusted input so we disables all shell based features.
+ try:
+ s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
+ except Exception:
+ Log.Fatal("Could not execute command: " + str(cmd))
+ return -1
+
+ # Return the elapsed time.
+ timer = self.parseTimer(s)
+ if not timer:
+ Log.Fatal("Can't parse the timer")
+ return -1
+ else:
+ time = self.GetTime(timer)
+ Log.Info(("total time: %fs" % time), self.verbose)
+
+ return time
+
+ '''
+ Parse the timer data form a given string.
- inputCmd = "-t " + self.dataset[0] + " -T " + self.dataset[1] + " " + options
- # Split the command using shell-like syntax.
- cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, NBC('"
- + inputCmd + "'), catch, exit(1), end, exit(0)\"")
-
- # Run command with the nessecary arguments and return its output as a byte
- # string. We have untrusted input so we disables all shell based features.
- try:
- s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
- except Exception:
- Log.Fatal("Could not execute command: " + str(cmd))
- return -1
-
- # Return the elapsed time.
- timer = self.parseTimer(s)
- if not timer:
- Log.Fatal("Can't parse the timer")
- return -1
- else:
- time = self.GetTime(timer)
- Log.Info(("total time: %fs" % time), self.verbose)
-
- return time
-
- '''
- Parse the timer data form a given string.
-
- @param data - String to parse timer data from.
- @return - Namedtuple that contains the timer data.
- '''
- def parseTimer(self, data):
- # Compile the regular expression pattern into a regular expression object to
- # parse the timer data.
- pattern = re.compile(r"""
- .*?total_time: (?P<total_time>.*?)s.*?
- """, re.VERBOSE|re.MULTILINE|re.DOTALL)
-
- match = pattern.match(data)
- if not match:
- Log.Fatal("Can't parse the data: wrong format")
- return -1
- else:
- # Create a namedtuple and return the timer data.
- timer = collections.namedtuple("timer", ["total_time"])
-
- return timer(float(match.group("total_time")))
-
- '''
- Return the elapsed time in seconds.
-
- @param timer - Namedtuple that contains the timer data.
- @return Elapsed time in seconds.
- '''
- def GetTime(self, timer):
- return timer.total_time
+ @param data - String to parse timer data from.
+ @return - Namedtuple that contains the timer data.
+ '''
+ def parseTimer(self, data):
+ # Compile the regular expression pattern into a regular expression object to
+ # parse the timer data.
+ pattern = re.compile(br"""
+ .*?total_time: (?P<total_time>.*?)s.*?
+ """, re.VERBOSE|re.MULTILINE|re.DOTALL)
+
+ match = pattern.match(data)
+ if not match:
+ Log.Fatal("Can't parse the data: wrong format")
+ return -1
+ else:
+ # Create a namedtuple and return the timer data.
+ timer = collections.namedtuple("timer", ["total_time"])
+
+ return timer(float(match.group("total_time")))
+
+ '''
+ Return the elapsed time in seconds.
+
+ @param timer - Namedtuple that contains the timer data.
+ @return Elapsed time in seconds.
+ '''
+ def GetTime(self, timer):
+ return timer.total_time
Modified: mlpack/conf/jenkins-conf/benchmark/methods/matlab/nmf.py
==============================================================================
--- mlpack/conf/jenkins-conf/benchmark/methods/matlab/nmf.py (original)
+++ mlpack/conf/jenkins-conf/benchmark/methods/matlab/nmf.py Thu Jul 25 16:27:01 2013
@@ -12,9 +12,9 @@
# Import the util path, this method even works if the path contains symlinks to
# modules.
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(
- os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
+ os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
if cmd_subfolder not in sys.path:
- sys.path.insert(0, cmd_subfolder)
+ sys.path.insert(0, cmd_subfolder)
from log import *
from profiler import *
@@ -29,80 +29,80 @@
'''
class NMF(object):
- '''
- Create the Non-negative Matrix Factorization benchmark instance.
+ '''
+ Create the Non-negative Matrix Factorization benchmark instance.
@param dataset - Input dataset to perform NMF on.
@param path - Path to the matlab binary.
@param verbose - Display informational messages.
- '''
- def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
- self.verbose = verbose
- self.dataset = dataset
- self.path = path
-
- '''
+ '''
+ def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
+ self.verbose = verbose
+ self.dataset = dataset
+ self.path = path
+
+ '''
Non-negative Matrix Factorization. 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 NMF.", self.verbose)
+ def RunMethod(self, options):
+ Log.Info("Perform NMF.", self.verbose)
+
+ inputCmd = "-i " + self.dataset + " " + options
+ # Split the command using shell-like syntax.
+ cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, NMF('"
+ + inputCmd + "'), catch, exit(1), end, exit(0)\"")
+
+ # Run command with the nessecary arguments and return its output as a byte
+ # string. We have untrusted input so we disables all shell based features.
+ try:
+ s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
+ except Exception:
+ Log.Fatal("Could not execute command: " + str(cmd))
+ return -1
+
+ # Return the elapsed time.
+ timer = self.parseTimer(s)
+ if not timer:
+ Log.Fatal("Can't parse the timer")
+ return -1
+ else:
+ time = self.GetTime(timer)
+ Log.Info(("total time: %fs" % time), self.verbose)
+
+ return time
+
+ '''
+ Parse the timer data form a given string.
- inputCmd = "-i " + self.dataset + " " + options
- # Split the command using shell-like syntax.
- cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, NMF('"
- + inputCmd + "'), catch, exit(1), end, exit(0)\"")
-
- # Run command with the nessecary arguments and return its output as a byte
- # string. We have untrusted input so we disables all shell based features.
- try:
- s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
- except Exception:
- Log.Fatal("Could not execute command: " + str(cmd))
- return -1
-
- # Return the elapsed time.
- timer = self.parseTimer(s)
- if not timer:
- Log.Fatal("Can't parse the timer")
- return -1
- else:
- time = self.GetTime(timer)
- Log.Info(("total time: %fs" % time), self.verbose)
-
- return time
-
- '''
- Parse the timer data form a given string.
-
- @param data - String to parse timer data from.
- @return - Namedtuple that contains the timer data.
- '''
- def parseTimer(self, data):
- # Compile the regular expression pattern into a regular expression object to
- # parse the timer data.
- pattern = re.compile(r"""
- .*?total_time: (?P<total_time>.*?)s.*?
- """, re.VERBOSE|re.MULTILINE|re.DOTALL)
-
- match = pattern.match(data)
- if not match:
- Log.Fatal("Can't parse the data: wrong format")
- return -1
- else:
- # Create a namedtuple and return the timer data.
- timer = collections.namedtuple("timer", ["total_time"])
-
- return timer(float(match.group("total_time")))
-
- '''
- Return the elapsed time in seconds.
-
- @param timer - Namedtuple that contains the timer data.
- @return Elapsed time in seconds.
- '''
- def GetTime(self, timer):
- return timer.total_time
+ @param data - String to parse timer data from.
+ @return - Namedtuple that contains the timer data.
+ '''
+ def parseTimer(self, data):
+ # Compile the regular expression pattern into a regular expression object to
+ # parse the timer data.
+ pattern = re.compile(br"""
+ .*?total_time: (?P<total_time>.*?)s.*?
+ """, re.VERBOSE|re.MULTILINE|re.DOTALL)
+
+ match = pattern.match(data)
+ if not match:
+ Log.Fatal("Can't parse the data: wrong format")
+ return -1
+ else:
+ # Create a namedtuple and return the timer data.
+ timer = collections.namedtuple("timer", ["total_time"])
+
+ return timer(float(match.group("total_time")))
+
+ '''
+ Return the elapsed time in seconds.
+
+ @param timer - Namedtuple that contains the timer data.
+ @return Elapsed time in seconds.
+ '''
+ def GetTime(self, timer):
+ return timer.total_time
Modified: mlpack/conf/jenkins-conf/benchmark/methods/matlab/pca.py
==============================================================================
--- mlpack/conf/jenkins-conf/benchmark/methods/matlab/pca.py (original)
+++ mlpack/conf/jenkins-conf/benchmark/methods/matlab/pca.py Thu Jul 25 16:27:01 2013
@@ -12,9 +12,9 @@
# Import the util path, this method even works if the path contains symlinks to
# modules.
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(
- os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
+ os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
if cmd_subfolder not in sys.path:
- sys.path.insert(0, cmd_subfolder)
+ sys.path.insert(0, cmd_subfolder)
from log import *
from profiler import *
@@ -29,80 +29,80 @@
'''
class PCA(object):
- '''
- Create the Principal Components Analysis benchmark instance.
+ '''
+ Create the Principal Components Analysis benchmark instance.
@param dataset - Input dataset to perform PCA on.
@param path - Path to the matlab binary.
@param verbose - Display informational messages.
- '''
- def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
- self.verbose = verbose
- self.dataset = dataset
- self.path = path
-
- '''
+ '''
+ def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
+ self.verbose = verbose
+ self.dataset = dataset
+ self.path = path
+
+ '''
Perform Principal Components Analysis. 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 PCA.", self.verbose)
+ def RunMethod(self, options):
+ Log.Info("Perform PCA.", self.verbose)
+
+ inputCmd = "-i " + self.dataset + " " + options
+ # Split the command using shell-like syntax.
+ cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, PCA('"
+ + inputCmd + "'), catch, exit(1), end, exit(0)\"")
+
+ # Run command with the nessecary arguments and return its output as a byte
+ # string. We have untrusted input so we disables all shell based features.
+ try:
+ s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
+ except Exception:
+ Log.Fatal("Could not execute command: " + str(cmd))
+ return -1
+
+ # Return the elapsed time.
+ timer = self.parseTimer(s)
+ if not timer:
+ Log.Fatal("Can't parse the timer")
+ return -1
+ else:
+ time = self.GetTime(timer)
+ Log.Info(("total time: %fs" % time), self.verbose)
+
+ return time
+
+ '''
+ Parse the timer data form a given string.
- inputCmd = "-i " + self.dataset + " " + options
- # Split the command using shell-like syntax.
- cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, PCA('"
- + inputCmd + "'), catch, exit(1), end, exit(0)\"")
-
- # Run command with the nessecary arguments and return its output as a byte
- # string. We have untrusted input so we disables all shell based features.
- try:
- s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
- except Exception:
- Log.Fatal("Could not execute command: " + str(cmd))
- return -1
-
- # Return the elapsed time.
- timer = self.parseTimer(s)
- if not timer:
- Log.Fatal("Can't parse the timer")
- return -1
- else:
- time = self.GetTime(timer)
- Log.Info(("total time: %fs" % time), self.verbose)
-
- return time
-
- '''
- Parse the timer data form a given string.
-
- @param data - String to parse timer data from.
- @return - Namedtuple that contains the timer data.
- '''
- def parseTimer(self, data):
- # Compile the regular expression pattern into a regular expression object to
- # parse the timer data.
- pattern = re.compile(r"""
- .*?total_time: (?P<total_time>.*?)s.*?
- """, re.VERBOSE|re.MULTILINE|re.DOTALL)
-
- match = pattern.match(data)
- if not match:
- Log.Fatal("Can't parse the data: wrong format")
- return -1
- else:
- # Create a namedtuple and return the timer data.
- timer = collections.namedtuple("timer", ["total_time"])
-
- return timer(float(match.group("total_time")))
-
- '''
- Return the elapsed time in seconds.
-
- @param timer - Namedtuple that contains the timer data.
- @return Elapsed time in seconds.
- '''
- def GetTime(self, timer):
- return timer.total_time
+ @param data - String to parse timer data from.
+ @return - Namedtuple that contains the timer data.
+ '''
+ def parseTimer(self, data):
+ # Compile the regular expression pattern into a regular expression object to
+ # parse the timer data.
+ pattern = re.compile(br"""
+ .*?total_time: (?P<total_time>.*?)s.*?
+ """, re.VERBOSE|re.MULTILINE|re.DOTALL)
+
+ match = pattern.match(data)
+ if not match:
+ Log.Fatal("Can't parse the data: wrong format")
+ return -1
+ else:
+ # Create a namedtuple and return the timer data.
+ timer = collections.namedtuple("timer", ["total_time"])
+
+ return timer(float(match.group("total_time")))
+
+ '''
+ Return the elapsed time in seconds.
+
+ @param timer - Namedtuple that contains the timer data.
+ @return Elapsed time in seconds.
+ '''
+ def GetTime(self, timer):
+ return timer.total_time
Modified: mlpack/conf/jenkins-conf/benchmark/methods/matlab/range_search.py
==============================================================================
--- mlpack/conf/jenkins-conf/benchmark/methods/matlab/range_search.py (original)
+++ mlpack/conf/jenkins-conf/benchmark/methods/matlab/range_search.py Thu Jul 25 16:27:01 2013
@@ -12,9 +12,9 @@
# Import the util path, this method even works if the path contains symlinks to
# modules.
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(
- os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
+ os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../util")))
if cmd_subfolder not in sys.path:
- sys.path.insert(0, cmd_subfolder)
+ sys.path.insert(0, cmd_subfolder)
from log import *
from profiler import *
@@ -29,86 +29,86 @@
'''
class RANGESEARCH(object):
- '''
- Create the Range Search benchmark instance.
+ '''
+ Create the Range Search benchmark instance.
@param dataset - Input dataset to perform Range Search on.
@param path - Path to the matlab binary.
@param verbose - Display informational messages.
- '''
- def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
- self.verbose = verbose
- self.dataset = dataset
- self.path = path
-
- '''
+ '''
+ def __init__(self, dataset, path=os.environ["MATLAB_BIN"], verbose=True):
+ self.verbose = verbose
+ self.dataset = dataset
+ self.path = path
+
+ '''
Perform Range Search. 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 Range Search.", self.verbose)
+ def RunMethod(self, options):
+ Log.Info("Perform Range Search.", self.verbose)
+
+ # If the dataset contains two files then the second file is the query file.
+ # In this case we add this to the command line.
+ if len(self.dataset) == 2:
+ inputCmd = "-r " + self.dataset[0] + " -q " + self.dataset[1] + " " + options
+ else:
+ inputCmd = "-r " + self.dataset + " " + options
+
+ # Split the command using shell-like syntax.
+ cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, " +
+ "RANGESEARCH('" + inputCmd + "'), catch, exit(1), end, exit(0)\"")
+
+ # Run command with the nessecary arguments and return its output as a byte
+ # string. We have untrusted input so we disables all shell based features.
+ try:
+ s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
+ except Exception:
+ Log.Fatal("Could not execute command: " + str(cmd))
+ return -1
+
+ # Return the elapsed time.
+ timer = self.parseTimer(s)
+ if not timer:
+ Log.Fatal("Can't parse the timer")
+ return -1
+ else:
+ time = self.GetTime(timer)
+ Log.Info(("total time: %fs" % time), self.verbose)
+
+ return time
+
+ '''
+ Parse the timer data form a given string.
- # If the dataset contains two files then the second file is the query file.
- # In this case we add this to the command line.
- if len(self.dataset) == 2:
- inputCmd = "-r " + self.dataset[0] + " -q " + self.dataset[1] + " " + options
- else:
- inputCmd = "-r " + self.dataset + " " + options
-
- # Split the command using shell-like syntax.
- cmd = shlex.split(self.path + "matlab -nodisplay -nosplash -r \"try, " +
- "RANGESEARCH('" + inputCmd + "'), catch, exit(1), end, exit(0)\"")
-
- # Run command with the nessecary arguments and return its output as a byte
- # string. We have untrusted input so we disables all shell based features.
- try:
- s = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False)
- except Exception:
- Log.Fatal("Could not execute command: " + str(cmd))
- return -1
-
- # Return the elapsed time.
- timer = self.parseTimer(s)
- if not timer:
- Log.Fatal("Can't parse the timer")
- return -1
- else:
- time = self.GetTime(timer)
- Log.Info(("total time: %fs" % time), self.verbose)
-
- return time
-
- '''
- Parse the timer data form a given string.
-
- @param data - String to parse timer data from.
- @return - Namedtuple that contains the timer data.
- '''
- def parseTimer(self, data):
- # Compile the regular expression pattern into a regular expression object to
- # parse the timer data.
- pattern = re.compile(r"""
- .*?total_time: (?P<total_time>.*?)s.*?
- """, re.VERBOSE|re.MULTILINE|re.DOTALL)
-
- match = pattern.match(data)
- if not match:
- Log.Fatal("Can't parse the data: wrong format")
- return -1
- else:
- # Create a namedtuple and return the timer data.
- timer = collections.namedtuple("timer", ["total_time"])
-
- return timer(float(match.group("total_time")))
-
- '''
- Return the elapsed time in seconds.
-
- @param timer - Namedtuple that contains the timer data.
- @return Elapsed time in seconds.
- '''
- def GetTime(self, timer):
- return timer.total_time
+ @param data - String to parse timer data from.
+ @return - Namedtuple that contains the timer data.
+ '''
+ def parseTimer(self, data):
+ # Compile the regular expression pattern into a regular expression object to
+ # parse the timer data.
+ pattern = re.compile(br"""
+ .*?total_time: (?P<total_time>.*?)s.*?
+ """, re.VERBOSE|re.MULTILINE|re.DOTALL)
+
+ match = pattern.match(data)
+ if not match:
+ Log.Fatal("Can't parse the data: wrong format")
+ return -1
+ else:
+ # Create a namedtuple and return the timer data.
+ timer = collections.namedtuple("timer", ["total_time"])
+
+ return timer(float(match.group("total_time")))
+
+ '''
+ Return the elapsed time in seconds.
+
+ @param timer - Namedtuple that contains the timer data.
+ @return Elapsed time in seconds.
+ '''
+ def GetTime(self, timer):
+ return timer.total_time
More information about the mlpack-svn
mailing list