コード例 #1
0
def assert_hmfc(presses, targets, foils, hmfco, rts, tmin=0.1, tmax=0.6):
    """Assert HMFC is correct."""
    out = ea.press_times_to_hmfc(presses, targets, foils, tmin, tmax)
    assert_array_equal(out, hmfco)
    out = ea.press_times_to_hmfc(presses, targets, foils, tmin, tmax)
    assert_array_equal(out, hmfco)
    out = ea.press_times_to_hmfc(presses, targets, foils, tmin, tmax,
                                 return_type=['counts', 'rts'])
    assert_array_equal(out[0][:4:2], list(map(len, out[1])))
    assert_array_equal(out[0], hmfco)
    assert_rts_equal(out[1], rts)
    # reversing targets and foils
    out = ea.press_times_to_hmfc(presses, foils, targets, tmin, tmax,
                                 return_type=['counts', 'rts'])
    assert_array_equal(out[0], np.array(hmfco)[[2, 3, 0, 1, 4]])
    assert_rts_equal(out[1], rts[::-1])
コード例 #2
0
def assert_hmfc(presses, targets, foils, hmfco, rts, tmin=0.1, tmax=0.6):
    """Assert HMFC is correct."""
    out = ea.press_times_to_hmfc(presses, targets, foils, tmin, tmax)
    assert_array_equal(out, hmfco)
    out = ea.press_times_to_hmfc(presses, targets, foils, tmin, tmax)
    assert_array_equal(out, hmfco)
    out = ea.press_times_to_hmfc(presses,
                                 targets,
                                 foils,
                                 tmin,
                                 tmax,
                                 return_type=['counts', 'rts'])
    assert_array_equal(out[0][:4:2], list(map(len, out[1])))
    assert_array_equal(out[0], hmfco)
    assert_rts_equal(out[1], rts)
    # reversing targets and foils
    out = ea.press_times_to_hmfc(presses,
                                 foils,
                                 targets,
                                 tmin,
                                 tmax,
                                 return_type=['counts', 'rts'])
    assert_array_equal(out[0], np.array(hmfco)[[2, 3, 0, 1, 4]])
    assert_rts_equal(out[1], rts[::-1])
コード例 #3
0
def test_presses_to_hmfc():
    """Test converting press times to HMFC"""
    # Simple example
    targets = [0., 1.]
    foils = [0.5, 1.5]
    tmin, tmax = 0.1, 0.6

    presses = [0.25, 1.25]
    hmfco = [2, 0, 0, 2, 0]
    out = ea.press_times_to_hmfc(presses, targets, foils, tmin, tmax)
    assert_array_equal(out, hmfco)

    presses = [0.75, 1.601]  # just past the boundary
    hmfco = [0, 2, 2, 0, 0]
    out = ea.press_times_to_hmfc(presses, targets, foils, tmin, tmax)
    assert_array_equal(out, hmfco)

    presses = [0.75, 1.55]  # smaller than tmin
    hmfco = [1, 1, 1, 1, 0]
    out = ea.press_times_to_hmfc(presses, targets, foils, tmin, tmax)
    assert_array_equal(out, hmfco)

    presses = [0.75, 2.11]  # greater than tmax
    hmfco = [0, 2, 1, 1, 1]
    out = ea.press_times_to_hmfc(presses, targets, foils, tmin, tmax)
    assert_array_equal(out, hmfco)

    # A complicated example
    targets = [0, 2, 3]
    foils = [1, 4]
    tmin, tmax = 0., 0.5

    presses = [0.1, 1.2, 1.3, 2.1, 2.7, 5.]  # multiple presses to same targ
    hmfco = [2, 1, 1, 1, 2]

    out = ea.press_times_to_hmfc(presses, targets, foils, tmin, tmax)
    assert_array_equal(out, hmfco)

    presses = []  # no presses
    hmfco = [0, 3, 0, 2, 0]
    out = ea.press_times_to_hmfc(presses, targets, foils, tmin, tmax)
    assert_array_equal(out, hmfco)

    presses = [-1, 7, 8]  # all errant presses
    hmfco = [0, 3, 0, 2, 3]
    out = ea.press_times_to_hmfc(presses, targets, foils, tmin, tmax)
    assert_array_equal(out, hmfco)

    # Bad inputs
    assert_raises(ValueError, ea.press_times_to_hmfc, presses, targets, foils,
                  tmin, 1.1)
コード例 #4
0
 def run_trial(ti, feedback=False):
     """Run a trial, optionally with feedback"""
     samples = read_wav(op.join(stim_dir, p['stim_names'][ti]))[0]
     ec.load_buffer(samples)
     id_ = decimals_to_binary(p['cond_mat'][ti], [1, 2, 2, 1])
     ec.identify_trial(ec_id=id_, ttl_id=id_, el_id=id_)
     ec.listen_presses()
     t0 = ec.start_stimulus(flip=False)
     wait_dur = p['trial_durs'][ti]
     wait_dur -= p['inter_trial_dur'] - 0.5 if feedback else 0
     presses = ec.wait_for_presses(wait_dur, relative_to=t0)
     ec.stop()
     ec.trial_ok()
     correct = True
     if feedback:
         press_times = [pp[1] for pp in presses]
         p['targ_pos'][ti][0]
         t = p['stim_times'][p['cond_mat'][ti][3]][2:]
         targ = t[p['targ_pos'][ti][0].astype(bool)]
         foil = t[p['targ_pos'][ti][1].astype(bool)]
         hmfc = press_times_to_hmfc(press_times, targ, foil, tmin, tmax)
         correct = (hmfc[1] == hmfc[2] == hmfc[4] == 0)
         if correct:
             msg = 'Correct!\n\n'
         else:
             msg = 'Incorrect:\n'
             if hmfc[1] > 0:
                 pl = 's' if hmfc[1] != 1 else ''
                 msg += '\n    - Missed %s target "O"%s\n' % (hmfc[1], pl)
             x = hmfc[2] + hmfc[4]
             if x > 0:
                 pl = 's' if x != 1 else ''
                 msg += '\n    - Pressed to %s non-target "O"%s' % (x, pl)
         ec.screen_prompt(msg + continue_msg, color=fcolor)
         fix.draw()
         ec.flip()
     return correct
コード例 #5
0
 assert np.all(
     (this_trial_df['attn'] == 'maintain') == maint_bool[trial_order])
 # add timing slots
 this_trial_df['slot_codes'] = slot_codes[trial_order].tolist()
 this_trial_df['slot_times'] = \
     (this_trial_df['trial_onset'].values[:, None] + stim_times).tolist()
 # add HMFC at trial level
 for letter in 'hmfc':
     this_trial_df[letter] = -1
 for row in this_trial_df.itertuples(index=False):
     targets = np.array(row.slot_times)[np.array(row.slot_codes) == 't']
     foils = np.array(row.slot_times)[np.array(row.slot_codes) == 'f']
     hmfco = np.array(
         press_times_to_hmfc(row.presses,
                             targets,
                             foils,
                             tmin=rt_min,
                             tmax=rt_max))
     hmfc = hmfco[:4].copy()
     hmfc[2] += hmfco[4]  # "other" presses treated as false alm.
     row_locator = (this_trial_df['seq_trial'] == row.seq_trial)
     this_trial_df.loc[row_locator, list('hmfc')] = hmfc
 assert np.all(this_trial_df[list('hmfc')].values >= 0)
 # make longform (1 row per slot)
 code_series = this_trial_df[['trial', 'slot_codes']].set_index('trial')
 time_series = this_trial_df[['trial', 'slot_times']].set_index('trial')
 slot_codes_df = spread_slots(code_series['slot_codes'], 'slot_code')
 slot_times_df = spread_slots(time_series['slot_times'], 'slot_onset')
 slots = pd.merge(slot_codes_df, slot_times_df, on=['trial', 'slot'])
 this_slots_df = this_trial_df.merge(slots, on='trial')
 # compute RTs