def plot_wide(datasets, axs, n_highlighted=0): axs[0].spines['left'].set_position(('outward', 5)) axs[0].set_ylabel("Table size") axs[1].spines['left'].set_color('none') y_min = 2000 y_max = 0 for model, ax, title in zip(nets, axs, net_titles): ax.set_title(title) ax.grid(False) ax.hlines(1024, -.5, len(datasets) * 2 + 1.5, linewidth=.5, colors=[(.5, ) * 3], zorder=0) ax.spines['top'].set_color('none') ax.spines['right'].set_color('none') ax.spines['bottom'].set_color('none') data = np.zeros((len(datasets), 144)) # Read all the data for i, (_, fn) in enumerate(datasets): fn = "{}{}_12_12_xyp.bin".format(fn, model) with open(fn, "rb") as f: data[i, :] = np.array(list(read_table_lengths(f).values())) xs = np.arange(len(datasets)) * 2 elems = ax.violinplot(data.T, xs, showextrema=False) for b in elems["bodies"][:-n_highlighted]: b.set_alpha(.3) b.set_facecolor((.85, .85, .85)) b.set_edgecolor((0, 0, 0)) b.set_linewidth(1) # The last 2 elements should be slightly highlighted for b in elems["bodies"][-n_highlighted:]: b.set_alpha(.8) b.set_facecolor((.85, .85, .85)) b.set_edgecolor((0, 0, 0)) b.set_linewidth(1) y_min = min(y_min, np.min(data)) y_max = max(y_max, np.max(data)) ax.set_xlim(-.5, max(xs) + .5) titles = (t for t, _ in datasets) ax.set_xticks(xs) ax.set_xticklabels(titles) axs[0].set_ylim(y_min, y_max) axs[0].set_yticks([y_min, 1024, y_max])
def plot_wide(datasets, axs, n_highlighted=0): axs[0].spines['left'].set_position(('outward', 5)) axs[0].set_ylabel("Table size") axs[1].spines['left'].set_color('none') y_min = 2000 y_max = 0 for model, ax, title in zip(nets, axs, net_titles): ax.set_title(title) ax.grid(False) ax.hlines(1024, -.5, len(datasets) * 2 + 1.5, linewidth=.5, colors=[(.5, )*3], zorder=0) ax.spines['top'].set_color('none') ax.spines['right'].set_color('none') ax.spines['bottom'].set_color('none') data = np.zeros((len(datasets), 144)) # Read all the data for i, (_, fn) in enumerate(datasets): fn = "{}{}_12_12_xyp.bin".format(fn, model) with open(fn, "rb") as f: data[i, :] = np.array(list(read_table_lengths(f).values())) xs = np.arange(len(datasets))*2 elems = ax.violinplot(data.T, xs, showextrema=False) for b in elems["bodies"][:-n_highlighted]: b.set_alpha(.3) b.set_facecolor((.85, .85, .85)) b.set_edgecolor((0, 0, 0)) b.set_linewidth(1) # The last 2 elements should be slightly highlighted for b in elems["bodies"][-n_highlighted:]: b.set_alpha(.8) b.set_facecolor((.85, .85, .85)) b.set_edgecolor((0, 0, 0)) b.set_linewidth(1) y_min = min(y_min, np.min(data)) y_max = max(y_max, np.max(data)) ax.set_xlim(-.5, max(xs) + .5) titles = (t for t, _ in datasets) ax.set_xticks(xs) ax.set_xticklabels(titles) axs[0].set_ylim(y_min, y_max) axs[0].set_yticks([y_min, 1024, y_max])
y_max = 0 for model, ax, title in zip(nets, axs, net_titles): ax.set_title(title) ax.grid(False) ax.hlines(1024, -.5, 8.5, linewidth=.5, colors=[(.5, ) * 3], zorder=0) ax.spines['top'].set_color('none') ax.spines['right'].set_color('none') ax.spines['bottom'].set_color('none') data = np.zeros((len(methods) + 2, 144)) # Read all the data fn = "uncompressed/{}_12_12_xyp.bin".format(model) with open(fn, "rb") as f: data[0, :] = np.array(list(read_table_lengths(f).values())) fn = "compressed/remove_default_{}_12_12_xyp.bin".format(model) with open(fn, "rb") as f: data[1, :] = np.array(list(read_table_lengths(f).values())) for j, method in enumerate(methods): fn = "compressed/{}_{}_12_12_xyp.bin".format(method, model) with open(fn, "rb") as f: data[j + 2, :] = np.array(list(read_table_lengths(f).values())) elems = ax.violinplot(data.T, np.arange(len(methods) + 2) * 2, showextrema=False) for b in elems["bodies"]: b.set_alpha(.75)
import argparse from common import read_table_lengths from matplotlib import pyplot as plt if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("filename", type=str) args = parser.parse_args() with open(args.filename, 'rb') as fp: lens = read_table_lengths(fp) plt.hist(list(lens.values())) plt.show()
y_max = 0 for model, ax, title in zip(nets, axs, net_titles): ax.set_title(title) ax.grid(False) ax.hlines(1024, -.5, 8.5, linewidth=.5, colors=[(.5, )*3], zorder=0) ax.spines['top'].set_color('none') ax.spines['right'].set_color('none') ax.spines['bottom'].set_color('none') data = np.zeros((len(methods) + 2, 144)) # Read all the data fn = "uncompressed/{}_12_12_xyp.bin".format(model) with open(fn, "rb") as f: data[0, :] = np.array(list(read_table_lengths(f).values())) fn = "compressed/remove_default_{}_12_12_xyp.bin".format(model) with open(fn, "rb") as f: data[1, :] = np.array(list(read_table_lengths(f).values())) for j, method in enumerate(methods): fn = "compressed/{}_{}_12_12_xyp.bin".format(method, model) with open(fn, "rb") as f: data[j+2, :] = np.array(list(read_table_lengths(f).values())) elems = ax.violinplot(data.T, np.arange(len(methods) + 2)*2, showextrema=False) for b in elems["bodies"]: b.set_alpha(.75) b.set_facecolor((.85, .85, .85)) b.set_edgecolor((0, 0, 0))
("centroid", "Centroid")] methods_titles = [("remove_default", "Default\nRouting"), ("esp_tables_no_offset", "Espresso"), ("esp_subtables_full", "Order-\nexploiting\nEspresso"), ("mtrie", "m-Trie"), ("oc_spinnaker", "Ordered\nCovering")] # Construct the data to go with the titles max_ys = dict() min_ys = dict() datasets = collections.defaultdict(dict) for model, _ in nets_titles: # Load the original data = np.zeros(144, dtype=np.int) with open("uncompressed/{}_12_12_xyp.bin".format(model), "rb") as fp: data[:] = list(read_table_lengths(fp).values()) # Update the sizes max_ys[model] = np.max(data) min_ys[model] = np.min(data) # Store the result datasets[model]["original"] = data # Load the results for method, _ in methods_titles: # Load the routing table lengths data = np.zeros(144, dtype=np.int) with open("compressed/{}_{}_12_12_xyp.bin".format(method, model), "rb") as fp: data[:] = list(read_table_lengths(fp).values())