Decide and learn
01 · State, action and return
State, action and return
A decision is judged by future consequences as well as immediate reward.
Your turn
Add
The target combines present reward and discounted future value.
Understand the calculation, step by step
An MDP specifies states, actions, transitions and rewards. Discounted return is Gₜ=Σₖγᵏrₜ₊ₖ₊₁; a policy selects action distributions from state. Partial observations need not form a Markov state. Separate training from evaluation; increasing reward does not prove delivery succeeds.
Bellman target
r=1 ; γ=0.9 ; target = 1 + 0.9V (nonterminal)Check my understanding
Keep a thought in my notebook
Read the source and go further
The extended record combines confirmed reading, interaction, correct answer and a note of at least 40 characters. You can continue at any time.
02 · Policy evaluation and improvement
Policy evaluation and improvement
With known rules, work backwards from the goal to evaluate decisions.
Your turn
Three backups
The third passes γ² to the initial state. This is value iteration, not an animated journey.
Understand the calculation, step by step
With known dynamics, Vπ(s)=Σₐπ(a|s)Σₛ′P(s′|s,a)[r+γVπ(s′)]. Evaluation approximates Vπ; improvement chooses actions with best predicted return. Value iteration directly uses a maximum over actions. Terminal states have no future continuation value. Compare with A* when movement becomes stochastic.
Four-state value iteration
states 0→1→2→3 terminal ; stay or advance ; reward 1 on arrival ; V←maxₐ(r+γV next)Check my understanding
Keep a thought in my notebook
Read the source and go further
The extended record combines confirmed reading, interaction, correct answer and a note of at least 40 characters. You can continue at any time.
03 · SARSA, Q-learning and exploration
SARSA, Q-learning and exploration
An agent updates what it expects from an action using what just happened.
Your turn
Correct by 20%
The new estimate moves 20% toward the target rather than replacing it entirely.
Understand the calculation, step by step
TD corrects a value using a partly estimated target. SARSA uses the actual next action: r+γQ(s′,a′). Q-learning uses r+γmaxₐQ(s′,a), even if exploration chooses differently. Both update Q←Q+α(target−Q). An ε-greedy policy explores; also evaluate without exploration.
TD update
Q=1 ; α=0.2 ; Q′=1+0.2(y−1)Check my understanding
Keep a thought in my notebook
Read the source and go further
The extended record combines confirmed reading, interaction, correct answer and a note of at least 40 characters. You can continue at any time.
04 · Eligibility traces and planning
Eligibility traces and planning
A delayed reward can update several recent decisions.
Your turn
Correct by 20%
The new estimate moves 20% toward the target rather than replacing it entirely.
Understand the calculation, step by step
Eligibility e(s,a) records recent visits, typically decaying by γλ. A TD error can update several past pairs: Q←Q+αδe. Planning reuses a learned model for additional updates; priority can favour large errors. Off-policy traces require a suitable rule, such as cutting them in Watkins Q(λ).
TD update
Q=1 ; α=0.2 ; Q′=1+0.2(y−1)Check my understanding
Keep a thought in my notebook
Read the source and go further
The extended record combines confirmed reading, interaction, correct answer and a note of at least 40 characters. You can continue at any time.
05 · Approximate Q with a network
Approximate Q with a network
A network can estimate action values when a simple table becomes too large.
Your turn
Loss gradient
The gradient is q−3. This is not a full DQN training simulation.
Understand the calculation, step by step
DQN replaces the table with Qθ(s,a), one output per discrete action. A transition provides a Bellman target detached from gradients; backpropagation adjusts the prediction. Replay mixes transitions, reducing temporal correlation. A separate target network is a common stabilization, not assumed in every historical version. This exercise isolates a squared-loss gradient.
DQN loss and gradient
detached target y=3 ; L=(q−3)²/2 ; ∂L/∂q=q−3Check my understanding
Keep a thought in my notebook
Read the source and go further
The extended record combines confirmed reading, interaction, correct answer and a note of at least 40 characters. You can continue at any time.
06 · PuckWorld: continuous state, discrete actions
PuckWorld: continuous state, discrete actions
Describing position with numbers lets an agent learn actions in continuous space.
Your turn
Loss gradient
The gradient is q−3. This is not a full DQN training simulation.
Understand the calculation, step by step
Continuous position and velocity yield too many states for a small table. A network can interpolate inputs while choosing a few discrete pushes. Normalize coordinates and distinguish learned performance from simple target chasing. The original demo shows full training; the local calculation handles one transition rather than training PuckWorld.
DQN loss and gradient
detached target y=3 ; L=(q−3)²/2 ; ∂L/∂q=q−3Check my understanding
Keep a thought in my notebook
Read the source and go further
The extended record combines confirmed reading, interaction, correct answer and a note of at least 40 characters. You can continue at any time.
07 · WaterWorld: perception and reward
WaterWorld: perception and reward
What an agent perceives limits what it can learn to avoid or seek.
Your turn
Add
The target combines present reward and discounted future value.
Understand the calculation, step by step
Perception rays encode nearby objects and distances in an observation vector. Reward can favour food and avoid hazards, but performance depends on visible information and reward design. Hidden state outside the rays may make the task partially observable. Compare with exact position in our grid.
Bellman target
r=1 ; γ=0.9 ; target = 1 + 0.9V (nonterminal)Check my understanding
Keep a thought in my notebook
Read the source and go further
The extended record combines confirmed reading, interaction, correct answer and a note of at least 40 characters. You can continue at any time.
08 · REINFORCE, baseline and recurrence
REINFORCE, baseline and recurrence
Action-selection probabilities can be adjusted directly from outcomes.
Your turn
Policy gradient
The gradient is 2(1−p): its effect shrinks when this action is already likely.
Understand the calculation, step by step
Stochastic policy gradients use ∇log πθ(a|s)(G−b). An action-independent baseline reduces variance without changing expectation; an actor chooses and a critic estimates value. An LSTM can retain observation history. Deterministic gradients chain ∂Q/∂a with ∂μθ/∂θ. The author flags these implementations as unstable: study the ideas without treating them as reliable training.
Policy gradient
p=sigmoid(θ) ; chosen action=1 ; advantage=2 ; ∂J/∂θ=2(1−p)Check my understanding
Keep a thought in my notebook
Read the source and go further
The extended record combines confirmed reading, interaction, correct answer and a note of at least 40 characters. You can continue at any time.
Take this further
atomsh / lab