PPO (Proximal Policy Optimization)
- PPO 的目標是解決傳統 Policy Gradient 樣本效率差,以及 TRPO 實作過於複雜的問題
- On-Policy 架構
- 透過 Importance Sampling 技術,重複使用同一批收集到的資料進行多次更新
- 提升樣本效率
- Trust Region
- 利用截斷或懲罰機制,限制新策略 與舊策略 之間的差異
- 防止更新步幅過大導致策略崩壞
- 兩種主要版本
- PPO1:基於 KL 散度的懲罰 (Adaptive KL Penalty)
- PPO2:截斷式目標函數 (Clipped Surrogate Objective)
PPO1 基於 KL 散度的懲罰
將 KL 散度 (兩個 Policy 的差距) 加入目標函數中作為懲罰項
- KL 散度
- 衡量的是行為上的距離(Output action distribution 的差異),而非參數數值上的距離
- 動態調整 (Adaptive KL):
- 若 :代表差距太大,增加 (懲罰加重)
- 若 :代表差距太小 (太保守),減少 (懲罰減輕)
- 前身 TRPO 是將 KL 設為硬性限制,難以計算,PPO 則設為懲罰項,較易實作
- 但效果未顯著優於 PPO2 的 Clip 版本,較少使用
Kullback-Leibler Divergence
The KLD is a measure of how much one probability distribution differs from another.
It compares the true distribution (the data ) with the approximate distribution (the model ) by calculating the difference between the cross entropy and the entropy.
Why it is not a distance?
- Not symmetric:
- Not triangle inequality:
Forward KL:
Approximates with
Penalizes: heavily if it assigns low probability to regions where has high probability ( becomes very large).
Behavior: Mass-covering, can’t be too small in any region where supports, spreads probability mass to cover all regions where exists.
Reverse KL:
Approximates with
Penalizes: if it assigns high probability to regions where has low probability ( becomes very large).
Behavior: Mode-seeking, focuses on matching a single mode (peak) of , it needs to be small in regions where is small.
Link to original
- KL 散度不是對稱的,以下是 Forward 與 Backward,若希望兩個分佈越接近,KL 值要越小
Forward 下, 不能在任何 有值的地方太小,否則 log term 會很大,傾向尋求平均, 對於整個 完整的覆蓋。
Backward 下, 不能在任何 小的地方太大,否則 log term 會很大,傾向尋求峰值, 擬合 的某個高機率區。
PPO2 截斷式目標函數
不計算複雜的 KL 散度,直接用 clip 函數限制比例,是目前較常用的版本
- :Hyperparameter (如 0.2),限制更新幅度
- 若 (好動作):希望增加機率 ,但若比值超過 ,就截斷不再獎勵避免機率增加過頭導致分佈偏差太大
- 若 (壞動作):希望減少機率 ,但若比值低於 ,就截斷不再處罰
- 確保 更新後的行為與 保持在一定範圍內 (Trust Region),既享受 Off-Policy 的效率,又維持訓練的穩定性
min的作用:悲觀下界,在原始效益與截斷後效益中永遠選擇較差者- 當比值越界時,
min強制選取邊界值(常數),使梯度歸零並停止該次更新,防止因單次步幅過大導致策略崩潰,確保模型是透過多次迭代穩健地進步