Course contents 05 / 27

05 / 27 · Reinforcement Learning

Q-learning and temporal-difference learning

Learning values from experience: exploration, Monte Carlo and TD targets, SARSA and Q-learning, convergence conditions, and finite-episode λ-returns. Exact fictional examples separate target noise from the cost of exploration.

On this page 10

A service can observe the result of a decision without knowing the probabilities of every possible result. The MDP note assumed those probabilities were available to a Bellman backup. Here the learner receives a transition, updates an estimate, and decides what to try next. Two choices matter: which experience to collect and how much of its future outcome to wait for.

We use three small, fictional cases: binary feedback for four alternatives, a two-stage processing job, and a continuing service with a rechargeable resource. Their inputs, figures and exact calculations were specified for this note with AI assistance. They are teaching examples, not measurements of a deployed system. The code enumerates their outcomes without downloading data or running a simulator.

At time tt the learner sees state StS_t, chooses action AtA_t, then observes reward Rt+1R_{t+1} and state St+1S_{t+1}. A policy π(a∣s)\pi(a\mid s) describes action probabilities. The discount is γ\gamma, the return is Gt=∑j=0T−t−1γjRt+j+1G_t=\sum_{j=0}^{T-t-1}\gamma^jR_{t+j+1} for a finite episode, and Vπ(s)=Eπ[Gt∣St=s]V^\pi(s)=\mathbb E_\pi[G_t\mid S_t=s]. Current tables VV and QQ are estimates; superscripts π\pi and ⋆\star denote the policy’s true values and optimal values. Our continuing example has γ=4/5<1\gamma=4/5<1; terminal states in episodic examples have value zero.

For a finite-horizon task, include time or the remaining horizon in the state whenever it affects future returns; otherwise the value also needs a time index. The notation here uses that state convention.

Baseline: value iteration needs the model#

A known model permits an exact expectation over possible successors. For optimal action values,

Q⋆(s,a)=E[Rt+1+γmax⁡bQ⋆(St+1,b)∣St=s,At=a].Q^\star(s,a)=\mathbb E\left[R_{t+1}+\gamma\max_bQ^\star(S_{t+1},b)\mid S_t=s,A_t=a\right].

A learner without the model cannot evaluate that expectation directly. It can observe one reward and successor, form a sample target, and adjust its current estimate. The arithmetic is the same as an incremental mean:

xˉn=xˉn−1+1n(xn−xˉn−1),v←v+α(y−v).\begin{gathered} \bar x_n=\bar x_{n-1}+\frac1n(x_n-\bar x_{n-1}), \\ v\leftarrow v+\alpha(y-v). \end{gathered}

The first equality exactly averages observations; the second replaces the averaging weight by a chosen step size. A constant α\alpha discounts older observations. This can track a changing target, but it does not satisfy the diminishing-step conditions used later for convergence. A further complication is that the target contains another value estimate, which also changes during learning.

Exploration first: the multi-armed bandit#

Before considering future states, suppose there are four alternatives with stationary, independent reward streams. Each reward is 0 or 1. The learner does not know their means μa\mu_a and chooses which stream to observe next. Greedy selection can stop trying a good alternative after unlucky early observations. Fixed ε-greedy selection instead chooses uniformly with probability ε>0\varepsilon>0, and otherwise uses a largest sample mean.

For this stationary bandit, every alternative is sampled infinitely often almost surely under fixed ε-greedy exploration. Its sample mean then converges. If some alternatives are suboptimal, random selection still incurs an expected loss on every future decision. Writing Δa=max⁡bμb−μa\Delta_a=\max_b\mu_b-\mu_a, the expected regret is

LT=∑aΔa E[NT(a)].L_T=\sum_a\Delta_a\,\mathbb E[N_T(a)].

Fixed uniform exploration alone contributes Tε∑aΔa/4T\varepsilon\sum_a\Delta_a/4. Thus constant ε generally leaves linear regret; this is not a statement about a schedule that reduces ε.

UCB1 gives rarely sampled alternatives an uncertainty bonus. After trying every alternative once, choose at decision tt

At∈arg⁡max⁡a[μ^a+2ln⁡tNa],A_t\in\arg\max_a\left[\widehat\mu_a+\sqrt{\frac{2\ln t}{N_a}}\right],

where counts and means use decisions before tt. The bonus follows a bounded-reward concentration argument; it is not an empirical standard deviation. For independent stationary rewards in [0,1][0,1], Auer, Cesa-Bianchi and Fischer (2002), Theorem 1 prove a gap-dependent logarithmic expected-regret bound. The coefficient and assumptions matter: arbitrary bonuses or dependent, drifting feedback do not inherit that theorem.

Our snapshot contains 40 observations. At the next decision, t=41t=41, it gives:

AlternativeTrialsSuccessesMeanUCB1 score
118110.6111111.253465
21250.4166671.203387
3620.3333331.445924
4410.2500001.612639

Greedy chooses alternative 1, while UCB1 chooses 4. Its large score expresses uncertainty, not a probability of success above one. These counts are constructed inputs: there is no hidden true mean or claim that alternative 4 is actually best. In an MDP, exploration must also reach states; randomizing actions in a state never reached cannot provide its data.

Monte Carlo prediction#

Prediction holds the policy fixed and estimates its values. In the processing example there is no action choice. Intake II gives reward −1-1 and leads to stage AA with probability 3/43/4, or stage MM with probability 1/41/4. Stage AA terminates with reward 0 or 4, equally likely; stage MM terminates with reward 1 or 3, equally likely. All episodes take two transitions, and γ=4/5\gamma=4/5.

Both successor stages have expected reward 2. Therefore

Vπ(A)=Vπ(M)=2,Vπ(I)=−1+45⋅2=35.\begin{gathered} V^\pi(A)=V^\pi(M)=2, \\ V^\pi(I)=-1+\frac45\cdot2=\frac35. \end{gathered}

A Monte Carlo target waits for the full return. From intake, the four possible returns and probabilities are

G0∈{−1,115,−15,75},p=(38,38,18,18).\begin{gathered} G_0\in\left\{-1,\frac{11}{5},-\frac15,\frac75\right\}, \\ p=\left(\frac38,\frac38,\frac18,\frac18\right). \end{gathered}

Updating V(I)←V(I)+α(G0−V(I))V(I)\leftarrow V(I)+\alpha(G_0-V(I)) uses an unbiased target for Vπ(I)V^\pi(I). This says nothing about whether one sampled target is close to the value. Full-return prediction must wait for termination; continuing tasks require another construction, such as a finite horizon with a tail estimate. Longer episodes do not universally have larger return variance: reward correlations, discounting and the reward distribution matter.

TD(0): learning a guess from a guess#

The Bellman expectation equation replaces the random future after the next state by its conditional mean. TD(0) substitutes the current value table for that mean and updates immediately:

yt=Rt+1+γV(St+1),δt=yt−V(St),V(St)←V(St)+αδt.\begin{gathered} y_t=R_{t+1}+\gamma V(S_{t+1}), \\ \delta_t=y_t-V(S_t), \\ V(S_t)\leftarrow V(S_t)+\alpha\delta_t. \end{gathered}

Using a learned estimate within a target is bootstrapping. Sutton (1988), §§2.2–2.3 and 5.1 develops temporal-difference prediction and the cumulative-reward extension. A terminal successor contributes zero. An artificial time limit is different from a true terminal state if the intended process would continue beyond it.

For one observed episode, intake goes to AA, then terminates with reward 4. Suppose initially V(I)=0V(I)=0, V(A)=3V(A)=3 and α=1/4\alpha=1/4. TD can update intake after the first transition:

y0=−1+45⋅3=75,V(I)←0+14⋅75=720=0.35.\begin{gathered} y_0=-1+\frac45\cdot3=\frac75, \\ V(I)\leftarrow0+\frac14\cdot\frac75=\frac7{20}=0.35. \end{gathered}

Monte Carlo waits for reward 4, obtains G0=11/5G_0=11/5, and would instead update the same initial intake estimate to 11/20=0.5511/20=0.55. Neither one-sample update equals the true value 3/53/5. TD is early because it uses the estimate 3; Monte Carlo is late because it uses the observed final reward 4.

Which target is better: bias against variance#

Treat VV as fixed when comparing the distributions of the next targets. In a Markov process under a fixed policy, its conditional TD bias is

E[yt∣St=s]−Vπ(s)=γ E[V(St+1)−Vπ(St+1)∣St=s].\mathbb E[y_t\mid S_t=s]-V^\pi(s) =\gamma\,\mathbb E[V(S_{t+1})-V^\pi(S_{t+1})\mid S_t=s].

The exact next-state values remove this bias. Indeed, the exact-value TD target is the conditional expectation of the return given the first reward and successor. The law of total variance then gives variance no larger than the return’s variance, provided those variances exist. Replacing those values with arbitrary estimates removes this guarantee.

In our example the Monte Carlo mean is 3/53/5 and variance 52/25=2.0852/25=2.08. With exact successor values, TD is always 3/53/5, so its variance is zero. Now deliberately use V(A)=10V(A)=10 and V(M)=−6V(M)=-6. TD targets become 7 and −29/5-29/5, with probabilities 3/43/4 and 1/41/4. Their mean is 19/519/5, bias 16/5=3.216/5=3.2, and variance 768/25=30.72768/25=30.72.

Figure

Variance depends on the continuation estimate

Variance depends on the continuation estimateFrom intake: target variances are 2.08, 0 and 30.72. The last row uses V(A)=10 and V(M)=−6 instead of the true 2. These are exact distribution moments, not a learning curve; wrong bootstrapping increases both bias and variance here.Monte CarloMean: 0.6Variance: 2.08TD: exact valuesMean: 0.6Variance: 0.00TD: wrong valuesMean: 3.8Variance: 30.7208162432Target variance
From intake: target variances are 2.08, 0 and 30.72. The last row uses V(A)=10 and V(M)=−6 instead of the true 2. These are exact distribution moments, not a learning curve; wrong bootstrapping increases both bias and variance here.

The experiment compares target distributions, not learning curves. A shorter sampled horizon alone does not ensure lower variance or smaller mean-squared error. Step size, approximation error and available experience also affect the learned table.

A useful exact identity holds with a frozen value table and terminal value zero. Expanding each δk=Rk+1+γV(Sk+1)−V(Sk)\delta_k=R_{k+1}+\gamma V(S_{k+1})-V(S_k) cancels intermediate values:

Gt−V(St)=∑j=0T−t−1γjδt+j.G_t-V(S_t)=\sum_{j=0}^{T-t-1}\gamma^j\delta_{t+j}.

This is an identity between errors, not equality of ordinary Monte Carlo and online TD(0) parameter updates. Online updates can change the table between terms; repeated states can make this difference visible. Eligibility traces below specify how later errors contribute back to earlier states. The policy-gradient note uses a related weighted sum to estimate advantages.

On a fixed dataset, the zero of the sum of tabular TD residual updates solves an empirical Bellman system, whereas averaging full returns gives empirical Monte Carlo values. With a discounted, fully specified empirical transition model, the former system has a unique solution. Replaying individual samples with a constant step need not reach that zero exactly, and neither empirical estimate is guaranteed better on an unknown true process.

From prediction to control: SARSA and Q-learning#

Action values let the agent compare actions without querying a transition model. Both methods update Q(St,At)←Q(St,At)+α(yt−Q(St,At))Q(S_t,A_t)\leftarrow Q(S_t,A_t)+\alpha(y_t-Q(S_t,A_t)), but use different targets:

ytSARSA=Rt+1+γQ(St+1,At+1),ytQ=Rt+1+γmax⁡bQ(St+1,b),ytexpected SARSA=Rt+1+γ∑bπ(b∣St+1)Q(St+1,b).\begin{aligned} y_t^{\rm SARSA}&=R_{t+1}+\gamma Q(S_{t+1},A_{t+1}),\\ y_t^{\rm Q}&=R_{t+1}+\gamma\max_b Q(S_{t+1},b),\\ y_t^{\rm expected\ SARSA}&=R_{t+1}+\gamma\sum_b\pi(b\mid S_{t+1})Q(S_{t+1},b). \end{aligned}

SARSA uses the next action actually selected by the behaviour policy, including its exploration. The five quantities in its name are state, action, reward, next state, next action. It is on-policy. With expected SARSA, averaging over the policy removes the randomness of this next-action draw, while environment randomness remains. Q-learning uses a greedy target even when the actual next action is exploratory: this is the off-policy distinction, not a promise that arbitrary data coverage suffices. See Singh et al. (2000), §2.1 and Watkins and Dayan (1992), §2.

For a local arithmetic check, let a transition give reward 2, with next-state action estimates 3 and −2-2, current updated entry 1, γ=4/5\gamma=4/5, and α=1/4\alpha=1/4. Q-learning uses target 4.4 and updates the entry to 1.85. If SARSA’s next action is the one valued at −2-2, it uses target 0.4 and updates to 0.85. With ε-greedy ε=1/5\varepsilon=1/5, the next-action probabilities are 0.9 and 0.1; expected SARSA uses target 4 and updates to 1.75. These are stipulated current estimates, not converged values.

An implementation chooses the next action before the SARSA update and executes that same choice. For a true terminal transition every method uses only the immediate reward. Otherwise interaction continues; changing the target does not change which reward was observed.

A rechargeable resource: what on-policy and off-policy learn#

Consider a continuing service with resource level s∈{0,1,2}s\in\{0,1,2\}. Action 0 charges; action 1 runs a job. The full model is provided here only so that we can calculate an exact reference for learning:

StateCharge: next state, rewardRun: next state, reward
01, −1/50, −6
12, −1/50, 2
22, −1/51, 5/2

Rewards are utility units. Running with no resource incurs a penalty; charging at capacity still costs time. There is no terminal state or reset, and γ=4/5\gamma=4/5. A deterministic skeleton g=(g(0),g(1),g(2))g=(g(0),g(1),g(2)) chooses one action per state. Uniform ε-greedy mixing around it gives

πg,ε(a∣s)=(1−ε)1[a=g(s)]+ε2.\pi_{g,\varepsilon}(a\mid s)=(1-\varepsilon)\mathbb 1[a=g(s)]+\frac\varepsilon2.

There are eight skeletons. For each, calculate its transition matrix and expected rewards, then solve

(I−γPg,ε)Vg,ε=rg,ε.(I-\gamma P_{g,\varepsilon})V_{g,\varepsilon}=r_{g,\varepsilon}.

The discounted system is invertible. The code compares all states and checks the Bellman residuals; it does not infer a best policy from one possibly unreachable starting state.

With no exploration, the optimal skeleton is (0,1,1)(0,1,1): charge at zero, run otherwise. Its values are (35/9,46/9,593/90)(35/9,46/9,593/90). But under permanent ε=1/5\varepsilon=1/5, each non-skeleton action still occurs with probability 1/101/10. The best skeleton becomes (0,0,1)(0,0,1), which also charges at level 1. Its values are

(267519890,976215,11821719780).\left(\frac{26751}{9890},\frac{976}{215},\frac{118217}{19780}\right).
Figure

Compare under the same exploration

Compare under the same explorationValue from resource level 1 with γ=4/5. The lower two rows share ε=1/5: charging at level 1 improves value. The top row turns exploration off and is a separate reference. Each value comes from solving three policy Bellman equations.ε=0 · g=(0,1,1)5.111ε=1/5 · g=(0,1,1)3.647ε=1/5 · g=(0,0,1)4.5400123456Value V(1)
Value from resource level 1 with γ=4/5. The lower two rows share ε=1/5: charging at level 1 improves value. The top row turns exploration off and is a separate reference. Each value comes from solving three policy Bellman equations.

From level 1, exploring around the no-exploration optimum gives 784/215≈3.647784/215\approx3.647. Choosing the best skeleton for that same exploration rate gives 976/215≈4.540976/215\approx4.540. Charging earlier changes the future state distribution and reduces exposure to running at zero. If exploration is switched off, the original optimum has value 46/9≈5.11146/9\approx5.111 there; comparing that number directly with an exploring policy would change the evaluation condition.

These are exact policy evaluations, not a finite-run SARSA benchmark. They show why evaluating persistent behaviour can favour a different action from optimizing a policy intended for greedy deployment. SARSA does not automatically converge to the best exploring policy for every arbitrary exploration rule; Singh et al. (2000), §3.2 gives conditions for persistent rank-based randomization. With vanishing exploration, convergence to the unrestricted optimum still needs the conditions below.

When the estimates converge#

Keep the statement to finite tabular, stationary MDPs with bounded rewards and 0≤γ<10\leq\gamma<1. For every updated state or state–action entry, the step sizes must obey

0<αn≤1,∑nαn=∞,∑nαn2<∞.\begin{gathered} 0<\alpha_n\leq1, \\ \sum_n\alpha_n=\infty, \\ \sum_n\alpha_n^2<\infty. \end{gathered}

Here nn counts that entry’s updates, not all global environment steps. A schedule αn=1/n\alpha_n=1/n satisfies these sums. The first sum prevents learning from stopping too early; the second controls accumulated sampling noise.

  • Fixed-policy tabular TD(0) converges to the policy value when every relevant state continues to be sampled and the stochastic-approximation conditions hold. This is a fixed-policy contraction problem, not a result for an arbitrarily changing policy.
  • Tabular Q-learning converges almost surely to optimal action values with infinitely many valid samples of every state–action pair and those step-size conditions. The behaviour may differ from the target policy, but must provide the required coverage.
  • For SARSA’s convergence to optimal values, exploration must additionally be greedy in the limit with infinite exploration (GLIE). Merely writing εt→0\varepsilon_t\to0 is insufficient: exploration may disappear before needed actions or states receive enough visits.

The precise results are Watkins and Dayan (1992), Jaakkola, Jordan and Singh (1993), and Singh et al. (2000), Theorem 1. We do not extend the discounted statement to every undiscounted episodic problem by assuming termination alone. Properness and other hypotheses need separate checking.

A constant positive step violates the square-summability condition and generally leaves noise; deterministic special cases can still converge. These theorems provide neither a useful finite-sample budget nor a universal horizon-dependent rate. Replacing the table by a neural network also changes the mathematical problem.

Between one step and the whole episode: n-step returns and eligibility traces#

For a frozen value function, an n-step target uses observed rewards until the chosen horizon, then bootstraps if the episode is still running:

Gt:t+n=∑j=0n−1γjRt+j+1+γnV(St+n),t+n<T.\begin{gathered} G_{t:t+n}=\sum_{j=0}^{n-1}\gamma^jR_{t+j+1}+\gamma^nV(S_{t+n}), \\ t+n<T. \end{gathered}

Once the horizon reaches the terminal time, use the full return GtG_t. Longer horizons replace some value-estimation error by additional sampled rewards. Bias and variance need not change monotonically with the horizon.

For a finite remaining length N=T−tN=T-t, the λ-return can include the terminal case explicitly:

Gtλ=(1−λ)∑n=1N−1λn−1Gt:t+n+λN−1Gt,0≤λ≤1.\begin{gathered} G_t^\lambda=(1-\lambda)\sum_{n=1}^{N-1}\lambda^{n-1}G_{t:t+n}+\lambda^{N-1}G_t, \\ 0\leq\lambda\leq1. \end{gathered}

The last term holds the remaining probability mass. At λ=0\lambda=0 this is the one-step target, and at λ=1\lambda=1 it is the full return. With one transition left, the expression is just GtG_t. In the continuing infinite-series formula, geometric weights sum to one only for 0≤λ<10\leq\lambda<1; substituting 1 into that series does not define its endpoint.

A separate three-transition trace has rewards (−1,2,3)(-1,2,3), frozen values (1/2,3/2,−1/4,0)(1/2,3/2,-1/4,0), and γ=4/5\gamma=4/5. The targets for horizons 1, 2 and 3 are 1/51/5, 11/2511/25 and 63/2563/25. For λ=1/2\lambda=1/2, their weights are 1/2,1/4,1/41/2,1/4,1/4, giving G0λ=21/25=0.84G_0^\lambda=21/25=0.84.

Eligibility traces accumulate how strongly a later TD error should affect previously visited states. Start each episode with zero traces; accumulating tabular traces use

zt(s)=γλzt−1(s)+1[s=St],V(s)←V(s)+αδtzt(s).\begin{gathered} z_t(s)=\gamma\lambda z_{t-1}(s)+\mathbb 1[s=S_t], \\ V(s)\leftarrow V(s)+\alpha\delta_tz_t(s). \end{gathered}

For frozen values, Gtλ−V(St)=∑j=0N−1(γλ)jδt+jG_t^\lambda-V(S_t)=\sum_{j=0}^{N-1}(\gamma\lambda)^j\delta_{t+j}. In our trace the TD errors are (−3/10,3/10,13/4)(-3/10,3/10,13/4); their weighted sum is 0.340.34, exactly 0.84−0.50.84-0.5. Accumulating these corrections and applying them after the episode yields the corresponding forward-view update. Ordinary online TD(λ) changes VV immediately, so finite-step equality with this frozen forward view is not automatic. Sutton (1988), §§2.2–2.3 and 5.2 distinguishes sequence-end and within-sequence updates.

What changed#

ChoiceWhat it usesWhat must be checked
Exact Bellman backupKnown transition probabilities and expected rewardsCorrect model
Monte Carlo targetObserved return to terminationFixed evaluation policy, finite moments
TD targetNext reward and estimated successor valueBootstrap error and coverage
SARSA targetThe next action actually selectedBehaviour and target agree
Q-learning targetA greedy next-state action valueOff-policy coverage and convergence conditions

Limitations#

The finite cases isolate mechanisms. They do not predict performance on text, images or continuous state spaces. Our exact evaluator uses a known model for validation, while the learner would only see sampled transitions. Tabular values cannot generalize to unvisited states, and ε-greedy exploration can waste actions on known poor choices. A transition may be stored and reused; neither TD nor Q-learning requires throwing it away after one update.

No learning curve in this note establishes a universal ranking of algorithms. Bootstrapping, noisy maximization, changing policies and function approximation introduce distinct errors. In particular, maximizing unbiased noisy action estimates can create upward bias; the next note discusses methods that separate selection from evaluation.

What you should remember#

  • A sample target replaces an unavailable Bellman expectation; the learner must still collect useful experience.
  • Monte Carlo waits for the return. TD updates sooner using another estimate; its variance advantage requires conditions.
  • SARSA evaluates the next action actually taken. Q-learning targets a greedy continuation even during exploration.
  • Permanent exploration can change the optimal behaviour, as the resource example shows under identical evaluation conditions.
  • Convergence needs coverage, appropriate step sizes and, for optimal SARSA, GLIE. Finite-episode λ-returns retain a terminal tail weight.

Code#

This standalone Python example uses only the standard library. It solves the eight skeletons at each of two exploration rates with exact fractions, checks the prediction target moments, and computes the UCB snapshot. Floating-point logarithms affect only the displayed UCB scores. It does not train an agent or require a third-party dataset.

from fractions import Fraction as F
from itertools import product
from math import log, sqrt


def solve(matrix, rhs):
    rows = [list(row) + [b] for row, b in zip(matrix, rhs)]
    n = len(rows)
    for col in range(n):
        pivot = next(i for i in range(col, n) if rows[i][col])
        rows[col], rows[pivot] = rows[pivot], rows[col]
        divisor = rows[col][col]
        rows[col] = [x / divisor for x in rows[col]]
        for i in range(n):
            if i != col:
                multiplier = rows[i][col]
                rows[i] = [x - multiplier * y for x, y in zip(rows[i], rows[col])]
    return [row[-1] for row in rows]


def step(state, action):
    if action == 0:  # charge
        return min(2, state + 1), -F(1, 5)
    return max(0, state - 1), [-F(6), F(2), F(5, 2)][state]


def evaluate(skeleton, epsilon):
    gamma = F(4, 5)
    matrix = [[F(i == j) for j in range(3)] for i in range(3)]
    reward = [F(0) for _ in range(3)]
    for s in range(3):
        for a in range(2):
            probability = epsilon / 2 + (1 - epsilon) * (a == skeleton[s])
            nxt, r = step(s, a)
            matrix[s][nxt] -= gamma * probability
            reward[s] += probability * r
    return solve(matrix, reward)


def best(epsilon):
    candidates = [(p, evaluate(p, epsilon)) for p in product(range(2), repeat=3)]
    return max(candidates, key=lambda item: sum(item[1]))


def moments(outcomes):
    mean = sum(p * x for p, x in outcomes)
    return mean, sum(p * (x - mean) ** 2 for p, x in outcomes)


def demo():
    for epsilon in (F(0), F(1, 5)):
        policy, values = best(epsilon)
        print('epsilon', epsilon, 'skeleton', policy, 'V', [str(x) for x in values])
    print('exploring optimal skeleton: V(1)', evaluate((0, 1, 1), F(1, 5))[1])
    mc = [(F(3, 8), -F(1)), (F(3, 8), F(11, 5)),
          (F(1, 8), -F(1, 5)), (F(1, 8), F(7, 5))]
    print('MC mean, variance', [str(x) for x in moments(mc)])
    print('wrong TD mean, variance', [str(x) for x in moments([(F(3, 4), F(7)), (F(1, 4), -F(29, 5))])])
    scores = [hits / n + sqrt(2 * log(41) / n) for n, hits in zip([18, 12, 6, 4], [11, 5, 2, 1])]
    print('UCB1 scores', [round(x, 6) for x in scores])


demo()
epsilon 0 skeleton (0, 1, 1) V ['35/9', '46/9', '593/90']
epsilon 1/5 skeleton (0, 0, 1) V ['26751/9890', '976/215', '118217/19780']
exploring optimal skeleton: V(1) 784/215
MC mean, variance ['3/5', '52/25']
wrong TD mean, variance ['19/5', '768/25']
UCB1 scores [1.253465, 1.203387, 1.445924, 1.612639]

The full verifier also checks all policy Bellman residuals, the finite λ-mixture endpoints and a repeated-state counterexample to applying the frozen identity to online updates. Saved results contain the exact fractions.

Next#

The deep Q-network note replaces separate table entries by a function of the state. This can transfer experience to related inputs, but it also changes stability and coverage questions. Keep the distinction between the behaviour that generates data and the target used in an update when reading about replay and target networks.

References#

The sources below support definitions and mathematical conditions. No source task, figure, code, dataset or reported experiment is used as the numerical case in this note.