[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,64 +2,175 @@
|
||||
id: wiki-2026-0508-state-space
|
||||
title: State Space
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-SPS-001]
|
||||
aliases: [ssm, state-space-model, mamba, s4, linear-rnn]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.94
|
||||
tags: [auto-reinforced, State-space, System-Theory, control, navigation, Search-Space, potential-outcomes]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [state-space, control-theory, ssm, mamba, sequence-modeling]
|
||||
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-mamba-jax
|
||||
---
|
||||
|
||||
# [[State-Space|State-Space]]
|
||||
# State Space
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "시스템이 존재할 수 있는 평행우주의 지도: 현재의 위치, 속도, 에너지 등 모든 변수의 조합을 하나의 점(Point)으로 표현하고, 이 점이 어디로 이동할 수 있는지(State Transition)를 한눈에 보여주는 시스템의 '행동 범위 전체'."
|
||||
## 매 한 줄
|
||||
> **"매 hidden state evolves over time, observations emerge from it"**. State space 는 매 control theory / signal processing 의 핵심 representation: $x_{t+1}=Ax_t+Bu_t,\; y_t=Cx_t+Du_t$. 매 2024-2026 의 deep learning 의 SSM (S4, Mamba, Mamba-2) 가 매 Transformer 의 long-context alternative 로 부상.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
상태 공간(State-Space)은 계(System)의 상태를 나타내는 모든 가능한 벡터들의 집합입니다.
|
||||
## 매 핵심
|
||||
|
||||
1. **핵심 메커니즘**:
|
||||
* **State Vector**: 시스템의 현재 상황을 요약한 수치 묶음. ([[Representation-Learning|Representation-Learning]]와 연결)
|
||||
* **Transition Function**: 현재 상태에서 어떤 행동을 했을 때 다음 상태로 어떻게 변하는지 결정. ([[Reinforcement Learning (RL)|Reinforcement Learning (RL)]]와 연결)
|
||||
2. **왜 중요한가?**:
|
||||
* 시스템이 가질 수 있는 모든 '경우의 수'를 수학적으로 정의함으로써, 원하는 상태([[goal|goal]])로 가기 위한 최적의 경로를 계산할 수 있기 때문임. ([[Optimization|Optimization]]의 토대)
|
||||
### 매 control-theory origin
|
||||
- **State** $x_t$: 매 system 의 internal memory.
|
||||
- **Input** $u_t$: 매 external control / observation.
|
||||
- **Output** $y_t$: 매 measurable.
|
||||
- **Matrices** $A, B, C, D$: 매 dynamics, input mapping, observation, feedthrough.
|
||||
- **Discrete vs continuous**: $\dot x = Ax + Bu$ (continuous) vs $x_{t+1}$ (discrete).
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌**: 과거에는 변수가 적은 선형적 물리 시스템 정책 위주였으나, 현대 정책은 수십억 개의 파라미터를 가진 신경망 내부의 잠재 상태 공간(Latent state space)을 다루는 방향으로 확장됨(RL Update).
|
||||
- **정책 변화(RL Update)**: 이제는 단순히 공간을 정의하는 정책을 넘어, 'Mamba'와 같은 최신 AI 아키텍처(SSM: State Space Model)를 통해 장기 문맥 정책을 압도적 효율성 정책으로 처리하는 등 하드웨어 최적화 정책의 핵심 도구로 쓰임.
|
||||
### 매 deep learning SSM 진화
|
||||
- **HiPPO (2020)**: 매 long-range memory 의 polynomial 근사 — 매 A matrix 의 영리한 init.
|
||||
- **S4 (2022)**: structured SSM, FFT-based convolution view, long-range arena SOTA.
|
||||
- **H3, Hyena**: 매 SSM + gating 의 hybrid.
|
||||
- **Mamba (2023)**: 매 selective SSM — 매 input-dependent A,B,C, hardware-aware parallel scan.
|
||||
- **Mamba-2 (2024)**: 매 SSD (state-space duality) — 매 attention 과 의 unification.
|
||||
- **Hybrid (2025+)**: 매 Jamba, Zamba, Samba — 매 Transformer + Mamba mix.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- [[Representation-Learning|Representation-Learning]], [[Reinforcement Learning (RL)|Reinforcement Learning (RL)]], [[Optimization|Optimization]], [[Search-Space|Search-Space]], [[Physics|Physics]]
|
||||
- **Modern Tech/Tools**: Control theory, Kalman filters, Mamba (S4 models), MDP (Markov Decision Process).
|
||||
---
|
||||
### 매 vs Transformer
|
||||
| 측면 | Transformer | SSM (Mamba) |
|
||||
|---|---|---|
|
||||
| Train | O(N²) parallel | O(N) parallel scan |
|
||||
| Infer | O(N) per token, KV cache | O(1) per token, fixed state |
|
||||
| Memory at infer | grows with context | constant |
|
||||
| Long context | quadratic cost | linear cost |
|
||||
| In-context recall | strong | weaker (improving with hybrids) |
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### 매 응용
|
||||
1. **Control systems** — 매 robotics, aerospace, Kalman filter.
|
||||
2. **Time series** — 매 Kalman / particle filter, dynamic factor model.
|
||||
3. **Long-context LLM** — 매 Mamba-3B, Jamba-1.5 의 1M+ context.
|
||||
4. **DNA / genomics** — 매 Caduceus, HyenaDNA 의 long sequence.
|
||||
5. **Audio** — 매 SaShiMi 의 raw-waveform generation.
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
## 💻 패턴
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### Classic discrete state space (control)
|
||||
```python
|
||||
import numpy as np
|
||||
def simulate(A, B, C, D, u, x0):
|
||||
x, ys = x0.copy(), []
|
||||
for ut in u:
|
||||
y = C @ x + D @ ut
|
||||
x = A @ x + B @ ut
|
||||
ys.append(y)
|
||||
return np.array(ys)
|
||||
```
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
### Kalman filter
|
||||
```python
|
||||
def kalman_step(x, P, u, z, A, B, C, Q, R):
|
||||
# predict
|
||||
x = A @ x + B @ u
|
||||
P = A @ P @ A.T + Q
|
||||
# update
|
||||
K = P @ C.T @ np.linalg.inv(C @ P @ C.T + R)
|
||||
x = x + K @ (z - C @ x)
|
||||
P = (np.eye(len(x)) - K @ C) @ P
|
||||
return x, P
|
||||
```
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
### S4 convolutional view (PyTorch)
|
||||
```python
|
||||
import torch, torch.nn.functional as F
|
||||
def s4_conv(u, A_bar, B_bar, C, L):
|
||||
# K_l = C A_bar^l B_bar → conv kernel of length L
|
||||
K = torch.stack([C @ torch.matrix_power(A_bar, l) @ B_bar for l in range(L)])
|
||||
y = F.conv1d(u.unsqueeze(0), K.flip(0).unsqueeze(0).unsqueeze(0))
|
||||
return y.squeeze()
|
||||
```
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
### Mamba selective scan (mamba-ssm package)
|
||||
```python
|
||||
from mamba_ssm import Mamba
|
||||
import torch
|
||||
model = Mamba(d_model=512, d_state=16, d_conv=4, expand=2).cuda()
|
||||
x = torch.randn(2, 1024, 512, device="cuda")
|
||||
y = model(x) # [B, L, D] — O(L) parallel scan
|
||||
```
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
### HiPPO initialization (LegS)
|
||||
```python
|
||||
def hippo_legs(N):
|
||||
A = np.zeros((N, N))
|
||||
for n in range(N):
|
||||
for k in range(N):
|
||||
if n > k: A[n, k] = -np.sqrt((2*n+1) * (2*k+1))
|
||||
elif n == k: A[n, k] = -(n + 1)
|
||||
return A
|
||||
```
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
### Mamba-2 SSD block (simplified)
|
||||
```python
|
||||
def ssd_block(X, A, B, C, chunk=64):
|
||||
# state-space duality: structured matrix multiply
|
||||
# parallelizable as matmul, shows attention-SSM equivalence
|
||||
L = X.shape[1]
|
||||
Y = torch.zeros_like(X)
|
||||
state = torch.zeros(...)
|
||||
for s in range(0, L, chunk):
|
||||
Y[:, s:s+chunk], state = ssd_chunk(X[:, s:s+chunk], A, B, C, state)
|
||||
return Y
|
||||
```
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
### Hybrid (Jamba-style: Mamba + attention)
|
||||
```python
|
||||
class JambaBlock(nn.Module):
|
||||
def __init__(self, d, use_attn=False):
|
||||
super().__init__()
|
||||
self.layer = MultiheadAttention(d, 8) if use_attn else Mamba(d_model=d)
|
||||
self.mlp = MoE(d) if use_moe else MLP(d)
|
||||
def forward(self, x): return self.mlp(self.layer(x) + x) + x
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Control system 의 design | classical SSM + LQR / Kalman |
|
||||
| Time-series filtering | Kalman / particle filter |
|
||||
| Long-context language (>128k) | Mamba / Jamba hybrid |
|
||||
| In-context recall heavy | Transformer or hybrid (not pure Mamba) |
|
||||
| Genomics 1M token | HyenaDNA / Caduceus |
|
||||
| Audio raw waveform | SaShiMi / Mamba-Audio |
|
||||
|
||||
**기본값**: 매 control 의 classical SSM. 매 long-context LM 의 Mamba-2 또는 Jamba 의 hybrid (pure Mamba 의 recall 약점 의 보완).
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Control-Theory]] · [[Sequence-Modeling]]
|
||||
- 변형: [[S4]] · [[Mamba]] · [[Mamba-2]] · [[Hyena]] · [[Linear-RNN]]
|
||||
- 응용: [[Kalman-Filter]] · [[Long-Context-LLM]] · [[HyenaDNA]] · [[Time-Series-Forecasting]]
|
||||
- Adjacent: [[Transformer]] · [[RNN]] · [[HiPPO]] · [[Selective-Scan]] · [[Linear-Attention]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: SSM literature 정리, mamba-ssm boilerplate, control-system identification 의 sympy / numpy code.
|
||||
**언제 X**: real-time safety-critical control (aerospace, medical) — 매 verified controller / formal methods 의 영역.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **HiPPO init 무시**: random init Mamba 의 long-range 성능 추락. 매 proper A init 필수.
|
||||
- **Pure Mamba 의 in-context retrieval 기대**: needle-in-haystack 약함. Hybrid 권장.
|
||||
- **No selective mechanism**: 매 vanilla S4 의 modern Mamba 보다 약함 — input-dependent param 필수.
|
||||
- **Classical SSM 의 nonlinearity 무시**: 매 real system 의 nonlinear — EKF / UKF / particle filter 사용.
|
||||
- **CUDA scan 미활용**: 매 naive Python loop 의 100배 slow. mamba-ssm 의 official kernel 사용.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Kalman 1960, Gu et al. S4 2022, Gu & Dao Mamba 2023, Dao & Gu Mamba-2 2024, Jamba 2024).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — control SSM + modern Mamba/Mamba-2/Jamba |
|
||||
|
||||
Reference in New Issue
Block a user