Jaychao2099
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 第十三章:增強式學習 (Reinforcement Learning, RL) 概述 >上課筆記 * 上課影片連結 * ==[**概述增強式學習(一) – 增強式學習跟機器學習一樣都是三個步驟**](https://youtu.be/XWukX-ayIrs)== * ==[**概述增強式學習(二) – Policy Gradient 與修課心情**](https://youtu.be/US8DFaAZcp4)== * ==[**概述增強式學習(三) – Actor-Critic**](https://youtu.be/kk6DqWreLeU)== * ==[**概述增強式學習(四) – 回饋非常罕見的時候怎麼辦?機器的望梅止渴**](https://youtu.be/73YyF1gmIus)== * ==[**概述增強式學習(五) – 如何從示範中學習?逆向增強式學習 (Inverse RL)**](https://youtu.be/75rZwxKBAf0)== --- ## 什麼是增強式學習 (What is RL?) ### 核心概念 增強式學習是機器學習的一個分支,其目標是讓智慧體 (Agent) 學習如何在一個環境 (Environment) 中透過採取行動 (Action) 來最大化累積的獎勵 (Reward)。 ### 與監督式學習的區別: * 監督式學習 (Supervised Learning) 需要明確的標籤 (Label) 告知機器在特定輸入下應有的正確輸出。例如,在影像分類中,需要標示圖片對應的類別。 * 增強式學習則**不需要**明確告知每一步的「正確」行動,而是透過環境回饋的「獎勵」訊號,讓智慧體自行學習何種策略 (Policy) 能獲得最好的長期結果。智慧體必須探索環境,從試錯中學習。 ![image](https://hackmd.io/_uploads/SyJ0HXMRye.png) ### **增強式學習框架 (RL Framework)**: * **智慧體 (Agent) / 參與者 (Actor)**:學習者與決策者,根據觀察到的狀態決定要採取的行動。在深度學習的脈絡下,通常由一個神經網路 (Policy Network)來表示。 * **環境 (Environment)**:智慧體互動的外部世界,會接收智慧體的行動並產生新的狀態與獎勵。 * **觀察 (Observation)**:智慧體從環境中感測到的資訊,用以判斷當前狀態 (State)。 * **行動 (Action)**:智慧體根據觀察所做出的決策。 * **獎勵 (Reward)**:環境根據智慧體的行動所給予的純量回饋訊號,表示該行動的好壞程度。 * **策略 (Policy)**:智慧體的行為模式,定義了從觀察 (狀態)到行動的對應關係,通常表示為一個函數 $\pi_\theta(a|s)$,即在狀態 $s$ 下採取行動 $a$ 的機率。 * **目標**:找到一個最佳策略 $\pi_{\theta^*}$,使得智慧體在與環境互動的過程中,能最大化預期累積總獎勵 (Expected Total Reward)。 ### 互動流程: 1. 智慧體觀察目前環境的狀態 $s_t$。 2. 智慧體根據其策略 $\pi_\theta$,選擇並執行一個行動 $a_t$。 3. 環境接收到行動 $a_t$,轉移到新的狀態 $s_{t+1}$,並給予智慧體一個獎勵 $r_t$。 4. 智慧體接收到新的觀察 $s_{t+1}$ 與獎勵 $r_t$,重複此過程。 ### 回合 (Episode) / 軌跡 (Trajectory) 一次完整的互動過程稱為 Episode,從初始狀態開始,經過一系列的狀態 $s_i$、行動 $a_i$,直到終止狀態,構成一個軌跡:$$\tau = (s_1, a_1, s_2, a_2, \dots, s_N, a_N)$$ ### 總獎勵 (Total Reward) 一個軌跡的總獎勵是該軌跡中所有時間步獎勵的總和,$$R(\tau) = \sum_{t=1}^N r_t$$ ### 預期總獎勵 (Expected Total Reward) 由於策略和環境可能具有隨機性,智慧體的目標是最大化所有可能軌跡的預期總獎勵:$$E[R(\tau)] = \sum_{\tau} P(\tau|\pi) R(\tau)$$其中 $P(\tau|\pi)$ 是在策略 $\pi$ 下產生軌跡 $\tau$ 的機率。 ### 應用範例: * **電子遊戲 (Video Games)**:如 Atari 遊戲 (太空侵略者)、AlphaGo (圍棋)。 * 觀察:遊戲畫面 (像素)。 * 行動:控制搖桿 (上、下、左、右、開火)或落子位置。 * 獎勵:遊戲分數的變化。 ![image](https://hackmd.io/_uploads/ryaaPmGA1x.png) ![image](https://hackmd.io/_uploads/HyuyuXMCyx.png) * **機器人控制**:學習走路、抓取物體等。 ### RL 的機器學習步驟: 1. **定義函數 (Actor/Policy)**:定義一個代表策略的函數 (通常是神經網路、CNN 處理影像、RNN 或 Transformer 處理序列數據),輸入是**觀察**,輸出是**行動** (或行動的 softmax 機率分佈)。![image](https://hackmd.io/_uploads/S1LV87MC1g.png) 2. **定義目標函式 (Goodness Function)**:目標是最大化累積 reward,因此定義 Loss $L$ 為負的總 reward,即 $−R$。 * **Episode**:指從開始到任務結束的一次完整互動,$R$ 是該 episode 的總 reward (也稱為 return) ![image](https://hackmd.io/_uploads/HkiWvQM01l.png) 3. **最佳化 (Optimization)**:找到一組最佳的函數參數 $\theta$,使得目標函式最大化。 * **挑戰**:環境與 reward 是黑盒子 (black box),無法直接求導,且具有隨機性 (actor 的 action 採樣、環境的反應均非確定性),無法用傳統梯度下降解決。 ![image](https://hackmd.io/_uploads/SyKwvmM0Jg.png) --- ## 策略梯度 (Policy Gradient, PG) ### 核心思想 直接訓練策略函數 $\pi_\theta(a|s)$,其中 $\theta$ 是策略網路的參數。透過調整參數 $\theta$,使得能獲得較高總獎勵的行動序列 (軌跡) 出現的機率變大。 ![image](https://hackmd.io/_uploads/BkTExDzRkx.png) ### 基本概念 1. **訓練資料**:收集 observation $s$ 與 action $a$ 的配對 $(s, a)$,並為每個配對**分配分數** $A$,表示該 action 的好壞。 2. **損失函數**:定義為交叉熵 (cross-entropy) 的加權和,權重為$A$,即 $L=\sum A_ne_n$。 3. **最佳化**:最小化 $L$,使 actor 傾向執行 $A>0$ 的 action,避免 $A<0$ 的 action。 ![image](https://hackmd.io/_uploads/BJMEcmf0kx.png) ### 如何確定 權重$A$ 的值? * **Version 0 (短視版本)** * **定義**:將 $A_t=r_t$,即時 reward。 * **問題**:僅考慮當前 reward,忽略長期影響。例如在 Space Invader 中,向左移動的 $r_t = 0$,但可能是瞄準外星人的關鍵步驟,Version 0 無法識別其價值,導致 actor 只學會狂開火。 ![image](https://hackmd.io/_uploads/SyXkxOfRye.png) * **Version 1 (累積獎勵 Accumulated reward)** * **定義**:$A_t = G_t$,其中 $G_t = \sum_{k=t}^T r_k$是從時間 $t$ 開始到 episode 結束的累積 reward。 * **優勢**:考慮 action 的長期影響。例如,向左移動後開火擊中外星人,$G_t$ 會**反映後續獎勵**,識別移動的重要性。 * **問題**:若 episode 很長,遠期 reward (如 $r_T$) 未必由早期 action (如 $a_1$) 決定,歸因不準確。 ![image](https://hackmd.io/_uploads/r1rbe_MC1e.png) * **Version 2 (折現累積獎勵 Discounted Accumulated reward)** * **定義**:$A_t = G'_t$,其中 $G'_t = \sum_{k=t}^T \gamma^{k-t} r_k$、$\gamma\ (0 < \gamma < 1,如 0.9 或 0.99)$ 是折現因子。 * **優勢**:降低遠期 reward 的影響,**聚焦近期效果**,避免過長規劃。 * **實用性**:需玩完整個 episode 才能計算 $G'_t$,效率低。 * **問題**:若所有 $r_t$ 都是正的 (例如遊戲分數恆正),則所有行動的機率都會被提升,這並不合理。 ![image](https://hackmd.io/_uploads/S1nXeuzAJe.png) * **Version 3 (引入 baseline)** * **定義**:$A_t = G'_t-b$,其中 $G'_t = \sum_{k=t}^T \gamma^{k-t} r_k$。從總獎勵中減去一個基線 $b$,通常設為平均總獎勵。 * **優勢**:只有當軌跡的獎勵高於平均水平時,才會增加其行動機率,反之則減少。有效**降低變異性**,且不改變梯度的期望值。 ![image](https://hackmd.io/_uploads/SkIqgOG0ke.png) ### 梯度上升 (Gradient Ascent) 由於目標是**最大化**預期總獎勵 $E[R(\tau)]$,使用梯度上升法來更新參數:$$\theta^i \leftarrow \theta^{i-1} - \eta \nabla L$$ * **直觀解釋**:若軌跡 $\tau^n$ 的總獎勵 $R(\tau^n)$ 是正的,則增加該軌跡中所有 (狀態, 行動) 配對的機率;若是負的,則減少其機率。 * **實作流程**: 1. 初始化參數 $\theta^0$ 2. For $(i = 0 \to T)$ // training iteration 1. 使用當前策略參數 $\theta^i$ 與環境互動,收集 1 個軌跡 $\tau = (s_1, a_1, s_2, a_2, \dots, s_N, a_N)$ 2. 計算每組$(s_n, a_n)$ 的權重 $A_n$。 3. 計算該軌跡的 $- \rm{Loss}\ L =$$$總獎勵 \ R = \sum_{n=1}^{N}{A_ne_n}$$若使用 version 3 計算 $A_n$,$$總獎勵 \ R = \sum_{n=1}^{N}{\left(\left(\sum_{k=n}^N \gamma^{k-n} r_k\right)-b\right)e_n}$$ 4. 更新策略參數:$\theta^{i+1} \leftarrow \theta^{i} - \eta \nabla L$。 * **缺點**:一回合 for-loop 就要蒐集**一整個 episode**,但僅更新一次參數。會訓練很久。 ### 同策略 vs. 異策略 (On-policy vs. Off-policy) * **同策略 (On-policy)**:用於更新策略 $\pi_\theta$ 的數據 (軌跡)必須是由 **當前** 的策略 $\pi_\theta$ 產生的。一旦策略更新,舊數據就不能再用。Policy Gradient 通常是 On-policy。 * **異策略 (Off-policy)**:允許使用由 **其他** 策略 $\pi_{\theta'}$ 產生的數據來更新當前策略 $\pi_\theta$,可以提高數據利用率。 * **重要性採樣 ([Importance Sampling](https://en.wikipedia.org/wiki/Importance_sampling))**:實現異策略學習的關鍵技術。透過引入重要性權重 $w_t$ 來修正梯度估計,使得來自舊策略的數據可以用於新策略的學習。 * **PPO ([Proximal Policy Optimization](https://youtu.be/OAKAZhFmYoI))**:一種流行的、基於 Importance Sampling 的 Off-policy 改進算法,透過限制新舊策略之間的變化幅度 (例如使用 KL 散度約束或裁剪重要性權重) 來提高訓練穩定性。 --- ## Actor-Critic 演算法, AC ### 動機: * Policy Gradient (version 3) 中對 權重$A$ 的估計 (基於 Discounted Accumulated reward 減去 baseline) 仍然存在較高的變異性。 * 引入一個 **獨立的模型 (評論家 Critic)** 來學習和評估狀態($s_t$)或狀態-行動對($s_t, a_t$)的未來期望價值,以提供更穩定、變異性更低的價值函數估計,從而指導 Actor 的策略更新。 ### 核心組件: * **Actor**:即 PG 中的 policy network $\pi_\theta(a|s)$,負責根據狀態 $s$ 選擇行動 $a$。 * **Critic**:一個獨立的網路 (通常是神經網路)$V^\theta(s)$ 或 $Q^\theta(s, a)$,負責評估狀態($s_n$)或狀態-行動對($s_n, a_n$)的未來期望價值。 * **狀態價值函數 (State Value Function)** $V^\theta(s)$:估計從狀態 $s$ 開始,遵循當前策略 $\pi_\theta$ 所能獲得的預期折扣累積獎勵。 * **狀態-行動價值函數 (State-Action Value Function)** $Q^\theta(s, a)$:估計在狀態 $s$ 採取行動 $a$ 後,繼續遵循當前策略 $\pi_\theta$ 所能獲得的預期折扣累積獎勵。 ### 運作流程: 1. **互動**:Actor $\pi_\theta$ 與環境互動,產生經驗 $(s_t, a_t, r_t, s_{t+1})$。 2. **Critic 評估**:Critic 使用其學習到的價值函數來評估Actor的行動。計算價值函數 $V^\theta(s_t)$、$\ Q^\theta(s_t, a_t)$。 3. **Actor更新**:$$\theta^{i+1} \leftarrow \theta^{i} - \eta \nabla L$$ * **Version 3.5**:Actor 根據 Critic 提供的價值函數估計值 $V^\theta(s_t),\ Q^\theta(s_t, a_t)$ 作為 baseline $b$ 更新其策略參數 $\theta$,使用類似 PG 的梯度上升:$$ \begin{align} -L =總獎勵 \ R &= \sum_{t=1}^{N}{A_te_t}\\ &= \sum_{t=1}^{N}{\left(G_t'-b\right)e_t}\\ &= \sum_{t=1}^{N}{\underbrace{\left[\left(\sum_{k=t}^N \gamma^{k-t} r_k\right)-V^\theta(s_t)\right]}_{A_t}e_t} \end{align}$$![image](https://hackmd.io/_uploads/rJQZihzR1g.png) * **Version 4 (Advantage Actor-Critic)**:單純以狀態 $s_t,\ s_{t+1}$ 進行梯度訓練:$$ \because\left\{\begin{array}{r,l} V^\theta(s_t)=& s_t 的期望價值\\r_t + V^\theta(s_{t+1})=& s_t 走 a_t 路線的期望價值 \end{array}\right\}$$$$令\ A_t = r_t + V^\theta(s_{t+1}) - V^\theta(s_t)$$$$\begin{align} \implies -L =總獎勵 \ R &= \sum_{t=1}^{N}{A_te_t}\\ &= \sum_{t=1}^{N}{\left(r_t + V^\theta(s_{t+1}) - V^\theta(s_t)\right)e_t} \end{align}$$![image](https://hackmd.io/_uploads/SJMdj2fCke.png) ### 訓練 Actor-Critic: * 常用的訓練方式包括: * **蒙地卡羅 (Monte Carlo, MC)**: * **作法**:使用完整 episode 的實際 Discounted Accumulated reward $G_t'$ 作為 $V^\theta(s_t)$ 或 $Q^\theta(s_t, a_t)$ 的目標值。 * **優點**:無偏估計。 * **缺點**:變異性高,且需要完整回合結束才能更新。 ![image](https://hackmd.io/_uploads/H1rkAjM01l.png) * **時間差分 (Temporal Difference, TD)**: Actor-Critic 通常採用 TD 方法來訓練 Critic。 * **推導**:$$ \left. \begin{array}{l,c,r} V^\theta(s_t)&=&r_t+\gamma^1 r_{t+1}+\gamma^2 r_{t+2}+\cdots \\ V^\theta(s_{t+1})&=&r_{t+1}+\gamma^1 r_{t+2}+\cdots \end{array} \right\} \implies V^\theta(s_t)=\gamma V^\theta(s_{t+1}) + r_t$$ * **作法**:使用**當前獎勵**加上**下一狀態的估計價值**作為目標值。例如,更新 $V^\theta(s_t)$ 的目標是 $\gamma V(s_{t+1}) + r_t$。 * **優點**:變異性低,可以在線學習 (每步都更新)。 * **缺點**:有偏估計 (因為依賴於當前的估計值)。 ![image](https://hackmd.io/_uploads/SyF8ehGC1x.png) * **Q-learning**:2018上課影片[[1]](https://youtu.be/o_g9JUMw1Oc)[[2]](https://youtu.be/2-zGCx4iv_k)[[3]](https://youtu.be/tnPVcec22cg) * **State–action–reward–state–action (SARSA)** * **訓練技巧**: * **共享參數**:Actor和 Critic 網路可以共享部分底層網路層 (例如 CNN 前層),只在輸出層分開,這樣可以加速學習。 ![image](https://hackmd.io/_uploads/H1VL8pMCJx.png) * **熵正規化 (Entropy Regularization)**:在Actor的目標函數中加入策略的熵項,鼓勵 Actor **探索更多樣的行動**,避免過早收斂到次優策略。 ![image](https://hackmd.io/_uploads/HJ8MwaG0kg.png) * **代表性算法集合:[Rainbow DQN](https://arxiv.org/abs/1710.02298)** 把 DQN (Deep Q-Network) 的七種改進整合起來,形成一個超強版本,它在很多測試 (如Atari遊戲) 中表現非常出色。這些改進包括: * 解決Q值過高估計的問題。 * 優先使用重要的經驗來學習。 * 改進網絡結構,提高效率。 * 考慮多步回報、回報分布等進階概念。 ![image](https://hackmd.io/_uploads/HkHFhaGAyl.png) --- ## 獎勵塑形 (Reward Shaping) ### 動機: * **稀疏獎勵 (Sparse Rewards)**:在許多現實世界的 RL 任務中,環境提供的獎勵非常稀少 (例如,只有在遊戲結束時才有分數,或者只有完成最終目標才有獎勵)。這使得 Agent 很難學習,因為**大部分行動都沒有立即的回饋訊號來判斷好壞**。 ### 概念: 透過設計額外的人工獎勵 (Artificial Rewards) 或修改環境的原始獎勵函數,來為 Agent 提供更頻繁、更具指導性的學習訊號,引導其更快地學習到期望的行為。 ### 方法範例: * **基於好奇心 (Curiosity-Driven)**:即使沒有外部獎勵,也內在地獎勵 Agent 去探索環境、到達新的狀態或做出讓其內部世界模型感到驚訝 (預測錯誤)的行動。例如 [Intrinsic Curiosity Module (ICM)](https://arxiv.org/abs/1705.05363),它包含: 1. **一個逆向模型 (Inverse Model)**:預測狀態 $s_t$ 和 $s_{t+1}$ 之間的行動 $a_t$。 2. **一個前向模型 (Forward Model)**:基於 $s_t$ 和 $a_t$ 預測下一狀態的特徵 $\hat{\phi}(s_{t+1})$。 3. **好奇心獎勵**:定義為前向模型預測的下一狀態特徵 $\hat{\phi}(s_{t+1})$ 與實際下一狀態特徵 $\phi(s_{t+1})$ 之間的差異。差異越大,表示越「好奇」,給予的內在獎勵越高。 * **基於子目標 (Sub-goals)**:將複雜任務分解為一系列子目標,並在 Agent 達成每個子目標時給予獎勵。 * **範例**:facebook 訓練 AI 玩 VizDoom 第一人稱射擊遊戲的測試。[論文](https://openreview.net/forum?id=Hk3mPK5gg&noteId=Hk3mPK5gg)中提到,他們設置了一些額外的reward讓機器學習的更好。 ![image](https://hackmd.io/_uploads/SkLD5ZECye.png) ### 潛在風險: 設計不良的塑形獎勵可能會導致 Agent 「鑽漏洞」,學會最大化人工獎勵而非完成實際任務。例如,賽艇遊戲中,如果錯誤地獎勵獲取道具, Agent 可能學會原地打轉吃道具而不去衝向終點。因此,獎勵塑形需要**基於領域知識 (Domain Knowledge) 謹慎設計**,避免誤導。 --- ## 沒有獎勵:從示範中學習 (No Reward: Learning from Demonstration) ### 動機: 在某些情況下,定義一個好的獎勵函數本身就很困難 (例如:自動駕駛、機器人),但我們很容易獲得專家 (Expert) 執行該任務的示範數據。從示範中學習旨在讓 Agent 模仿專家的行為。 ### 主要方法: * **行為克隆 (Behavior Cloning, BC)**: * **概念**:最簡單的方法,將問題視為一個**監督式學習**問題。收集專家的示範數據,即一軌跡 $\hat \tau = \{s_1,\hat a_1, s_2,\hat a_2, \cdots\}$(狀態 $s$, 專家行動 $\hat a$)。訓練一個 Policy Network $\pi_\theta(a|s)$,使其在輸入狀態 $s$ 時,以專家會採取的行動 $\hat a$ 為訓練目標。![image](https://hackmd.io/_uploads/HkReAWN0ke.png) * **優點**:簡單直觀,易於實現。 * **缺點**: * **因果混淆 (Causal Confusion)**:可能學習到虛假的相關性而非因果關係。 * 可能模仿無關行為 (如個人習慣) * **複合誤差 (Compounding Errors) / 分佈不匹配 (Distribution Mismatch)**:學習到的策略 $\pi_\theta$ 可能會**遇到專家從未遇到過的狀態**。一旦在這些狀態犯錯,可能導致狀態偏離專家軌跡越來越遠,錯誤會累積放大。(例如:專家開車過彎都沒問題,但若 AI 在轉彎處不小心犯錯,會不知道如何處理,因為沒有訓練過這種狀況)![image](https://hackmd.io/_uploads/HJBSkfNCJx.png) * **需要大量示範數據**。 * **改進:DAgger (Dataset Aggregation)**:一種迭代方法。先用 BC 訓練一個策略,然後讓這個策略與環境互動收集新的狀態數據,再請專家標註這些新狀態下應採取的行動,將新數據加入訓練集,重新訓練策略。 * **逆增強式學習 (Inverse Reinforcement Learning, IRL)**: * **概念**:與 BC 直接模仿行動不同,IRL 試圖從專家的示範中**反推出**專家內在的、未知的「獎勵函數」$R^*$。 * **原則**:假設**專家示範的行為是在最大化某個潛在的獎勵函數**。一旦找到這個獎勵函數,就可以用標準的 RL 算法 (如 PG 或 AC) 來訓練 Agent,使其最大化這個學到的獎勵函數。 * **流程**: 1. 收集一堆專家示範軌跡 $\{\hat \tau_1, \hat \tau_2, \cdots, \hat \tau_K\}$。 2. 訓練一個獎勵函數 $R(s, a)$,使得專家軌跡在該函數下的總獎勵盡可能高,而其他 (非專家) 軌跡的總獎勵相對較低。$\sum{R(\hat \tau)}必須>\sum{R(\tau)}$。 3. 使用 RL 算法訓練一個策略 $\pi_\theta$,使其最大化從 $R$ 獲得的預期總獎勵。 4. 迭代進行步驟 2 和 3。![image](https://hackmd.io/_uploads/Hk_m-fN0yx.png) * **與生成對抗網路 ([GAN](https://hackmd.io/@Jaychao2099/imrobot7)) 的類比**:IRL 的過程常被類比為 GAN。 * **獎勵函數 (Reward Function)** 類似於 **判別器 (Discriminator)**:目標是區分專家軌跡和 Agent 生成的軌跡,給予專家軌跡高分 (獎勵),給予 Agent 軌跡低分。 * **Agent /Actor (Agent/Actor)** 類似於 **生成器 (Generator)**:目標是生成能夠「欺騙」獎勵函數 (判別器)的軌跡,即獲得高獎勵。![image](https://hackmd.io/_uploads/rJJf7GNAyg.png) * **優點**:可能比 BC 更具泛化能力,因為它訓練的是目標 (獎勵函數) 而非特定行為。學習到的策略可能超越專家 (如果 RL 優化做得好、為特定行為訂製獎勵...)。 * **缺點**:通常比 BC 更複雜,計算成本更高。 * **目標條件式學習 (Goal-Conditioned Learning)**:一種較新的趨勢,直接給定目標狀態 (例如一張圖片),讓 Agent 學習如何達到這個目標狀態,而無需人工示範或獎勵函數。 Agent 可以透過自我設定目標並嘗試達成來進行訓練。![image](https://hackmd.io/_uploads/BymSEfEC1l.png) 論文:[[1]](https://arxiv.org/abs/1807.04742)[[2]](https://arxiv.org/abs/1903.03698) --- ## 結論 增強式學習是一個強大且活躍的研究領域,涵蓋從基本概念、核心算法 (如 Policy Gradient、Actor-Critic) 到處理挑戰性問題 (如稀疏獎勵、無獎勵學習) 的各種技術。理解這些基本原理是深入探索和應用 RL 的關鍵。 --- 回[主目錄](https://hackmd.io/@Jaychao2099/aitothemoon/)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully