示例#1
0
def generatePlot(exp_paths):
    ax = plt.gca()
    # ax.semilogx()
    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        results = loadResults(exp)

        use_ideal_h = exp._d['metaParameters'].get('use_ideal_h', False)
        dashed = use_ideal_h
        color = colors[exp.agent]

        label = exp.agent.replace('adagrad', '')
        if use_ideal_h:
            label += '-h*'

        plot(results,
             ax,
             label=label,
             color=color,
             dashed=dashed,
             bestBy='end')

    # plt.show()
    save(exp, f'rmsve_learning-curve', type='svg')
    plt.clf()
示例#2
0
def generatePlot(exp_paths):
    ax = plt.gca()
    # ax.semilogx()
    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        results = loadResults(exp, 'rmspbe_summary.npy')

        use_ideal_h = exp._d['metaParameters'].get('use_ideal_h', False)
        dashed = use_ideal_h

        label = exp.agent
        if use_ideal_h:
            label += '-h*'

        if use_ideal_h:
            continue

        if 'SmoothTDC' in exp.agent:
            agents = splitOverParameter(results, 'averageType')
            smooth_colors = {
                'ema': 'pink',
                'buffer': 'grey',
                'window': 'black',
            }
            plot(agents['ema'],
                 ax,
                 label=label + '_ema',
                 bestBy='auc',
                 color=smooth_colors['ema'],
                 dashed=dashed)
            # plot(agents['buffer'], ax, label=label + '_buffer', bestBy='auc', color=smooth_colors['buffer'], dashed=dashed)
            # plot(agents['window'], ax, label=label + '_window', bestBy='auc', color=smooth_colors['window'], dashed=dashed)

        else:
            color = colors[exp.agent]
            plot(results,
                 ax,
                 label=label,
                 bestBy='auc',
                 color=color,
                 dashed=dashed)

    plt.show()
    exit()
    # save(exp, f'rmspbe', type='png')
    problem = fileName(exp.getExperimentName())
    save_path = f'plots/'
    os.makedirs(save_path, exist_ok=True)

    fig = plt.gcf()
    fig.set_size_inches((13, 12), forward=False)
    plt.savefig(f'{save_path}/{problem}_rmspbe.png')
示例#3
0
def generatePlotSSA(ax, exp_path, bounds):
    exp = loadExperiment(exp_path)
    results = loadResults(exp, errorfile)

    color = colors[exp.agent]
    label = exp.agent

    b = plot(results, ax, window=window, smoothing=smoothing, label=label, color=color, alpha=0.2, dashed=False, bestBy=bestBy)
    bounds.append(b)
示例#4
0
def generatePlot(exp_paths):
    ax = plt.gca()
    # ax.semilogx()
    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        results = loadResults(exp)

        is_h_star = exp.getPermutation(0)['metaParameters']['use_ideal_h']
        agent = exp.agent.replace('adagrad', '')

        label = agent
        if is_h_star:
            label += '-h*'

        plot(results, ax, label=label)

    plt.show()
    # save(exp, f'learning-curve')
    plt.clf()
示例#5
0
def generatePlot(exp_paths):
    b_fig = plt.figure("Mean Update Variance")
    w_fig = plt.figure("W Update Variance")
    h_fig = plt.figure("H Update Variance")
    b_ax = b_fig.add_subplot(1, 1, 1)
    w_ax = w_fig.add_subplot(1, 1, 1)
    h_ax = h_fig.add_subplot(1, 1, 1)

    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        results = loadResults(exp, 'variance_summary.npy')

        both, w, h = tee(results, 3)

        both = map(lambda r: r.reducer(columnReducer(0)), both)
        w = map(lambda r: r.reducer(columnReducer(1)), w)
        h = map(lambda r: r.reducer(columnReducer(2)), h)

        plot(both, b_ax)
        plot(w, w_ax)
        plot(h, h_ax)

    plt.show()
    exit()

    exp_name = exp.getExperimentName()
    save_path = f'experiments/{exp_name}'
    os.makedirs(save_path, exist_ok=True)
    b_fig.savefig(f'{save_path}/both_variance-curve.pdf')
    w_fig.savefig(f'{save_path}/w_variance-curve.pdf')
    h_fig.savefig(f'{save_path}/h_variance-curve.pdf')
def generatePlotTTA(ax, exp_paths, bestBy, bounds):
    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        results = loadResults(exp, errorfile)

        color = colors[exp.agent]
        label = exp.agent

        dashed = False
        if 'TDC' in label:
            dashed = True

        results = whereParameterGreaterEq(results, 'ratio', 1)

        b = plot(results, ax, label=label, color=color, dashed=dashed, bestBy=bestBy)
        bounds.append(b)
def generatePlot(exp_paths):
    f, axes = plt.subplots(2, 2)
    # ax.semilogx()

    # RMSPBE plots
    ax = axes[0, 0]
    rmspbe_bounds = []
    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        results = loadResults(exp, 'rmspbe_summary.npy')

        use_ideal_h = exp._d['metaParameters'].get('use_ideal_h', False)
        dashed = False
        color = colors[exp.agent]

        label = exp.agent.replace('adagrad', '')
        # if use_ideal_h:
        #     label += '-h*'

        bounds = plot(results, ax, label=label, color=color, dashed=dashed)
        rmspbe_bounds.append(bounds)
        ax.set_ylabel("RMSPBE")
        ax.set_title("RMSPBE")

    ax = axes[0, 1]
    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        rmsve = loadResults(exp, 'errors_summary.npy')
        results = loadResults(exp, 'rmspbe_summary.npy')

        best = getBestEnd(rmsve)
        best_rmspbe = find(results, best)

        use_ideal_h = exp._d['metaParameters'].get('use_ideal_h', False)
        dashed = False
        color = colors[exp.agent]

        label = exp.agent.replace('adagrad', '')
        # if use_ideal_h:
        #     label += '-h*'

        bounds = plotBest(best_rmspbe,
                          ax,
                          label=label,
                          color=color,
                          dashed=dashed)
        rmspbe_bounds.append(bounds)
        ax.set_title("RMSVE")

    # RMSVE plots
    ax = axes[1, 0]
    rmsve_bounds = []
    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        rmsve = loadResults(exp, 'errors_summary.npy')
        rmspbe = loadResults(exp, 'rmspbe_summary.npy')

        # if exp.agent == 'TDadagrad':
        #     continue

        # best PBE using AUC
        best = getBestEnd(rmspbe)
        best_rmsve = find(rmsve, best)

        use_ideal_h = exp._d['metaParameters'].get('use_ideal_h', False)
        dashed = False
        color = colors[exp.agent]

        label = exp.agent.replace('adagrad', '')
        # if use_ideal_h:
        #     label += '-h*'

        bounds = plotBest(best_rmsve,
                          ax,
                          label=label,
                          color=color,
                          dashed=dashed)
        rmsve_bounds.append(bounds)
        ax.set_ylabel("RMSVE")

    ax = axes[1, 1]
    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        results = loadResults(exp)

        use_ideal_h = exp._d['metaParameters'].get('use_ideal_h', False)
        dashed = False
        color = colors[exp.agent]

        label = exp.agent.replace('adagrad', '')
        # if use_ideal_h:
        #     label += '-h*'

        bounds = plot(results, ax, label=label, color=color, dashed=dashed)
        rmsve_bounds.append(bounds)

    # rmspbe
    rmspbe_lower = min(map(lambda x: x[0], rmspbe_bounds)) * 0.9
    rmspbe_upper = max(map(lambda x: x[1], rmspbe_bounds)) * 1.05
    axes[0, 0].set_ylim([rmspbe_lower, rmspbe_upper])
    axes[0, 1].set_ylim([rmspbe_lower, rmspbe_upper])

    # rmsve
    rmsve_lower = min(map(lambda x: x[0], rmsve_bounds)) * 0.9
    rmsve_upper = max(map(lambda x: x[1], rmsve_bounds)) * 1.05
    axes[1, 0].set_ylim([rmsve_lower, rmsve_upper])
    axes[1, 1].set_ylim([rmsve_lower, rmsve_upper])

    plt.show()
示例#8
0
def generatePlot(exp_paths):
    f, axes = plt.subplots(2, 2)

    # get LSTD solution
    path = up(up(first(exp_paths))) + '/lstd.json'
    exp = loadExperiment(path)
    LSTD_rmsve_results = loadResults(exp, 'errors_summary.npy')
    LSTD_rmspbe_results = loadResults(exp, 'rmspbe_summary.npy')

    LSTD_rmsve = metric(LSTD_rmsve_results)
    LSTD_rmspbe = metric(LSTD_rmspbe_results)

    rmspbe_bounds = []
    rmsve_bounds = []

    bounds = plotBest(LSTD_rmspbe,
                      axes[0, 0],
                      color=colors['LSTD'],
                      label='LSTD',
                      alphaMain=0.5)
    rmspbe_bounds.append(bounds)

    bounds = plotBest(LSTD_rmspbe,
                      axes[0, 1],
                      color=colors['LSTD'],
                      label='LSTD',
                      alphaMain=0.5)
    rmspbe_bounds.append(bounds)

    bounds = plotBest(LSTD_rmsve,
                      axes[1, 0],
                      color=colors['LSTD'],
                      label='LSTD',
                      alphaMain=0.5)
    rmsve_bounds.append(bounds)

    bounds = plotBest(LSTD_rmsve,
                      axes[1, 1],
                      color=colors['LSTD'],
                      label='LSTD',
                      alphaMain=0.5)
    rmsve_bounds.append(bounds)

    # RMSPBE plots
    ax = axes[0, 0]
    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        results = loadResults(exp, 'rmspbe_summary.npy')
        const, unconst = tee(results)

        const = whereParameterGreaterEq(const, 'ratio', 1)

        use_ideal_h = exp._d['metaParameters'].get('use_ideal_h', False)

        agent = exp.agent
        if 'SmoothTDC' in agent:
            average = exp._d['metaParameters']['averageType']
            agent += '_' + average

        color = colors[agent]
        label = agent.replace('adagrad', '')

        if not (exp.agent in ['TDadagrad', 'TDschedule', 'TD', 'TDamsgrad']
                or use_ideal_h):
            if UNCONSTRAINED:
                bounds = plot(unconst,
                              ax,
                              label=label + '_unc',
                              color=color,
                              dashed=True,
                              bestBy=bestBy)
                rmspbe_bounds.append(bounds)
            bounds = plot(const,
                          ax,
                          label=label,
                          color=color,
                          dashed=False,
                          bestBy=bestBy)
            rmspbe_bounds.append(bounds)
        else:
            bounds = plot(unconst,
                          ax,
                          label=label,
                          color=color,
                          dashed=False,
                          bestBy=bestBy)
            rmspbe_bounds.append(bounds)

        ax.set_ylabel("MSPBE")
        ax.set_title("MSPBE")

    ax = axes[0, 1]
    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        rmsve = loadResults(exp, 'errors_summary.npy')
        results = loadResults(exp, 'rmspbe_summary.npy')
        const, unconst = tee(rmsve)
        const_res, unconst_res = tee(results)

        const = whereParameterGreaterEq(const, 'ratio', 1)

        use_ideal_h = exp._d['metaParameters'].get('use_ideal_h', False)

        agent = exp.agent
        if 'SmoothTDC' in agent:
            average = exp._d['metaParameters']['averageType']
            agent += '_' + average

        color = colors[agent]
        label = agent.replace('adagrad', '')

        if not (exp.agent in ['TDadagrad', 'TDschedule', 'TD', 'TDamsgrad']
                or use_ideal_h):
            best = metric(const)
            best_unc = metric(unconst)
            best_rmspbe = find(const_res, best)
            best_rmspbe_unc = find(unconst_res, best_unc)

            bounds = plotBest(best_rmspbe,
                              ax,
                              label=label,
                              color=color,
                              dashed=False)
            rmspbe_bounds.append(bounds)

            if UNCONSTRAINED:
                bounds = plotBest(best_rmspbe_unc,
                                  ax,
                                  label=label + '_unc',
                                  color=color,
                                  dashed=True)
                rmspbe_bounds.append(bounds)
        else:
            best = metric(unconst)
            best_rmspbe = find(unconst_res, best)

            bounds = plotBest(best_rmspbe,
                              ax,
                              label=label,
                              color=color,
                              dashed=False)
            rmspbe_bounds.append(bounds)

        ax.set_title("MSVE")

    # RMSVE plots
    ax = axes[1, 0]
    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        rmsve = loadResults(exp, 'errors_summary.npy')
        rmspbe = loadResults(exp, 'rmspbe_summary.npy')
        const, unconst = tee(rmspbe)
        const_res, unconst_res = tee(rmsve)

        const = whereParameterGreaterEq(const, 'ratio', 1)

        use_ideal_h = exp._d['metaParameters'].get('use_ideal_h', False)

        agent = exp.agent
        if 'SmoothTDC' in agent:
            average = exp._d['metaParameters']['averageType']
            agent += '_' + average

        color = colors[agent]
        label = agent.replace('adagrad', '')

        if not (exp.agent in ['TDadagrad', 'TDschedule', 'TD', 'TDamsgrad']
                or use_ideal_h):
            # best PBE using AUC
            best = metric(const)
            best_unc = metric(unconst)
            best_rmsve = find(const_res, best)
            best_rmsve_unc = find(unconst_res, best_unc)

            print('rmsve_over_rmspbe')
            print(label, best_rmsve.params)
            print(label, best_rmsve_unc.params)

            bounds = plotBest(best_rmsve,
                              ax,
                              label=label,
                              color=color,
                              dashed=False)
            rmsve_bounds.append(bounds)

            if UNCONSTRAINED:
                bounds = plotBest(best_rmsve_unc,
                                  ax,
                                  label=label + '_unc',
                                  color=color,
                                  dashed=True)
                rmsve_bounds.append(bounds)

        else:
            best = metric(unconst)
            best_rmsve = find(unconst_res, best)
            bounds = plotBest(best_rmsve,
                              ax,
                              label=label,
                              color=color,
                              dashed=False)
            rmsve_bounds.append(bounds)

        ax.set_ylabel("MSVE")

    ax = axes[1, 1]
    for exp_path in exp_paths:
        exp = loadExperiment(exp_path)
        results = loadResults(exp)
        const, unconst = tee(results)

        const = whereParameterGreaterEq(const, 'ratio', 1)

        use_ideal_h = exp._d['metaParameters'].get('use_ideal_h', False)

        agent = exp.agent
        if 'SmoothTDC' in agent:
            average = exp._d['metaParameters']['averageType']
            agent += '_' + average

        color = colors[agent]
        label = agent.replace('adagrad', '')

        if not (exp.agent in ['TDadagrad', 'TDschedule', 'TD', 'TDamsgrad']
                or use_ideal_h):
            bounds = plot(const,
                          ax,
                          label=label,
                          color=color,
                          dashed=False,
                          bestBy=bestBy)
            rmsve_bounds.append(bounds)

            if UNCONSTRAINED:
                bounds = plot(unconst,
                              ax,
                              label=label + '_unc',
                              color=color,
                              dashed=True,
                              bestBy=bestBy)
                rmsve_bounds.append(bounds)

        else:
            bounds = plot(unconst,
                          ax,
                          label=label,
                          color=color,
                          dashed=False,
                          bestBy=bestBy)
            rmsve_bounds.append(bounds)

    # rmspbe
    rmspbe_lower = min(map(lambda x: x[0], rmspbe_bounds)) * 0.9
    rmspbe_upper = max(map(lambda x: x[1], rmspbe_bounds)) * 1.05

    if rmspbe_lower < 0.01:
        rmspbe_lower = -0.01

    axes[0, 0].set_ylim([rmspbe_lower, rmspbe_upper])
    axes[0, 1].set_ylim([rmspbe_lower, rmspbe_upper])

    # rmsve
    rmsve_lower = min(map(lambda x: x[0], rmsve_bounds)) * 0.9
    rmsve_upper = max(map(lambda x: x[1], rmsve_bounds)) * 1.05

    if rmsve_lower < 0.01:
        rmsve_lower = -0.01

    axes[1, 0].set_ylim([0, 20])
    axes[1, 1].set_ylim([0, 20])