5.2.13 · D5Deep & Advanced RL
Question bank — Reward shaping and sparse rewards
Prerequisites worth having loaded: Markov Decision Processes, Value Functions and Bellman Equations, Exploration vs Exploitation.
True or false — justify
Adding any reward that "points toward the goal" is safe as long as it is small.
False. Magnitude is not the issue — shape is. A tiny per-step bonus for hugging a wall still lets an infinite loop accumulate unbounded reward, so the agent maximizes the loop, not the task. Only potential-based form guarantees safety, no matter the size.
Potential-based reward shaping (PBRS) always speeds up learning.
False. PBRS guarantees the optimal policy is unchanged, but speed depends entirely on whether resembles the true value . A useless or misleading (say , or one pointing away) preserves correctness while giving no learning boost — or even a temporarily misleading gradient.
Under PBRS with , the value function itself is unchanged.
False. The policy is unchanged, but the value is shifted: . The shift is a per-state constant over actions, which is exactly why survives while the numbers do not.
If two states have equal potential, , then moving between them earns zero shaping reward.
False in general. With discount , unless . The equality only forces when . This is exactly why the cannot be dropped.
A shaped reward that changes the sign of some transitions must change the optimal policy.
False. PBRS routinely makes some transitions negative (moving away from goal) and others positive, yet the optimal policy is provably identical because the whole shaping term telescopes to a start-state constant.
Hindsight Experience Replay can corrupt the optimal policy the way naïve shaping does.
False. HER relabels goals on already-collected transitions; it never injects extra reward into a loop. There is no free reward to milk, so it cannot create reward hacking — it just densifies the learning signal.
Curriculum learning changes the reward function.
False. It changes the distribution of goals / start states over training, not itself. The reward stays the true task reward; only the difficulty of the tasks the agent faces is scheduled.
Making rewards dense is always better than keeping them sparse.
False. A sparse-but-correct reward defines the true objective exactly. A dense reward is only better if it is faithful; a badly designed dense reward invites specification gaming. Sparse is safe but slow; dense is fast but risky.
Spot the error
"I used and got policy invariance in my discounted MDP."
The is missing. Without it the telescoping leaves residual terms proportional to , so the shaping does not collapse to a start-state constant and the optimal policy can shift. Correct form is .
"My potential is , a function of the action too, so I can steer specific moves."
Illegitimate. The invariance proof requires to depend on the state only; a term does not telescope and behaves like arbitrary shaping, so it can change the optimal policy. Steer via state potentials only.
"To reward finishing fast, I add each time the agent reaches checkpoint ."
This is per-visit reward, not potential-based. Re-entering pays again every loop, so the agent learns to oscillate through forever. The fix is so entering is cancelled by leaving.
"Shaping gives the agent enough signal, so I removed all exploration bonuses even though I have no idea where the goal is."
If you don't know where the goal is you cannot build a useful , so shaping gives no real gradient. You still need exploration — an intrinsic curiosity bonus or HER — that needs no domain knowledge.
" — I kept the final potential too."
The telescope collapses everything except the very first term to zero; the last potential is annihilated by the discount factor of the term after it (in the infinite-horizon / absorbing sum). Only survives, so .
"I set the intrinsic count bonus to so more-visited states are encouraged."
Backwards. Curiosity rewards novelty, so it must decrease with visits: . As written it rewards revisiting familiar states and kills exploration.
Why questions
Why does a sparse reward make -values "flat" over the visited region early in training?
Almost every observed , so the return is for essentially all visited states. With near-zero returns everywhere the agent has been, no action's estimated value exceeds another, so there is nothing to be greedy about.
Why does the probability of stumbling onto a sparse reward by luck decay exponentially with required steps?
Reaching the goal by random exploration means hitting a specific sequence of choices; each step multiplies the success probability by a factor below 1, so an -step goal has success probability roughly , which vanishes fast in .
Why must the shaping bonus for entering a state exactly cancel the bonus for leaving it to prevent hacking?
If entry and exit cancel, then any closed loop sums the shaping to zero, so looping yields no extra reward. That kills the incentive to repeat a cycle, which is precisely the mechanism of reward hacking.
Why is the ideal potential?
It makes the shaped optimal value roughly zero everywhere, so from step one the shaped reward already distinguishes good moves (small loss) from bad ones (large loss). The agent starts life with a near-perfect gradient, so learning becomes almost trivial.
Why does PBRS preserve even though it subtracts from every -value?
depends on the state, not the action, so it is the same constant subtracted from every action's . Subtracting a shared constant never changes which action is largest.
Why is a wall-hugging bonus a specification gaming risk but distance-to-goal-as-a-potential is not?
The wall bonus is per-step and non-potential, so a wall-hugging loop banks it repeatedly. The distance term written as telescopes to zero over any loop, so no cyclic exploit exists.
Why does HER turn "failures" into learning signal without inventing fake reward?
It relabels the intended goal to the goal the agent actually reached, so a trajectory that failed at becomes a genuine success at . The transitions and true reward are unchanged — only the goal input is swapped, so no reward is fabricated.
Edge cases
If (undiscounted), does the PBRS formula still preserve the optimal policy?
Yes, provided the potential of any absorbing/terminal state is fixed (commonly there). With the shaping is and still telescopes to over a finite episode, so invariance holds.
What happens if is constant, for all ?
Then , a fixed per-step reward. It is a legal potential (policy still invariant) but adds a uniform bias each step — useful as a "living penalty" ( gives ) yet it provides no directional gradient.
What is the shaping reward on a self-loop ?
. For and this is negative, discouraging idling — and it can never be positive-plus-repeatable in a way that beats the task, preserving safety.
At a terminal/absorbing state , what convention keeps the proof valid?
Set (or treat the episode as ending, so no next-state potential is added after ). Otherwise a nonzero terminal potential leaks an uncancelled term into the return and can distort the policy.
Does shaping help if the agent has literally never reached the goal region even once?
Only if was built from prior knowledge (e.g. a distance heuristic), because then supplies a gradient before any goal contact. If was to be learned from experience, it is uninformative until the goal is found — so you still need exploration first.
What if the potential is negative everywhere, e.g. with ?
Perfectly fine. Signs of are irrelevant to invariance; only the telescoping form matters. Negative-distance potentials are the standard "closer is better" heuristic and change nothing about the guarantee.
Can two different potentials and (shifted by a constant) give different optimal policies?
No. A constant shift adds to every transition uniformly — itself a valid potential shaping — so both preserve the same optimal policy. The added constant washes out of .
Recall Quick self-check before you leave
Which single ingredient of makes loops net to zero and, if dropped, breaks invariance in discounted MDPs? ::: The discount factor multiplying the next-state potential ; drop it and the sum no longer telescopes.