Reinforcement Learning Overview
- 22Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the primary inspiration for reinforcement learning, and how does it differ from supervised and unsupervised learning?
22 questions
- 1
What is the primary inspiration for reinforcement learning, and how does it differ from supervised and unsupervised learning?
Model answer
Reinforcement learning is inspired by operant conditioning in psychology. It differs from supervised learning, which uses labeled data and error correction, and unsupervised learning, which finds natural groupings in data. RL learns through sparse reward signals without explicit correct outputs.
Explanation
The text states RL is inspired by operant conditioning, where actions leading to good outcomes are reinforced. Supervised learning uses labels and error, unsupervised finds clusters via K-means, while RL uses rewards.
- 2
In reinforcement learning, what is an episode?
Model answer
An episode is a round of execution in an environment with a beginning and an end; after reaching a terminal state, the environment resets.
Explanation
The text defines an episode as having a start and end, resetting after a terminal state is reached.
- 3
What does it mean for an environment to be discrete?
Model answer
A discrete environment has a finite and countable number of states, such as the 16 squares in the 4x4 grid.
Explanation
The text explicitly states the problem is discrete because the agent is always in one of 16 possible states.
- 4
Explain why the grid environment in the example is considered fully observable and deterministic.
Model answer
Fully observable means the agent knows exactly which state it is in with no hidden information. Deterministic means that a given action always leads to a predictable next state; for example, moving up always goes to the square above (or stays at the top wall).
Explanation
The text describes the environment as fully observable because the agent knows its location, and deterministic because there are no probabilities in transitions.
- 5
What is a Q-value, and how does it differ from an immediate reward?
Model answer
A Q-value is an expectation of the accumulated future rewards from taking a specific action in a given state and then always choosing the best action thereafter. An immediate reward is the reward received instantly upon entering a state, not an expectation.
Explanation
The text distinguishes Q-values as expectations of total future reward, whereas the +100 and -100 are immediate rewards.
- 6
In Q-learning, what is a policy, and how is it derived from Q-values?
Model answer
A policy is a function that maps each state to the action that should be taken. It is derived by selecting, for each state, the action with the highest Q-value.
Explanation
The text defines policy as a function that given a state returns the action, and it is graphically represented by arrows showing the best action in each state.
- 7
Why is it important to randomly select among tied Q-values when choosing the best action?
Model answer
If the agent always chooses the first action among ties (e.g., left), it could get stuck repeating an action that leads nowhere and never explore other actions, preventing learning.
Explanation
The text gives an example where always choosing left when all Q-values are zero causes the agent to be stuck hitting the left wall.
- 8
What is the epsilon-greedy exploration strategy, and what problem does it solve?
Model answer
Epsilon-greedy means with probability epsilon (e.g., 0.1), the agent chooses a random action instead of the best one. It solves the problem of never discovering better alternatives that exist outside the current best path.
Explanation
The text introduces epsilon-greedy to allow the agent to occasionally explore and discover alternative rewards or paths that it would otherwise miss by always exploiting.
- 9
Describe the exploration versus exploitation dilemma.
Model answer
Exploration is taking random actions to discover new information, while exploitation is using current knowledge to maximize reward. The dilemma is balancing the two: too much exploitation prevents discovering better options, too much exploration prevents accumulating high rewards.
Explanation
The text explains this dilemma: always exploiting leads to missing better paths, always exploring leads to never optimizing.
- 10
What is the role of the discount factor gamma in Q-learning?
Model answer
Gamma (γ) discounts future rewards, making rewards further away worth less than immediate rewards. This helps the agent differentiate between paths that lead to the same reward but take different lengths.
Explanation
The text uses gamma to penalize longer paths, so the agent prefers rewards received sooner. Example: 100 immediate vs 90 discounted for one step away.
- 11
What is the learning rate alpha, and how does it affect learning in a non-deterministic environment?
Model answer
Alpha (α) controls how much the new estimate overrides the old Q-value. In a non-deterministic environment, a small alpha (e.g., 0.2) prevents the Q-value from jumping to extreme values by gradually moving toward the target, allowing an average to represent the expected outcome.
Explanation
The text shows that with alpha=0.2, a Q-value of 100 is moved toward -100 only to 60, not all the way, reflecting the probabilistic outcome.
- 12
Write the Q-learning update formula and explain each term.
Model answer
Q(S,A)←Q(S,A)+α[R+γmaxaQ(S′,a)−Q(S,A)] where Q(S,A) is the current Q-value, α is learning rate, R is immediate reward, γ is discount factor, maxaQ(S′,a) is the maximum Q-value in the next state, and the bracket is the temporal difference error.
Explanation
The text gives this formula and explains each component: current value, alpha, reward, gamma times highest future value, minus current value.
- 13
How should the Q-learning update be modified when the next state is terminal?
Model answer
When the next state is terminal, the term γmaxaQ(S′,a) should be omitted (set to 0) because there is no future beyond the terminal state.
Explanation
The text shows that for terminal states, the expected future is zero, so the formula becomes just Q(S,A)←Q(S,A)+α[R−Q(S,A)].
- 14
What is optimistic initialization, and how can it act as an exploration strategy?
Model answer
Optimistic initialization sets all initial Q-values to a high positive number (e.g., 100). This makes the agent initially curious to try actions because it believes they have high value, effectively encouraging exploration even without epsilon-greedy.
Explanation
The text demonstrates that with initial Q=100, the agent explores actions it hasn't tried, but notes a potential problem if terminal states also have high initial values (requires handling in the update).
- 15
In the grid world example, starting at bottom-left, what is the goal state and what is the trap state?
Model answer
The goal state is the top-right corner (reward +100), and the trap state is the square directly below the goal (reward -100).
Explanation
The text specifies the upper right corner gives +100 and ends the episode, the square below gives -100 and ends the episode.
- 16
How does the agent learn to avoid the trap in the deterministic environment?
Model answer
When the agent enters the trap from a previous state, the -100 reward is copied to the Q-value of the action that led there. In subsequent visits, the agent chooses other actions with higher Q-values, thus avoiding the trap.
Explanation
The text steps through the learning process: the reward is copied to the Q-value of the action from the preceding state, making that action unattractive.
- 17
Why does the agent eventually learn the shortest path to the reward when gamma < 1?
Model answer
With gamma < 1, Q-values decay for actions further from the reward. The agent compares Q-values and chooses actions that lead to higher discounted sums, which correspond to shorter paths because rewards are discounted less.
Explanation
The text shows that Q-values decrease as distance increases (e.g., 100, 90, 81, etc.), so the agent selects actions with higher values that are closer to the goal.
- 18
In the provided code, what does the
get_actionmethod implement, and how?Model answer
get_actionimplements epsilon-greedy: it generates a random number; if less than epsilon, it returns a random action; otherwise, it returns the action with the highest Q-value (randomly selecting among ties).Explanation
The code shows: if random < epsilon -> random action, else -> max action with tie-breaking via random choice among best.
- 19
What is the purpose of the
stumble_probabilityparameter in the environment class?Model answer
It makes the environment non-deterministic by randomly altering the intended movement direction. With probability stumble_probability, the agent may move to a different adjacent square instead of the chosen direction.
Explanation
The text introduces stumble probability to simulate real-world randomness; the code adds random offsets to the row/column if a random number is less than stumble_probability.
- 20
Why does the author note that debugging machine learning code is difficult?
Model answer
Because machine learning seeks approximate solutions and tolerates errors, a bug may produce results that still work (e.g., the agent still finds the goal), making it hard to distinguish between a bug and normal algorithm behavior.
Explanation
The text shares an anecdote about a bug that only caused small value changes but the agent still worked, highlighting the difficulty.
- 21
What are two other reinforcement learning algorithms mentioned besides Q-learning?
Model answer
SARSA and Monte Carlo methods.
Explanation
The text lists SARSA and Monte Carlo as other RL algorithms the interested reader can explore.
- 22
What is a potential issue when using optimistic initialization without correctly handling terminal states?
Model answer
If terminal states also have high initial Q-values (e.g., 100), the agent believes there is future reward after reaching a terminal state, which is incorrect because the episode ends. This can lead to inflated Q-values beyond the maximum possible cumulative reward.
Explanation
The text demonstrates this issue: with initial Q=100, final states show values >100 because the agent expects future reward, which is fixed by modifying the update for terminal states.

Ask anything
We've read this whole study set, so questions about it get the best answers.