Commit 81f0ca95 authored by Rivera, Dario Cuevas's avatar Rivera, Dario Cuevas

Results finalized in the paper. Changed some plots.

Version sent to Stefan.
parent 3777d7d7
No preview for this file type
This diff is collapsed.
article/images/figure_10.png

487 KB | W: | H:

article/images/figure_10.png

328 KB | W: | H:

article/images/figure_10.png
article/images/figure_10.png
article/images/figure_10.png
article/images/figure_10.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -29,7 +29,7 @@ plt.rcdefaults()
SAVE_FIGS = True
FIG_DIR = '../article/images/'
COLORS = np.array(['#463f3a', '#d5a021', '#5a845a', '#baaea7'])
COLORS = np.array(['#463f3a', '#d5a021', '#5a845a', '#baaea7', '#586ba4', '#006e90', '#78c091'])
BH_COLORS = np.array(['#8dd3c7', '#bebada', '#fb8072', '#b3de69', '#80b1d3'])
TYPE_TREND = 'count'
......@@ -288,14 +288,15 @@ def figure_8_single_vs_sequential(fignum=8, save=SAVE_FIGS):
'with': data_with,
'no': data_no}
fig = plt.figure(fignum, figsize=(5, 5), clear=True)
outer_grid = gs.GridSpec(3, 1, figure=fig, height_ratios=[8, 8, 1])
mags = {'hyperbolic': gs.GridSpecFromSubplotSpec(1, 2, outer_grid[0]),
'sigmoid': gs.GridSpecFromSubplotSpec(1, 3, outer_grid[1])}
outer_grid = gs.GridSpec(3, 1, figure=fig, height_ratios=[8, 1, 8])
mags = {'hyperbolic': gs.GridSpecFromSubplotSpec(1, 2, outer_grid[0])}
low_axes = [fig.add_subplot(one_gs)
for one_gs in gs.GridSpecFromSubplotSpec(1, 2, outer_grid[2])]
varnames = {'hyperbolic': ('kappa_prob_mean', 'kappa_eff_mean'),
'sigmoid': ('kappa_prob_mean', 'eff_slope_mean',
'eff_intercept_mean')}
categories = re.good_bad_ugly()
categories = re.good_bad_ugly()
participants = np.unique(list(categories['late'])
+ list(categories['early']))
......@@ -303,7 +304,7 @@ def figure_8_single_vs_sequential(fignum=8, save=SAVE_FIGS):
participants = participants[participants != 1034]
abc = ('(A)', '(B)')
titles = [[r'$\kappa_p$', r'$\kappa_e$'], [r'$\kappa_p$', '$m$', r'$x_0$']]
for ix_agent, agent_subtype in enumerate(('hyperbolic', 'sigmoid')):
for ix_agent, agent_subtype in enumerate(('hyperbolic', )):
for ix_var, varname in enumerate(varnames[agent_subtype]):
axis = plt.Subplot(fig, mags[agent_subtype][ix_var])
if ix_var == 0:
......@@ -325,9 +326,10 @@ def figure_8_single_vs_sequential(fignum=8, save=SAVE_FIGS):
axis.scatter(x_values[ix_point], points[ix_point],
color=colors[ix_point], zorder=90,
s=3)
axis.plot(x_values, points, color=colors[-1], zorder=1,
axis.plot(x_values, points, color=colors[3], zorder=1,
linewidth=0.5)
axis = fig.add_subplot(outer_grid[2])
_figure_8_diff_fitting(low_axes, colors[4:], titles[0])
axis = fig.add_subplot(outer_grid[1])
_figure_legend(axis, colors[:3], [
'Single-trial', 'Chained', 'Independent'])
fig.tight_layout()
......@@ -337,6 +339,56 @@ def figure_8_single_vs_sequential(fignum=8, save=SAVE_FIGS):
plt.savefig(FIG_DIR + '/figure_{}.png'.format(fignum), dpi=600)
def _figure_8_diff_fitting(axes, colors, titles):
"""Plots histograms for the difference between parameter estimations
between the data sets in --comps--.
Parameters
----------
comps : str or array of strings
String or list of string denoting which comparisons to plot. Must be
combinations of 's', 'i' and 'c', for single-trial, independent and
chained, respectively. For example, 'si' will compare single-trial
and independent fitting, using the independent as the reference
(i.e. (i - s) / i). 'is' will use single-trial as a reference. Lists
can be passed, e.g. ['si', 'sc'].
"""
comps = ['sc', 'si', 'ci']
varnames = ['kappa_prob', 'kappa_eff']
if isinstance(comps, str):
comps = [comps]
all_elements = ''.join(comps)
data = {}
if 's' in all_elements:
with open('./inferred_with_priors.pi', 'rb') as mafi:
data['s'] = pickle.load(mafi).query('exp_type == "single"')
if 'i' in all_elements:
with open('./inferred_no_priors.pi', 'rb') as mafi:
data['i'] = pickle.load(mafi)
if 'c' in all_elements:
with open('./inferred_with_priors.pi', 'rb') as mafi:
data['c'] = pickle.load(mafi).query('exp_type == "sequential"')
restrictions = {'agent_subtype': ['hyperbolic'],
'compound': [('stack', 'stack')]}
diffs = {}
for ix_comp, comp in enumerate(comps):
diffs[comp] = re.diff_fitting(data[comp[0]], data[comp[1]],
restrictions=restrictions,)
diffs = pd.concat(diffs, names=['comp']).reset_index(0)
for ix_var, varname in enumerate(varnames):
sns.boxplot(x='comp', y=varname, data=diffs, ax=axes[ix_var],
palette=colors)
axes[ix_var].set_title(titles[ix_var])
axes[ix_var].set_xlabel('')
if ix_var == 0:
ylabel = '(B)\nRelative difference'
else:
ylabel = ''
axes[ix_var].set_ylabel(ylabel)
def figure_9_mean_effort(fignum=9, save=SAVE_FIGS, panda=None):
"""Figure which compares the overall probability of effort for
the sequential data, between experimental data and the inferred
......@@ -488,10 +540,10 @@ def figure_10_eff_vs_ratio(fignum=10, save=SAVE_FIGS, panda=None):
# fig.tight_layout()
# plt.draw()
# plt.show(block=False)
# if save:
# plt.savefig(FIG_DIR + '/figure_{}.png'.format(fignum), dpi=600)
if save:
plt.savefig(FIG_DIR + '/figure_{}.png'.format(fignum), dpi=600)
# return panda, inferred
return panda, inferred
def table_2_inferred_parameters():
......
......@@ -11,6 +11,7 @@ import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import pymc3 as pm
import seaborn as sns
from utilities.plots import calc_subplots
......@@ -236,50 +237,3 @@ def good_bad_ugly(ax=None, fignum=4, colors=None, **good_bad_ugly_kwargs):
plt.show(block=False)
def diff_fitting(comps=None, axes=None, fignum=5):
"""Plots histograms for the difference between parameter estimations
between the data sets in --comps--.
Parameters
----------
comps : str or array of strings
String or list of string denoting which comparisons to plot. Must be
combinations of 's', 'i' and 'c', for single-trial, independent and
chained, respectively. For example, 'si' will compare single-trial
and independent fitting, using the independent as the reference
(i.e. (i - s) / i). 'is' will use single-trial as a reference. Lists
can be passed, e.g. ['si', 'sc'].
"""
if comps is None:
comps = ['sc', 'si', 'ci']
if isinstance(comps, str):
comps = [comps]
num_comps = len(comps)
all_elements = ''.join(comps)
data = {}
if 's' in all_elements:
with open('./inferred_with_priors.pi', 'rb') as mafi:
data['s'] = pickle.load(mafi).query('exp_type == "single"')
if 'i' in all_elements:
with open('./inferred_no_priors.pi', 'rb') as mafi:
data['i'] = pickle.load(mafi)
if 'c' in all_elements:
with open('./inferred_with_priors.pi', 'rb') as mafi:
data['c'] = pickle.load(mafi).query('exp_type == "sequential"')
restrictions = {'agent_subtype': ['hyperbolic'], 'compound': [('stack', 'stack')]}
if axes is None:
subplots = calc_subplots(num_comps)
fig = plt.figure(fignum)
fig.clear()
axes = fig.subplots(*subplots, squeeze=False)
axes = axes.reshape(-1)
diffs = {}
for ix_comp, comp in enumerate(comps):
diffs[comp] = re.diff_fitting(data[comp[0]], data[comp[1]],
restrictions=restrictions,)
axes[ix_comp].hist(diffs[comp]['kappa_prob'])
axes[ix_comp].set_title(comp)
plt.draw()
plt.show(block=False)
return diffs
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment