From e37ed32d9b861581942ec5cfb8948f0602c0a481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=2E=20Brandenburg?= Date: Wed, 24 Nov 2010 14:59:25 -0500 Subject: add --hist option to vplot.py to plot histograms --- vplot.py | 106 +++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 26 deletions(-) (limited to 'vplot.py') diff --git a/vplot.py b/vplot.py index 71344c6..81ec2e8 100755 --- a/vplot.py +++ b/vplot.py @@ -6,7 +6,7 @@ from util import load_csv_file, write_csv_file from math import ceil -from numpy import amin, amax, mean, median, std, histogram +from numpy import amin, amax, mean, median, std, histogram, zeros from os.path import splitext, basename from optparse import make_option as o @@ -23,6 +23,7 @@ options = [ # formatting options # These may or may not be supported by a particular experiment plotter. o(None, '--smooth', action='store_true', dest='smooth'), + o(None, '--hist', action='store_true', dest='histogram'), ] defaults = { @@ -32,9 +33,20 @@ defaults = { 'prefix' : '', # formatting options - 'alternate' : False, + 'histogram' : False, + 'smooth' : False, + + 'binsize' : 0.1, } +def get_stats_label(samples): + avg = mean(samples) + med = median(samples) + dev = std(samples) + max = amax(samples) + min = amin(samples) + return "min=%.2fms max=%.2fms avg=%.2fms median=%.2fms std=%.2fms" \ + % (min, max, avg, med, dev) class VideoPlotter(defapp.App): def __init__(self): @@ -59,18 +71,44 @@ class VideoPlotter(defapp.App): else: return False - def load(self, datafile, name): - data = load_csv_file(datafile) - # make a copy without comments, etc. + def write(self, data, name, ext='data'): if self.options.save_script: - fname = "%s.data" % name + fname = "%s.%s" % (name, ext) write_csv_file(fname, data) - return (data, fname) + return fname else: tmp = write_csv_file(None, data) # keep a reference so that it isn't deleted self.tmpfiles.append(tmp) - return (data, tmp.name) + return tmp.name + + def load(self, datafile, name): + data = load_csv_file(datafile) + # make a copy without comments, etc. + return (data, self.write(data, name)) + + def write_histogram(self, samples, name, labels=10): + max = ceil(amax(samples)) + bin_size = self.options.binsize + num_bins = int(max / bin_size) + (bins, edges) = histogram(samples, bins=num_bins, + range=(self.options.binsize / 2, + max + self.options.binsize / 2)) + data = zeros((num_bins, 3)) + cumulative = 0 + for i in xrange(len(bins)): + data[i, 0] = (edges[i] + edges[i + 1]) / 2.0 + data[i, 1] = bins[i] + cumulative += bins[i] + data[i, 2] = cumulative + + label_rate = len(bins) / labels + for_file = [] + for i, row in enumerate(data): + label = '%.2f' % row[0] if i % label_rate == 0 else '' + for_file.append([row[0], row[1], row[2], label]) + + return (data, self.write(for_file, name, ext='hist')) def render(self, p): if self.options.save_script: @@ -81,31 +119,47 @@ class VideoPlotter(defapp.App): def plot_vdecode(self, datafile, name, conf): (data, fname) = self.load(datafile, name) - decode_times = data[:,0] + max_cost = amax(data[:,0]) - avg = mean(decode_times) - med = median(decode_times) - dev = std(decode_times) - max = amax(decode_times) - min = amin(decode_times) - - stats_label = "min=%.2fms max=%.2fms avg=%.2fms median=%.2fms std=%.2fms" \ - % (min, max, avg, med, dev) + if self.options.histogram: + name += '_hist' p = self.make_plot(name) - p.title = "raw decoding cost; input=%s; host=%s" \ - % (conf['file'], conf['host']) + p.labels = [label(0.5, 0.9, get_stats_label(data[:,0]), + coord=['graph', 'screen'], align='center')] + + if self.options.histogram: + (data, fname) = self.write_histogram(data[:,0], name) + + p.setup_histogram(gap=1, boxwidth=1.0) + + p.title = "decoding costs; input=%s; host=%s" \ + % (conf['file'], conf['host']) - p.ylabel = "decoding cost (ms)" - p.xlabel = "frame number" - p.xrange = (0, len(data)) + p.ylabel = "number of frames" + p.xlabel = "decoding cost in milliseconds (bin size = %.2fms)" \ + % self.options.binsize +# p.xrange = (0, ceil(max_cost)) + p.xticks = (0, 10) +# p.yticks = (0, 1) + p.yrange = (0, (ceil(amax(data[:,1]) / 100) * 100)) + p.curves = [curve(histogram=fname, col=2, labels_col=4)] + + else: + # plot raw samples + p.title = "raw decoding cost; input=%s; host=%s" \ + % (conf['file'], conf['host']) + + p.ylabel = "decoding cost (ms)" + p.xlabel = "frame number" + p.xrange = (0, len(data)) #p.xticks = (0, 100) - p.yticks = (0, 1) - p.yrange = (0, ceil(max)) + p.yticks = (0, 1) + p.yrange = (0, ceil(max_cost)) + + p.curves = [curve(fname=fname, xcol=2, ycol=1, title="decoding cost")] - p.curves = [curve(fname=fname, xcol=2, ycol=1, title="decoding cost")] - p.labels = [label(0.5, 0.9, stats_label, coord=['graph', 'screen'], align='center')] #### Styling. -- cgit v1.2.2