Policy Objective Functions
An objective function says what a good policy means: total return from the start, average value over visits, or reward per step forever.
Why Does This Exist?
Policy gradients climb , but what is ? Value methods hide their target inside Bellman error, while policy methods must name the number they maximize. The honest answer depends on the task shape: a game ends, a server queue never does, and a refinery cares about throughput per hour, not discounted sums.
Pick the wrong score and the agent optimizes the wrong thing. Discounting a never ending task invents a horizon that is not there; scoring a game by steady state throughput ignores that only the final result counts. This page defines the three standard scores, shows they share one gradient form, and works one policy under all three so you can feel the difference.
Think of It Like This
Three ways to judge a night market stall
A stall owner can be judged three ways. Total profit from opening night to closing day suits a one week festival stall. Average till balance across evenings, weighted by how often each crowd shows up, suits a seasonal stall that discounts later weeks. Profit per hour suits a permanent stall that never closes.
Same stall, same cooking, three scoreboards. The permanent stall owner who chases opening night totals will overstaff week one and burn out. Match the scoreboard to the stall's lifespan, or the numbers will lie to you.
The analogy stops where math starts: market crowds shift with seasons, while these objectives assume the environment's dynamics stay fixed.
How It Actually Works
Write the parameterized policy and let be how often the policy visits . Three scores cover the task shapes:
- Start value for episodic tasks: expected discounted return from the start state . Visits are counted with discounting, .
- Average value for continuing discounted tasks: state values weighted by the stationary visit frequencies.
- Average reward for continuing undiscounted tasks: plain reward per step, where is the expected immediate reward.
Differentiating looks hopeless because moves both the actions and the visit frequencies. The policy gradient theorem removes the second dependence: for all three scores,
which rewrites with the log trick as an expectation over sampled steps, . That single form is what REINFORCE and actor critic methods sample.
Worked example
Two market nights cycle: night 1 offers safe stir fry (stay, reward 1) or fancy seafood (switch to night 2, reward 3); night 2 always returns with reward 0. Let be the switch probability, discount . Visit frequencies solve to and .
- At (never switch): visits , start value , average value , reward rate .
- At (mix): visits , start value , average value , reward rate .
- At (always switch): visits , start value , average value , reward rate .
Check one by hand: at the reward rate is . All three scoreboards rise together and crown . They disagree on units but agree on the winner, which is exactly why one gradient serves all three.
Code
This snippet evaluates all three scores for any switch probability using the closed forms above.
def objectives(p: float, gamma: float = 0.8): """Closed form scores for the two night market: never, mix, always switch.""" d1 = 1.0 / (1.0 + p) d2 = p / (1.0 + p) reward_rate = (1.0 + 2.0 * p) / (1.0 + p) start_value = (1.0 + 2.0 * p) / ((1.0 - gamma) + p * gamma * (1.0 - gamma)) avg_value = d1 * start_value + d2 * gamma * start_value return {"d": [round(d1, 3), round(d2, 3)], "J1": round(start_value, 3), "JavV": round(avg_value, 3), "JavR": round(reward_rate, 3)}
print(objectives(0.0))print(objectives(0.5))print(objectives(1.0))Watch Out For
Discounting a task that never ends
Applying discounted scores to a permanent process invents a fake horizon: early rewards count, late ones fade, and the agent chases startup transients instead of steady throughput.
Symptom: the learned policy depends on the arbitrary start state and the arbitrary discount. Fix: switch to the average reward score with differential returns, , which measure each reward against the steady rate instead of against zero.
Averaging values under the wrong visits
Average value weights states by visit frequency, so a stale frequency estimate silently reweights the whole objective toward places the new policy never goes.
Symptom: the score improves on paper while the deployed policy earns less. Fix: re-estimate visit frequencies from fresh rollouts after every substantial policy change, and distrust averages computed under last month's behavior.
The Quick Version
- Start value suits episodes, average value suits discounted continuing tasks, reward rate suits permanent ones.
- All three gradients share one form, so one sampler optimizes whichever scoreboard fits.
- Here never, mix, and always switch scored reward rates 1.000, 1.333, and 1.500.
- All three scoreboards peaked at always switch, disagreeing on units but agreeing on the winner.
- Discounting a never ending task fakes a horizon; use reward rate with differential returns instead.