[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,68 +2,154 @@
|
||||
id: wiki-2026-0508-reward-prediction-error
|
||||
title: Reward Prediction Error
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-RWPE-001]
|
||||
aliases: [RPE, TD Error, Dopamine Prediction Error]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.99
|
||||
tags: [auto-reinforced, neuroscience, machine-learning, Dopamine, Reinforcement-Learning]
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [neuroscience, reinforcement-learning, dopamine, td-learning]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: PyTorch/Gymnasium
|
||||
---
|
||||
|
||||
# [[Reward Prediction Error|Reward Prediction Error]]
|
||||
# Reward Prediction Error
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "학습을 만드는 엔진: 기대했던 보상과 실제 받은 보상 사이의 '차이'를 계산하여, 그 간극만큼 미래의 행동 지침을 수정해나가는 뇌와 AI의 공통 지능 알고리즘."
|
||||
## 매 한 줄
|
||||
> **"매 actual reward minus predicted reward — 매 학습 의 driver."**. Wolfram Schultz 의 1997 dopamine experiments 가 monkey VTA neuron 의 firing 가 TD-error δ = r + γV(s') − V(s) 와 매 same signature 의 보임. 매 neuroscience 와 RL 의 connect 의 historic moment, 매 modern dopamine RL theory 의 foundation.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
보상 예측 오류(Reward Prediction Error, RPE)는 학습 시스템이 현재의 정책을 업데이트하기 위해 사용하는 핵심 신호입니다.
|
||||
## 매 핵심
|
||||
|
||||
1. **수학적 정의 (TD Error)**:
|
||||
* $RPE = (\text{실제 보상} + \text{이미 알고 있는 미래 가치}) - \text{예상했던 가치}$
|
||||
* **Positive Error (+)**: 기대보다 결과가 좋을 때. 행동 확률을 높임.
|
||||
* **Negative Error (-)**: 기대보다 결과가 나쁠 때. 행동 확률을 낮춤.
|
||||
2. **신경과학적 구현 (도파민)**:
|
||||
* 뇌의 중뇌 도파민 뉴런이 RPE를 계산하는 것으로 알려짐 (슐츠의 연구).
|
||||
* 예상치 못한 보상이 주어질 때 도파민이 폭발하고, 예상대로 나오면 잠잠하며, 예상했는데 안 나오면 도파민 화력이 급락함.
|
||||
3. **강화학습에서의 역할**:
|
||||
* Q-Learning, Actor-Critic 등 대부분의 현대 RL 알고리즘이 이 오차를 0으로 만드는 방향으로 가중치를 최적화함.
|
||||
### 매 RPE definition
|
||||
- **δ_t = r_t + γ·V(s_{t+1}) − V(s_t)** — temporal difference error.
|
||||
- δ > 0: better than expected → strengthen association.
|
||||
- δ = 0: as predicted → no learning needed.
|
||||
- δ < 0: worse than expected → weaken / extinct.
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌**: 과거에는 보상 그 자체가 학습을 일으킨다고 믿었으나, 현대 과학은 '보상 그 자체'가 아니라 '예측하지 못한 보상의 차이(오류)'가 시냅스 가소성을 유발하는 진짜 범인임을 증명함.
|
||||
- **정책 변화(RL Update)**: 중독(Addiction)이나 도박 정책 수립 시, 단순히 행위를 막는 것이 아니라 뇌의 RPE 시스템을 가짜 데이터로 교란하는 '변동 보상(Slot Machine 메커니즘)' 디자인을 규제하는 방향으로 기술 정책이 강화됨.
|
||||
### 매 dopamine signature (Schultz 1997)
|
||||
1. Untrained: dopamine neurons fire at reward delivery.
|
||||
2. After conditioning: fire at predictive cue, 의 X reward.
|
||||
3. Cue followed by no reward: firing dips below baseline (negative RPE).
|
||||
4. 매 exact pattern 의 TD-error δ 와 match.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- [[Reinforcement Learning (RL)|Reinforcement Learning (RL)]], [[Neurobiology-of-Reward|Neurobiology-of-Reward]], [[Probability Theory|Probability Theory]], Performance systems]], [[Ps-Reinforce|Ps-Reinforce]]
|
||||
- **Modern Tech/Tools**: [[Deep Q-Networks (DQN)|Deep Q-Networks (DQN)]], Dopamine level monitoring, [[Behavior|Behavior]]al RL models.
|
||||
---
|
||||
### 매 응용
|
||||
1. Classical/operant conditioning models.
|
||||
2. RL algorithms (TD, Q-learning, Actor-Critic).
|
||||
3. Addiction theory (drugs hijack RPE signal).
|
||||
4. RLHF reward model interpretation (LLM training).
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
## 💻 패턴
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
### TD(0) Update
|
||||
```python
|
||||
def td_update(V, s, r, s_next, alpha=0.1, gamma=0.99):
|
||||
rpe = r + gamma * V[s_next] - V[s] # 매 RPE
|
||||
V[s] += alpha * rpe
|
||||
return V, rpe
|
||||
```
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### Q-Learning RPE
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
def q_learning_step(Q, s, a, r, s_next, alpha=0.1, gamma=0.99):
|
||||
target = r + gamma * np.max(Q[s_next])
|
||||
rpe = target - Q[s, a]
|
||||
Q[s, a] += alpha * rpe
|
||||
return Q, rpe
|
||||
```
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
### Actor-Critic with RPE as Advantage
|
||||
```python
|
||||
import torch
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
def actor_critic_step(actor, critic, opt_a, opt_c, s, a, r, s_next, gamma=0.99):
|
||||
v_s, v_next = critic(s), critic(s_next).detach()
|
||||
rpe = r + gamma * v_next - v_s # 매 RPE = advantage
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
critic_loss = rpe.pow(2)
|
||||
log_prob = actor(s).log_prob(a)
|
||||
actor_loss = -(log_prob * rpe.detach())
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
opt_c.zero_grad(); critic_loss.backward(); opt_c.step()
|
||||
opt_a.zero_grad(); actor_loss.backward(); opt_a.step()
|
||||
return rpe.item()
|
||||
```
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
### Distributional RPE (C51-style)
|
||||
```python
|
||||
# 매 modern: scalar RPE 의 X, 의 reward distribution.
|
||||
def distributional_td_target(r, p_next, support, gamma=0.99):
|
||||
"""p_next: prob over atoms; support: atom values."""
|
||||
Tz = r + gamma * support # shifted support
|
||||
return Tz, p_next # project onto original support next
|
||||
```
|
||||
|
||||
### RLHF reward model RPE
|
||||
```python
|
||||
def rlhf_advantage(rewards, values, gamma=1.0, lam=0.95):
|
||||
"""GAE — generalized advantage estimation. Each step δ_t = RPE."""
|
||||
advantages = []
|
||||
gae = 0
|
||||
for t in reversed(range(len(rewards))):
|
||||
v_next = values[t + 1] if t + 1 < len(values) else 0
|
||||
delta = rewards[t] + gamma * v_next - values[t] # 매 RPE
|
||||
gae = delta + gamma * lam * gae
|
||||
advantages.insert(0, gae)
|
||||
return advantages
|
||||
```
|
||||
|
||||
### Phasic vs Tonic Dopamine simulation
|
||||
```python
|
||||
def simulate_dopamine(trial, cue_time, reward_time, predicted=True):
|
||||
"""Phasic burst at predictive cue (after learning); dip at omitted reward."""
|
||||
signal = []
|
||||
for t in range(trial):
|
||||
if t == cue_time and predicted: signal.append(+1.0) # phasic burst
|
||||
elif t == reward_time and not predicted: signal.append(+1.0)
|
||||
elif t == reward_time and predicted: signal.append(0.0)
|
||||
else: signal.append(0.05) # tonic baseline
|
||||
return signal
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Tabular small state space | TD(0) / Q-learning |
|
||||
| Continuous state, value-based | DQN (RPE = TD target − Q) |
|
||||
| Policy + value | Actor-Critic with RPE as advantage |
|
||||
| Distribution matters | Distributional RL (C51, QR-DQN) |
|
||||
| LLM RLHF | PPO with GAE — RPE summed |
|
||||
|
||||
**기본값**: PPO + GAE — 매 modern RPE 의 actor-critic instantiation.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Reinforcement Learning]] · [[Computational Neuroscience]]
|
||||
- 변형: [[TD Learning]] · [[Q-Learning]] · [[Distributional RL]]
|
||||
- 응용: [[Actor-Critic]] · [[RLHF]] · [[Addiction Models]]
|
||||
- Adjacent: [[Dopamine]] · [[Schultz Experiments]] · [[Bellman Equation]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: RLHF/DPO/GRPO 의 advantage computation 의 understand, 의 reward model debugging.
|
||||
**언제 X**: LLM 의 의 RPE 의 conceptual explanation 의 helpful 의 X — 의 raw neural data 의 X.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Confusing reward and RPE**: r 의 X RPE — RPE = r − prediction.
|
||||
- **Always positive RPE**: 의 X — negative RPE (omission) 의 critical for extinction learning.
|
||||
- **Ignoring discount**: γ 의 omit 의 X — temporal credit assignment 의 broken.
|
||||
- **Dopamine = pleasure**: 의 X — dopamine 의 reward signal 의 X, 의 prediction error 의.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Schultz, Dayan, Montague 1997 Science; Sutton & Barto Ch 6).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — RPE neuroscience + RL bridge |
|
||||
|
||||
Reference in New Issue
Block a user