Guest. Introduction to Reinforcement Learning
Given by: Asst. Prof. Gokhan Alcan
- Define cost-to-go (min cost from time k to N)
- Split the problem ( Current step + Future)
- The Result (Recursive Optimality)
Pro:
- Decoupling: dont solve the full trajectory at once, solve one step at a time, working backwards from N to 0.
- The RL connection:
- in optimal control, we calculate V using the model f.
- in RL, we learn Q directly so we can pick u without needing f.
From OC to RL
Section titled “From OC to RL”| 最优控制 (Optimal Control) | 强化学习 (Reinforcement Learning) |
|---|---|
| 状态 (State) | 状态 (State) |
| 控制输入 (Control Input) | 动作 (Action) |
| 阶段代价 (Stage Cost) | 回报 (Reward) |
| 终端代价 (Terminal Cost) | 终端回报 (Terminal Reward) |
| 动力学 (Dynamics) | 环境 (Env.) |
| 时界 (Horizon) | 折扣因子 (Discount) |
| 控制器 (Controller) | 策略 (Policy) |
graph LR
Agent --->|Action a_t| Environment
Environment --->|State s_t+1 <br> Reward r_t| Agent
RL Objective
Section titled “RL Objective”Maximize the expected cumulative discounted reward:
- :折扣因子 (Discount factor),在无限时界问题中替代了有限时界 。
- :期望值 (Expectation),用于处理环境或策略中的随机性 (stochasticity)。
The Vocabulary of RL
Section titled “The Vocabulary of RL”| 核心概念 (Concept) | 数学符号 (Notation) | 倒立摆示例 (Cart-Pole Example) |
|---|---|---|
| 策略 (Policy) (The Controller) |
| “如果杆子向右倾斜 (),以 0.9 的概率向右推 ()。” |
| 价值函数 (Value Functions) (The Critic) |
| |
| 优势函数 (Advantage) (Relative Value) | “相比于当前策略的平均表现,做这个动作能好多少?” | |
| 轨迹 (Trajectory) (Rollout) | 从开始(杆子竖直)到失败(杆子倒下)的单次完整模拟运行。 |
Critical Assumptions
Section titled “Critical Assumptions”- Environment Assumptions (The Physics)
- Markov Property: the state is sufficient. History doesnt matter (ONLY the current state matter, its enough to transit to next state)
- Stationarity: The environment dynamics do not change over time. (mass or something stays constant)
- Ergodicity & Coverage: The agent can reach all relevant states with non-zero probability. (Implication: If we stop exploring (greedy), we violate this and stop learning)
- Structural Assumptions
- Reward Boundedness: Rewards are finite. We use a discount factor to ensure the infinite sum converges:
- Function Approximation Class:
- Linear: Convex optimization, convergence guarantees, able to find global optima.
- Neural Networks: Non-convex, no strong guarantees, but scales to high dimensions (images, complex dynamics)
- Deep Q-Networks
- : Parameterized by weights .
- : Parameterized by weight (a frozen copy of ).
Bell man optimality for RL
Section titled “Bell man optimality for RL”- recursive optimality(OC)
- Action value current state cost + remaining states’ within the bracket as the action value, consequently, the state value function can be simplified to minimising :
- subsitute into Q. Recursive form, purely in
- Bellman optimality equation in RL
Exploration policy: - greedy schedule. Experience Replay: Buffer D of past transitions decorrelate samples. TD target & loss:: 在训练时,我们通过当前步的奖励 和下一步的极大动作价值来构建 TD 目标值 (TD Target) :
随后,利用均方误差 (MSE) 构建 损失函数 (Loss Function),通过梯度下降来更新当前网络参数 :
Target update rule
为了解决训练中的非平稳目标问题,DQN 引入了目标网络 (Target Network):
- :当前网络 (Online Network),其参数 在每一步都在通过梯度下降进行实时更新。
- :目标网络 (Target Network),其参数 保持冻结,仅进行周期性同步 (Periodic copy):
Explorations schedule The exploration rate linearly decays from an initial value to a minimum floor over a fixed duration , then remains constant.

- 动作选择 (Action Selection: -Greedy)
在当前时间步,智能体以 的概率进行随机探索:
否则(以 的概率),根据当前策略网络选择能够带来最大估计价值的贪婪动作:
- 环境模拟步 (Simulation Step)
在环境中执行选择的动作 ,并从环境反馈中获取以下信息:
- 下一状态 (Next state)
- 奖励 (Reward)
- 终止标志 (Termination flag):若达到终止状态则 ,否则 。
- 数据存储与状态更新 (Storage & Update)
存储经验:将这一步产生的五元组(转移数据 Transition)存入经验回放缓冲区 (Replay Buffer) 中:
更新当前状态:向前推进时间步,将当前状态设为下一状态,进入新的循环:
5-Tuple:
Section titled “5-Tuple:”It carries everything needed to evaluate the TD target later:
TD Target with Termination
Loss Function
Core Training Loop
Section titled “Core Training Loop”For every train step:
1. Sampling
Section titled “1. Sampling”从经验回放缓冲区 中随机抽取一个大小为 的小批次(Minibatch)数据:
2. Target Calculation
Section titled “2. Target Calculation”Compute Temporal Difference TD using Targe Network目标网络 计算离策(Off-Policy)的时序差分目标值 。此步骤不需要计算梯度:
3. Loss Calculation
Section titled “3. Loss Calculation”计算目标网络输出的 与当前网络 预测值之间的均方误差(MSE):
4. Gradient Descent
Section titled “4. Gradient Descent”对当前网络参数 执行梯度下降步以完成参数更新:
4. Target Network Update
Section titled “4. Target Network Update”为了保证训练的稳定性,每隔固定的步数(满足 target_frequency 步数要求时),更新目标网络权重 :
- Hard Update, :直接将当前网络的权重完全复制给目标网络:
- Soft Update, :让目标网络向当前网络平滑逼近:
Hyper Parameters
Section titled “Hyper Parameters”| Hyper Parameteres | Math | Classical value | Usuage |
|---|---|---|---|
| 经验回放区容量 | Capacity | 10,000 | 存储历史转移数据 的上限 |
| 优化器与学习率 | Adam () | 控制当前网络 梯度下降的步长 | |
| 折扣因子 | 0.99 | 衡量未来长远奖励的衰减权重 |
Weight :
- : Greedy, only cares about the immediate reward .
- : Strategic, values long term cumulative return.
Moving Target In standard supervised learning, targets(y) are fixed. In RL the target useing the changing network:
- When we update weights to approach y_t, the target y_t moves as well.
- Result: Correlation loops, maximization bias, and divergence.
Solution: Twin Network , a clone of the main network that is frozen in time.
- Main Net: Updates every step.
- Target Net: Frozen, Constant.
- Sync: Every C steps, copy weights.
graph LR
Main --->|Copy slow| Target
Target --->|target y_t | Main
Practical Design Knobs
Section titled “Practical Design Knobs”1. Exploration Strategy
Section titled “1. Exploration Strategy”How do we encourage trying new things?
- -greedy (Discrete): Flip a coin. With prob , take random action. Simple.
- Entropy Reg. (Continuous): Add penalty to loss. Keeps policy uncertain to prevent premature convergence.
2. On-Policy vs. Off-Policy
Section titled “2. On-Policy vs. Off-Policy”- On-Policy (e.g., PPO): Use data generated only by current . Stable, but sample inefficient (throws data away).
- Off-Policy (e.g., DDPG, DQN): Use data from any past policy (Replay Buffer). Efficient, but mathematically risky (bias).
3. Stability Hacks (Essential)
Section titled “3. Stability Hacks (Essential)”Neural Networks hate correlated data. Fixes:
- Replay Buffers: Store . Sample random batches to break temporal correlations (i.i.d.).
- Target Networks: Compute loss targets with a frozen network copy. Prevents “chasing your own tail.”
RL Taxonomy / Classifying the Algorithms
Section titled “RL Taxonomy / Classifying the Algorithms”1. Action Space
Section titled “1. Action Space”- Discrete: Finite choices (e.g., Left/Right). Output is a probability mass. (Ex: DQN, Q-Learning)
- Continuous: Real-valued vectors (e.g., Torques). Output is a distribution or value. (Ex: DDPG, SAC)
2. Model Usage
Section titled “2. Model Usage”- Model-Based: Uses dynamics to plan. High sample efficiency. (Ex: Dyna-Q, AlphaZero)
- Model-Free: Learns mapping via trial-and-error. Low bias, easier impl. (Ex: DDPG, DQN)
3. Data Regime (Sampling)
Section titled “3. Data Regime (Sampling)”- On-Policy: Learns only from current policy . Stable but sample heavy. (Ex: PPO, TRPO)
- Off-Policy: Learns from Replay Buffer (old data). Efficient but complex. (Ex: SAC, DQN)
4. Learning Target (The “Brain”)
Section titled “4. Learning Target (The “Brain”)”- Value-Based: Learns . Implicit policy. (Ex: DQN - Discrete only)
- Policy-Based: Optimizes directly via gradients. (Ex: REINFORCE)
- Actor-Critic: Hybrid. Actor () acts, Critic () judges to reduce variance. (Ex: PPO, SAC)
5. Safety & Constraints
Section titled “5. Safety & Constraints”- Unconstrained: Maximize . Violations punished by negative reward. (Ex: Vanilla RL)
- Constrained (CMDP): Max s.t. cost . Uses Lagrangian multipliers. (Ex: CPO)
- Safe / Filtered: Safety layer (Model/Barrier) overrides dangerous actions. (Ex: MPC-in-loop)