def draw_violin(dataset, posns, alpha=1, color='royalblue', meanmarker="*"): """ Draw a violin to the current plot. Color the mean point. (Shared helper for `violin_plot` and `double_violin`) """ ## Add data vp = plt.violinplot(dataset, positions=posns, showmeans=True, showextrema=True, showmedians=True) ## Re-color bodies for v in vp['bodies']: v.set_edgecolors('k') v.set_facecolors(color) v.set_alpha(alpha) ## Draw mean markers # Make original mean line invisible vp['cmeans'].set_alpha(0) # Draw data points for i in range(len(dataset)): plt.plot([posns[i]] * len(dataset[i]), dataset[i], "r+") ## Re-color median, min, max lines to be black for field in ['cmaxes', 'cmins', 'cbars', 'cmedians']: vp[field].set_color('k') # Draw the mean marker for i in range(len(dataset)): plt.plot(posns[i], [np.average(dataset[i])], color='w', marker=meanmarker, markeredgecolor='k') # Draw confidence interval (should be optional) for i in range(len(dataset)): stat = util.stats_of_row(dataset[i]) plt.errorbar(posns[i], stat["mean"], yerr=stat["ci"][1] - stat["mean"], ecolor="magenta", capthick=4) return
def of_tab(self, tabfile): """ Initialize `stats_by_config` table from the spreadsheet `tabfile` """ util.fold_file( tabfile, None, lambda acc, row: self.set_stats(row[0], util.stats_of_row([int(v) for v in row[1:]])) )
def stats_of_predicate(self, pred): """ Return an array of the experimental results for each configuration matching `pred`. """ unflattened = [self.stats_of_config(cfg) for cfg in self.all_configurations() if pred(cfg)] return util.stats_of_row([x for st in unflattened for x in st["raw"]])
def sample_stats(self, pred, tag): """ Get statistics about the samples matching predicate `pred` """ all_samples = [(k,v['raw']) for (k,v) in self.stats_by_config.items() if pred(k)] configs = [k for (k,_) in all_samples] vals = [v for (k,vs) in all_samples for v in vs] stat = util.stats_of_row(vals) return [tag ,len(set(configs)) ,len(vals) ,round(stat["mean"], 2) ,round(stat["variance"], 2) ,"%s~\\textendash~%s" % (round(stat["ci"][0], 2), round(stat["ci"][1], 2)) ,round(math.sqrt(stat["variance"]) / math.sqrt(len(vals)), 2) ,round(jarque_bera(vals)[0], 2)]
def results_of_config(self, config): # Execute the config for a pre-set number of iterations return util.stats_of_row(self.run_config(config))
def results_of_config(self, config): return util.fold_file( self.source, None, lambda acc, row: acc or (util.stats_of_row([int(x) for x in row[1:]]) if row[0] == config else None), )