示例#1
0
def test_mean():
    means = rand.random(100)
    min_val = means.min()
    max_val = means.max()
    boots = bootstrap.mean(means, 200)
    assert boots.shape == (200,)
    assert np.all(boots >= min_val)
    assert np.all(boots <= max_val)

    perc_boots = bootstrap.mean(means, 200, [2.5, 97.5])
    assert perc_boots.shape == (2,)
    assert np.all(perc_boots >= min_val)
    assert np.all(perc_boots <= max_val)
示例#2
0
def main(args):
    data = json.load(args.input)
    if args.regret is not None:
        game, serial = gameio.read_base_game(json.load(args.regret[0]))
        mix = serial.from_prof_json(json.load(args.regret[1]))
        devs = load_devs(game, serial, data)
        expect = game.role_reduce(devs * mix)
        result = bootstrap.sample_regret(game, expect, devs, args.num_bootstraps, args.percentiles)
        if args.mean:
            mdevs = devs.mean(0)
            mexpect = game.role_reduce(mdevs * mix, keepdims=True)
            mean = np.max(mdevs - mexpect)

    elif args.dev_surplus is not None:
        game, serial = gameio.read_base_game(json.load(args.dev_surplus[0]))
        mix = serial.from_prof_json(json.load(args.dev_surplus[1]))
        devs = load_devs(game, serial, data)
        surpluses = np.sum(devs * mix * game.role_repeat(game.num_players), 1)
        result = bootstrap.mean(surpluses, args.num_bootstraps, args.percentiles)
        if args.mean:
            mean = surpluses.mean()

    else:
        data = np.asarray(data, float)
        result = bootstrap.mean(data, args.num_bootstraps, args.percentiles)
        if args.mean:
            mean = data.mean()

    if args.percentiles is None:
        args.percentiles = np.linspace(0, 100, args.num_bootstraps)
    jresult = {str(p).rstrip("0").rstrip("."): v.item() for p, v in zip(args.percentiles, result)}
    if args.mean:
        jresult["mean"] = mean

    json.dump(jresult, args.output)
    args.output.write("\n")