コード例 #1
0
ファイル: bts_scores.py プロジェクト: jpmccoy/bts_spade
def testing():
    responses = [1, 1, 0]
    meta_true = [0.7, 0.3, 0.4]
    bts_easy = calc_easy_bts_binary(responses, meta_true)
    correct_surprise = [0.4201811, 0.4201811, -0.4081212]
    correct_accuracy = [-0.002593396, -0.285026016, -0.144621528]
    assert jmutils.bounded(sum(bts_easy['bts']), -0.000001, 0.000001)
    assert all([jmutils.fuzzy_equals(c, a, 0.0001) for c, a in zip(correct_surprise, bts_easy['surprise'])])
    assert all([jmutils.fuzzy_equals(c, a, 0.0001) for c, a in zip(correct_accuracy, bts_easy['accuracy'])])
    print('done testing')
コード例 #2
0
def prob_noisy(given, bayes, noise_type, noise):
    """Prob of saying given when rational bayesian would say bayes
    Args: given: in [0,1], what respondent said
          bayes: in [0, 1]
          model_params: dict, incl keys with noise info
    Returns: prob in [0, 1]
    Different types of noise models: beta, binomial, noiseless.
    """
    if noise_type == "noiseless":
        tolerance = 1e-04
        if jmutils.fuzzy_equals(given, bayes, tolerance):
            return 1
        else:
            return 0
    elif noise_type == "binomial":
        num_trials = noise
        num_successes = int(given * num_trials)
        #return binom.pmf(num_successes, num_trials, bayes)
        return my_binom_pmf(num_successes, num_trials, bayes)
    elif noise_type == "beta":
        print("Optimize the beta stuff almost certainly!!!")
        alpha_beta = jmutils.beta_shape(bayes, noise)
        return beta.pdf(given, *alpha_beta)
    elif noise_type == "truncnorm":
        scale = noise
        #return truncnorm.pdf(given, -bayes / scale, (1 - bayes) / scale, 
        #                     loc=bayes, scale=scale)
        return mytruncpdf_01bounds(given, bayes, noise)
    else:
        print("Error: meta noise_type not specified correctly")
        sys.exit()
コード例 #3
0
def test_prob_responses_signals():
    responses = np.array([0,0,1,1])
    signals = np.array([0,1,1,0])
    noise = .9
    tolerance = 1e-04
    assert fuzzy_equals(agg.prob_responses_signals(responses, signals, noise),
                        0.008100000000000, tolerance)
コード例 #4
0
def test_prob_meta_noisy():
    given = .5
    bayes = .45
    model_params = {'noise_meta': 'noiseless'}
    assert agg.prob_meta_noisy(given, bayes, model_params) == 0
    model_params = {'noise_meta': 'binomial', 'binomial_num_trials': 100}
    tolerance = 1e-04
    assert fuzzy_equals(agg.prob_meta_noisy(given, bayes, model_params), 
                        0.048151971498, tolerance)