def test_reconstruct(): """Test Tracker objects reconstruction""" # test with one TrackerUD with ExperimentController(*std_args, **std_kwargs) as ec: tr = TrackerUD(ec, 1, 1, 3, 1, 5, np.inf, 3) while not tr.stopped: tr.respond(np.random.rand() < tr.x_current) tracker = reconstruct_tracker(ec.data_fname)[0] assert_true(tracker.stopped) tracker.x_current # test with one TrackerBinom with ExperimentController(*std_args, **std_kwargs) as ec: tr = TrackerBinom(ec, .05, .5, 10) while not tr.stopped: tr.respond(True) tracker = reconstruct_tracker(ec.data_fname)[0] assert_true(tracker.stopped) tracker.x_current # tracker not stopped with ExperimentController(*std_args, **std_kwargs) as ec: tr = TrackerUD(ec, 1, 1, 3, 1, 5, np.inf, 3) tr.respond(np.random.rand() < tr.x_current) assert_true(not tr.stopped) assert_raises(ValueError, reconstruct_tracker, ec.data_fname) # test with dealer with ExperimentController(*std_args, **std_kwargs) as ec: tr = [TrackerUD(ec, 1, 1, 3, 1, 5, np.inf, 3) for _ in range(3)] td = TrackerDealer(ec, tr) for _, x_current in td: td.respond(np.random.rand() < x_current) dealer = reconstruct_dealer(ec.data_fname)[0] assert_true(all(td._x_history == dealer._x_history)) assert_true(all(td._tracker_history == dealer._tracker_history)) assert_true(all(td._response_history == dealer._response_history)) assert_true(td.shape == dealer.shape) assert_true(td.trackers.shape == dealer.trackers.shape) # no tracker/dealer in file with ExperimentController(*std_args, **std_kwargs) as ec: ec.identify_trial(ec_id='one', ttl_id=[0]) ec.start_stimulus() ec.write_data_line('misc', 'trial one') ec.stop() ec.trial_ok() ec.write_data_line('misc', 'end') assert_raises(ValueError, reconstruct_tracker, ec.data_fname) assert_raises(ValueError, reconstruct_dealer, ec.data_fname)
for ss, level in td: # Get information of which trial type is next and what the level is at # that time from TrackerDealer td.respond(rng_human.rand() < sigmoid( level - true_thresh[sum(ss)], lower=chance, slope=slope)) ############################################################################### # Reconstructing the TrackerDealer Object # --------------------------------------- # The TrackerDealer object has many built in analysis functions that are can # only be access through the object itself (not the log files alone). By using # :func:`expyfun.io.reconstruct_dealer`, the object can be recreated such that # the analysis functions are accessible. Note that the function always returns # a list of objects. Similar reconstructions of single trackers can be done # with :func:`expyfun.io.reconstruct_tracker`. td_tab = reconstruct_dealer(ec.data_fname)[0] ############################################################################## # Plotting the Results # --------------------------- axes = plt.subplots(2, 1)[1] for i in [0, 1]: fig, ax, lines = td_tab.trackers.ravel()[i].plot(ax=axes[i], n_skip=4) ax.legend(loc='best') ax.set_title('Adaptive track of model human trial type {} (true threshold ' 'is {})'.format(i + 1, true_thresh[i])) fig.tight_layout()
'027', '029', '030', '031', '032', '034', '036', '037', '038', '039', '042', '043'] pvals = [] d_prime = [] per_cor = [] diff = [] diff_per = [] responses = [] biases = [] ind = 1 for subject, fname in zip(subjects, fnames): print(subject) # %% read, reformat data td = reconstruct_dealer(path + fname + '.tab')[0] conditions = [1.25, 2.5, 5, 10, 20] x = [np.concatenate([-td.trackers.flat[2*ii].x, td.trackers.flat[2*ii +1].x]) for ii in range(len(conditions) * 2)] responses.append([np.concatenate([np.expand_dims(np.asarray(td.trackers.flat[2* ii].responses, dtype=bool), 1), np.expand_dims(np.asarray(td.trackers.flat[2 * ii + 1].responses, dtype=bool), 1)], 1) for ii in range(len(conditions * 2))]) per_cor.append(get_per_correct(responses[-1])) percent = [per_cor[-1][:5], per_cor[-1][5:]] # %% do fits data = np.array(percent) / 100. lower = 0.5 upper = 1 conditions = 20 * np.log10(conditions)
for ss, level in td: # Get information of which trial type is next and what the level is at # that time from TrackerDealer td.respond(rng_human.rand() < sigmoid(level - true_thresh[sum(ss)], lower=chance, slope=slope)) ############################################################################### # Reconstructing the TrackerDealer Object # --------------------------------------- # The TrackerDealer object has many built in analysis functions that are can # only be access through the object itself (not the log files alone). By using # :func:`expyfun.io.reconstruct_dealer`, the object can be recreated such that # the analysis functions are accessible. Note that the function always returns # a list of objects. Similar reconstructions of single trackers can be done # with :func:`expyfun.io.reconstruct_tracker`. td_tab = reconstruct_dealer(ec.data_fname)[0] ############################################################################## # Plotting the Results # --------------------------- axes = plt.subplots(2, 1)[1] for i in [0, 1]: fig, ax, lines = td_tab.trackers.ravel()[i].plot(ax=axes[i], n_skip=4) ax.legend(loc='best') ax.set_title('Adaptive track of model human trial type {} (true threshold ' 'is {})'.format(i + 1, true_thresh[i])) fig.tight_layout()