Ejemplo n.º 1
0
def plot_longs():
    for n in [500, 5000, 20000]:
        long_metric = Metric('x', 'y')
        for i in range(n):
            long_metric.add_record(random.random(), random.random())

        plot(long_metric, 'temp', name=f'longer_metric_{n}')
Ejemplo n.º 2
0
def test_some_empty_plots(tmpdir):
    files_before = len(os.listdir(tmpdir))

    m1 = Metric('empty')
    m2 = Metric('empty2')
    m2.add_record(1, 1)

    plot_group([m1, m2], folder=tmpdir)

    assert len(os.listdir(tmpdir)) > files_before
Ejemplo n.º 3
0
def test_discard_warmup():

    m = Metric()
    for i in range(10):
        m.add_record(i, i % 2)

    m.discard_warmup(0.5)

    assert 4 < len(m.data) < 6
    assert 0 not in m.data
    assert 8 in m.data
Ejemplo n.º 4
0
def test_ezplot(tmpdir):
    m = Metric('x', 'y')
    m.add_ys(1, [1, 2, 3])
    m.add_record(2, 4)
    m.add_record(2, 4)
    m.add_record(2, 4)
    m.add_ys(4, [5, 6, 12])

    files_before = len(os.listdir(tmpdir))
    plot(m, folder=tmpdir, name="bla3")
    files_after = len(os.listdir(tmpdir))

    assert files_after > files_before
Ejemplo n.º 5
0
def reinforce(lr: float):
    assert 0 < lr < 1

    m = Metric(f"lr={lr:.5f}")
    env = ShortCoridorEnv()
    agent = CoridorAgent()

    for episode in range(3_000):
        history, total_reward = rollout(agent, env)
        m.add_record(episode, total_reward)
        G = sum(r for o, a, r in history)
        for o, a, r in history:
            apply_grad(G, a, agent, lr)
            G -= r
Ejemplo n.º 6
0
def test_plot_group(tmpdir):
    m = Metric('x', 'y')
    m.add_ys(1, [1, 2, 3])
    m.add_record(2, 4)
    m.add_record(2, 4)
    m.add_record(2, 4)
    m.add_ys(4, [5, 6, 12])

    m2 = Metric('x', 'y')
    m2.add_ys(1, [4, 3, 5])
    m2.add_record(2, 5)
    m2.add_record(2, 9)
    m2.add_record(2, 9)
    m2.add_ys(4, [5, 6, -1])

    files_before = len(os.listdir(tmpdir))
    plot_group([m, m2], folder=tmpdir, name="bla3")
    files_after = len(os.listdir(tmpdir))

    assert files_after > files_before
Ejemplo n.º 7
0
from pennpaper import Metric, plot

import random

metrics = [Metric('x', 'y') for x in range(10)]
for m in metrics:
    for i in range(50):
        m.add_record(random.random(), random.random())
    m._sort()

m11 = sum(metrics)

plot(metrics[0], 'temp', name="single_random")
plot(m11, 'temp', name="summ_10_random")

straight = Metric('x', 'y')
for i in range(50):
    straight.add_record(i, i + 0.1 * random.random())

plot(straight, 'temp', name='straight')
Ejemplo n.º 8
0
    return _


pow2 = noisy_mapping(lambda x: x ** 2)


"""
lets record the pairs (x, f(x)) in a metric and make a plot:
"""

from pennpaper import Metric, plot_group, plot

m1 = Metric("pow2")
for x in X:
    m1.add_record(x, pow2(x))

plot(m1)


m2 = Metric("pow2_2")
for x in X:
    m2.add_record(x, pow2(x))

plot_group([m1, m2])


# Actually, m1 and m2 are metrics of the same process.
# What if we create a new metric tracking the mean and stddev of this process?
m3 = m1 + m2
plot(m3)
Ejemplo n.º 9
0
from pennpaper import Metric, plot

m1 = Metric()
m1.add_record(1,1)
m1.add_record(5,5)

m2 = Metric()
m2.add_record(2, 3)
m2.add_record(4, 3)


m3 = m1 + m2

print(m3.data, m3.samples)

plot(m3)
plot(m3, smoothen=False, name='true')