def test_calc_belief_matrix():
    sm = np.array([[.3, .6], [.7, .4]])
    wp = np.array([.5, .5])
    beliefs = fwd.calc_belief_matrix(sm, wp)
    correct_beliefs = np.array([[0.33333333,  0.63636364],
                               [ 0.66666667,  0.36363636]])
    npt.assert_allclose(beliefs, correct_beliefs, rtol=1e-04)
Beispiel #2
0
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
Beispiel #3
0
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 bijection(self, sm, wp):
     beliefs = fwd.calc_belief_matrix(sm, wp)
     bijection = True
     for probs in beliefs.T:
         if sum(np.max(probs) == probs) > 1:
             bijection = False
             break
     argmaxs = np.argmax(beliefs, axis=0)
     if len(np.unique(argmaxs)) < sm.shape[0]:
         bijection = False
     return bijection, argmaxs
Beispiel #5
0
def prob_beliefs_signals(given, sm, wp, noise, params, belief_matrix=None):
    if not params.use_beliefs:
        return np.ones((sm.shape[0], 1))
    if belief_matrix is None:
        belief_matrix = fwd.calc_belief_matrix(sm, wp)
    if params.binary_beliefs:
        pas = prob_binary_beliefs_signals(given, noise, params, belief_matrix)
    else:
        if params.votes_confs:
            pas = prob_votes_confs(given, noise, params, belief_matrix)
        else:
            pas = prob_non_binary_beliefs(given, noise, params, belief_matrix)
    #pas = mask_nan_probs(pas, given)
    return pas