Actor–critic: coordinate policy and value learning
Actor–Critic
Calculate TD errors and train an episodic actor and critic, separating bootstrap bias from state baselines.
actor-criticCan an action be evaluated before the episode ends?
Going right in the two-step game costs 0.1 before a possible reward of 1. Immediate reward alone discourages that branch; a complete episode reveals the return but may take a long time in a larger task. Actor–critic uses a critic’s estimate of future value to help an actor adjust action probabilities. The actor is a policy and the critic a value function, not two competing agents in the environment. Original actor–critic analysis
We retain the game in which left action 0 earns 0.4, right action 1 earns 1, and gamma is 0.9. The actor has three Bernoulli logits and the critic three state values. Read policy gradients and temporal-difference learning first.
When does TD error estimate advantage?
V is expected return when continuing with the policy; Q additionally fixes the current action. Advantage measures how much better that action is than the state’s usual performance. With exact V, the Markov property and a consistent discounted objective give the following identity, where d indicates genuine termination:
The critic actually has an approximation V_w. A transition supplies a TD error, and the critic treats its bootstrap target as fixed in a semi-gradient update:
This is not the full residual gradient through both V terms. In our table, only the visited state’s value receives beta times delta. Genuine termination removes the next value. An external collection limit on a continuing task keeps next-state bootstrap but separates the transition from the reset trajectory. TD residuals and advantage
For a start-discounted objective, replacing complete return minus baseline with TD error gives the episodic actor update:
The actor treats delta as constant. Critic error and the update’s sampling distribution affect this approximate gradient; naming a quantity an advantage does not make it unbiased. Write V_w=V_pi+e. The conditional advantage error becomes:
The current-state term−e(s) is an action-independent baseline and disappears after multiplying by the score and taking its conditional expectation. Next-state error, however, may depend on the action. An inaccurate critic can therefore bias the actor, but need not always do so. In a one-step terminal task there is no next value: any action-independent V_w is merely a baseline. This refutes the claim that every inaccurate critic necessarily biases the gradient. Baselines and compatibility conditions
Under zero logits, this game’s true left value is 0.2, right value 0.5 and start value 0.265. If only the right-state estimate is too high by 1, the first actor-gradient component gains an extra:
This is a concrete path from action-dependent successors to gradient bias, even without a large network. Separately, a transition with reward 2, current value 0.4 and next value 10 has different errors at two boundaries:
The second expression assumes the task continues and the next observation is the pre-reset successor. Substituting the reset observation creates another error.
Freeze one episode, then update the two tables separately
The standard-library program runs 6000 two-step episodes with actor rate 0.08, critic rate 0.15 and seeds 0–7. To make timing inspectable, both tables remain fixed during an episode. The two collected TD errors update their respective tables afterward; the next episode uses the new values. This is not the full two-timescale algorithm from Konda and Tsitsiklis.
"""Finite episodic tabular actor-critic; not the Konda convergence algorithm."""
import json
import math
import random
def sigmoid(x):
if not math.isfinite(x):
raise ValueError('finite logit required')
return 1/(1+math.exp(-x)) if x >= 0 else math.exp(x)/(1+math.exp(x))
def td_error(reward, value, next_value, terminated, gamma=0.9):
if not all(math.isfinite(x) for x in (reward, value, next_value, gamma)) or not 0 <= gamma <= 1:
raise ValueError('finite values and gamma in [0,1] required')
return reward + (0. if terminated else gamma*next_value) - value
def collect(theta, values, rng):
"""Freeze both tables throughout the two-step episode."""
p0 = sigmoid(theta[0])
a0 = int(rng.random() < p0)
branch = 1+a0
p1 = sigmoid(theta[branch])
a1 = int(rng.random() < p1)
d0 = td_error(-0.1*a0, values[0], values[branch], False)
d1 = td_error(float(a1) if a0 else 0.4*(1-a1), values[branch], 0., True)
return [(0, a0-p0, d0), (branch, a1-p1, d1)]
def train(seed=0, episodes=6000, actor_lr=0.08, critic_lr=0.15):
if episodes < 0 or not all(math.isfinite(x) and x > 0 for x in (actor_lr, critic_lr)):
raise ValueError('nonnegative episodes and positive finite rates required')
theta, values, rng = [0., 0., 0.], [0., 0., 0.], random.Random(seed)
for _ in range(episodes):
updates = collect(theta, values, rng)
for t, (state, score, delta) in enumerate(updates):
theta[state] += actor_lr*0.9**t*score*delta
# Semi-gradient TD: target and actor advantage are not differentiated.
values[state] += critic_lr*delta
p0, left, right = map(sigmoid, theta)
value = (1-p0)*0.9*0.4*(1-left)+p0*(-0.1+0.9*right)
exact_v = [value, 0.4*(1-left), right]
return {'seed': seed, 'return': value, 'logits': theta, 'critic': values,
'exact_values': exact_v, 'critic_max_error': max(abs(x-y) for x, y in zip(values, exact_v))}
def main():
runs = [train(seed) for seed in range(8)]
print(json.dumps({'initial_return': 0.265, 'optimal_return': 0.8, 'runs': runs,
'failures_below_0_7': [r['seed'] for r in runs if r['return'] < 0.7],
'boundary': {'terminal': td_error(2., 0.4, 10., True),
'time_limit': td_error(2., 0.4, 10., False)}}, indent=2))
if __name__ == '__main__':
main()
Inspect the complete recorded output
{
"initial_return": 0.265,
"optimal_return": 0.8,
"runs": [
{
"seed": 0,
"return": 0.7957748333104974,
"logits": [
5.541668832830929,
-1.4221997535406732,
5.992210520266784
],
"critic": [
0.7996178967118394,
0.2524256083848647,
0.9999528352923803
],
"exact_values": [
0.7957748333104974,
0.3222732147018956,
0.9975080893685404
],
"critic_max_error": 0.06984760631703091
},
{
"seed": 1,
"return": 0.7958536540096947,
"logits": [
5.498238875825717,
-1.2102545949922132,
6.095316284246828
],
"critic": [
0.7999999999999994,
0.27181858927667985,
0.9999999999999997
],
"exact_values": [
0.7958536540096947,
0.30813759743880165,
0.9977516690689605
],
"critic_max_error": 0.0363190081621218
},
{
"seed": 2,
"return": 0.7956367964725679,
"logits": [
5.3547232595684235,
-1.112514221872784,
6.167125310285512
],
"critic": [
0.7999798929773196,
0.38751344264617865,
0.9999999999999997
],
"exact_values": [
0.7956367964725679,
0.30103901716988496,
0.9979071329743205
],
"critic_max_error": 0.08647442547629369
},
{
"seed": 3,
"return": 0.7950547283023515,
"logits": [
5.382326732238279,
-1.343051598246328,
5.84295524245659
],
"critic": [
0.7999999999999994,
0.3357553155128457,
0.9999999999999997
],
"exact_values": [
0.7950547283023515,
0.3171965310992868,
0.9971081281969572
],
"critic_max_error": 0.018558784413558904
},
{
"seed": 4,
"return": 0.7964322731588315,
"logits": [
5.538220542889688,
-1.3153153532933317,
6.361528770340474
],
"critic": [
0.7995929138119986,
0.27041753222850057,
0.9999478058035194
],
"exact_values": [
0.7964322731588315,
0.3153604990071073,
0.9982762515123061
],
"critic_max_error": 0.04494296677860671
},
{
"seed": 5,
"return": 0.7960381593310617,
"logits": [
5.594062954747708,
-1.3022392856062153,
6.0805486703230125
],
"critic": [
0.7999999988862421,
0.3365119873666522,
0.9999999999999997
],
"exact_values": [
0.7960381593310617,
0.3144846439678741,
0.9977182965341587
],
"critic_max_error": 0.0220273433987781
},
{
"seed": 6,
"return": 0.7961870273051321,
"logits": [
5.454167201543116,
-1.3154603894296621,
6.317611674555731
],
"critic": [
0.799998774610438,
0.24366902465232637,
0.9999999999802833
],
"exact_values": [
0.7961870273051321,
0.315370176847438,
0.9981990019514955
],
"critic_max_error": 0.07170115219511164
},
{
"seed": 7,
"return": 0.795829972297071,
"logits": [
5.560223734622066,
-1.1923293509091835,
6.0250476823227785
],
"critic": [
0.7999995546594025,
0.29301910784274393,
0.9999999996876661
],
"exact_values": [
0.795829972297071,
0.3068629631637861,
0.9975883936091814
],
"critic_max_error": 0.013843855321042153
}
],
"failures_below_0_7": [],
"boundary": {
"terminal": 1.6,
"time_limit": 10.6
}
}Across eight seeds, exact expected returns are approximately 0.7951–0.7964, all above the preset 0.7 check threshold; the best deterministic route earns 0.8. The critic still has error: the maximum state error ranges around 0.0138–0.0865. A rarely visited left branch can be inaccurate while the policy almost always goes right. High policy return does not certify every critic prediction.
The table requires constant arithmetic per transition and O(S) parameters for each of actor and critic, with S=3 here. A general d-dimensional policy adds O(d) score accumulation, and a neural critic adds backpropagation. Online, batched and shared-network versions use different update timing that should be documented separately.
Two learners can hinder each other
A critic lagging behind a changing policy supplies stale or wrong update weights; a rapidly changing actor shifts the critic’s data distribution. A slower actor, more critic updates or a more stable estimator may help. Merely choosing a smaller actor rate does not establish convergence conditions.
The read portion of Konda and Tsitsiklis concerns finite chains, smooth policies, average-cost minimization, particular linear critic features and two timescales. Those conclusions do not automatically cover arbitrary deep networks, constant rates or our episodic game. Original conditions REINFORCE avoids bootstrap; advantage estimation combines residuals across multiple horizons.
Trace the entry point of an error
- Do actor and critic both minimize squared TD error? Answer: No. The critic fits a value target, while the actor uses score times estimated advantage to improve return. Our actor does not backpropagate through delta.
- With reward 2, V=0.4 and next value 10, what are terminal and time-limit deltas? Answer: They are1.6 and 10.6. The latter requires a continuing task and the actual pre-reset next observation.
- In a one-step terminal task with p=0.8 and reward equal to action, does an incorrect V=0.7 bias the expected logit gradient? Answer: No. Delta is a−0.7, and the expected gradient remains p(1−p)=0.16. Conditional advantage values shift, but the score cancels the action-independent baseline.
- Return approaches 0.8 while left-branch value error remains large. How should evaluation report this? Answer: Separate return under the actual visitation distribution, per-state value error and visit counts. If deployment can force entry into the left branch, collect and evaluate that state’s data rather than hiding the gap behind overall return.
A family name does not specify a theorem’s assumptions
Konda and Tsitsiklis 1999, PDF 1–5, was read for assumptions, critic features and update relations; full conditions and proofs on 6–7 were not audited. Sutton and colleagues 1999, PDF 2–4, supplies policy-gradient and compatible-approximation conditions. GAE v6, PDF 1–5, supports the TD-advantage and discount discussion. Actor–critic Policy gradients Advantage estimation
This article maximizes reward; Konda’s original formulation minimizes average cost. Our constant-rate finite-episode results are independent examples, not reproductions of that convergence proof or a control benchmark.
Make a prediction, then check
With reward2, V=0.4, next value10 and gamma=0.9, what is terminal TD error?
Learning objectives
- Explain when TD error estimates advantage in conditional expectation and how approximate next-state values can bias it.
- Implement actor and semi-gradient critic updates separately with correct termination and truncation handling.
Prerequisites & connections
Explore related knowledge →References
- Actor-Critic Algorithms — scoped assumptions and recursions
Vijay R. Konda; John N. Tsitsiklis · 1999 - Policy Gradient Methods for Reinforcement Learning with Function Approximation — scoped theorem reading
Richard S. Sutton; David McAllester; Satinder Singh; Yishay Mansour · 1999 - High-Dimensional Continuous Control Using Generalized Advantage Estimation — arXiv v6
John Schulman; Philipp Moritz; Sergey Levine; Michael I. Jordan; Pieter Abbeel · 2018
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-23 · Single AI author. Scoped reading: Read PDF1–5, viewed5. Finite chains, average cost, linear critic features and two timescales. Full conditions/proof on6–7 unread; a constant-step episodic toy does not inherit that convergence result. Identity on PDF1; read2–4 and viewed3/4. Average reward, discounted occupancy and both compatible-approximation conditions. No later full proof audit or experiment replication. First2015-06-08, ICLR2016, selected v6 dated2018-10-20. Read PDF1–5, viewed5; gamma-just, TD and GAE, keeping its undiscounted-objective surrogate distinct from the ordinary discounted gradient. Later result tables and appendices unread. 6 paired equations and four explained exercises. Exact-value TD advantage identity, action-dependent next-value error and inexact terminal-baseline counterexample checked. Actor score and critic semi-gradient targets are frozen within each episode. Eight seeds and state-value errors retained; no claim to reproduce Konda two-timescale convergence.
- Exact-value TD advantage identity, action-dependent next-value error and inexact terminal-baseline counterexample checked. Actor score and critic semi-gradient targets are frozen within each episode. Eight seeds and state-value errors retained; no claim to reproduce Konda two-timescale convergence.
- Four computed SVG variants per topic;16 numeric/geometry tests and36 current responsive cases passed. All twelve selected current captures directly viewed. Three groups retain initial captures; three use their actually viewed revised captures. Actual assets and manuscripts are SHA bound. Full article acceptance recorded separately.
Source locations checked:
- Actor-Critic Algorithms — scoped assumptions and recursions · Read PDF1–5, viewed5. Finite chains, average cost, linear critic features and two timescales. Full conditions/proof on6–7 unread; a constant-step episodic toy does not inherit that convergence result.
- Policy Gradient Methods for Reinforcement Learning with Function Approximation — scoped theorem reading · Identity on PDF1; read2–4 and viewed3/4. Average reward, discounted occupancy and both compatible-approximation conditions. No later full proof audit or experiment replication.
- High-Dimensional Continuous Control Using Generalized Advantage Estimation — arXiv v6 · First2015-06-08, ICLR2016, selected v6 dated2018-10-20. Read PDF1–5, viewed5; gamma-just, TD and GAE, keeping its undiscounted-objective surrogate distinct from the ordinary discounted gradient. Later result tables and appendices unread.
Related topics