Exemple #1
0
def plot(results_path, fig_path):
    data = pd.read_csv(
        results_path.joinpath("trial_accuracy_means.csv"))\
        .groupby('model').get_group('exp')\
        .sort('trial')

    trials = data['trial']
    acc = data['median'] * 100

    fig, ax = plt.subplots()
    ax.plot(trials, acc, 'k.')
    ax.set_xlim(1, 200)
    ax.set_ylim(70, 100)
    ax.set_xlabel("Trial", fontsize=14)
    ax.set_ylabel("Percent correct", fontsize=14)
    util.clear_right(ax)
    util.clear_top(ax)
    util.outward_ticks(ax)
    fig.set_figheight(3.5)
    fig.set_figwidth(4.5)
    plt.draw()
    plt.tight_layout()

    pths = [fig_path.joinpath("trial_accuracy.%s" % ext)
            for ext in ('png', 'pdf')]
    for pth in pths:
        util.save(pth, close=False)
    return pths
def plot(results_path, fig_path):
    data = pd.read_csv(
        results_path.joinpath("trial_time_means.csv"))\
        .groupby('model').get_group('exp')\
        .sort_values(by='trial')

    trials = data['trial']
    times = data['median']

    fig, ax = plt.subplots()
    ax.plot(trials, times, 'k.')
    ax.set_xlim(1, 200)
    ax.set_xlabel("Trial", fontsize=14)
    ax.set_ylabel("Response time", fontsize=14)
    util.clear_right(ax)
    util.clear_top(ax)
    util.outward_ticks(ax)
    fig.set_figheight(3.5)
    fig.set_figwidth(4.5)
    plt.draw()
    plt.tight_layout()

    pths = [fig_path.joinpath("trial_time.%s" % ext)
            for ext in ('png', 'pdf')]
    for pth in pths:
        util.save(pth, close=False)
    return pths
Exemple #3
0
def plot(results_path, fig_path):
    order = ['exp', 'oc', 'th', 'hc', 'bq', 'bqp']
    titles = {
        'exp': "Human",
        'oc': "Oracle",
        'th': "Threshold",
        'hc': "HC",
        'bq': "BQ (equal prior)",
        'bqp': "BQ (unequal prior)"
    }

    pth = results_path.joinpath("all_response_times.pkl")
    with open(pth, "r") as fh:
        times = pickle.load(fh)

    fig, axes = plt.subplots(1, len(order), sharey=True)
    for i, key in enumerate(order):
        ax = axes[i]
        bins = 200

        if key == 'exp':
            hist, edges = np.histogram(
                times[key] / 1000., bins=bins,
                range=(0, 20))
        else:
            hist, edges = np.histogram(
                times[key], bins=bins,
                range=(0, bins))

        edges = edges[:101]
        hist = hist[:100]
        hist = hist * 100 / float(len(times[key]))
        width = edges[1] - edges[0]
        ax.bar(edges[:-1], hist, width=width, color='k')

        ax.set_xlim(0, edges[-1])
        ax.set_title(titles[key], fontsize=14)
        util.clear_right(ax)
        util.clear_top(ax)
        util.outward_ticks(ax)

        if key == 'exp':
            ax.set_xlabel("RT (seconds)", fontsize=14)
        else:
            ax.set_xlabel("Number of actions", fontsize=14)
    axes[0].set_ylabel("Percent", fontsize=14)

    fig.set_figheight(2.5)
    fig.set_figwidth(16)

    plt.draw()
    plt.tight_layout()

    pths = [fig_path.joinpath("response_time_histograms.%s" % ext)
            for ext in ('png', 'pdf')]
    for pth in pths:
        util.save(pth, close=False)
    return pths
def plot(results_path, fig_path):
    order = ['hc', 'bq', 'bqp']
    titles = {
        'exp': "Human",
        'hc': "HC",
        'bq': "BQ (equal prior)",
        'bqp': "BQ (unequal prior)"
    }

    results = pd.read_csv(
        results_path.joinpath("accuracy_means.csv"))\
        .set_index(['stimulus', 'theta', 'flipped', 'model'])['median']\
        .unstack(['model', 'flipped']) * 100

    fig, axes = plt.subplots(1, len(order), sharey=True, sharex=True)

    for i, key in enumerate(order):
        ax = axes[i]
        for flipped in ['same', 'flipped']:
            ax.plot(
                results[(key, flipped)],
                results[('exp', flipped)],
                '.', alpha=0.8, label=flipped)

        ax.set_xlabel("Model accuracy", fontsize=14)
        ax.set_title(titles[key], fontsize=14)
        util.clear_right(ax)
        util.clear_top(ax)
        util.outward_ticks(ax)

    axes[0].set_ylabel("Human accuracy", fontsize=14)
    axes[0].set_xlim(-5, 105)
    axes[0].set_ylim(45, 105)
    axes[0].legend(loc=0, numpoints=1)

    fig.set_figheight(3)
    fig.set_figwidth(8)
    plt.draw()
    plt.tight_layout()

    pths = [fig_path.joinpath("accuracy_scatters.%s" % ext)
            for ext in ('png', 'pdf')]
    for pth in pths:
        util.save(pth, close=False)
    return pths
def plot_key(key, results_path, fig_path):
    fig, axes = plt.subplots(4, 5, sharey=True, sharex=True)

    means = pd.read_csv(
        results_path.joinpath("theta_time_stimulus.csv"))\
        .set_index(['stimulus', 'flipped', 'model'])\
        .groupby(level='model').get_group(key)

    for i, (stim, sdf) in enumerate(means.groupby(level='stimulus')):
        ax = axes.flat[i]

        for flipped, stats in sdf.groupby(level='flipped'):
            lower = stats['median'] - stats['lower']
            upper = stats['upper'] - stats['median']
            ax.errorbar(
                stats['modtheta'], stats['median'],
                yerr=[lower, upper],
                label=flipped, lw=3)

        ax.set_xlabel("Rotation")
        ax.set_xticks([0, 60, 120, 180])
        ax.set_xlim(-10, 190)
        util.clear_right(ax)
        util.clear_top(ax)
        util.outward_ticks(ax)
        ax.set_title("Stim %s" % stim)

    fig.set_figheight(8)
    fig.set_figwidth(10)

    plt.draw()
    plt.tight_layout()

    pths = [fig_path.joinpath("response_time_stimuli_%s.%s" % (key, ext))
            for ext in ('png', 'pdf')]
    for pth in pths:
        util.save(pth, close=False)
    return pths
def plot(results_path, fig_path):
    order = ['exp', 'oc', 'th', 'hc', 'bq', 'bqp']
    titles = {
        'exp': "Human",
        'oc': "Oracle",
        'th': "Threshold",
        'hc': "HC",
        'bq': "BQ (equal prior)",
        'bqp': "BQ (unequal prior)"
    }

    colors = {
        'same': [ 0.16339869,  0.4449827 ,  0.69750096],
        'flipped': [ 0.72848904,  0.1550173 ,  0.19738562]
    }

    time_results = pd.read_csv(
        results_path.joinpath("theta_time.csv"))
    acc_results = pd.read_csv(
        results_path.joinpath("theta_accuracy.csv"))

    fig, axes = plt.subplots(2, len(order), sharex=True)
    for i, key in enumerate(order):
        ax = axes[0, i]
        df = time_results.groupby('model').get_group(key)

        for flipped, stats in df.groupby('flipped'):
            if key == 'exp':
                median = stats['median'] / 1000.
                lower = (stats['median'] - stats['lower']) / 1000.
                upper = (stats['upper'] - stats['median']) / 1000.
            else:
                median = stats['median']
                lower = stats['median'] - stats['lower']
                upper = stats['upper'] - stats['median']

            ax.errorbar(
                stats['modtheta'], median,
                yerr=[lower, upper], lw=3,
                color=colors[flipped],
                ecolor=colors[flipped])

        ax.set_xticks(np.arange(0, 200, 30))
        ax.set_xlim(-10, 190)

        ax.set_title(titles[key], fontsize=14)

        if key == 'exp':
            ax.set_ylabel("Response time", fontsize=14)
        else:
            ax.set_ylabel("# actions", fontsize=14)

    util.sync_ylims(axes[0, order.index('bq')], axes[0, order.index('bqp')])

    for i, key in enumerate(order):
        ax = axes[1, i]
        df = acc_results.groupby('model').get_group(key)

        for flipped, stats in df.groupby('flipped'):
            lower = stats['median'] - stats['lower']
            upper = stats['upper'] - stats['median']
            ax.errorbar(
                stats['modtheta'], stats['median'],
                yerr=[lower, upper], lw=3,
                color=colors[flipped],
                ecolor=colors[flipped])

        ax.set_xlim(-10, 190)
        ax.set_ylim(25, 105)
        ax.set_xticks(np.arange(0, 200, 30))
        ax.set_xlabel("Rotation", fontsize=14)

        ax.set_ylabel("Accuracy", fontsize=14)

    for ax in axes.flat:
        util.clear_right(ax)
        util.clear_top(ax)
        util.outward_ticks(ax)

    p0 = plt.Rectangle(
        (0, 0), 1, 1,
        fc=colors['same'],
        ec=colors['same'])
    p1 = plt.Rectangle(
        (0, 0), 1, 1,
        fc=colors['flipped'],
        ec=colors['flipped'])

    leg = axes[1, 1].legend(
        [p0, p1], ["\"same\" pairs", "\"flipped\" pairs"],
        numpoints=1, fontsize=12,
        loc='lower center',
        title='Stimuli')
    frame = leg.get_frame()
    frame.set_edgecolor('#FFFFFF')

    util.sync_ylabel_coords(axes.flat, -0.175)

    fig.set_figheight(4)
    fig.set_figwidth(18)

    plt.draw()
    plt.tight_layout()
    plt.subplots_adjust(wspace=0.4)

    pths = [fig_path.joinpath("response_time_accuracy.%s" % ext)
            for ext in ('png', 'pdf')]
    for pth in pths:
        util.save(pth, close=False)
    return pths
Exemple #7
0
def plot(results_path, fig_path):
    order = ['exp', 'th', 'bqp']
    titles = {
        'exp': "Human",
        'oc': "Oracle",
        'th': "Threshold",
        'hc': "HC",
        'bq': "BQ (equal prior)",
        'bqp': "BQ (unequal prior)"
    }

    colors = {
        'same': 'r',
        'flipped': 'b'
    }

    means = pd.read_csv(
        results_path.joinpath("theta_time_stimulus.csv"))\
        .set_index(['stimulus', 'flipped', 'model'])\
        .groupby(level='stimulus').get_group(2)

    fig, axes = plt.subplots(1, len(order), sharex=True)
    for i, key in enumerate(order):
        ax = axes[i]
        df = means.groupby(level='model').get_group(key)

        for flipped, stats in df.groupby(level='flipped'):
            if key == 'exp':
                median = stats['median'] / 1000.
                lower = (stats['median'] - stats['lower']) / 1000.
                upper = (stats['upper'] - stats['median']) / 1000.
            else:
                median = stats['median']
                lower = stats['median'] - stats['lower']
                upper = stats['upper'] - stats['median']

            ax.errorbar(
                stats['modtheta'], median,
                yerr=[lower, upper], lw=3,
                color=colors[flipped],
                ecolor=colors[flipped])

        ax.set_xticks(np.arange(0, 200, 30))
        ax.set_xlim(-10, 190)
        ax.set_xlabel("Rotation")
        ax.set_title(titles[key], fontsize=14)

        if key == 'exp':
            ax.set_ylabel("Response time", fontsize=14)
        else:
            ax.set_ylabel("Number of actions", fontsize=14)

    # util.sync_ylims(axes[order.index('bq')], axes[order.index('bqp')])

    for ax in axes.flat:
        util.clear_right(ax)
        util.clear_top(ax)
        util.outward_ticks(ax)
        ax.set_axis_bgcolor('0.95')

    p0 = plt.Rectangle(
        (0, 0), 1, 1,
        fc=colors['same'],
        ec=colors['same'])
    p1 = plt.Rectangle(
        (0, 0), 1, 1,
        fc=colors['flipped'],
        ec=colors['flipped'])

    leg = axes[0].legend(
        [p0, p1], ["same", "flipped"],
        numpoints=1, fontsize=12,
        loc='lower right')
    frame = leg.get_frame()
    frame.set_edgecolor('#FFFFFF')

    util.sync_ylabel_coords(axes.flat, -0.175)

    fig.set_figheight(3)
    fig.set_figwidth(9)

    plt.draw()
    plt.tight_layout()
    plt.subplots_adjust(wspace=0.4)

    pths = [fig_path.joinpath("response_time_stimulus.%s" % ext)
            for ext in ('png', 'pdf')]
    for pth in pths:
        util.save(pth, close=False)
    return pths
def plot(results_path, fig_path):
    keys = ['exp', 'oc', 'th', 'hc', 'bq', 'bqp']
    corrs = pd.read_csv(results_path.joinpath("theta_accuracy_corrs.csv"))\
              .set_index(['model', 'flipped'])\
              .unstack('flipped')\
              .reindex(keys)

    fig, ax = plt.subplots()
    width = 1
    offset = width * 5 / 2.
    colors = {
        'same': '#ff5555',
        'flipped': '#5555ff'
    }
    titles = {
        'exp': "Human",
        'oc': "Oracle",
        'th': "Threshold",
        'hc': "HC",
        'bq': "BQ\n(equal)",
        'bqp': "BQ\n(unequal)"
    }

    order = ['same', 'flipped']
    for i, flipped in enumerate(order):
        y = corrs.xs(flipped, axis=1, level='flipped')
        median = y['median']
        lerr = median - y['lower']
        uerr = y['upper'] - median
        ax.bar(
            i * width + np.arange(len(median)) * offset,
            -median,
            yerr=[-uerr, -lerr],
            color=colors[flipped],
            ecolor='k',
            width=width,
            edgecolor='none',
            capsize=0)

    ax.set_ylim(0, 1)
    ax.set_xlim(-width / 2., len(median) * offset)
    ax.set_xticks(np.arange(len(median)) * offset + width)
    ax.set_xticklabels([titles[key] for key in keys], fontsize=10)

    util.clear_right(ax)
    util.clear_top(ax)
    util.outward_ticks(ax)

    ax.set_ylabel(r"Spearman correlation ($r_s$)", fontsize=14)

    p0 = plt.Rectangle(
        (0, 0), 1, 1,
        fc=colors['same'],
        ec=colors['same'])
    p1 = plt.Rectangle(
        (0, 0), 1, 1,
        fc=colors['flipped'],
        ec=colors['flipped'])

    leg = ax.legend(
        [p0, p1], ["\"same\" pairs", "\"flipped\" pairs"],
        numpoints=1, fontsize=12,
        loc='upper right',
        bbox_to_anchor=(1, 1.05))
    frame = leg.get_frame()
    frame.set_facecolor('0.9')
    frame.set_edgecolor('#FFFFFF')

    fig.set_figwidth(5)
    fig.set_figheight(3)

    plt.draw()
    plt.tight_layout()

    pths = [fig_path.joinpath("theta_accuracy_corrs.%s" % ext)
            for ext in ('png', 'pdf')]
    for pth in pths:
        util.save(pth, close=False)
    return pths
Exemple #9
0
def plot(results_path, fig_path):
    order = ['oc', 'th', 'hc', 'bq', 'bqp']
    titles = {
        'oc': "Oracle",
        'th': "Threshold",
        'hc': "HC",
        'bq': "BQ (equal prior)",
        'bqp': "BQ (unequal prior)"
    }

    results = pd.read_csv(
        results_path.joinpath("response_time_means.csv"))\
        .set_index(['stimulus', 'theta', 'flipped', 'model'])['median']\
        .groupby(level='model')\
        .apply(util.zscore)\
        .unstack('model')

    corrs = pd.read_csv(
        results_path.joinpath("response_time_corrs.csv"))\
        .set_index(['model', 'flipped'])\
        .stack()\
        .unstack(['model', 'flipped'])\
        .xs('all', level='flipped', axis=1)

    fig, axes = plt.subplots(1, len(order), sharey=True, sharex=True)

    for i, key in enumerate(order):
        ax = axes[i]
        xmean = results[key]
        ymean = results['exp']
        corr = util.report_pearson.format(**dict(corrs[key]))

        ax.plot([-4, 4], [-4, 4], ls='--', color='#666666')
        ax.plot(xmean, ymean, '.', alpha=0.9, color='k')

        ax.set_xticks([])
        ax.set_yticks([])

        ax.set_title(titles[key], fontsize=14)
        ax.set_xlabel(corr, fontsize=14)
        util.clear_right(ax)
        util.clear_top(ax)
        util.outward_ticks(ax)

        ax.set_axis_bgcolor('0.95')

    util.sync_xlims(axes[order.index('bq')], axes[order.index('bqp')])

    axes[0].set_xlim(-4, 4)
    axes[0].set_ylim(-4, 4)
    axes[0].set_ylabel("Human", fontsize=14)

    fig.set_figheight(2.5)
    fig.set_figwidth(16)
    plt.draw()
    plt.tight_layout()

    plt.subplots_adjust(wspace=0.1, bottom=0.2, top=0.9)

    pths = [fig_path.joinpath("response_time_scatters.%s" % ext)
            for ext in ('png', 'pdf')]
    for pth in pths:
        util.save(pth, close=False)
    return pths
def plot(results_path, fig_path):
    keys = ['exp', 'oc', 'th', 'hc', 'bq', 'bqp']

    human = pd.read_csv(results_path.joinpath("human_corrs.csv"))\
              .set_index('measure')
    human['flipped'] = 'all'

    time = pd.read_csv(results_path.joinpath("response_time_corrs.csv"))
    time = time.append(human.xs('time'))\
               .set_index(['model', 'flipped'])\
               .unstack('flipped')\
               .reindex(keys)

    acc = pd.read_csv(results_path.joinpath("accuracy_corrs.csv"))
    acc = acc.append(human.xs('accuracy'))\
             .set_index(['model', 'flipped'])\
             .unstack('flipped')\
             .reindex(keys)

    fig, ax = plt.subplots()
    width = 1
    offset = width * 5 / 2.
    titles = {
        'exp': "Human",
        'oc': "Oracle",
        'th': "Threshold",
        'hc': "HC",
        'bq': "BQ\n(equal)",
        'bqp': "BQ\n(unequal)"
    }

    colors = ['#55cc77', '#cc55aa']

    y = time.xs('all', axis=1, level='flipped')
    median = y['median']
    lerr = median - y['lower']
    uerr = y['upper'] - median
    ax.bar(
        np.arange(len(median)) * offset,
        median,
        yerr=[lerr, uerr],
        color=colors[0],
        ecolor='k',
        width=width,
        edgecolor='none',
        capsize=0)

    y = acc.xs('all', axis=1, level='flipped')
    median = y['median']
    lerr = median - y['lower']
    uerr = y['upper'] - median
    ax.bar(
        width + np.arange(len(median)) * offset,
        median,
        yerr=[lerr, uerr],
        color=colors[1],
        ecolor='k',
        width=width,
        edgecolor='none',
        capsize=0)

    ax.set_ylim(0, 1)
    ax.set_xlim(-width / 2., len(median) * offset)
    ax.set_xticks(np.arange(len(median)) * offset + width)
    ax.set_xticklabels([titles[key] for key in keys], fontsize=10)

    util.clear_right(ax)
    util.clear_top(ax)
    util.outward_ticks(ax)

    ax.set_ylabel(r"Pearson correlation ($r$)", fontsize=14)

    p0 = plt.Rectangle(
        (0, 0), 1, 1,
        fc=colors[0],
        ec=colors[0])
    p1 = plt.Rectangle(
        (0, 0), 1, 1,
        fc=colors[1],
        ec=colors[1])

    leg = ax.legend(
        [p0, p1], ["response time", "accuracy"],
        numpoints=1, fontsize=12,
        loc='upper right',
        bbox_to_anchor=(1, 1.05))
    frame = leg.get_frame()
    frame.set_facecolor('0.9')
    frame.set_edgecolor('#FFFFFF')

    fig.set_figwidth(5)
    fig.set_figheight(3)

    plt.draw()
    plt.tight_layout()

    pths = [fig_path.joinpath("human_model_corrs.%s" % ext)
            for ext in ('png', 'pdf')]
    for pth in pths:
        util.save(pth, close=False)
    return pths