def test_simulate_sample():
    dataDict = loadData.load_sim_data('tests/test_simdata/')
    x, y, dur_dat, im_dat, densities_dat, d_range = loadData.dataDict2vars(dataDict)

    kwargs_d = {"coupled_oms": True, "exponents":1}
    sw_args = ['subtractive', 'zero', 'off', "off", 'off', {'x': d_range[0], 'y': d_range[1]}, kwargs_d]
    sw_model = scenewalk_obj(*sw_args)
    chains_dict = np.load("tests/test_estimation/sample_dict.npy", allow_pickle=True).item()

    sim_id = sim.simulate_sample(dur_dat, im_dat, densities_dat, sw_model, chains_dict, "trial", start_loc="center", x_path=None, y_path=None, resample_durs=False)
    #sim_id = "sim_20191025-101400"
    sim_id = sim_id[4:]
    cwd = os.getcwd()
    folderPath = cwd + "/sim_%s" % sim_id

    simdataDict = loadData.load_sim_data(folderPath+'/')
    x_sim, y_sim, dur_sim, im_sim, _, _ = loadData.dataDict2vars(simdataDict)
    

    for s, o in zip([x_sim, y_sim, dur_sim, im_sim], [x, y, dur_dat, im_dat]):
        assert len(s) == len(o)
        assert type(s) == type(o)
        testsub = np.random.randint(len(o))
        assert len(s[testsub]) == len(o[testsub])
        assert type(s[testsub]) == type(o[testsub])
        testtrial = np.random.randint(len(o[testsub]))
        assert len(s[testsub][testtrial]) == len(o[testsub][testtrial])
        assert type(s[testsub][testtrial]) == type(o[testsub][testtrial])
    shutil.rmtree(folderPath)
Esempio n. 2
0
def test_contributing_fixs(inhib_method, att_map_init_type, shifts, exponents,
                           locdep_decay_switch, n_hist):

    dataDict = loadData.load_sim_data('tests/test_simdata/')
    x_sim, y_sim, dur_sim, _, densities, rng = loadData.dataDict2vars(dataDict)
    rng2 = {'x': rng[0], 'y': rng[1]}
    fix_dens = densities[0]

    lsw = lsw_model(inhib_method, att_map_init_type, shifts,
                    locdep_decay_switch, "off", rng2, {
                        "n_history": n_hist,
                        "exponents": exponents
                    })
    lsw.update_params(sw_params)

    _, hist_list = lsw.get_scanpath_likelihood(x_sim[0][0],
                                               y_sim[0][0],
                                               dur_sim[0][0],
                                               fix_dens,
                                               debug=True)

    n_normal = [i[0] for i in hist_list if i[0] == 'normal']
    n_chopped = [i[0] for i in hist_list if i[0] == 'chopped']
    assert len(n_normal) == n_hist
    assert len(n_chopped) == (len(x_sim[0][0]) - len(n_normal) - 1)
    triplets = [i[1] for i in hist_list if i[0] == 'chopped']
    n_triplets = [len(i) for i in triplets]
    assert (np.asarray(n_triplets) == n_hist).all
Esempio n. 3
0
def test_simulate_scanpath(inhib_method, att_map_init_type, shifts, exponents,
                           locdep_decay_switch):
    """Tests that simulated scanpaths the right type, range and length"""
    sw = sw_model(inhib_method, att_map_init_type, shifts, locdep_decay_switch,
                  "off", {
                      'x': (23, 100),
                      'y': (0, 90)
                  }, {"exponents": exponents})
    sw.update_params(sw_params)

    dataDict = loadData.load_sim_data('tests/test_simdata/')
    _, _, dur_sim, _, densities, _ = loadData.dataDict2vars(dataDict)
    fix_dens = densities[0]

    startpos = (np.sum((23, 100)) / 2, np.sum((0, 90)) / 2)
    x_path, y_path, avg_log_ll = sw.simulate_scanpath(dur_sim[0][0],
                                                      fix_dens,
                                                      startpos,
                                                      get_LL=True)
    assert len(x_path) == len(y_path) == len(dur_sim[0][0])
    assert (np.asarray(x_path) <= 100).all()
    assert (np.asarray(x_path) >= 23).all()
    assert (np.asarray(y_path) <= 90).all()
    assert (np.asarray(y_path) >= 0).all()
    assert x_path[0] == startpos[0]
    assert y_path[0] == startpos[1]
    assert isinstance(avg_log_ll, np.float128)
Esempio n. 4
0
def test_save2dict_by_subj():
    # setup a pretend data set
    dataDict = loadData.load_sim_data('tests/test_simdata/')
    x, y, dur, im, densities, _ = loadData.dataDict2vars(dataDict)

    def_args = OrderedDict({
        'omegaAttention': None,
        'omfrac': 10,
        'sigmaAttention': None,
        "sigmaInhib" : None,
        'gamma': None,
        #"lamb":None,
        'inhibStrength': 0.3,
        'zeta': None,
        'sigmaShift': None,
        'shift_size':None,
        'first_fix_OmegaAttention':1.5,
        'cb_sd_x':4,
        'cb_sd_y':3,
        'omega_prevloc_frac':10,
    })
    all_vp_list = list(range(len(im)))
    chains_list = [np.random.rand(3, 500, 7) for v in all_vp_list]
    utils.save2dict_by_subj(chains_list, all_vp_list, def_args, "tests/test_estimation/sample_dict.npy")

    vp_params = np.load("tests/test_estimation/sample_dict.npy", allow_pickle=True).item()
    assert isinstance(vp_params, dict)
    assert list(vp_params.keys()) == all_vp_list
    testsub = np.random.randint(0, len(all_vp_list))
    assert vp_params[testsub].keys() == def_args.keys()
    print(vp_params[testsub].values())
    assert any([isinstance(v, (list, np.ndarray)) for v in vp_params[testsub].values()])
    assert any([isinstance(v, (int, float)) for v in vp_params[testsub].values()])
def test_para_vs_seq_trials(inhib_method, att_map_init_type, shifts, exponents,
                            locdep_decay_switch):
    """
    Checks parallized result is the same as non parallelized evaluation
    """
    # Load Data
    dataDict = loadData.load_sim_data(os.path.join(THIS_DIR, 'test_simdata/'))
    x_dat, y_dat, dur_dat, im_dat, densities_dat, dat_range = loadData.dataDict2vars(
        dataDict)

    sw = sw_model(inhib_method, att_map_init_type, shifts, locdep_decay_switch,
                  "off", dat_range, {"exponents": exponents})
    sw.update_params(sw_params)

    # get one subject dataset
    x_dat_sub = x_dat[0]
    y_dat_sub = y_dat[0]
    dur_dat_sub = dur_dat[0]
    im_dat_sub = im_dat[0]

    sequential_list = evaluate_sw_parallel.get_total_list_LL_trials(
        sw, x_dat_sub, y_dat_sub, dur_dat_sub, im_dat_sub, densities_dat)
    nLL_parallel = evaluate_sw_parallel.get_neg_tot_like_trials_parallel(
        sw, x_dat_sub, y_dat_sub, dur_dat_sub, im_dat_sub, densities_dat, 5)
    nLL_sequential = np.negative(np.sum(sequential_list))
    assert np.isclose(nLL_parallel, nLL_sequential)
def test_para_vs_seq_both(inhib_method, att_map_init_type, shifts, exponents,
                          locdep_decay_switch):
    """
    Checks parallized result is the same as non parallelized evaluation
    """
    # Load Data
    dataDict = loadData.load_sim_data(os.path.join(THIS_DIR, 'test_simdata/'))
    x_dat, y_dat, dur_dat, im_dat, densities_dat, dat_range = loadData.dataDict2vars(
        dataDict)

    sw = sw_model(inhib_method, att_map_init_type, shifts, locdep_decay_switch,
                  "off", dat_range, {"exponents": exponents})
    sw.update_params(sw_params)
    nLL_sequential = evaluate_sw_parallel.get_total_neg_LL_subjs(
        sw, x_dat, y_dat, dur_dat, im_dat, densities_dat, 1)
    nLL_parallel = evaluate_sw_parallel.get_neg_tot_like_parallel(
        sw, x_dat, y_dat, dur_dat, im_dat, densities_dat, 5, 3)
    assert np.isclose(nLL_parallel, nLL_sequential)
Esempio n. 7
0
def test_get_scanpath_likelihood(inhib_method, att_map_init_type, shifts,
                                 exponents, locdep_decay_switch):
    """Tests that returned scanpath likelihhods are not nan and have the right type"""
    sw = sw_model(inhib_method, att_map_init_type, shifts, locdep_decay_switch,
                  "off", {
                      'x': (23, 100),
                      'y': (0, 90)
                  }, {"exponents": exponents})
    sw.update_params(sw_params)

    dataDict = loadData.load_sim_data('tests/test_simdata/')
    x_sim, y_sim, dur_sim, _, densities, _ = loadData.dataDict2vars(dataDict)
    fix_dens = densities[0]

    avg_log_ll = sw.get_scanpath_likelihood(x_sim[0][0], y_sim[0][0],
                                            dur_sim[0][0], fix_dens)

    assert isinstance(avg_log_ll, np.float128)
    assert not np.isnan(avg_log_ll)
Esempio n. 8
0
def bla():
    inhib_method = "subtractive"
    att_map_init_type = "cb"
    shifts = "both"
    exponents = 1
    locdep_decay_switch = "on"

    sw_params = OrderedDict({
        "omegaAttention" : 1,
        "omegaInhib": 0.1,
        "omfrac": 2,
        "sigmaAttention" : 5,
        "sigmaInhib" : 4,
        "gamma" : 1,
        "lamb" : 1,
        "inhibStrength" : 0.01,
        "zeta" : 0.01,
        "sigmaShift" : 5,
        "shift_size" : 2,
        "phi" : 100,
        "first_fix_OmegaAttention" : 3,
        "cb_sd_x" : 5,
        "cb_sd_y" : 4,
        "omega_prevloc": 1,
        "chi": 0.5,
        "ompfactor":0.1
    })

    sw = sw_model(inhib_method, att_map_init_type, shifts, exponents, locdep_decay_switch, {'x': (23, 100), 'y': (0, 90)}, {"omp":"add"})
    sw.update_params(sw_params)

    dataDict = loadData.load_sim_data('test_simdata/')
    x_sim, y_sim, dur_sim, _, densities, _ = loadData.dataDict2vars(dataDict)
    fix_dens = densities[0]

    avg_log_ll = sw.get_scanpath_likelihood(x_sim[0][0], y_sim[0][0], dur_sim[0][0], fix_dens)
Esempio n. 9
0
def test_something(inhib_method, att_map_init_type, shifts, exponents,
                   locdep_decay_switch):
    dataDict = loadData.load_sim_data('tests/test_simdata/')
    chop_dataDict = loadData.chop_scanpaths(0, 10, dataDict)
    x_sim, y_sim, dur_sim, _, densities, rng = loadData.dataDict2vars(
        chop_dataDict)
    rng2 = {'x': rng[0], 'y': rng[1]}
    fix_dens = densities[0]

    sw = sw_model(inhib_method, att_map_init_type, shifts, locdep_decay_switch,
                  "off", rng2, {"exponents": exponents})
    sw.update_params(sw_params)
    lsw = lsw_model(inhib_method, att_map_init_type, shifts,
                    locdep_decay_switch, "off", rng2, {
                        "n_history": 10,
                        "exponents": exponents
                    })
    lsw.update_params(sw_params)

    sw_LL = sw.get_scanpath_likelihood(x_sim[0][0], y_sim[0][0], dur_sim[0][0],
                                       fix_dens)
    lsw_LL = lsw.get_scanpath_likelihood(x_sim[0][0], y_sim[0][0],
                                         dur_sim[0][0], fix_dens)
    assert sw_LL == lsw_LL