Skip to content
    Neuron City

    REINFORCEMENT LEARNING · 10 MIN

    Reinforcement Learning

    An agent learns which actions earn the most reward by trying them.

    PIXEL explains

    • State → action → reward → next state, over and over.
    • Q-learning keeps a table Q[state][action] of expected future reward.
    • Balance exploring new actions with exploiting the best-known one (ε-greedy).

    Real world: Training a dog with treats: good actions get rewarded and become habits.

    Code

    q = {"left": 0.0, "right": 0.0}
    reward = {"left": 0, "right": 1}
    lr = 0.5
    for _ in range(4):
        for a in q:
            q[a] += lr * (reward[a] - q[a])
    print(max(q, key=q.get), round(q["right"], 3))
    Output ›
    right 0.938
    Try it in the online compiler →

    Checkpoint quiz

    Trying a random action sometimes is called…