Esempio n. 1
0
def test_noob():
    assert istat(mknoob()) == (0.0, 1.0)
    p = Population([mknoob(), mknoob()])
    assert strat_mean(pstat(p).mean_proposer_strategy) == 0.0
    assert strat_mean(pstat(p).mean_responder_strategy) == 1.0
    p2 = Population([mknoob(), Individ(mkuniform(), mkuniform())])
    assert strat_mean(pstat(p2).mean_proposer_strategy) > 0.0
Esempio n. 2
0
def test_evolve():
    for i in range(100):
        pop = Population([mknoob(), Individ(mkuniform(), mkuniform())])
        comp = Competition(pop, 10)
        compete(comp, pop)
        assert scores(comp, 0) == 0
        e = Evolution(0.5)
        pop2 = evolve(e, comp, pop)
        for i in pop2.individs:
            assert not isnoob(i)
Esempio n. 3
0
def test_compete():
    for i in range(100):
        pop = Population([mknoob(), Individ(mkuniform(), mkuniform())])
        assert isnoob(pop.individs[0])
        comp = Competition(pop, 10)
        compete(comp, pop)
        # print('--->', comp.pscores, comp.rscores)
        assert comp.pscores[0] == 0
        assert comp.rscores[0] == 0, f"{comp.log}"
        assert scores(comp, 0) <= scores(
            comp, 1), f"{scores(comp,0)} should be < {scores(comp,1)}"
Esempio n. 4
0
def test_propose():
    p = Individ(
        normalized([(0 if (x < 0.1 or x > 0.4) else 20) for x in OFFERS]),
        mkuniform())
    for x in range(1000):
        offer = propose(p)
        assert_valid_offer(offer)
        assert (offer >= 0.1 and offer <= 0.4)
Esempio n. 5
0
def test_mutate():
    e = Evolution()
    st = mkuniform()
    s = set(range(len(st)))
    for i in range(1000):
        st2, nbin = mutate_(e, st)
        s -= set([nbin])

    assert s == set([])
Esempio n. 6
0
def test_response():
    r = Individ(
        mkuniform(),
        normalized([(0.0 if (x < 0.1 or x > 0.4) else 20.0) for x in OFFERS]))
    r1s = set()
    r2s = set()
    r3s = set()
    for x in range(1000):
        r1s.add(respond(r, 1.0 - 0.05))
        r2s.add(respond(r, 1.0 - 0.2))
        r3s.add(respond(r, 1.0 - 0.9))
    assert r1s == set([False]), f"{r1s}"
    assert r2s == set([False, True]), f"{r2s}"
    assert r3s == set([True]), f"{r3s}"
Esempio n. 7
0
def pop1(n=30) -> Population:
    return Population([Individ(mkuniform(), mkuniform()) for x in range(n)])
Esempio n. 8
0
def test_mean_strategy():
    ms = mean_strategy([mkuniform(), mknorm()])
    s = np.sum(ms)
    assert isclose(s, 1.0), f"{s}"