comparisonfigs.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:rnnlab 作者: phueb 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号