viceroy

git clone git://git.codymlewis.com/viceroy.git
Log | Files | Refs | README

commit 3b87460fa18aee8ca294aba64dfbd464518a0f09
parent 43097fd23401060ecff9b55175422a9140591d6f
Author: Cody Lewis <cody@codymlewis.com>
Date:   Thu, 11 Feb 2021 16:52:34 +1100

Made on-off toggle bar plots

Diffstat:
Moptions.json | 2+-
Mtoggle_stats.py | 47+++++++++++++++++++++++++++++++++++------------
2 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/options.json b/options.json @@ -25,7 +25,7 @@ "to": 0, "scale_up": false, "toggle_times": null, - "delay": 1, + "delay": 1000, "beta": 0.1, "gamma": 0.7, "optimized": true diff --git a/toggle_stats.py b/toggle_stats.py @@ -7,12 +7,11 @@ Generate stats on the toggles of a simulation Author: Cody Lewis """ -import pickle +import matplotlib.pyplot as plt +import pandas from pathlib import Path -import utils - def avg(a): return sum(a) / l if (l := len(a)) > 0 else 0 @@ -66,14 +65,38 @@ def write_results(options, toggle_record, file_name): stats = get_stats(options, toggle_record) write_stats(options, stats, file_name) -if __name__ == '__main__': - import matplotlib.pyplot as plt - import pandas - df = pandas.read_csv('toggle_record.csv') - df.plot(kind='bar') - plt.xticks(range(len(df)), [x[:1] for x in df['ds']]) +def presentable(X): + return [x.replace('_', ' ').title() for x in X] + +def make_plot(df, indices, title, stacked, img_name): + df[indices].plot.bar(stacked=stacked, rot=0) + plt.xticks(range(len(df)), presentable(df['ds'])) plt.xlabel("Dataset and Model") plt.ylabel("Number of Epochs") - plt.title("Comparison of Attack Timings") - plt.legend(loc=1, fontsize=5, framealpha=0.4) - plt.show() + plt.title(title) + plt.legend( + labels=presentable(indices[1:]), + loc=1, + fontsize=5, + framealpha=0.4 + ) + plt.savefig(img_name, dpi=320) + print(f"Done. Saved plot as {img_name}") + + +if __name__ == '__main__': + df = pandas.read_csv('toggle_record.csv') + make_plot( + df, + ['ds', 'time_on', 'time_off'], + "Times Spent On and Off", + True, + "on_off_times.png" + ) + make_plot( + df, + ['ds', 'off_to_on', 'on_to_off'], + "Times Taken for Toggles Between States", + False, + "on_off_toggles.png" + )