Rewards and returns: when does changing the score change the task?
奖励与回报
Compute discounted returns, inspect truncation and derive when reward shifts or potential shaping preserve preferences.
rewards-returnsA harmless-looking point penalty changes the winner
Two invented ways to finish a task produce rewards [2] and [0, 0, 3]. With discount 0.9, their returns are 2 and 2.43, so the longer route is preferable. Now subtract one point from every reward before termination. The sequences become [1] and [-1, -1, 2], with returns 1 and −0.28. The shorter route wins.
Nothing about the transitions changed. The reward transformation changed how much duration costs. Adding the same constant to every immediate reward is not generally the same as adding one constant to every policy’s total score.
This article separates rewards, return definitions and transformations of the objective. Sutton and Barto’s working draft, Sections 3.2–3.4 explains the reward formulation and episodic/continuing distinction. Ng, Harada and Russell study conditions under which additional rewards preserve optimal policies. We will derive a sufficient condition and expose its boundary term.
Count transitions, then choose the objective
A reward is a scalar received on a transition. A return combines a sequence of future rewards. If an episode terminates at time T, the discounted return from time t includes the reward received on entry to the terminal state:
The first reward has exponent zero. The terminal state’s future value is zero because no additional rewards follow; that does not erase the reward on the transition into it. With discount 1, this is the ordinary finite sum. For an infinite continuing task, bounded rewards and discount strictly below 1 provide a simple sufficient condition for a finite return. These are different assumptions, as the working draft emphasizes.
The immediate reward is not a label saying which action should have been taken. A negative reward can be part of a useful long-term strategy. Nor is maximizing a scalar score proof that the designer chose the right score: the reward hypothesis is a modeling stance, not a guarantee that every human preference is faithfully captured by one supplied number.
A cutoff leaves a remainder
Separate a prefix of H transitions from the remaining return:
Replacing the final random return by the exact conditional value under the same policy gives a correct conditional-expectation target in a Markov model. Replacing it by an estimate introduces that estimate’s error. Setting it to zero at a mere time limit can discard valuable continuation. For a one-step prefix [0] followed by a known policy value 4, the bootstrapped target is 3.6 at discount 0.9; without continuation it is zero. At a genuine terminal state, zero continuation is correct.
If rewards have magnitude at most M and discount is below 1, the omitted tail after H observed rewards obeys a geometric-series bound:
The bound is attained by a continuing sequence of rewards all equal to M. It becomes loose for many other sequences. It does not apply with discount 1 without additional horizon or termination assumptions. The program rejects that use rather than dividing by zero.
Constant shifts depend on the horizon
Adding a constant c on every one of L remaining transitions changes the return by:
If all policies have the same fixed horizon, this extra term is policy-independent. In a truly continuing discounted formulation, adding c on every future step gives the common shift c/(1−gamma). But an episodic transformation that stops paying the added constant after termination has a policy-dependent duration. With random episode lengths, even the expected shift can depend on the policy. That is why the opening example reverses its preference.
One can represent an episode by an absorbing zero-reward state, as the working draft does. Adding c even on that state’s endless self-loops restores the common continuing shift; keeping those self-loops at zero describes a different transformation. State which operation is actually being performed.
Multiplying all rewards by a positive constant is simpler, provided the returns exist:
For the two routes, multiplying by 2 changes 2 and 2.43 to 4 and 4.86. A negative multiplier reverses preference; a zero multiplier removes the reward distinction. Mathematical preference preservation also does not promise unchanged numerical learning behavior when optimizer steps, clipping or other algorithm settings are kept fixed.
Potential shaping works by cancellation
Let a potential Phi(s) assign a real number to each state. Add the following reward on a transition, using the same discount as the return:
This is the potential-based form in Ng, Harada and Russell’s Theorem 1. Expand the discounted sum along a finite trajectory: every intermediate positive potential cancels a matching negative one from the next term. What remains is:
For an episodic implementation that stops summing at termination, setting terminal potential to zero makes the change depend only on the start state. For a fixed start distribution, every policy receives the same expected shift, so their preferences are preserved. In a continuing discounted formulation, bounded potentials make the remaining boundary tend to zero as the horizon grows. These conditions are doing the work; “add progress rewards” by itself is not a theorem.
For rewards [0, 4], potentials [2, 1, 0] and discount 0.9, the shaped rewards are [-1.1, 3]. Their return is 1.6, exactly the original 3.6 minus the starting potential 2. If the terminal potential is instead 5 while summation still stops there, the shaped rewards become [-1.1, 7.5], and the return is 5.65. The extra boundary 0.9² × 5 has not vanished. It can depend on arrival time or terminal state, so one cannot silently claim invariance.
Inspect every term of the transformation
Save this original program as returns.py and run it with Python 3.12 or later. It uses only the standard library. It accepts explicit finite reward and potential sequences, not an environment or a learned model. discounted evaluates backward from an optional bootstrap value; shape returns both the transformed sequence and the predicted boundary term.
"""Original return arithmetic and explicit reward-transformation boundaries."""
import json
import math
def discount_check(gamma):
if not math.isfinite(gamma) or not 0 <= gamma <= 1:
raise ValueError('gamma must be in [0, 1]')
def discounted(rewards, gamma, bootstrap=0.0):
discount_check(gamma)
rewards = list(rewards)
if not all(math.isfinite(r) for r in rewards) or not math.isfinite(bootstrap):
raise ValueError('finite rewards and bootstrap required')
value = bootstrap
for reward in reversed(rewards):
value = reward + gamma*value
return value
def tail_bound(max_reward, gamma, horizon):
discount_check(gamma)
if gamma == 1 or not math.isfinite(max_reward) or max_reward < 0:
raise ValueError('bounded rewards and gamma < 1 required')
if type(horizon) is not int or horizon < 0:
raise ValueError('nonnegative integer horizon required')
return max_reward*gamma**horizon/(1-gamma)
def shape(rewards, potentials, gamma):
rewards, potentials = list(rewards), list(potentials)
discount_check(gamma)
if len(potentials) != len(rewards)+1 or not all(math.isfinite(x) for x in rewards+potentials):
raise ValueError('one finite potential per visited state required')
shaped = [r+gamma*potentials[i+1]-potentials[i] for i,r in enumerate(rewards)]
return dict(rewards=shaped, original=discounted(rewards,gamma),
shaped=discounted(shaped,gamma),
boundary=gamma**len(rewards)*potentials[-1]-potentials[0])
def demo():
short, long = [2.0], [0.0, 0.0, 3.0]
return dict(discounts=[dict(gamma=g,short=discounted(short,g),long=discounted(long,g)) for g in (0,.5,.9,1)],
shifted_minus_one=dict(short=discounted([r-1 for r in short],.9),long=discounted([r-1 for r in long],.9)),
scaled_two=dict(short=discounted([2*r for r in short],.9),long=discounted([2*r for r in long],.9)),
continuing_shift=-1/(1-.9),
zero_terminal_potential=shape([0,4],[2,1,0],.9),
nonzero_terminal_potential=shape([0,4],[2,1,5],.9),
cutoff_with_bootstrap=discounted([0],.9,bootstrap=4),
cutoff_without_bootstrap=discounted([0],.9),
constant_reward_tail=dict(actual=.9**10/(1-.9),bound=tail_bound(1,.9,10)))
if __name__ == '__main__':
print(json.dumps(demo(), indent=2, allow_nan=False))
The output reproduces the preference reversal, positive scaling, terminal-potential examples and cutoff target. It also compares the exact tail of a constant-reward sequence with the bound: with unit reward, discount 0.9 and ten observed steps, both are approximately 3.4867844. This is a deliberately tight case, not an empirical estimate of typical truncation error.
For a sequence of L rewards, backward accumulation takes O(L) time. This implementation copies the input to a list, so it also uses O(L) auxiliary space; a caller with an already reversible sequence could avoid that copy. Shaping explicitly stores L transformed rewards. Inputs must be finite and lengths consistent. Discount 1 is accepted for finite-sequence arithmetic, but excluded from the continuing geometric-tail helper.
Preserving preferences is narrower than preserving a task
The shaping identity assumes the reward transformation uses the same discount and the stated trajectory boundaries. Nonzero terminal potentials, a different discount inside the shaping term, changing start distributions or time-dependent potentials need separate analysis. For an undiscounted continuing process, bounded immediate rewards alone do not make total return finite.
Even a preference-preserving transformation changes the numbers encountered during learning. It may change variance and finite-sample behavior. The shaping paper gives a formal framework; this tutorial checks the telescoping identity and its sufficient conditions, not the paper’s necessity proof or its experimental speed claims.
The examples also do not tell you which rewards are ethically or operationally appropriate. A time penalty expresses a preference about duration. If duration really matters, changing the optimal policy may be exactly the intended effect. The mistake is describing that choice as a harmless algebraic rewrite.
Look for a term that failed to cancel
-
Explain termination. Why is terminal continuation zero while the reward received on entering the terminal state may be nonzero?
Answer: The last transition still belongs to the episode and contributes its reward. Zero continuation refers to rewards after arrival. Deleting the last transition reward would change the objective, rather than merely representing termination.
-
Calculate a penalty. At discount 0.9, subtract one from each reward in
[2]and[0, 0, 3]. Show the resulting returns and the source of the different shifts.Answer: They become 1 and
−1 − 0.9 + 0.81 × 2 = −0.28. The first loses 1; the second loses1 + 0.9 + 0.81 = 2.71. The original long route scored 2.43, so its preference over 2 is reversed. -
Test a cycle. For potentials
[2, 1, 2], calculate the total shaping contribution with discount 1 and with discount 0.9. Are both zero?Answer: At discount 1 the contributions are −1 and 1, summing to zero. At discount 0.9 they are −1.1 and 0.8, whose discounted sum is
−1.1 + 0.9 × 0.8 = −0.38. The boundary formula gives the same value,(0.9² − 1) × 2. A finite discounted cycle does not generally have zero shaping sum. -
Design the objective. A task has variable-length episodes. You want faster completion, and someone proposes a per-step penalty while saying it cannot change the optimal policy. What needs to be corrected?
Answer: A per-step penalty can change preference because policies incur different discounted durations. That may be desirable if speed is part of the objective. Specify the penalty and termination convention, then evaluate the new task. If the aim is only additional learning guidance with preserved preferences, analyze a potential-based transformation and its terminal/start conditions instead.
Read the conditions beside the reward formula
The 2014–2015 Sutton–Barto working draft develops rewards, returns, discounting and zero-reward absorbing completion. Ng, Harada and Russell state the potential-based transformation and its assumptions. The derivations here use finite trajectories to make the boundary visible, and bounded discounted limits only when their assumptions hold.
Continue with policies and values to turn random returns into conditional expectations. Bellman equations use the same one-step decomposition; forgetting the continuation term there creates the same error as confusing a time limit with termination here.
Make a prediction, then check
Does subtracting one from every reward before termination always preserve the best episodic policy?
Learning objectives
- Calculate return with the correct time index, terminal boundary and omitted-tail bound.
- Construct a variable-length episode counterexample to constant reward-shift invariance and derive the shaping boundary term.
Prerequisites & connections
Explore related knowledge →References
- Reinforcement Learning: An Introduction — second-edition working draft (2014–2015)
Richard S. Sutton; Andrew G. Barto · 2015 - Policy invariance under reward transformations: Theory and application to reward shaping
Andrew Y. Ng; Daishi Harada; Stuart Russell · 1999
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-23 · Single AI author. Scoped reading: PDF71 reward hypothesis framed as a hypothesis,73–75 return/discount/absorbing completion. Read2026-09-23, not the completed2018 edition. Text extraction was unreadable; directly viewed PDF1,3,4. Identity, additive shaping, finite-state/proper-episode conditions and Theorem1 potential difference. No proof of necessity, benchmark, bicycle experiment or unrestricted reward-invariance claim audited. Tutorial separately derives the finite-trajectory boundary term. 7 paired equations and four explained exercises. Checked finite backward returns against direct sums, discount endpoints, variable-length shift reversal, positive scaling, potential telescoping including nonzero endpoints, bootstrap cutoff and a tight geometric tail.
- Checked finite backward returns against direct sums, discount endpoints, variable-length shift reversal, positive scaling, potential telescoping including nonzero endpoints, bootstrap cutoff and a tight geometric tail.
- Four computed SVG variants per topic;12 numeric/geometry tests and36 responsive cases passed. Twelve selected current captures visually checked: eight byte-identical to viewed initial images and four reviewed final images; line-wrap revisions retained. Full article acceptance recorded separately.
Source locations checked:
- Reinforcement Learning: An Introduction — second-edition working draft (2014–2015) · PDF71 reward hypothesis framed as a hypothesis,73–75 return/discount/absorbing completion. Read2026-09-23, not the completed2018 edition.
- Policy invariance under reward transformations: Theory and application to reward shaping · Text extraction was unreadable; directly viewed PDF1,3,4. Identity, additive shaping, finite-state/proper-episode conditions and Theorem1 potential difference. No proof of necessity, benchmark, bicycle experiment or unrestricted reward-invariance claim audited. Tutorial separately derives the finite-trajectory boundary term.
Related topics