Skip to content
AI360Xpert
Beta

Deep Reinforcement Learning

Deep reinforcement learning pairs neural perception with trial and error control, so agents learn features and decisions together from raw input.

Raw state passes through an encoder into compact features, then a decision head outputs values or a policy trained by reward
Raw state passes through an encoder into compact features, then a decision head outputs values or a policy trained by reward

Why Does This Exist?

Tabular methods need one entry per state. With an 84 by 84 grayscale camera frame the count of possible images is 2567056256^{7056}, far beyond any table. The agent also never sees the same exact frame twice, so memorization cannot generalize.

Linear approximation helped but moved the work to people. Engineers hand built tile codings and basis functions, and those features broke under lighting shifts or new viewpoints. Raw video, lidar and torque streams need features that adapt with the task.

Deep RL joins representation learning to control. One network maps raw input to compact features zz and then to values or a policy, trained end to end by reward. Early layers learn edges and motion, later layers learn decisions. This page frames that joint loop. For the value instance see deep Q-networks. For the policy instance see policy gradient. For the memory trick that stabilizes it see experience replay.

The one idea you need first

A Markov decision process has states S\mathcal{S}, actions A\mathcal{A}, transition odds P\mathcal{P}, rewards R\mathcal{R} and discount γ\gamma. A parametrized function fθ(s)f_{\theta}(s) with weights θ\theta replaces the table. In deep RL that function is a neural network trained by reward feedback.

Think of It Like This

A rookie short order cook who also designs the kitchen

A rookie starts with random instincts. Tickets arrive as raw orders. Over months the cook learns two things at once: where to place each tool so the counter makes sense, and which move to make next given that layout. Better layout makes better moves easier, and better moves teach which layout matters.

The counter layout is the encoder output zz. Tool placement is weights ψ\psi. Cooking moves are the policy or values from head weights ϕ\phi. Reward is tips and returned plates. No coach hands over a perfect kitchen map. The map and the moves improve together.

Where it stops: a human brings prior senses and imitation. The agent starts from random weights and needs far more trial plates to reach the same fluency.

How It Actually Works

Write the network as an encoder gψg_{\psi} plus a head hϕh_{\phi}:

fθ(s)=hϕ(gψ(s))f_{\theta}(s) = h_{\phi}(g_{\psi}(s))

Here ss is the raw observation, z=gψ(s)z = g_{\psi}(s) is the compact feature vector and θ\theta collects ψ\psi and ϕ\phi. The head outputs either action values Qθ(s,a)Q_{\theta}(s, a) or a policy πθ(a∣s)\pi_{\theta}(a \mid s). Both train from the same reward stream that also shapes the encoder.

Three decision styles on shared features

  • Value style learns Qθ(s,a)Q_{\theta}(s, a) against the Bellman target y=r+γmax⁡a′Qθ−(s′,a′)y = r + \gamma \max_{a^{\prime}} Q_{\theta^{-}}(s^{\prime}, a^{\prime}) from a frozen target net.
  • Policy style climbs expected return J(θ)J(\theta) with the score gradient ∇θlog⁡πθ(a∣s)\nabla_{\theta} \log \pi_{\theta}(a \mid s) times return or advantage.
  • Actor critic style keeps both: the actor proposes πθ\pi_{\theta} and the critic VϕV_{\phi} judges with bootstrapped targets to cut variance.

All three reuse the same encoder, which is why perception and control improve together.

Why training is harder than supervised learning

Targets move because yy depends on the same weights being trained. Data correlates because st+1s_{t+1} follows sts_t. Representations shift because new rooms overwrite old features. The trio of function approximation plus bootstrapping plus off policy data can diverge, a pattern called the deadly triad. Replay buffers, frozen targets and clipped objectives exist to tame exactly these effects.

Worked example

Take s=[1.0,0.5]s = [1.0, 0.5] with two actions, discount γ=0.90\gamma = 0.90 and step size α=0.1\alpha = 0.1. Hidden width 22 with ReLU. Weights:

W1=[0.5,−0.2;0.4,0.6],b1=[0.1,−0.1]W_1 = [0.5, -0.2; 0.4, 0.6], \quad b_1 = [0.1, -0.1] W2=[0.8,−0.5;0.3,0.7],b2=[0.2,−0.3]W_2 = [0.8, -0.5; 0.3, 0.7], \quad b_2 = [0.2, -0.3]

Forward pass. Pre activations:

z1=0.5×1.0−0.2×0.5+0.1=0.50z_1 = 0.5 \times 1.0 - 0.2 \times 0.5 + 0.1 = 0.50 z2=0.4×1.0+0.6×0.5−0.1=0.60z_2 = 0.4 \times 1.0 + 0.6 \times 0.5 - 0.1 = 0.60

ReLU keeps both, so h=[0.50,0.60]h = [0.50, 0.60]. Outputs:

Q(s,0)=0.8×0.50−0.5×0.60+0.2=0.30Q(s, 0) = 0.8 \times 0.50 - 0.5 \times 0.60 + 0.2 = 0.30 Q(s,1)=0.3×0.50+0.7×0.60−0.3=0.27Q(s, 1) = 0.3 \times 0.50 + 0.7 \times 0.60 - 0.3 = 0.27

Transition. Act a=0a = 0, earn r=1.0r = 1.0. Target net rates the next state best at 0.800.80. Target and error:

y=1.0+0.90×0.80=1.72y = 1.0 + 0.90 \times 0.80 = 1.72 δ=1.72−0.30=1.42\delta = 1.72 - 0.30 = 1.42 L=0.5×1.422=1.0082\mathcal{L} = 0.5 \times 1.42^2 = 1.0082

One gradient step with α=0.1\alpha = 0.1 moves Q(s,0)Q(s, 0) from 0.300.30 toward 1.721.72. The same backward pass also reshapes the encoder that built hh, so perception and values learn from one number.

Code

This snippet repeats the forward pass and Bellman numbers with plain Python.

def relu(v: float) -> float:    """Rectified linear unit."""    return v if v > 0.0 else 0.0

s = [1.0, 0.5]W1 = [[0.5, -0.2], [0.4, 0.6]]b1 = [0.1, -0.1]W2 = [[0.8, -0.5], [0.3, 0.7]]b2 = [0.2, -0.3]
z1 = [W1[0][0] * s[0] + W1[0][1] * s[1] + b1[0], W1[1][0] * s[0] + W1[1][1] * s[1] + b1[1]]print([round(v, 4) for v in z1])  # -> [0.5, 0.6]h = [relu(v) for v in z1]print([round(v, 4) for v in h])  # -> [0.5, 0.6]Q = [W2[0][0] * h[0] + W2[0][1] * h[1] + b2[0], W2[1][0] * h[0] + W2[1][1] * h[1] + b2[1]]print([round(v, 4) for v in Q])  # -> [0.3, 0.27]y = 1.0 + 0.90 * 0.80print(f"{y:.4f}")  # -> 1.7200td = y - Q[0]print(f"{td:.4f}")  # -> 1.4200print(f"{0.5 * td * td:.4f}")  # -> 1.0082

Hidden values, Q values, target, error and loss match the hand pass, which ties the diagram to the prose.

Watch Out For

New rooms erase old features

Online streams feed long correlated runs from one region. Gradient steps tune the encoder for that region and overwrite features older rooms needed. Return to an old room and values collapse even though the head looks trained.

Symptom: performance swings as the agent moves, with frozen target values lagging behind. Fix it with random replay sampling, a frozen or slowly averaged target and, when needed, an auxiliary objective like reconstruction that forces the encoder to keep global shape.

The Quick Version

  • Deep RL trains fθ(s)=hϕ(gψ(s))f_{\theta}(s) = h_{\phi}(g_{\psi}(s)) end to end, so features zz and decisions improve from one reward signal.
  • Value, policy and actor critic heads share the encoder and differ only in what the head predicts.
  • Moving Bellman targets, correlated streams and shifting features make training less stable than supervised fits.
  • Worked numbers: s=[1.0,0.5]s = [1.0, 0.5], h=[0.50,0.60]h = [0.50, 0.60], Q=[0.30,0.27]Q = [0.30, 0.27], y=1.72y = 1.72, loss 1.00821.0082.
  • Replay, frozen targets and clipped updates are the standard stabilizers, not optional extras.
  • Hand features fail on raw high dimensional input, which is why the encoder earns its keep.