Ejemplo n.º 1
0
def getSensitivityData(results, param, reducer='best', bestBy='auc'):
    if reducer == 'best':
        split = splitOverParameter(results, param)
        bestStream = {}
        for k in split:
            bestStream[k] = getBest(split[k], prefer='big')

    elif reducer == 'slice':
        l, r = tee(results)
        best = getBest(l, prefer='big')

        bestStream = sliceOverParameter(r, best, param)

    else:
        raise NotImplementedError()

    x = sorted(list(bestStream))
    best = bestStream

    metric = getCurveReducer(bestBy)

    y = np.array([metric(best[k].mean()) for k in x])
    e = np.array([metric(best[k].stderr()) for k in x])

    e[np.isnan(y)] = 0.000001
    y[np.isnan(y)] = 100000

    return x, y, e
Ejemplo n.º 2
0
def generatePlot(exp_paths):
    exp = ExperimentModel.load(exp_paths[0])
    results = loadResults(exp, 'step_return.csv')

    results_dict = splitOverParameter(results, 'tile-coder')

    # two new streams over results
    mine = results_dict['mine']
    tiles3 = results_dict['tiles3']

    # figure out what values of "tiles" we swept
    tiles = splitOverParameter(mine, 'tiles').keys()
    # figure out what values of "tilings" we swept
    tilings = splitOverParameter(mine, 'tilings').keys()

    f, axes = plt.subplots(len(tiles), len(tilings))

    # create an empty (2, tiles, tilings) shape array
    data = createEmptyList([2, len(tiles), len(tilings)])
    for tiles_idx, num_tiles in enumerate(tiles):
        for tilings_idx, num_tilings in enumerate(tilings):
            mine_result = whereParametersEqual(mine, { 'tiles': num_tiles, 'tilings': num_tilings })
            mine_result = getBest(mine_result, prefer='big')

            tiles3_result = whereParametersEqual(tiles3, { 'tiles': num_tiles, 'tilings': num_tilings })
            tiles3_result = getBest(tiles3_result, prefer='big')

            mine_data = [np.mean(curve) for curve in mine_result.load()]
            tiles3_data = [np.mean(curve) for curve in tiles3_result.load()]

            data[0][tiles_idx][tilings_idx] = mine_data
            data[1][tiles_idx][tilings_idx] = tiles3_data

    min_perf = np.min(data)
    max_perf = np.max(data)
    for rep, rep_name in enumerate(['Mine', 'Tiles3']):
        for tiles_idx, num_tiles in enumerate(tiles):
            for tilings_idx, num_tilings in enumerate(tilings):
                performance = data[rep][tiles_idx][tilings_idx]
                color = 'blue' if rep == 0 else 'red'

                kde = gaussian_kde(performance)
                lo = 0.95 * min_perf
                hi = 1.05 * max_perf
                dist_space = np.linspace(lo, hi, FIDELITY)
                dist = kde(dist_space)
                # dist = minMaxScale(kde(dist_space)) * DIST_HEIGHT
                axes[tiles_idx][tilings_idx].plot(dist_space, dist, label=rep_name, linewidth=2.0, color=color)
                axes[tiles_idx][tilings_idx].fill_between(dist_space, np.zeros(FIDELITY), dist, color=color, alpha=0.2)

                axes[tiles_idx][tilings_idx].set_xlim((0.95 * min_perf, 1.05 * max_perf))
                # axes[tiles_idx][tilings_idx].set_xlabel('Reward')

                title = f'({num_tiles} tiles, {num_tilings} tilings)'
                axes[tiles_idx][tilings_idx].set_title(title)

    plt.legend()

    return f, axes
Ejemplo n.º 3
0
def plot(results, ax, color=None, label=None, labelParams=None, bestBy='end', dashed=False):
    if bestBy == 'end':
        best = getBest(results, percent=0.1)
    elif bestBy == 'auc':
        best = getBest(results)
    else:
        raise Exception('I can only get best by "end" or "auc"')

    print(best.exp.agent, best.params)
    return plotBest(best, ax, color, label, labelParams=labelParams, dashed=dashed)
Ejemplo n.º 4
0
def generatePlot(ax, exp_paths):
    exp = ExperimentModel.load(exp_paths[0])
    results = loadResults(exp, 'step_return.csv')

    results_dict = splitOverParameter(results, 'tile-coder')

    # two new streams over results
    mine = results_dict['mine']
    tiles3 = results_dict['tiles3']

    # figure out what values of "tiles" we swept
    tiles = splitOverParameter(mine, 'tiles').keys()
    # figure out what values of "tilings" we swept
    tilings = splitOverParameter(mine, 'tilings').keys()

    for num_tiles in tiles:
        for num_tilings in tilings:
            mine_result = whereParametersEqual(mine, {
                'tiles': num_tiles,
                'tilings': num_tilings
            })
            mine_result = getBest(mine_result, prefer='big')

            tiles3_result = whereParametersEqual(tiles3, {
                'tiles': num_tiles,
                'tilings': num_tilings
            })
            tiles3_result = getBest(tiles3_result, prefer='big')

            d_curves = []
            mine_curves = mine_result.load()
            tiles3_curves = tiles3_result.load()

            min_len = min(len(mine_curves), len(tiles3_curves))
            print(min_len)
            for i in range(min_len):
                d = mine_curves[i] - tiles3_curves[i]
                d_curves.append(d)

            mean = np.mean(d_curves, axis=0)
            stderr = np.std(d_curves, axis=0, ddof=1) / np.sqrt(len(d_curves))

            lineplot(ax,
                     mean,
                     stderr=stderr,
                     label=f'({num_tiles}, {num_tilings})')

    ax.set_xlim(0, 500)
    ax.axhline(0, color='black', linestyle='--', alpha=0.4)
    ax.set_ylabel(f'd = Mine - Tiles3 \n Bigger is better')
    plt.legend()
Ejemplo n.º 5
0
def generatePlot(exp_paths):
    exp = ExperimentModel.load(exp_paths[0])
    results = loadResults(exp, 'step_return.csv')

    results_dict = splitOverParameter(results, 'tile-coder')

    # two new streams over results
    mine = results_dict['mine']
    tiles3 = results_dict['tiles3']

    # figure out what values of "tiles" we swept
    tiles = splitOverParameter(mine, 'tiles').keys()
    # figure out what values of "tilings" we swept
    tilings = splitOverParameter(mine, 'tilings').keys()

    f, axes = plt.subplots(len(tiles), len(tilings))

    for tiles_idx, num_tiles in enumerate(tiles):
        for tilings_idx, num_tilings in enumerate(tilings):
            mine_result = whereParametersEqual(mine, {
                'tiles': num_tiles,
                'tilings': num_tilings
            })
            mine_result = getBest(mine_result, prefer='big')

            tiles3_result = whereParametersEqual(tiles3, {
                'tiles': num_tiles,
                'tilings': num_tilings
            })
            tiles3_result = getBest(tiles3_result, prefer='big')

            plotBest(mine_result,
                     axes[tiles_idx][tilings_idx],
                     color='blue',
                     label='Mine')
            plotBest(tiles3_result,
                     axes[tiles_idx][tilings_idx],
                     color='red',
                     label='Tiles3')

            axes[tiles_idx][tilings_idx].set_title(
                f'Tiles: {num_tiles} Tilings: {num_tilings}')

    axes[0][0].legend()

    return f, axes
Ejemplo n.º 6
0
    def test_getBest(self):
        # lowest
        load_counter = 0

        class TestResult(Result):
            def _load(self):
                nonlocal load_counter
                load_counter += 1
                return (np.ones(100) * load_counter, np.ones(100), 3)

        results = (TestResult('fake/path', exp, i) for i in listIndices(exp))

        best = getBest(results)
        self.assertEqual(best.mean()[0], 1)

        # highest
        results = (TestResult('fake/path', exp, i) for i in listIndices(exp))

        best = getBest(results, comparator=lambda a, b: a > b)
        self.assertEqual(best.mean()[0], load_counter)
Ejemplo n.º 7
0
def generatePlot(ax, exp_paths, bounds):
    for exp_path in exp_paths:
        exp = ExperimentModel.load(exp_path)
        raise Exception(
            'Set the name of the results file saved from these experiments')

        results = loadResults(exp, 'results.npy')
        results = whereParameterEquals(results, 'initial_value', 0)

        best = getBest(results)

        b = plotBest(best, ax, label='TD', color='yellow', dashed=False)
        bounds.append(b)