/
plots_fitexperiment_sequential.py
417 lines (363 loc) · 14.7 KB
/
plots_fitexperiment_sequential.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
#!/usr/bin/env python
# encoding: utf-8
import matplotlib.pyplot as plt
import numpy as np
import progress
import pycircstat
import scipy.stats as spst
import utils
import warnings
# plt.rcParams['font.size'] = 24
def _plot_kappa_mean_error(T_space, mean, yerror, ax=None, title='', **args):
'''
Main plotting function to show the evolution of Kappa.
'''
if ax is None:
f, ax = plt.subplots()
ax = utils.plot_mean_std_area(
T_space, mean, np.ma.masked_invalid(yerror).filled(0.0),
ax_handle=ax, linewidth=3, markersize=8, **args)
# ax.legend(prop={'size': 15}, loc='best')
if title:
ax.set_title('Kappa: %s' % title)
ax.set_xlim([0.9, T_space.max()+0.1])
ax.set_ylim([0.0, max(np.max(mean)*1.1, ax.get_ylim()[1])])
ax.set_xticks(range(1, T_space.max()+1))
ax.set_xticklabels(range(1, T_space.max()+1))
ax.get_figure().canvas.draw()
return ax
def _plot_emmixture_mean_error(T_space, mean, yerror, ax=None, title='',
**args):
'''
Main plotting function to show the evolution of an EM Mixture.
'''
if ax is None:
f, ax = plt.subplots()
utils.plot_mean_std_area(
T_space, mean, np.ma.masked_invalid(yerror).filled(0.0),
ax_handle=ax, linewidth=3, markersize=8, **args)
# ax.legend(prop={'size': 15}, loc='best')
if title:
ax.set_title('Mixture prop: %s' % title)
ax.set_xlim([0.9, T_space.max() + 0.1])
ax.set_ylim([0.0, 1.01])
ax.set_xticks(range(1, T_space.max()+1))
ax.set_xticklabels(range(1, T_space.max()+1))
ax.get_figure().canvas.draw()
return ax
class PlotsFitExperimentSequential(object):
"""
This class does plots akin to paper, but for the Sequential dataset.
"""
def __init__(self, fit_experiment_sequential,
do_histograms_errors_triangle=True,
do_mixtcurves_lasttrecall_fig6=True,
do_mixtcurves_collapsedpowerlaw_fig7=True,
):
self.fit_exp = fit_experiment_sequential
self.experiment_id = self.fit_exp.experiment_id
self.collapsed_em_fits = None
self.do_histograms_errors_triangle = do_histograms_errors_triangle
self.do_mixtcurves_lasttrecall_fig6 = do_mixtcurves_lasttrecall_fig6
self.do_mixtcurves_collapsedpowerlaw_fig7 = do_mixtcurves_collapsedpowerlaw_fig7
print "Doing Sequential plots for %s. \nHist %d, Fig6 %d, Fig7 %d" % (
self.experiment_id,
self.do_histograms_errors_triangle,
self.do_mixtcurves_lasttrecall_fig6,
self.do_mixtcurves_collapsedpowerlaw_fig7
)
def do_plots(self):
'''
Do all plots for that FitExperimentAllT.
These correspond to a particular experiment_id only, not multiple.
'''
if self.do_histograms_errors_triangle:
self.plots_histograms_errors_triangle()
if self.do_mixtcurves_lasttrecall_fig6:
self.plots_mixtcurves_lasttrecall_fig6()
if self.do_mixtcurves_collapsedpowerlaw_fig7:
self.plots_mixtcurves_collapsedpowerlaw_fig7()
def plots_histograms_errors_triangle(self, size=12):
'''
Histograms of errors, for all n_items/trecall conditions.
'''
# Do the plots
f, axes = plt.subplots(
ncols=self.fit_exp.T_space.size,
nrows=2*self.fit_exp.T_space.size,
figsize=(size, 2*size))
angle_space = np.linspace(-np.pi, np.pi, 51)
for n_items_i, n_items in enumerate(self.fit_exp.T_space):
for trecall_i, trecall in enumerate(self.fit_exp.T_space):
if trecall <= n_items:
print "\n=== N items: {}, trecall: {}".format(
n_items, trecall)
# Sample
self.fit_exp.setup_experimental_stimuli(n_items, trecall)
if 'samples' in self.fit_exp.get_names_stored_responses():
self.fit_exp.restore_responses('samples')
else:
self.fit_exp.sampler.force_sampling_round()
self.fit_exp.store_responses('samples')
responses, targets, nontargets = (
self.fit_exp.sampler.collect_responses())
# Targets
errors_targets = utils.wrap_angles(targets - responses)
utils.hist_angular_data(
errors_targets,
bins=angle_space,
# title='N=%d, trecall=%d' % (n_items, trecall),
norm='density',
ax_handle=axes[2*n_items_i, trecall_i],
pretty_xticks=False)
axes[2*n_items_i, trecall_i].set_ylim([0., 1.4])
axes[2*n_items_i, trecall_i].xaxis.set_major_locator(
plt.NullLocator())
axes[2*n_items_i, trecall_i].yaxis.set_major_locator(
plt.NullLocator())
# Nontargets
if n_items > 1:
errors_nontargets = utils.wrap_angles((
responses[:, np.newaxis] - nontargets).flatten())
utils.hist_angular_data(
errors_nontargets,
bins=angle_space,
# title='Nontarget %s N=%d' % (dataset['name'], n_items),
norm='density',
ax_handle=axes[2*n_items_i + 1, trecall_i],
pretty_xticks=False)
axes[2*n_items_i + 1, trecall_i].set_ylim([0., 0.3])
axes[2*n_items_i + 1, trecall_i].xaxis.set_major_locator(plt.NullLocator())
axes[2*n_items_i + 1, trecall_i].yaxis.set_major_locator(plt.NullLocator())
else:
axes[2*n_items_i, trecall_i].axis('off')
axes[2*n_items_i + 1, trecall_i].axis('off')
return axes
def plots_mixtcurves_lasttrecall_fig6(self,
num_repetitions=1,
use_cache=True,
use_sem=True,
size=6):
'''
Plots memory fidelity and mixture proportions for the last item
recall.
This reproduces Figure 6 in Gorgo 11.
'''
T_space = self.fit_exp.T_space
data_em_fits = self.fit_exp.get_data_em_fits()
model_em_fits = self.fit_exp.get_model_em_fits(
num_repetitions, use_cache)
if use_sem:
errorbars = 'sem'
else:
errorbars = 'std'
f, axes = plt.subplots(nrows=1, ncols=2, figsize=(12, 5))
# Memory fidelity last trecall
# Data
_plot_kappa_mean_error(
T_space,
data_em_fits['mean'][
'kappa'][:, 0],
data_em_fits[errorbars][
'kappa'][:, 0],
label="Data",
fmt="o-",
ax=axes[0])
# Model
_plot_kappa_mean_error(
T_space,
model_em_fits['mean'][
'kappa'][:, 0],
model_em_fits[errorbars][
'kappa'][:, 0],
label='Model',
fmt="o-",
ax=axes[0],
xlabel='items', ylabel='Memory fidelity $[rad^{-2}]$')
axes[0].legend(loc='upper right', bbox_to_anchor=(1., 1.))
# Mixture proportions last trecall
# Model
_plot_emmixture_mean_error(
T_space,
model_em_fits['mean'][
'mixt_target_tr'][:, 0],
model_em_fits[errorbars][
'mixt_target_tr'][:, 0],
label='Target',
fmt="o-",
ax=axes[1])
_plot_emmixture_mean_error(
T_space,
model_em_fits['mean'][
'mixt_nontargets_tr'][:, 0],
model_em_fits[errorbars][
'mixt_nontargets_tr'][:, 0],
label='Nontarget',
fmt="o-",
ax=axes[1])
_plot_emmixture_mean_error(
T_space,
model_em_fits['mean'][
'mixt_random_tr'][:, 0],
model_em_fits[errorbars][
'mixt_random_tr'][:, 0],
label='Random',
fmt="o-",
ax=axes[1],
xlabel='items', ylabel='Mixture proportions')
# Data
_plot_emmixture_mean_error(
T_space,
data_em_fits['mean'][
'mixt_target_tr'][:, 0],
data_em_fits[errorbars][
'mixt_target_tr'][:, 0],
label='Data target',
fmt="s--",
ax=axes[1])
_plot_emmixture_mean_error(
T_space,
data_em_fits['mean'][
'mixt_nontargets_tr'][:, 0],
data_em_fits[errorbars][
'mixt_nontargets_tr'][:, 0],
label='Data nontarget',
fmt="s--",
ax=axes[1])
_plot_emmixture_mean_error(
T_space,
data_em_fits['mean'][
'mixt_random_tr'][:, 0],
data_em_fits[errorbars][
'mixt_random_tr'][:, 0],
label='Data random',
fmt="s--",
ax=axes[1])
axes[1].legend(loc='upper left', bbox_to_anchor=(1., 1.))
f.suptitle('Fig 6: Last trecall')
f.canvas.draw()
return axes
def plots_mixtcurves_collapsedpowerlaw_fig7(self,
num_repetitions=1,
use_cache=True,
use_sem=True,
size=6):
'''
Plots memory fidelity and mixture proportions for all nitems, with
trecall on the x-axis.
This reproduces Figure 7 in Gorgo 11.
'''
T_space = self.fit_exp.T_space
data_em_fits = self.fit_exp.get_data_em_fits()
model_em_fits = self.fit_exp.get_model_em_fits(
num_repetitions, use_cache)
# Do the plot
if use_sem:
errorbars = 'sem'
else:
errorbars = 'std'
_, axes_data = plt.subplots(nrows=2, ncols=2, figsize=(10, 10))
_, axes_model = plt.subplots(nrows=2, ncols=2, figsize=(10, 10))
# Data
for nitems_i, nitems in enumerate(T_space):
# Memory fidelity
_plot_kappa_mean_error(
T_space[:nitems],
data_em_fits['mean'][
'kappa'][nitems_i, :nitems],
data_em_fits[errorbars][
'kappa'][nitems_i, :nitems],
label='%d items' % nitems,
xlabel='Serial order (reversed)',
fmt="o-",
zorder=7 - nitems,
ax=axes_data[0, 0])
axes_data[0, 0].set_ylim((0, 11))
# Mixture proportions
_plot_emmixture_mean_error(
T_space[:nitems],
data_em_fits['mean'][
'mixt_target_tr'][nitems_i, :nitems],
data_em_fits[errorbars][
'mixt_target_tr'][nitems_i, :nitems],
label='%d items' % nitems,
xlabel='Serial order (reversed)',
fmt="o-",
zorder=7 - nitems,
ax=axes_data[0, 1])
_plot_emmixture_mean_error(
T_space[:nitems],
data_em_fits['mean'][
'mixt_nontargets_tr'][nitems_i, :nitems],
data_em_fits[errorbars][
'mixt_nontargets_tr'][nitems_i, :nitems],
label='%d items' % nitems,
xlabel='Serial order (reversed)',
fmt="o-",
zorder=7 - nitems,
ax=axes_data[1, 0])
_plot_emmixture_mean_error(
T_space[:nitems],
data_em_fits['mean'][
'mixt_random_tr'][nitems_i, :nitems],
data_em_fits[errorbars][
'mixt_random_tr'][nitems_i, :nitems],
label='%d items' % nitems,
xlabel='Serial order (reversed)',
fmt="o-",
zorder=7 - nitems,
ax=axes_data[1, 1])
# Model
for nitems_i, nitems in enumerate(T_space):
# Memory fidelity
_plot_kappa_mean_error(
T_space[:nitems],
model_em_fits['mean'][
'kappa'][nitems_i, :nitems],
model_em_fits[errorbars][
'kappa'][nitems_i, :nitems],
label='%d items' % nitems,
xlabel='Serial order (reversed)',
fmt="o-",
zorder=7 - nitems,
ax=axes_model[0, 0])
axes_model[0, 0].set_ylim((0, 11))
# Mixture proportions
_plot_emmixture_mean_error(
T_space[:nitems],
model_em_fits['mean'][
'mixt_target_tr'][nitems_i, :nitems],
model_em_fits[errorbars][
'mixt_target_tr'][nitems_i, :nitems],
label='%d items' % nitems,
xlabel='Serial order (reversed)',
fmt="o-",
zorder=7 - nitems,
ax=axes_model[0, 1])
_plot_emmixture_mean_error(
T_space[:nitems],
model_em_fits['mean'][
'mixt_nontargets_tr'][nitems_i, :nitems],
model_em_fits[errorbars][
'mixt_nontargets_tr'][nitems_i, :nitems],
label='%d items' % nitems,
xlabel='Serial order (reversed)',
fmt="o-",
zorder=7 - nitems,
ax=axes_model[1, 0])
_plot_emmixture_mean_error(
T_space[:nitems],
model_em_fits['mean'][
'mixt_random_tr'][nitems_i, :nitems],
model_em_fits[errorbars][
'mixt_random_tr'][nitems_i, :nitems],
label='%d items' % nitems,
xlabel='Serial order (reversed)',
fmt="o-",
zorder=7 - nitems,
ax=axes_model[1, 1])
axes_data[0, 1].legend(loc='upper left', bbox_to_anchor=(1., 1.))
axes_model[0, 1].legend(loc='upper left', bbox_to_anchor=(1., 1.))
axes_data[0, 0].figure.canvas.draw()
axes_model[0, 0].figure.canvas.draw()
return axes_data, axes_model