def test_add_noise(): """checks fixation density has correct size and type and has legal values and is density""" sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) sw.update_params(sw_params) x_deg = (67, 50, 24) y_deg = (37, 50, 29) durations = (0.6, 0.6, 0.4) init_map = sw.initialize_map_unif() att_g = sw.make_attention_gauss(x_deg, y_deg) evolved_map_att = sw.differential_time_att(durations[1], att_g, init_map, fixs_x=x_deg, fixs_y=y_deg) inhib_g = sw.make_inhib_gauss(x_deg, y_deg) evolved_map_inhib = sw.differential_time_basic(durations[1], inhib_g, init_map, sw.omegaInhib) comb_map = sw.combine(evolved_map_att, evolved_map_inhib) u = sw.make_positive(comb_map) uFinal = sw.add_noise(u) assert uFinal.shape == (128, 128) assert isinstance(uFinal.flatten()[0], np.float128) assert not np.isnan(uFinal).any() assert not (uFinal == 0).all() assert not (uFinal < 0).any() assert np.isclose(np.sum(uFinal), 1)
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_update_params(): """that params are correctly fed into the model""" sw_params1 = OrderedDict({ "omegaAttention": 1, "omegaInhib": 0.1, "sigmaAttention": 5, "sigmaInhib": 4, "gamma": 1, "lamb": 1, "inhibStrength": 0.01, "zeta": 0.01, "sigmaShift": 5, "shift_size": 2, "first_fix_OmegaAttention": 3, "cb_sd_x": 5, "cb_sd_y": 4, "omega_prevloc": 1, "tau_pre": 50, "tau_post": 50, "chi": 0.5, "ompfactor": 0.5, }) sw = sw_model("subtractive", "cb", "both", "on", "add", { 'x': (23, 100), 'y': (0, 90) }, { "estimate_times": True, "exponents": 2 }) sw.update_params(sw_params1) res1 = sw.get_params() sw.clear_params() sw.update_params(list(sw_params1.values())) res2 = sw.get_params() assert res1 == res2
def test_make_attention_post_outside(): """checks what happens when post attention is outside the grid""" sw = sw_model("subtractive", "zero", "post", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) sw_params2 = OrderedDict({ "omegaAttention": 1, "omegaInhib": 0.1, "omfrac": 2, "sigmaAttention": 5, "sigmaInhib": 4, "gamma": 1, "lamb": 1, "inhibStrength": 0.01, "zeta": 0.01, "sigmaShift": 0.00005, "shift_size": 4, "phi": 100, "first_fix_OmegaAttention": 3, "cb_sd_x": 5, "cb_sd_y": 4, "omega_prevloc": 1 }) sw.update_params(sw_params2) x_deg = (50, 99, 40) y_deg = (50, 89, 40) #durations = (0.6, 0.6, 0.4) att_g = sw.make_attention_gauss_post_shift(x_deg, y_deg) assert att_g.shape == (128, 128) assert isinstance(att_g.flatten()[0], np.float128) assert not np.isnan(att_g).any() assert not (att_g < 0).any() assert not (att_g == 0).all()
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)
def test_combine(exponents, inhib): """checks fixation density has correct size and type and has legal values""" sw = sw_model(inhib, "zero", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }, {"exponents": exponents}) sw.update_params(sw_params) x_deg = (67, 50, 24) y_deg = (37, 50, 29) durations = (0.6, 0.6, 0.4) init_map = sw.initialize_map_unif() att_g = sw.make_attention_gauss(x_deg, y_deg) evolved_map_att = sw.differential_time_att(durations[1], att_g, init_map, fixs_x=x_deg, fixs_y=y_deg) inhib_g = sw.make_inhib_gauss(x_deg, y_deg) evolved_map_inhib = sw.differential_time_basic(durations[1], inhib_g, init_map, sw.omegaInhib) comb_map = sw.combine(evolved_map_att, evolved_map_inhib) assert comb_map.shape == (128, 128) assert isinstance(comb_map.flatten()[0], np.float128) assert not np.isnan(comb_map).any() assert not (comb_map == 0).all()
def test_convert_px_to_deg(): """checks conversion """ sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) deg_val = (23 + 100) / 2 calc_px = sw.convert_deg_to_px(deg_val, 'x', fix=True) calc_deg = sw.convert_px_to_deg(calc_px, 'x') assert np.isclose(calc_deg, deg_val)
def test_evolve_maps_durs(inhib_method, att_map_init_type, shifts, exponents, locdep_decay_switch, nth, durs): """ tests whether all duration edge cases still produce usefull results with regards to: evolve maps function in all different configurations. Checks - uFinal is correct shape, type, non-negative, nonzero, non-nan, density - attmap is correct shape, type, non-negative, nonzero, non-nan - inhmap is correct shape, type, non-negative, nonzero, non-nan - next_pos is in legal range and right type - LL is not nan """ 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) init_map_att = sw.att_map_init() init_map_inhib = sw.initialize_map_unif() fix_dens = np.load('tests/emp_dens.npy') x_deg1 = (67, 50, 24) y_deg1 = (37, 50, 29) att1, inh1, uFinal1, next1, LL1 = sw.evolve_maps(durs, x_deg1, y_deg1, init_map_att, init_map_inhib, fix_dens, nth, sim=False) assert next1[0] == x_deg1[2] assert next1[1] == y_deg1[2] assert isinstance(LL1, np.float128) assert not np.isnan(LL1) assert uFinal1.shape == (128, 128) assert isinstance(uFinal1.flatten()[0], np.float128) assert not np.isnan(uFinal1).any() assert not (uFinal1 == 0).all() assert not (uFinal1 < 0).any() assert np.isclose(np.sum(uFinal1), 1) assert att1.shape == (128, 128) assert isinstance(att1.flatten()[0], np.float128) assert not np.isnan(att1).any() assert not (att1 < 0).any() assert not (att1 == 0).all() assert inh1.shape == (128, 128) assert isinstance(inh1.flatten()[0], np.float128) assert not np.isnan(inh1).any() assert not (inh1 < 0).any() assert not (inh1 == 0).all()
def test_get_unit_vector(): """checks unit vector length and magnitude""" sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) correct_mag = np.sqrt(8) correct_u = (np.sqrt(1 / 2), np.sqrt(1 / 2)) u, mag = sw.get_unit_vector((2, 3), (4, 5)) assert np.isclose(u[0], correct_u[0]) assert mag == correct_mag
def test_get_phase_times_both(nth, durs, expected): """Checks that helper function returns the correct phase times in all cases""" sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) sw.update_params(sw_params) sw.tau_post = 0.05 sw.tau_pre = 0.05 post, main, pre = sw.get_phase_times_both(nth, durs) assert np.isclose((post, main, pre), expected).all()
def test_convert_deg_to_px(): """checks conversion and conversion edge case where fix is outside range""" sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) deg_val = (23 + 100) / 2 correct_x_px = 64 calc_px = sw.convert_deg_to_px(deg_val, 'x', fix=True) assert calc_px == correct_x_px assert sw.convert_deg_to_px(91, 'y', fix=True) == 127
def test_simulate_durations(): """checks durations have right type and amount""" sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) n_points = 10 durs = sw.simulate_durations(n_points) assert len(durs) == n_points types = [isinstance(x, float) for x in durs] assert sum(types) == n_points
def test_initialize_map_unif(): """checks fixation density has correct size and type and value""" sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) init_map = sw.initialize_map_unif() assert init_map.shape == (128, 128) assert (init_map.flatten() == sw.EPS).all() assert isinstance(init_map.flatten()[0], np.float128) assert not np.isnan(init_map).any()
def test_initialize_center_bias(): """checks fixation density has correct size and type and has legal values""" sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) sw.cb_sd = (8, 5) cb_map = sw.initialize_center_bias() assert cb_map.shape == (128, 128) assert isinstance(cb_map.flatten()[0], np.float128) assert not np.isnan(cb_map).any() assert not (cb_map < 0).any() assert not (cb_map == 0).all()
def test_empirical_fixation_density(): """checks fixation density has correct size and type""" sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) x_locs = [43, 90, 30, 80] y_locs = [35, 12, 41, 75] x_locs_px, y_locs_px, fix_dens = sw.empirical_fixation_density( x_locs, y_locs) assert fix_dens.shape == (128, 128) print(type(fix_dens[0][0])) assert isinstance(fix_dens[0][0], np.float128) assert len(x_locs_px) == len(x_locs) == len(y_locs_px)
def test_fixation_picker_max(): """check the right el is picked out of matrix""" sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) mat = np.zeros((128, 128)) correct_ij = (80, 20) mat[correct_ij] = 1 mat = mat / np.sum(mat) x, y = sw.fixation_picker_max(mat) j = sw.convert_deg_to_px(x, 'x', fix=True) i = sw.convert_deg_to_px(y, 'y', fix=True) assert np.isclose(i, correct_ij[0]) and np.isclose(j, correct_ij[1])
def test_make_inhib_gauss(): """checks fixation density has correct size and type and has legal values""" sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) sw.update_params(sw_params) x_deg = (67, 50, 24) y_deg = (37, 50, 29) att_g = sw.make_inhib_gauss(x_deg, y_deg) assert att_g.shape == (128, 128) assert isinstance(att_g.flatten()[0], np.float128) assert not np.isnan(att_g).any() assert not (att_g < 0).any() assert not (att_g == 0).all()
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)
def test_check_params_in_bounds(inhib_method, att_map_init_type, shifts, exponents, locdep_decay_switch, oms_couple): """Tests that the bounds checker reacts appropriately:h""" sw = sw_model(inhib_method, att_map_init_type, shifts, locdep_decay_switch, "off", { 'x': (23, 100), 'y': (0, 90) }, {"exponents": exponents}) if oms_couple == "on": sw.coupled_oms = True z = [5, -1, 0.5] exp = [False, False, True] for i in range(3): params = sw_params.copy() params["zeta"] = z[i] sw.update_params(params) assert sw.check_params_in_bounds() == exp[i]
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)
def test_combine_att_fixdens(): """checks fixation density has correct size and type and has legal values""" sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) sw.update_params(sw_params) x_deg = (None, 50, None) y_deg = (None, 50, None) x_locs = [43, 90, 30, 80] y_locs = [35, 12, 41, 75] _, _, fix_dens = sw.empirical_fixation_density(x_locs, y_locs) att_g = sw.make_attention_gauss(x_deg, y_deg) comb_map = sw.combine_att_fixdens(att_g, fix_dens) assert comb_map.shape == (128, 128) assert isinstance(comb_map.flatten()[0], np.float128) assert not np.isnan(comb_map).any() assert not (comb_map < 0).any() assert not (comb_map == 0).all()
def test_differential_time_basic(): """checks fixation density has correct size and type and has legal values""" sw = sw_model("subtractive", "cb", "off", "off", "off", { 'x': (23, 100), 'y': (0, 90) }) sw.update_params(sw_params) x_deg = (67, 50, 24) y_deg = (37, 50, 29) durations = (0.6, 0.6, 0.4) init_map = sw.initialize_map_unif() att_g = sw.make_attention_gauss(x_deg, y_deg) evolved_map = sw.differential_time_basic(durations[1], att_g, init_map, sw.omegaAttention) assert evolved_map.shape == (128, 128) assert isinstance(evolved_map.flatten()[0], np.float128) assert not np.isnan(evolved_map).any() assert not (evolved_map < 0).any() assert not (evolved_map == 0).all()
def test_pass_input_params(inhib_method, att_map_init_type, shifts, exponents, locdep_decay_switch, oms_couple): """Tests that the values passed in are correctly assigned to the paramters""" sw = sw_model(inhib_method, att_map_init_type, shifts, locdep_decay_switch, "off", { 'x': (23, 100), 'y': (0, 90) }, {"exponents": exponents}) if oms_couple == "on": sw.coupled_oms = True needed_param_names = sw.get_param_list_order() p_list = list(range(len(needed_param_names))) sw.update_params(p_list) if oms_couple == "on": p_list[1] = p_list[0] / p_list[1] current = sw.get_params() sw.check_params_for_config() assert list(current.values()) == p_list
def test_evolve_maps_other_mapsize_error(inhib_method, att_map_init_type, shifts, exponents, locdep_decay_switch): """ tests evolve maps function in all different configurations. Checks - uFinal is correct shape, type, non-negative, nonzero, non-nan, density - attmap is correct shape, type, non-negative, nonzero, non-nan - inhmap is correct shape, type, non-negative, nonzero, non-nan - next_pos is in legal range and right type - LL is not nan """ sw = sw_model(inhib_method, att_map_init_type, shifts, locdep_decay_switch, "off", { 'x': (23, 100), 'y': (0, 90) }, {"exponents": exponents}) #sw.set_mapsize(sz) sw.update_params(sw_params) init_map_att = sw.att_map_init() init_map_inhib = sw.initialize_map_unif() fix_dens = np.load('tests/emp_dens33.npy') durations1 = (0.2, 0.3, 0.4) x_deg1 = (67, 50, 24) y_deg1 = (37, 50, 29) with pytest.raises(Exception) as execinfo: sw.evolve_maps(durations1, x_deg1, y_deg1, init_map_att, init_map_inhib, fix_dens, 1, sim=False) assert 'The input fixation density map needs to be the same' in str( execinfo.value)
def benchmark_sw(sw_args, bounds_dict, file_path): """ Tests the model with the given model specs and bounds. """ sw = sw_model(*sw_args) str(sw.get_param_list_order()) #bounds_dict = update_bounds(sw) #print(sw_dict) red_bd = reduce_bouds_dict(sw, bounds_dict) perms = get_perms(red_bd) print("begin") faulty_perms = [] all_ok = True for p in progressbar(perms): sw.update_params(list(p)) try: for dur in durations: run_test(sw, dur) except AssertionError: all_ok = False faulty_perms.append(p) np.save(file_path, faulty_perms) return all_ok, faulty_perms, sw
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)
def test_param_passing(): """checks that the routine for passing parameters through dream keeps the correct order!""" parvals = [123] * 8 print(parvals) sw_params = dream_estim.param_list_from_estim_and_default( priors, default_params, parvals) print(sw_params) kwargs_d = {"saclen_shift": True, "exponents": 1} sw_args = [ 'subtractive', 'cb', 'both', 'on', 'add', { 'x': (0, 128), 'y': (0, 128) }, kwargs_d ] sw = sw_model(*sw_args) sw.update_params(sw_params) recieved_params = sw.get_params() print(recieved_params) for key in recieved_params: print(key) if key in priors.keys(): assert recieved_params[key] == 123 else: assert recieved_params[key] == default_params[key]
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
def test_evolve_maps_boundaries(inhib_method, att_map_init_type, shifts, exponents, locdep_decay_switch, omegaAttention, omegaInhib, sigmaAttention, sigmaInhib, gamma, lamb, inhibStrength, zeta, sigmaShift, shift_size, first_fix_OmegaAttention, cb_sd_x, cb_sd_y, omega_prevloc, durations): sw_dict = { "omegaAttention": omegaAttention, "omegaInhib": omegaInhib, "sigmaAttention": sigmaAttention, "sigmaInhib": sigmaInhib, "gamma": gamma, "lamb": lamb, "inhibStrength": inhibStrength, "zeta": zeta, "sigmaShift": sigmaShift, "shift_size": shift_size, "first_fix_OmegaAttention": first_fix_OmegaAttention, "cb_sd_x": cb_sd_x, "cb_sd_y": cb_sd_y, "omega_prevloc": omega_prevloc, } sw = sw_model(inhib_method, att_map_init_type, shifts, exponents, locdep_decay_switch, { 'x': (23, 100), 'y': (0, 90) }) sw.update_params(sw_dict) init_map_att = sw.att_map_init() init_map_inhib = sw.initialize_map_unif() fix_dens = np.load('tests/emp_dens.npy') durations1 = durations x_deg1 = (67, 50, 24) y_deg1 = (37, 50, 29) att1, inh1, uFinal1, nextF, LL = sw.evolve_maps(durations1, x_deg1, y_deg1, init_map_att, init_map_inhib, fix_dens, 1) assert uFinal1.shape == (128, 128) assert isinstance(uFinal1.flatten()[0], np.float128) assert not np.isnan(uFinal1).any() assert not (uFinal1 == 0).all() assert not (uFinal1 < 0).any() assert np.isclose(np.sum(uFinal1), 1) assert att1.shape == (128, 128) assert isinstance(att1.flatten()[0], np.float128) assert not np.isnan(att1).any() assert not (att1 < 0).any() assert not (att1 == 0).all() assert inh1.shape == (128, 128) assert isinstance(inh1.flatten()[0], np.float128) assert not np.isnan(inh1).any() assert not (inh1 < 0).any() assert not (inh1 == 0).all() durations2 = durations x_deg2 = (50, 24, 56) y_deg2 = (50, 29, 66) att2, inh2, uFinal2, nextF, LL = sw.evolve_maps(durations2, x_deg2, y_deg2, att1, inh1, fix_dens, 2) assert uFinal2.shape == (128, 128) assert isinstance(uFinal2.flatten()[0], np.float128) assert not np.isnan(uFinal2).any() assert not (uFinal2 == 0).all() assert not (uFinal2 < 0).any() assert np.isclose(np.sum(uFinal2), 1) assert att2.shape == (128, 128) assert isinstance(att2.flatten()[0], np.float128) assert not np.isnan(att2).any() assert not (att2 < 0).any() assert not (att2 == 0).all() assert inh2.shape == (128, 128) assert isinstance(inh2.flatten()[0], np.float128) assert not np.isnan(inh2).any() assert not (inh2 < 0).any() assert not (inh2 == 0).all()
def test_evolve_maps_boundaries(omegaAttention, omegaInhib, sigmaAttention, sigmaInhib, gamma, lamb, inhibStrength, zeta, durations): sw_dict = { "omegaAttention": omegaAttention, "omegaInhib": omegaInhib, "sigmaAttention": sigmaAttention, "sigmaInhib": sigmaInhib, "gamma": gamma, "lamb": lamb, "inhibStrength": inhibStrength, "zeta": zeta, } sw = sw_model("subtractive", "zero", "off", 2, "off", { 'x': (23, 100), 'y': (0, 90) }) param_names = sw.get_param_list_order() sw_params = [sw_dict[n] for n in param_names] print(sw_params) sw.update_params(sw_params) sw_params = [ omegaAttention, omegaInhib, sigmaAttention, sigmaInhib, gamma, lamb, inhibStrength, zeta ] init_map_att = sw.att_map_init() init_map_inhib = sw.initialize_map_unif() fix_dens = np.load(os.path.join(THIS_DIR, 'emp_dens.npy')) durations1 = durations x_deg1 = (67, 50, 24) y_deg1 = (37, 50, 29) att1, inh1, uFinal1, nextF, LL = sw.evolve_maps(durations1, x_deg1, y_deg1, init_map_att, init_map_inhib, fix_dens, 1) assert uFinal1.shape == (128, 128) assert isinstance(uFinal1.flatten()[0], np.float128) assert not np.isnan(uFinal1).any() assert not (uFinal1 == 0).all() assert not (uFinal1 < 0).any() assert np.isclose(np.sum(uFinal1), 1) assert att1.shape == (128, 128) assert isinstance(att1.flatten()[0], np.float128) assert not np.isnan(att1).any() assert not (att1 < 0).any() assert not (att1 == 0).all() assert inh1.shape == (128, 128) assert isinstance(inh1.flatten()[0], np.float128) assert not np.isnan(inh1).any() assert not (inh1 < 0).any() assert not (inh1 == 0).all() durations2 = durations x_deg2 = (50, 24, 56) y_deg2 = (50, 29, 66) att2, inh2, uFinal2, nextF, LL = sw.evolve_maps(durations2, x_deg2, y_deg2, att1, inh1, fix_dens, 2) assert uFinal2.shape == (128, 128) assert isinstance(uFinal2.flatten()[0], np.float128) assert not np.isnan(uFinal2).any() assert not (uFinal2 == 0).all() assert not (uFinal2 < 0).any() assert np.isclose(np.sum(uFinal2), 1) assert att2.shape == (128, 128) assert isinstance(att2.flatten()[0], np.float128) assert not np.isnan(att2).any() assert not (att2 < 0).any() assert not (att2 == 0).all() assert inh2.shape == (128, 128) assert isinstance(inh2.flatten()[0], np.float128) assert not np.isnan(inh2).any() assert not (inh2 < 0).any() assert not (inh2 == 0).all()