def dispersed_init(k, params): #initial = random_init(len(beliefs)) #initial = initial_using_actual(actual, len(beliefs)) state = {} wp_apart = [[.1, .9], [.5, .5], [.9, .1]] sm_apart = [np.array([[.5, .4], [.5, .6]]), np.array([[.9, .8], [.1, .2]]), np.array([[.1, .05], [.9, .95]])] worlds_apart = [0, 1, 0] state['wp'] = wp_apart[k] state['sm'] = sm_apart[k] state['world'] = worlds_apart[k] state['signals'] = fwd.sample_signals(state['world'], state['sm'], params['num_responses']) state['meta_noise'] = params['meta_noise'] if params['fixed_noise']: state['own_noise'] = params['own_noise'] else: state['own_noise'] = .25 return state
def wp_expt(sm=np.array([[.7, .4], [.3, .6]]), wp=np.array([.1, .9]), change_wp=True): params = setup_params.init_params_demo1() params['binary_beliefs'] = False indiv = fwd.generate_individual(params) grid = 100 diff = 0 res0 = np.zeros((grid-grid*diff, grid-grid*diff)) res1 = np.zeros((grid-grid*diff, grid-grid*diff)) bm0 = np.zeros((grid-grid*diff, grid-grid*diff)) bm1 = np.zeros((grid-grid*diff, grid-grid*diff)) mm0 = np.zeros((grid-grid*diff, grid-grid*diff)) mm1 = np.zeros((grid-grid*diff, grid-grid*diff)) mm0avg = np.zeros((grid-grid*diff, grid-grid*diff)) #hacky since grid needn't be nice num.: for k, gen in enumerate(np.arange(diff * grid, grid)): actual = {} gen_s0 = gen / grid + .01 if change_wp: gen_wp = np.array([gen_s0, 1 - gen_s0]) actual['wp'] = gen_wp actual['sm'] = sm else: actual['wp'] = wp gen_sm = np.array([[gen_s0, gen_s0 - diff], [1 - gen_s0, 1 - gen_s0 + diff]]) actual['sm'] = gen_sm actual['world'] = 0 actual['signals'] = fwd.sample_signals(actual['world'], actual['sm'], params['num_responses']) beliefs, meta = fwd.generate_data(actual, indiv, params) for j, ans in enumerate(np.arange(grid*diff, grid)): ans_s0 = ans / grid + .01 if change_wp: ans_wp = np.array([ans_s0, 1 - ans_s0]) ans_sm = actual['sm'] else: ans_wp = actual['wp'] ans_sm = np.array([[ans_s0, ans_s0 - diff], [1 - ans_s0, 1 - ans_s0 + diff]]) ll = np.array([aggregation.reports_ll_marg(beliefs, meta, w, ans_sm, ans_wp, indiv['own_noise'], indiv['meta_noise'], params) for w in [0, 1]]) ll += aggregation.log_prob_world(actual['world'], ans_wp) bel = fwd.calc_belief_matrix(ans_sm, ans_wp) bm0[k, j] = bel[0,0] bm1[k, j] = bel[0,1] met = fwd.calc_meta_matrix(ans_sm, ans_wp) mm0[k, j] = met[0,0] mm1[k, j] = met[0,1] if bel[0, 0] < .5: mm0avg[k,j] = 0 elif bel[0, 1] > .5: mm0avg[k,j] = 1 else: mm0avg[k,j] = met[0,0] if bel[0, 1] > .5: non_bij = 1 elif bel[0,0] < .5: non_bij = -1 else: non_bij = 0 res0[k, j] = ll[0] res1[k, j] = ll[1] plt.imshow(res0, cmap=cm.Greys_r) plt.imshow(res1, cmap=cm.Greys_r) 1/0 return res