def make_probes_ba_traj_fig(models1, models2=None, palette=None): # TODO ylim
"""
Returns fig showing trajectory of probes balanced accuracy
"""
start = time.time()
sns.set_style('white')
# load data
xys = []
model_groups = [models1] if models2 is None else [models1, models2]
for n, models in enumerate(model_groups):
model_probes_ba_trajs = []
for nn, model in enumerate(models):
model_probes_ba_trajs.append(model.get_traj('probes_ba'))
x = models[0].get_data_step_axis()
traj_mat = np.asarray([traj[:len(x)] for traj in model_probes_ba_trajs]) # all trajs are truncated to shortest
y = np.mean(traj_mat, axis=0)
sem = [stats.sem(model_probes_bas) for model_probes_bas in traj_mat.T]
xys.append((x, y, sem))
# fig
fig, ax = plt.subplots(figsize=(FigsConfigs.MAX_FIG_WIDTH, 3))
ax.set_ylim([50, 75])
ax.set_xlabel('Mini Batch', fontsize=FigsConfigs.AXLABEL_FONT_SIZE)
ax.set_ylabel('Probes Balanced Accuracy', fontsize=FigsConfigs.AXLABEL_FONT_SIZE)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.tick_params(axis='both', which='both', top='off', right='off')
ax.xaxis.set_major_formatter(FuncFormatter(human_format))
ax.yaxis.grid(True)
# plot
for (x, y, sem) in xys:
color = next(palette) if palette is not None else 'black'
ax.plot(x, y, '-', linewidth=FigsConfigs.LINEWIDTH, color=color)
ax.fill_between(x, np.add(y, sem), np.subtract(y, sem), alpha=FigsConfigs.FILL_ALPHA, color='grey')
plt.tight_layout()
print('{} completed in {:.1f} secs'.format(sys._getframe().f_code.co_name, time.time() - start))
return fig
评论列表
文章目录