diff options
| author | Björn B. Brandenburg <bbb@cs.unc.edu> | 2010-11-24 14:59:25 -0500 |
|---|---|---|
| committer | Björn B. Brandenburg <bbb@cs.unc.edu> | 2010-11-24 14:59:25 -0500 |
| commit | e37ed32d9b861581942ec5cfb8948f0602c0a481 (patch) | |
| tree | f5a3d92e64af05b4cc416fe77617d18587112143 /vplot.py | |
| parent | 0bd8dea3a724fcb2d4ffa3435f00fe45529e7868 (diff) | |
add --hist option to vplot.py to plot histogramswip-video
Diffstat (limited to 'vplot.py')
| -rwxr-xr-x | vplot.py | 106 |
1 files changed, 80 insertions, 26 deletions
| @@ -6,7 +6,7 @@ from util import load_csv_file, write_csv_file | |||
| 6 | 6 | ||
| 7 | from math import ceil | 7 | from math import ceil |
| 8 | 8 | ||
| 9 | from numpy import amin, amax, mean, median, std, histogram | 9 | from numpy import amin, amax, mean, median, std, histogram, zeros |
| 10 | 10 | ||
| 11 | from os.path import splitext, basename | 11 | from os.path import splitext, basename |
| 12 | from optparse import make_option as o | 12 | from optparse import make_option as o |
| @@ -23,6 +23,7 @@ options = [ | |||
| 23 | # formatting options | 23 | # formatting options |
| 24 | # These may or may not be supported by a particular experiment plotter. | 24 | # These may or may not be supported by a particular experiment plotter. |
| 25 | o(None, '--smooth', action='store_true', dest='smooth'), | 25 | o(None, '--smooth', action='store_true', dest='smooth'), |
| 26 | o(None, '--hist', action='store_true', dest='histogram'), | ||
| 26 | ] | 27 | ] |
| 27 | 28 | ||
| 28 | defaults = { | 29 | defaults = { |
| @@ -32,9 +33,20 @@ defaults = { | |||
| 32 | 'prefix' : '', | 33 | 'prefix' : '', |
| 33 | 34 | ||
| 34 | # formatting options | 35 | # formatting options |
| 35 | 'alternate' : False, | 36 | 'histogram' : False, |
| 37 | 'smooth' : False, | ||
| 38 | |||
| 39 | 'binsize' : 0.1, | ||
| 36 | } | 40 | } |
| 37 | 41 | ||
| 42 | def get_stats_label(samples): | ||
| 43 | avg = mean(samples) | ||
| 44 | med = median(samples) | ||
| 45 | dev = std(samples) | ||
| 46 | max = amax(samples) | ||
| 47 | min = amin(samples) | ||
| 48 | return "min=%.2fms max=%.2fms avg=%.2fms median=%.2fms std=%.2fms" \ | ||
| 49 | % (min, max, avg, med, dev) | ||
| 38 | 50 | ||
| 39 | class VideoPlotter(defapp.App): | 51 | class VideoPlotter(defapp.App): |
| 40 | def __init__(self): | 52 | def __init__(self): |
| @@ -59,18 +71,44 @@ class VideoPlotter(defapp.App): | |||
| 59 | else: | 71 | else: |
| 60 | return False | 72 | return False |
| 61 | 73 | ||
| 62 | def load(self, datafile, name): | 74 | def write(self, data, name, ext='data'): |
| 63 | data = load_csv_file(datafile) | ||
| 64 | # make a copy without comments, etc. | ||
| 65 | if self.options.save_script: | 75 | if self.options.save_script: |
| 66 | fname = "%s.data" % name | 76 | fname = "%s.%s" % (name, ext) |
| 67 | write_csv_file(fname, data) | 77 | write_csv_file(fname, data) |
| 68 | return (data, fname) | 78 | return fname |
| 69 | else: | 79 | else: |
| 70 | tmp = write_csv_file(None, data) | 80 | tmp = write_csv_file(None, data) |
| 71 | # keep a reference so that it isn't deleted | 81 | # keep a reference so that it isn't deleted |
| 72 | self.tmpfiles.append(tmp) | 82 | self.tmpfiles.append(tmp) |
| 73 | return (data, tmp.name) | 83 | return tmp.name |
| 84 | |||
| 85 | def load(self, datafile, name): | ||
| 86 | data = load_csv_file(datafile) | ||
| 87 | # make a copy without comments, etc. | ||
| 88 | return (data, self.write(data, name)) | ||
| 89 | |||
| 90 | def write_histogram(self, samples, name, labels=10): | ||
| 91 | max = ceil(amax(samples)) | ||
| 92 | bin_size = self.options.binsize | ||
| 93 | num_bins = int(max / bin_size) | ||
| 94 | (bins, edges) = histogram(samples, bins=num_bins, | ||
| 95 | range=(self.options.binsize / 2, | ||
| 96 | max + self.options.binsize / 2)) | ||
| 97 | data = zeros((num_bins, 3)) | ||
| 98 | cumulative = 0 | ||
| 99 | for i in xrange(len(bins)): | ||
| 100 | data[i, 0] = (edges[i] + edges[i + 1]) / 2.0 | ||
| 101 | data[i, 1] = bins[i] | ||
| 102 | cumulative += bins[i] | ||
| 103 | data[i, 2] = cumulative | ||
| 104 | |||
| 105 | label_rate = len(bins) / labels | ||
| 106 | for_file = [] | ||
| 107 | for i, row in enumerate(data): | ||
| 108 | label = '%.2f' % row[0] if i % label_rate == 0 else '' | ||
| 109 | for_file.append([row[0], row[1], row[2], label]) | ||
| 110 | |||
| 111 | return (data, self.write(for_file, name, ext='hist')) | ||
| 74 | 112 | ||
| 75 | def render(self, p): | 113 | def render(self, p): |
| 76 | if self.options.save_script: | 114 | if self.options.save_script: |
| @@ -81,31 +119,47 @@ class VideoPlotter(defapp.App): | |||
| 81 | def plot_vdecode(self, datafile, name, conf): | 119 | def plot_vdecode(self, datafile, name, conf): |
| 82 | (data, fname) = self.load(datafile, name) | 120 | (data, fname) = self.load(datafile, name) |
| 83 | 121 | ||
| 84 | decode_times = data[:,0] | 122 | max_cost = amax(data[:,0]) |
| 85 | 123 | ||
| 86 | avg = mean(decode_times) | 124 | if self.options.histogram: |
| 87 | med = median(decode_times) | 125 | name += '_hist' |
| 88 | dev = std(decode_times) | ||
| 89 | max = amax(decode_times) | ||
| 90 | min = amin(decode_times) | ||
| 91 | |||
| 92 | stats_label = "min=%.2fms max=%.2fms avg=%.2fms median=%.2fms std=%.2fms" \ | ||
| 93 | % (min, max, avg, med, dev) | ||
| 94 | 126 | ||
| 95 | p = self.make_plot(name) | 127 | p = self.make_plot(name) |
| 96 | 128 | ||
| 97 | p.title = "raw decoding cost; input=%s; host=%s" \ | 129 | p.labels = [label(0.5, 0.9, get_stats_label(data[:,0]), |
| 98 | % (conf['file'], conf['host']) | 130 | coord=['graph', 'screen'], align='center')] |
| 131 | |||
| 132 | if self.options.histogram: | ||
| 133 | (data, fname) = self.write_histogram(data[:,0], name) | ||
| 134 | |||
| 135 | p.setup_histogram(gap=1, boxwidth=1.0) | ||
| 136 | |||
| 137 | p.title = "decoding costs; input=%s; host=%s" \ | ||
| 138 | % (conf['file'], conf['host']) | ||
| 99 | 139 | ||
| 100 | p.ylabel = "decoding cost (ms)" | 140 | p.ylabel = "number of frames" |
| 101 | p.xlabel = "frame number" | 141 | p.xlabel = "decoding cost in milliseconds (bin size = %.2fms)" \ |
| 102 | p.xrange = (0, len(data)) | 142 | % self.options.binsize |
| 143 | # p.xrange = (0, ceil(max_cost)) | ||
| 144 | p.xticks = (0, 10) | ||
| 145 | # p.yticks = (0, 1) | ||
| 146 | p.yrange = (0, (ceil(amax(data[:,1]) / 100) * 100)) | ||
| 147 | p.curves = [curve(histogram=fname, col=2, labels_col=4)] | ||
| 148 | |||
| 149 | else: | ||
| 150 | # plot raw samples | ||
| 151 | p.title = "raw decoding cost; input=%s; host=%s" \ | ||
| 152 | % (conf['file'], conf['host']) | ||
| 153 | |||
| 154 | p.ylabel = "decoding cost (ms)" | ||
| 155 | p.xlabel = "frame number" | ||
| 156 | p.xrange = (0, len(data)) | ||
| 103 | #p.xticks = (0, 100) | 157 | #p.xticks = (0, 100) |
| 104 | p.yticks = (0, 1) | 158 | p.yticks = (0, 1) |
| 105 | p.yrange = (0, ceil(max)) | 159 | p.yrange = (0, ceil(max_cost)) |
| 160 | |||
| 161 | p.curves = [curve(fname=fname, xcol=2, ycol=1, title="decoding cost")] | ||
| 106 | 162 | ||
| 107 | p.curves = [curve(fname=fname, xcol=2, ycol=1, title="decoding cost")] | ||
| 108 | p.labels = [label(0.5, 0.9, stats_label, coord=['graph', 'screen'], align='center')] | ||
| 109 | 163 | ||
| 110 | #### Styling. | 164 | #### Styling. |
| 111 | 165 | ||
