[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,89 +2,163 @@
|
||||
id: wiki-2026-0508-linear-algebra-foundations
|
||||
title: Linear Algebra Foundations
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [MATH-LA-001]
|
||||
aliases: [Matrix Algebra, Vector Spaces, Linear Algebra]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 1.0
|
||||
tags: [math, Linear-Algebra, vector-space, matrix, ai-foundations]
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [linear-algebra, math, ml-foundations, matrix]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-26
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: python
|
||||
framework: numpy, jax, torch
|
||||
---
|
||||
|
||||
# Linear Algebra Foundations (선형대수학 기초)
|
||||
# Linear Algebra Foundations
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "세상의 모든 데이터를 숫자들의 격자(Matrix)로 치환하고, 그들 사이의 관계를 공간의 변환(Transformation)으로 이해하라" — 벡터와 행렬을 통해 다차원 데이터를 표현하고 연산하는 수학적 체계이자, 인공지능이 세상을 수치화하고 처리하는 공용어.
|
||||
## 매 한 줄
|
||||
> **"매 ML 의 universal language"**. Linear Algebra 는 vector space, linear map, eigendecomposition, SVD 의 study — 매 modern ML/DL 의 numerical backbone. 2026 LLM era 에서 attention 은 매 Q@K.T softmax @V — 매 pure linear algebra 의 chain. GPU/TPU 의 design 자체가 매 LA primitive (GEMM) 위에 built.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
- **추출된 패턴:** "Space Mapping" — 데이터를 고차원 벡터 공간의 점으로 정의하고, 행렬 곱을 통해 공간을 회전, 확대, 투영함으로써 데이터 내의 숨겨진 구조와 특징을 추출하는 수학적 추상화 패턴.
|
||||
- **핵심 구성 요소:**
|
||||
- **Vectors & Scalars:** 데이터의 방향과 크기 표현.
|
||||
- **Matrices:** 데이터 집합체이자 선형 변환의 도구.
|
||||
- **Eigenvalues & Eigenvectors:** 행렬 변환 시 방향이 변하지 않는 고유한 축(핵심 특징).
|
||||
- **Inverse Matrix & Determinant:** 시스템의 해를 구하거나 공간의 부피 변화 측정.
|
||||
- **의의:** 신경망의 가중치 연산, 차원 축소(PCA), 추천 시스템, 그래픽스 등 현대 모든 지능형 소프트웨어의 물리적 토대.
|
||||
## 매 핵심
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 정적인 수식 풀이 중심에서, 이제는 거대한 규모의 행렬 연산을 효율적으로 처리하기 위한 수치 선형대수(Numerical Linear Algebra)와 GPU 가속 하드웨어 연산 최적화가 더 중요한 쟁점으로 부상함.
|
||||
- **정책 변화:** Antigravity 프로젝트는 에이전트의 지식 임베딩 연산 시, 선형대수적 원리를 바탕으로 유사도 측정 및 공간 투영 최적화를 수행하여 연산 효율을 극대화함.
|
||||
### 매 Vector spaces
|
||||
- field $\mathbb{F}$ (보통 $\mathbb{R}, \mathbb{C}$)
|
||||
- closed under linear combinations
|
||||
- basis: minimal spanning set, dim
|
||||
- linear map $T: V \to W$ — represent as matrix in basis
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- [[Inner-Product-Spaces|Inner-Product-Spaces]], [[Eigenvalues-and-Eigenvectors|Eigenvalues-and-Eigenvectors]], [[Dimensionality-Reduction|Dimensionality-Reduction]], [[GPU-Architecture|GPU-Architecture]]-for-AI
|
||||
- **Raw Source:** 10_Wiki/Topics/AI/Linear-Algebra-Foundations.md
|
||||
### 매 Decompositions
|
||||
- **LU**: $A = LU$ — Gaussian elimination, $O(n^3)$
|
||||
- **QR**: $A = QR$, $Q$ orthogonal — least squares
|
||||
- **Eigendecomposition**: $A = V\Lambda V^{-1}$, square only
|
||||
- **SVD**: $A = U\Sigma V^\top$ — universal, rectangular
|
||||
- **Cholesky**: $A = LL^\top$, SPD only, fastest
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### 매 Norms / inner products
|
||||
- $\|x\|_2 = \sqrt{x^\top x}$, $\|x\|_p$, $\|x\|_\infty$
|
||||
- Frobenius: $\|A\|_F = \sqrt{\sum a_{ij}^2}$
|
||||
- Spectral: $\|A\|_2 = \sigma_{\max}(A)$
|
||||
- Cauchy-Schwarz: $|x^\top y| \le \|x\| \|y\|$
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
### 매 응용
|
||||
1. **Attention**: $\text{softmax}(QK^\top / \sqrt{d}) V$.
|
||||
2. **PCA**: SVD of centered $X$.
|
||||
3. **Linear regression**: normal eq $w = (X^\top X)^{-1} X^\top y$.
|
||||
4. **Graph Laplacian**: spectral clustering.
|
||||
5. **Quantum states**: complex Hilbert space.
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
## 💻 패턴
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
### NumPy basics
|
||||
```python
|
||||
import numpy as np
|
||||
A = np.random.randn(5, 3)
|
||||
# Solve Ax = b in least-squares
|
||||
b = np.random.randn(5)
|
||||
x, *_ = np.linalg.lstsq(A, b, rcond=None)
|
||||
# rank, condition number, determinant
|
||||
print(np.linalg.matrix_rank(A), np.linalg.cond(A))
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### SVD + low-rank approx
|
||||
```python
|
||||
U, S, Vt = np.linalg.svd(A, full_matrices=False)
|
||||
k = 2
|
||||
A_lr = U[:, :k] @ np.diag(S[:k]) @ Vt[:k] # rank-k approx
|
||||
err = np.linalg.norm(A - A_lr, "fro")
|
||||
```
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### Eigendecomposition (symmetric)
|
||||
```python
|
||||
S = np.random.randn(4, 4); S = S + S.T
|
||||
w, V = np.linalg.eigh(S) # use eigh for symmetric (stable, real)
|
||||
# reconstruction
|
||||
assert np.allclose(V @ np.diag(w) @ V.T, S, atol=1e-10)
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### Cholesky for SPD systems
|
||||
```python
|
||||
import scipy.linalg as la
|
||||
A = np.random.randn(50, 50)
|
||||
A = A.T @ A + np.eye(50) # SPD
|
||||
L = la.cholesky(A, lower=True)
|
||||
b = np.random.randn(50)
|
||||
y = la.solve_triangular(L, b, lower=True)
|
||||
x = la.solve_triangular(L.T, y, lower=False)
|
||||
```
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
### JAX matmul + autodiff
|
||||
```python
|
||||
import jax, jax.numpy as jnp
|
||||
@jax.jit
|
||||
def loss(W, x, y):
|
||||
return jnp.mean((x @ W - y) ** 2)
|
||||
grad_fn = jax.grad(loss)
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### Power iteration (top eigenvector)
|
||||
```python
|
||||
def power_iter(A, n_iter=200, tol=1e-10):
|
||||
x = np.random.randn(A.shape[0])
|
||||
x /= np.linalg.norm(x)
|
||||
for _ in range(n_iter):
|
||||
x_new = A @ x
|
||||
x_new /= np.linalg.norm(x_new)
|
||||
if np.linalg.norm(x_new - x) < tol: break
|
||||
x = x_new
|
||||
eig = x @ A @ x
|
||||
return eig, x
|
||||
```
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
### PyTorch attention (linear algebra core)
|
||||
```python
|
||||
import torch, math
|
||||
def attention(Q, K, V, mask=None):
|
||||
d = Q.size(-1)
|
||||
s = Q @ K.transpose(-2, -1) / math.sqrt(d)
|
||||
if mask is not None: s = s.masked_fill(mask == 0, -1e9)
|
||||
return torch.softmax(s, dim=-1) @ V
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| Problem | Method |
|
||||
|---|---|
|
||||
| solve Ax = b, square nonsingular | LU (np.linalg.solve) |
|
||||
| SPD | Cholesky |
|
||||
| least squares | QR or SVD |
|
||||
| dimensionality reduction | SVD / PCA |
|
||||
| symmetric eigen | eigh |
|
||||
| sparse large | scipy.sparse.linalg / iterative |
|
||||
|
||||
**기본값**: SVD when in doubt — most stable, universal.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Mathematics]] · [[Vector-Space]]
|
||||
- 변형: [[SVD]] · [[Eigendecomposition]] · [[Tensor-Algebra]]
|
||||
- 응용: [[PCA]] · [[Attention-Mechanism]] · [[Linear-Regression]]
|
||||
- Adjacent: [[Numerical-Methods]] · [[Convex-Optimization]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 ML 의 derivation, debugging matrix shapes, performance reasoning.
|
||||
**언제 X**: 매 task 가 combinatorial — graph algorithms 등.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **`inv(A) @ b` 사용**: numerically unstable + slow → use `solve`.
|
||||
- **eig vs eigh 혼동**: symmetric 인데 `eig` 사용 → complex eigenvalues from numerical noise.
|
||||
- **Memory layout 무시**: row vs column major → 10× slowdown.
|
||||
- **Condition number 무시**: ill-conditioned matrix → inversion blows up.
|
||||
- **Dense for sparse**: huge sparse → use scipy.sparse.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Strang 2016 textbook, Trefethen & Bau 1997, Golub & Van Loan 2013).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — vector spaces, decompositions, norms, NumPy/JAX patterns |
|
||||
|
||||
Reference in New Issue
Block a user