def reports_ll_person(beliefs, meta, world, sm, wp, own_noise, meta_noise, expertise, bias, params, bmat=None, mmat=None, debug=None): if params.use_expertise: if params.ppl_know_expertise: if params.orig_expertise_code: bmat = [fwd.calc_belief_matrix_expertise(sm, wp, ee) for ee in expertise] else: bmat = [fwd.calc_belief_matrix_expertise_min(sm, wp, ee, bias) for ee in expertise] mmat = [fwd.calc_meta_matrix(sm, wp, bm) for bm in bmat] if bmat is None: bmat = fwd.calc_belief_matrix(sm, wp) if mmat is None: mmat = fwd.calc_meta_matrix(sm, wp, bmat) prob_signals = calc_prob_signals(sm, world, expertise, bias, params) pbs_vec = prob_beliefs_signals(beliefs, sm, wp, own_noise, params, bmat) pms_vec = prob_meta_signals(meta, sm, wp, meta_noise, params, bmat, mmat) ll = np.log((prob_signals * pbs_vec * pms_vec).sum(axis=0)) if debug is not None: 1/0 #check_log = np.log(prob_signals) + np.log(pbs_vec) + np.log(pms_vec) #check_exp = np.exp(check_log) #check_final = np.log(np.nansum(check_exp, 0)) return ll
def test_calc_meta_matrix(): sm = np.array([[1, 0], [0, 1]]) wp = np.array([.4, .6]) meta = fwd.calc_meta_matrix(sm, wp) correct_meta = np.array([[1, 0], [0, 1]]) npt.assert_allclose(meta, correct_meta, rtol=1e-04) sm = np.array([[.2, .1], [.8, .9]]) meta = fwd.calc_meta_matrix(sm, wp) correct_meta = np.array([[0.15714286, 0.1372093], [0.84285714, 0.8627907]]) npt.assert_allclose(meta, correct_meta, rtol=1e-04)
def prob_meta_signals(given, sm, wp, noise, params, belief_matrix=None, meta_matrix=None): if not params.use_metas: return np.ones((sm.shape[0], 1)) if params.prior_wp_sm in ["none", "signal_assumption", "gen_bij_infer_all", "bijection"]: if belief_matrix is None: belief_matrix = fwd.calc_belief_matrix(sm, wp) if meta_matrix is None: meta_matrix = fwd.calc_meta_matrix(sm, wp, belief_matrix) if (params.use_expertise and params.ppl_know_expertise): bayes_s0_sig = np.array([unanimity_metas(bm, mm, params.prior_wp_sm) for bm, mm in zip(belief_matrix, meta_matrix)]) bayes_s0_sig0 = bayes_s0_sig[:,0] bayes_s0_sig1 = bayes_s0_sig[:,1] else: bayes_s0_sig = unanimity_metas(belief_matrix, meta_matrix, params.prior_wp_sm) bayes_s0_sig0 = bayes_s0_sig[0] bayes_s0_sig1 = bayes_s0_sig[1] pas = np.zeros((2, given.shape[1])) pas[0,:] = prob_noisy_vec(given[0,:], bayes_s0_sig0, params.meta_noise_type, noise) #if bayes_s0_sig[1] == bayes_s0_sig[0]: # pas[1,:] = pas[0,:] #else: pas[1,:] = prob_noisy_vec(given[0,:], bayes_s0_sig1, params.meta_noise_type, noise) #pas = mask_nan_probs(pas, given) return pas