Reinforcement learning: elements and scope
Introduction to reinforcement learning elements: agent, environment, rewards, returns, policies, value functions, models, Markov decision processes, and the scope of RL compared with other learning paradigms.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Reinforcement learning (RL) is used by engineers to design systems that learn by trial and error from interaction: robots learning to walk, recommendation systems adapting to user clicks, and control systems optimising long-run performance. This topic explains the basic elements and mathematical scope so you can recognise RL problems, state assumptions, and set up learning or planning algorithms (later topics: Multi-armed bandits, Finite Markov decision processes, Policies and value functions, Policy evaluation and iteration, etc.).
Key ideas
Explain every term before use.
- Agent: the decision-maker that selects actions. Appears in the system as an entity that observes some information and outputs actions.
- Environment: everything outside the agent that the agent interacts with. The environment returns an observation (often a state) and a scalar reward after each action.
- Action (A_t): the choice the agent makes at time t. Actions come from an action set A (finite or continuous).
- State (S_t): a representation of the relevant information about the environment at time t. The set of all possible states is S.
- Reward (R_t): a scalar signal the environment gives after a transition; higher is better for the agent. Rewards are measured in "reward units" (unitless quantity specific to the problem).
- Policy (π): a rule the agent uses to select actions. Formal definition: a policy π is a probability distribution over actions given states: π(a|s) = P(A_t = a | S_t = s). A policy is deterministic if π(s) = a for each s, otherwise stochastic.
- Return (G_t): the total future discounted reward from time t: G_t = R_{t+1} + γ R_{t+2} + γ^2 R_{t+3} + ... . The discount factor (γ) satisfies 0 ≤ γ ≤ 1; it controls present value of future rewards. Episodic tasks terminate at a terminal state (finite horizon), while continuing tasks do not terminate.
- Value function: expected return under a policy.
- State-value function (v_π): v_π(s) = E_π[G_t | S_t = s].
- Action-value function (q_π): q_π(s,a) = E_π[G_t | S_t = s, A_t = a].
- Model: a description of the environment's dynamics, typically the transition probabilities and reward distribution. If known, the problem is a planning problem; if unknown, it is a learning-from-interaction problem.
- Markov property: a process has the Markov property if the future depends on the past only through the present state. Formally: P(S_{t+1}, R_{t+1} | S_0, A_0, R_1, ..., S_t, A_t) = P(S_{t+1}, R_{t+1} | S_t, A_t).
- Markov decision process (MDP): a tuple (S, A, P, R, γ) where S is state set, A is action set, P gives transitions P(s', r | s, a), R is reward function (or captured in P), and γ is discount. An MDP assumes the Markov property and stationary dynamics (probabilities do not change over time).
Exact statements used in exams
Bellman expectation equation for v_π (assumptions: process is an MDP, expectations exist and finite): v_π(s) = E_π[R_{t+1} + γ v_π(S_{t+1}) | S_t = s]. Derivation (steps):
- Start with definition: v_π(s) = E_π[G_t | S_t = s].
- Expand G_t: G_t = R_{t+1} + γ G_{t+1}.
- Take expectation conditional on S_t=s: v_π(s) = E_π[R_{t+1} + γ G_{t+1} | S_t=s].
- Use law of total expectation: = E_π[R_{t+1} + γ v_π(S_{t+1}) | S_t=s].
- If given transition probabilities p(s', r | s, a) and policy π, write explicitly: v_π(s) = Σ_a π(a|s) Σ_{s',r} p(s',r|s,a) [r + γ v_π(s')].
Bellman optimality equation (assumptions: an MDP with either γ<1 (and bounded per-step rewards) or episodic tasks with termination; v* denotes optimal value): v_*(s) = max_a Σ_{s',r} p(s',r | s,a) [r + γ v_*(s')]. Explanation: the optimal value equals the value of the best first action then following the optimal policy.
Connection between v and q: q_π(s,a) = E[R_{t+1} + γ v_π(S_{t+1}) | S_t=s, A_t=a]; and v_π(s) = Σ_a π(a|s) q_π(s,a).
Describe what to draw for an exam diagram:
- Draw a time-line with nodes S_t, A_t, R_{t+1}, S_{t+1}, A_{t+1}, R_{t+2}. Label arrows from S_t to A_t (agent), from A_t to environment, then environment to R_{t+1} and S_{t+1}. For MDP transitions, draw a small state-transition graph: two or three states as circles, labelled, with arrows labelled by actions and transition probabilities p(s'|s,a) and immediate rewards r(s,a,s').
Scope and relationships (plain):
- RL is different from supervised learning because supervision (correct actions) is not provided; only scalar rewards are given. It is different from unsupervised learning because there is a clear objective: maximise expected return. RL overlaps with planning when a model is known. The multi-armed bandit problems are a simpler subset (no states or trivial one-state MDP).
Formulas
G_t = R_{t+1} + γ R_{t+2} + γ^2 R_{t+3} + … — G_t: return (reward units); R_k: reward at time k (reward units); γ: discount factor (unitless). Applies to both episodic and continuing tasks; for continuing tasks require γ<1 (with bounded per-step rewards) for convergence; with γ=1, require episodic tasks that terminate almost surely with finite expected episode length.
v_π(s) = E_π[G_t | S_t = s] — v_π(s): state-value under policy π (reward units).
q_π(s,a) = E_π[G_t | S_t = s, A_t = a] — q_π(s,a): action-value (reward units).
v_π(s) = Σ_a π(a|s) Σ_{s',r} p(s',r | s,a) [r + γ v_π(s')] — explicit Bellman expectation; π(a|s) unitless probability; p(s',r | s,a) probability.
v_*(s) = max_a Σ_{s',r} p(s',r | s,a) [r + γ v_*(s')] — Bellman optimality equation.
q_*(s,a) = Σ_{s',r} p(s',r | s,a) [r + γ max_{a'} q_*(s',a')] — optimal action-value. q_π(s,a) = Σ_{s',r} p(s',r | s,a) [r + γ Σ_{a'} π(a'|s') q_π(s',a')] — Bellman expectation equation for action-value.
v_π(s) = Σ_a π(a|s) q_π(s,a) — relation between v and q.
Units: rewards are unitless ("reward units"). These formulas apply when the environment is an MDP and expectations exist (for infinite-horizon discounted return, require γ<1 with bounded per-step rewards; with γ=1 use finite-horizon/episodic tasks).
Worked examples
Example 1 — compute a discounted return (numerical, episodic): Problem: An episode gives rewards R_1=2, R_2=0, R_3=4, then terminates. Let γ=0.9. Compute G_0. Solution steps:
- Use formula
G_0 = R_1 + γ R_2 + γ^2 R_3. - Substitute: = 2 + 0.9·0 + 0.9^2·4.
- Compute 0.9^2 = 0.81; 0.81·4 = 3.24.
- Sum: 2 + 0 + 3.24 = 5.24 reward units. Answer: G_0 = 5.24 (reward units).
Example 2 — policy evaluation in a small MDP (solve linear equations): Problem: Two-state MDP with states S={s1,s2}. Single action always (so trivial policy). Transition and reward: from s1 always go to s2 with reward 5; from s2 always go to s1 with reward 2. Discount γ=0.5. Compute v(s1) and v(s2). Solution steps:
- Write Bellman equations v(s) = E[R_{t+1} + γ v(S_{t+1}) | S_t=s]. For deterministic transitions: v(s1) = 5 + 0.5 v(s2). v(s2) = 2 + 0.5 v(s1).
- Solve the linear system. Substitute v(s2) from second into first: v(s1) = 5 + 0.5 [2 + 0.5 v(s1)] = 5 + 1 + 0.25 v(s1) = 6 + 0.25 v(s1).
- Rearr. 0.75 v(s1) = 6 ⇒ v(s1) = 6 / 0.75 = 8.
- Then v(s2) = 2 + 0.5·8 = 2 + 4 = 6. Answer: v(s1) = 8, v(s2) = 6 (reward units).
Example 3 — choose best action using Bellman optimality (short theory): Problem: At state s you have two actions a1 and a2. After a1 you get immediate reward 3 and move to terminal (value 0). After a2 you get immediate reward 0 and move to s' with v*(s')=5. Discount γ=0.9. Which action is optimal? Compute action values. Solution: q*(s,a1) = 3 + 0.9·0 = 3. q*(s,a2) = 0 + 0.9·5 = 4.5. So a2 is optimal because 4.5 > 3. The optimal value v*(s) = 4.5. Answer: Choose a2; v(s)=4.5 (reward units)*.
Common mistakes
- Using infinite sum for G_t with γ=1 without guaranteed termination — even with bounded rewards the sum can diverge; must state conditions for convergence (finite horizon/termination).
- Treating reward scale as utility without considering long-run trade-offs — reward shaping can change optimal policies.
- Writing Bellman expectation equation but forgetting to sum over both actions (π(a|s)) and next-state distributions p(s',r|s,a).
- Mixing up v_π and q_π: v_π averages q_π under π; q_π conditions on the first action.
For your exam
Question types you will see:
- Definitions and short notes: define agent, environment, policy, return, value function, MDP, Markov property.
- Derivations: derive Bellman expectation equation step-by-step; derive linear system for v_π in a small MDP and solve it.
- Numericals: compute returns with discount, compute v-values by solving equations, compute q-values and choose optimal action.
- Diagrams: draw agent–environment loop and a small MDP transition graph and label probabilities/rewards.
What full-marks answers include:
- Clear definitions with bold naming (agent/environment/policy/state/reward/return/value/model/MDP).
- Explicit statement of assumptions (Markov property, stationarity, γ range, boundedness of rewards when needed).
- Correct derivation steps for Bellman equations, showing the law of total expectation and substitution of G_t = R_{t+1} + γ G_{t+1}.
- For numericals, show formulas used, substitute numbers with units ("reward units"), carry arithmetic, and give final answer with units.
- Diagrams: labelled timeline and transition graph, arrow labels showing probabilities and rewards.
Quick check
- Define the policy π(a|s) in one line.
- Write the Bellman expectation equation for v_π(s) (one formula line).
- If rewards are R_1=1, R_2=1, R_3=1 and γ=0.5, what is G_0 for an episode that stops after time 3? Answers: π(a|s) = P(A_t=a | S_t=s).; v_π(s) = E_π[R_{t+1} + γ v_π(S_{t+1}) | S_t=s].; G_0 = 1 + 0.5·1 + 0.5^2·1 = 1 + 0.5 + 0.25 = 1.75 (reward units).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?