[mlpack-svn] r15577 - in mlpack/conf/jenkins-conf/benchmark: benchmark util
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Aug 1 16:19:54 EDT 2013
Author: marcus
Date: Thu Aug 1 16:19:53 2013
New Revision: 15577
Log:
Add functions to plot a bar chart.
Added:
mlpack/conf/jenkins-conf/benchmark/util/graph.py
mlpack/conf/jenkins-conf/benchmark/util/misc.py
Modified:
mlpack/conf/jenkins-conf/benchmark/benchmark/run_benchmark.py
Modified: mlpack/conf/jenkins-conf/benchmark/benchmark/run_benchmark.py
==============================================================================
--- mlpack/conf/jenkins-conf/benchmark/benchmark/run_benchmark.py (original)
+++ mlpack/conf/jenkins-conf/benchmark/benchmark/run_benchmark.py Thu Aug 1 16:19:53 2013
@@ -19,6 +19,7 @@
from loader import *
from parser import *
from convert import *
+from misc import *
import argparse
import datetime
@@ -113,19 +114,7 @@
for f in dataset:
if os.path.isfile(f):
- os.remove(f)
-
-'''
-Add all rows from a given matrix to a given table.
-
- at param matrix - 2D array contains the row.
- at param table - Table in which the rows are inserted.
- at return Table with the inserted rows.
-'''
-def AddMatrixToTable(matrix, table):
- for row in matrix:
- table.append(row)
- return table
+ os.remove(f)
'''
Count all datasets to determine the dataset size.
@@ -144,19 +133,6 @@
return len(datasetList)
'''
-Search the correct row to insert the new data. We look at the left column for
-a free place or for the matching name.
-
- at param dataMatrix - In this Matrix we search for the right position.
- at param datasetName - Name of the dataset.
- at param datasetCount - Maximum dataset count.
-'''
-def FindRightRow(dataMatrix, datasetName, datasetCount):
- for row in range(datasetCount):
- if (dataMatrix[row][0] == datasetName) or (dataMatrix[row][0] == "-"):
- return row
-
-'''
Start the main benchmark routine. The method shows some DEBUG information and
prints a table with the runtime information.
Added: mlpack/conf/jenkins-conf/benchmark/util/graph.py
==============================================================================
--- (empty file)
+++ mlpack/conf/jenkins-conf/benchmark/util/graph.py Thu Aug 1 16:19:53 2013
@@ -0,0 +1,80 @@
+'''
+ @file graph.py
+ @author Marcus Edel
+
+ FUnctions to plot graphs.
+'''
+
+import os, sys, inspect
+
+# 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')))
+if cmd_subfolder not in sys.path:
+ sys.path.insert(0, cmd_subfolder)
+
+from misc import *
+
+import numpy as np
+import matplotlib
+import matplotlib.pyplot as plt
+
+'''
+Generate a bar chart with the specified informations.
+
+ at param header - Contains the names for the x-axis.
+ at param data - Contains the values for the chart.
+ at param name - Contains the name for the chart.
+'''
+def GenerateBarChart(header, data, name):
+ # Bar chart settings.
+ colors = ['#3366CC', '#DC3912', '#FF9900', '#FFFF32', '#109618', '#990099', '#DD4477']
+ barWidth = 0.25
+ opacity = 0.8
+ fill = True
+ windowWidth = 12
+ windowHeight = 8
+ backgroundColor = '#F5F5F5'
+
+ # Create figure and set the color.
+ matplotlib.rc('axes', facecolor=backgroundColor)
+ fig = plt.figure(figsize=(windowWidth, windowHeight), facecolor=backgroundColor)
+ ax = plt.subplot(1,1,1)
+
+ # Bar and legend position.
+ barIndex = np.arange(len(header)) * 2
+ legendIndex = barIndex
+
+ for i, values in enumerate(data):
+ dataset = values[0] # Dataset name.
+
+ # Convert values to float.
+ values = values[1:]
+ values = [float(x) if isFloat(x) else 0 for x in values]
+
+ # Get the bar chart position for the dataset.
+ barIndex = [barIndex[j] + barWidth if x != 0 and i != 0 else barIndex[j] for j, x in enumerate(values)]
+
+ # Plot the bar chart with the defined setting.
+ foo = plt.bar(barIndex, values, barWidth, alpha=opacity, color=colors[i%len(colors)], label=dataset, fill=fill, lw=0.2)
+
+ # Get the position for the x-axis legend.
+ legendIndex = [legendIndex[j]+(0.5*barWidth) if x != 0 else legendIndex[j] for j, x in enumerate(values)]
+
+ # Set the labels for the y-axis.
+ plt.ylabel('Seconds (lower is better)')
+
+ # Set the titel for the bar chart.
+ plt.title(name)
+
+ # Set the labels for the x-axis.
+ plt.xticks(legendIndex , header)
+
+ # Create the legend under the bar chart.
+ lgd = ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), fancybox=True, shadow=True, ncol=8)
+
+ # Save the bar chart.
+ fig.savefig(name, bbox_extra_artists=(lgd,), bbox_inches='tight', facecolor=fig.get_facecolor(), edgecolor='none')
+
+ plt.show()
Added: mlpack/conf/jenkins-conf/benchmark/util/misc.py
==============================================================================
--- (empty file)
+++ mlpack/conf/jenkins-conf/benchmark/util/misc.py Thu Aug 1 16:19:53 2013
@@ -0,0 +1,60 @@
+'''
+ @file misc.py
+ @author Marcus Edel
+
+ Supporting functions.
+'''
+
+'''
+This function determinate if the given number is a float.
+
+ at param n - Number to test.
+ at return If the number a float returns True otherwise the function returns False.
+'''
+def isFloat(n):
+ try:
+ float(n)
+ except ValueError, TypeError:
+ return False
+ else:
+ return True
+
+'''
+Count all datasets to determine the dataset size.
+
+ at param libraries - Contains the Dataset List.
+ at return Dataset count.
+'''
+def CountLibrariesDatasets(libraries):
+ datasetList = []
+ for libary, data in libraries.items():
+ for dataset in data:
+ if not dataset[0] in datasetList:
+ datasetList.append(dataset[0])
+
+ return len(datasetList)
+
+'''
+Add all rows from a given matrix to a given table.
+
+ at param matrix - 2D array contains the row.
+ at param table - Table in which the rows are inserted.
+ at return Table with the inserted rows.
+'''
+def AddMatrixToTable(matrix, table):
+ for row in matrix:
+ table.append(row)
+ return table
+
+'''
+Search the correct row to insert the new data. We look at the left column for
+a free place or for the matching name.
+
+ at param dataMatrix - In this Matrix we search for the right position.
+ at param datasetName - Name of the dataset.
+ at param datasetCount - Maximum dataset count.
+'''
+def FindRightRow(dataMatrix, datasetName, datasetCount):
+ for row in range(datasetCount):
+ if (dataMatrix[row][0] == datasetName) or (dataMatrix[row][0] == "-"):
+ return row
More information about the mlpack-svn
mailing list