docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
+191
@@ -0,0 +1,191 @@
|
||||
---
|
||||
id: wiki-2026-0508-abstract-syntax-tree-transformat
|
||||
title: Abstract Syntax Tree Transformation
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [AST Transform, AST Rewrite, Code Transformation]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
verification_status: applied
|
||||
tags: [compiler, ast, codemod, transformation, static-analysis]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: TypeScript/Python
|
||||
framework: Babel/ts-morph/LibCST
|
||||
---
|
||||
|
||||
# Abstract Syntax Tree Transformation
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 source-as-data — 매 string 의 X, 매 tree 의 mutation."**. AST transformation 의 source code 의 parse tree 의 structured manipulation — 매 1970s compiler theory 의 root, 매 2026 의 codemod / linter / formatter / LLM-assisted refactor backbone (Babel, ts-morph, LibCST, tree-sitter).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Pipeline
|
||||
- **Parse**: source string → token stream → AST (lexer + parser).
|
||||
- **Visit/Traverse**: 매 node 의 type-based dispatch (visitor pattern).
|
||||
- **Transform**: node insert / replace / remove / wrap.
|
||||
- **Print**: AST → source string (preserving comments / formatting via concrete syntax tree or sourcemap).
|
||||
|
||||
### 매 Tools (2026)
|
||||
- **Babel** (JS/TS): `@babel/parser` + `@babel/traverse` + `@babel/generator`. 매 ecosystem standard.
|
||||
- **ts-morph** (TS): high-level wrapper over TypeScript compiler API. 매 type-aware transform.
|
||||
- **LibCST** (Python): concrete syntax tree, formatting-preserving. Instagram-grade codemod.
|
||||
- **tree-sitter**: incremental parser, multi-language. 매 editor / LSP foundation.
|
||||
- **jscodeshift**: Facebook codemod runner over Babel.
|
||||
- **swc / oxc**: Rust-based, 10-50x faster than Babel.
|
||||
|
||||
### 매 응용
|
||||
1. **Codemod**: API migration (e.g., React class → hooks).
|
||||
2. **Linter / formatter**: ESLint, Prettier, Ruff.
|
||||
3. **LLM context compression**: AST-based code summarization.
|
||||
4. **Security scanner**: Semgrep AST pattern matching.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — Babel: Replace function call name
|
||||
|
||||
```typescript
|
||||
import * as parser from "@babel/parser";
|
||||
import traverse from "@babel/traverse";
|
||||
import generate from "@babel/generator";
|
||||
import * as t from "@babel/types";
|
||||
|
||||
const code = `console.log("hi"); console.error("err");`;
|
||||
const ast = parser.parse(code, { sourceType: "module" });
|
||||
|
||||
traverse(ast, {
|
||||
CallExpression(path) {
|
||||
const callee = path.node.callee;
|
||||
if (t.isMemberExpression(callee) && t.isIdentifier(callee.object, { name: "console" })) {
|
||||
callee.object = t.identifier("logger");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
console.log(generate(ast).code);
|
||||
// → logger.log("hi"); logger.error("err");
|
||||
```
|
||||
|
||||
### Pattern 2 — ts-morph: Add type annotation
|
||||
|
||||
```typescript
|
||||
import { Project } from "ts-morph";
|
||||
|
||||
const project = new Project();
|
||||
const sf = project.addSourceFileAtPath("src/foo.ts");
|
||||
|
||||
sf.getFunctions().forEach((fn) => {
|
||||
fn.getParameters().forEach((p) => {
|
||||
if (!p.getTypeNode()) p.setType("unknown");
|
||||
});
|
||||
});
|
||||
|
||||
await sf.save();
|
||||
```
|
||||
|
||||
### Pattern 3 — LibCST: Python codemod (preserves formatting)
|
||||
|
||||
```python
|
||||
import libcst as cst
|
||||
|
||||
class RenameImport(cst.CSTTransformer):
|
||||
def leave_ImportFrom(self, orig, updated):
|
||||
if updated.module and updated.module.value == "old_pkg":
|
||||
return updated.with_changes(module=cst.Attribute(
|
||||
value=cst.Name("new_pkg"), attr=cst.Name("submod")
|
||||
))
|
||||
return updated
|
||||
|
||||
tree = cst.parse_module(open("foo.py").read())
|
||||
new_tree = tree.visit(RenameImport())
|
||||
open("foo.py", "w").write(new_tree.code)
|
||||
```
|
||||
|
||||
### Pattern 4 — tree-sitter query (Semgrep-like)
|
||||
|
||||
```scheme
|
||||
; Find all `console.log(...)` calls
|
||||
(call_expression
|
||||
function: (member_expression
|
||||
object: (identifier) @obj
|
||||
property: (property_identifier) @prop)
|
||||
(#eq? @obj "console")
|
||||
(#eq? @prop "log")) @match
|
||||
```
|
||||
|
||||
### Pattern 5 — jscodeshift script
|
||||
|
||||
```javascript
|
||||
module.exports = function (file, api) {
|
||||
const j = api.jscodeshift;
|
||||
return j(file.source)
|
||||
.find(j.VariableDeclaration, { kind: "var" })
|
||||
.forEach((p) => { p.value.kind = "const"; })
|
||||
.toSource();
|
||||
};
|
||||
```
|
||||
|
||||
### Pattern 6 — Type-aware refactor with TS compiler API
|
||||
|
||||
```typescript
|
||||
import ts from "typescript";
|
||||
|
||||
function transformer<T extends ts.Node>(ctx: ts.TransformationContext) {
|
||||
return (root: T) => {
|
||||
function visit(node: ts.Node): ts.Node {
|
||||
if (ts.isCallExpression(node) && node.expression.getText() === "deprecated") {
|
||||
return ts.factory.createCallExpression(
|
||||
ts.factory.createIdentifier("modern"),
|
||||
undefined, node.arguments
|
||||
);
|
||||
}
|
||||
return ts.visitEachChild(node, visit, ctx);
|
||||
}
|
||||
return ts.visitNode(root, visit) as T;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| JS/TS quick codemod | jscodeshift + Babel |
|
||||
| Type-aware TS refactor | ts-morph |
|
||||
| Python large-scale | LibCST |
|
||||
| Multi-language editor / search | tree-sitter |
|
||||
| Performance-critical CI | swc / oxc |
|
||||
| Security pattern detection | Semgrep |
|
||||
| LLM-driven refactor | tree-sitter + LLM tool-use |
|
||||
|
||||
**기본값**: Babel for JS/TS, LibCST for Python, tree-sitter for cross-language.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Static-Analysis]]
|
||||
- 변형: [[Concrete-Syntax-Tree]]
|
||||
- 응용: [[Linter]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: large-scale code migration, repo-wide rename, API deprecation cleanup, structured code understanding for LLM context.
|
||||
**언제 X**: one-off edits (use sed/IDE), formatting-only changes (use Prettier/Ruff direct), single-file simple regex.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Regex-as-AST**: complex code transform 의 regex 의 fragile — comment / string literal 의 false match.
|
||||
- **Format loss**: 매 round-trip 의 comment / whitespace 의 drop — concrete syntax tree (LibCST) 또는 sourcemap 사용.
|
||||
- **Type-blind refactor**: TS 의 type info 의 ignore — runtime error.
|
||||
- **No idempotency**: codemod 의 re-run 의 duplicate transform — guard idempotent.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Babel docs, ts-morph docs, LibCST Instagram engineering blog).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (Babel/ts-morph/LibCST/tree-sitter, 6 patterns, decision table) |
|
||||
@@ -0,0 +1,147 @@
|
||||
---
|
||||
id: wiki-2026-0508-adaptive-curation
|
||||
title: Adaptive Curation
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Dynamic Curation, Personalized Curation, Active Curation]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.88
|
||||
verification_status: applied
|
||||
tags: [recsys, curation, personalization, active-learning, feedback]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: PyTorch/scikit-learn
|
||||
---
|
||||
|
||||
# Adaptive Curation
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 selection 의 close-loop — 매 user feedback 의 corpus 의 reshape."**. Adaptive curation 의 static collection 의 X, 매 user signal (click, dwell, rating, embedding drift) 의 use → 매 corpus / ranking / recommendation 의 dynamic adjust. 매 2026 의 LLM-augmented (semantic embedding + bandits + RLHF) 의 standard.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Components
|
||||
- **Catalog / corpus**: candidate items.
|
||||
- **User signal**: explicit (rating, like) + implicit (click, dwell, scroll depth).
|
||||
- **Ranker / selector**: scoring function (often embedding sim + bandit + LTR).
|
||||
- **Update loop**: feedback → model update → next selection.
|
||||
|
||||
### 매 Algorithms
|
||||
- **Collaborative filtering**: matrix factorization (SVD, ALS).
|
||||
- **Content-based**: TF-IDF / semantic embedding (sentence-transformers, OpenAI ada-3, Cohere v4).
|
||||
- **Hybrid**: 매 collaborative + content.
|
||||
- **Bandits**: ε-greedy, UCB, Thompson sampling — 매 explore/exploit.
|
||||
- **Contextual bandit / LinUCB**: user feature 의 use.
|
||||
- **RLHF / DPO**: 매 LLM-era curation (Claude, GPT-5).
|
||||
|
||||
### 매 응용
|
||||
1. News feed (TikTok, X).
|
||||
2. E-commerce product ranking (Amazon, Coupang).
|
||||
3. Knowledge base curation (Notion AI, Glean).
|
||||
4. RAG corpus filtering — 매 LLM context 의 dynamic selection.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — Embedding-based candidate retrieval
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
from sentence_transformers import SentenceTransformer
|
||||
|
||||
model = SentenceTransformer("all-MiniLM-L12-v2")
|
||||
docs = ["AI safety", "RAG patterns", "vector DB"]
|
||||
doc_emb = model.encode(docs, normalize_embeddings=True)
|
||||
|
||||
def retrieve(query: str, k=5):
|
||||
q = model.encode(query, normalize_embeddings=True)
|
||||
scores = doc_emb @ q
|
||||
return np.argsort(-scores)[:k]
|
||||
```
|
||||
|
||||
### Pattern 2 — Thompson Sampling bandit
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
class ThompsonSampler:
|
||||
def __init__(self, n_arms):
|
||||
self.alpha = np.ones(n_arms)
|
||||
self.beta = np.ones(n_arms)
|
||||
def select(self):
|
||||
samples = np.random.beta(self.alpha, self.beta)
|
||||
return int(np.argmax(samples))
|
||||
def update(self, arm, reward):
|
||||
if reward > 0: self.alpha[arm] += 1
|
||||
else: self.beta[arm] += 1
|
||||
```
|
||||
|
||||
### Pattern 3 — Click-through online update
|
||||
|
||||
```python
|
||||
def on_click(user_id, item_id, dwell_s):
|
||||
reward = 1 if dwell_s > 5 else 0
|
||||
bandit.update(item_id, reward)
|
||||
feature_store.log(user_id, item_id, dwell_s)
|
||||
```
|
||||
|
||||
### Pattern 4 — Contextual ranker (LightGBM LTR)
|
||||
|
||||
```python
|
||||
import lightgbm as lgb
|
||||
ranker = lgb.LGBMRanker(objective="lambdarank", n_estimators=300)
|
||||
ranker.fit(X_train, y_train, group=group_train)
|
||||
scores = ranker.predict(X_val)
|
||||
```
|
||||
|
||||
### Pattern 5 — RAG with adaptive filter
|
||||
|
||||
```python
|
||||
def adaptive_rag(query, user_profile):
|
||||
candidates = vector_db.search(query, k=50)
|
||||
reranked = cross_encoder.rerank(query, candidates)
|
||||
filtered = [c for c in reranked if user_profile.relevance(c) > 0.6]
|
||||
return filtered[:5]
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Cold start, no user data | Content-based + popularity prior |
|
||||
| Rich interaction logs | Hybrid + LTR |
|
||||
| Real-time exploration | Thompson / LinUCB |
|
||||
| LLM context curation | Embedding + cross-encoder rerank |
|
||||
| Long-tail discovery | UCB exploration boost |
|
||||
|
||||
**기본값**: embedding retrieval + cross-encoder rerank + Thompson exploration.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Recommender-Systems]] · [[Active Learning]]
|
||||
- 변형: [[Collaborative-Filtering]] · [[Multi-Armed-Bandit]]
|
||||
- 응용: [[RAG]]
|
||||
- Adjacent: [[Relevance-Feedback]] · [[Ranking-Algorithms]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: dynamic corpus, user feedback available, explore/exploit tradeoff matters, RAG context selection.
|
||||
**언제 X**: static catalog (use plain ranking), no feedback (cold start dominates), regulated content (use rule-based).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Filter bubble**: pure exploit 의 user 의 narrow exposure.
|
||||
- **Feedback contamination**: bot click 의 model 의 poison.
|
||||
- **No exploration decay**: ε constant — 매 mature system 의 ε ↓.
|
||||
- **Position bias ignore**: top item 의 click 의 inflate — debiasing essential.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Netflix tech blog, TikTok recsys papers, RecSys 2024 proceedings).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (bandits, LTR, RAG patterns) |
|
||||
@@ -0,0 +1,163 @@
|
||||
---
|
||||
id: wiki-2026-0508-additive-type-logic
|
||||
title: Additive Type Logic
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Sum Types, Tagged Union, Discriminated Union, Algebraic Data Types]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.93
|
||||
verification_status: applied
|
||||
tags: [type-theory, adt, sum-type, pattern-matching, functional]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Rust/TypeScript/Haskell
|
||||
framework: ADT
|
||||
---
|
||||
|
||||
# Additive Type Logic
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 OR 의 type-level — 매 either A or B, 매 never both."**. Additive type (sum / coproduct) 의 algebra 의 `+` operator — Either, Option, Result 의 backbone. 매 type theory (Curry-Howard) 의 OR proposition 의 mirror, 매 2026 의 Rust/TS/Haskell/Swift idiom.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Theory
|
||||
- **Sum type** `A + B`: value 의 either A 또는 B (with tag).
|
||||
- **Product type** `A × B`: value 의 both A and B (tuple/struct).
|
||||
- **Curry-Howard**: sum ↔ logical OR (∨), product ↔ AND (∧).
|
||||
- **Initial object**: `Void` (empty sum) — never inhabited.
|
||||
- **Unit**: `()` (empty product) — single inhabitant.
|
||||
- **Distributivity**: `A × (B + C) = A × B + A × C`.
|
||||
|
||||
### 매 Implementations
|
||||
- **Haskell/Elm**: `data Maybe a = Nothing | Just a`.
|
||||
- **Rust**: `enum Result<T, E> { Ok(T), Err(E) }`.
|
||||
- **TS**: discriminated union `{ tag: 'ok'; v: T } | { tag: 'err'; e: E }`.
|
||||
- **Swift**: `enum` with associated values.
|
||||
- **Kotlin**: `sealed class`.
|
||||
- **Scala 3**: `enum` (formerly sealed trait).
|
||||
|
||||
### 매 응용
|
||||
1. Error handling without exceptions (Result).
|
||||
2. State machine encoding.
|
||||
3. JSON variant (tagged union).
|
||||
4. Parser combinator output.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — Rust Result / Option
|
||||
|
||||
```rust
|
||||
fn parse_age(s: &str) -> Result<u32, String> {
|
||||
s.parse::<u32>().map_err(|e| format!("parse: {e}"))
|
||||
}
|
||||
|
||||
match parse_age("42") {
|
||||
Ok(n) if n < 150 => println!("ok {n}"),
|
||||
Ok(n) => println!("suspicious {n}"),
|
||||
Err(e) => eprintln!("{e}"),
|
||||
}
|
||||
```
|
||||
|
||||
### Pattern 2 — TypeScript discriminated union
|
||||
|
||||
```typescript
|
||||
type Shape =
|
||||
| { kind: "circle"; r: number }
|
||||
| { kind: "rect"; w: number; h: number };
|
||||
|
||||
const area = (s: Shape): number => {
|
||||
switch (s.kind) {
|
||||
case "circle": return Math.PI * s.r ** 2;
|
||||
case "rect": return s.w * s.h;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
### Pattern 3 — Exhaustiveness check (TS never)
|
||||
|
||||
```typescript
|
||||
function assertNever(x: never): never { throw new Error(`unhandled: ${x}`); }
|
||||
|
||||
const handle = (s: Shape) => {
|
||||
switch (s.kind) {
|
||||
case "circle": return "c";
|
||||
case "rect": return "r";
|
||||
default: return assertNever(s); // compile error if missed
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
### Pattern 4 — Haskell ADT + pattern match
|
||||
|
||||
```haskell
|
||||
data Tree a = Leaf | Node (Tree a) a (Tree a)
|
||||
|
||||
depth :: Tree a -> Int
|
||||
depth Leaf = 0
|
||||
depth (Node l _ r) = 1 + max (depth l) (depth r)
|
||||
```
|
||||
|
||||
### Pattern 5 — State machine via enum
|
||||
|
||||
```rust
|
||||
enum Conn {
|
||||
Disconnected,
|
||||
Connecting { since: Instant },
|
||||
Connected { id: SessionId },
|
||||
Closing,
|
||||
}
|
||||
|
||||
fn step(c: Conn, ev: Event) -> Conn { /* exhaustive match */ }
|
||||
```
|
||||
|
||||
### Pattern 6 — Zod (TS runtime ADT)
|
||||
|
||||
```typescript
|
||||
import { z } from "zod";
|
||||
const Result = z.discriminatedUnion("tag", [
|
||||
z.object({ tag: z.literal("ok"), v: z.number() }),
|
||||
z.object({ tag: z.literal("err"), e: z.string() }),
|
||||
]);
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Error handling | Result / Either |
|
||||
| Optional value | Option / Maybe |
|
||||
| 3+ variant state | sealed enum / sum type |
|
||||
| External JSON variant | discriminated union + schema |
|
||||
| Boolean only | bool (sum 의 unit + unit) |
|
||||
|
||||
**기본값**: discriminated union with explicit tag + exhaustive pattern match.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Type Theory]] · [[Algebraic-Data-Types]]
|
||||
- 응용: [[Error-Handling]] · [[State-Machine]]
|
||||
- Adjacent: [[Pattern-Matching]] · [[Curry-Howard]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: type-driven design, error handling without exceptions, state machine, schema variant modeling.
|
||||
**언제 X**: dynamic / duck-typed contexts (Python without union types), single-variant case (just struct).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Boolean blindness**: `bool` 의 use 의 meaning lost — named variant 의 prefer.
|
||||
- **Stringly-typed tag**: free-form string 의 tag — typo unsafe.
|
||||
- **Non-exhaustive match**: default arm 의 silent — exhaustiveness check 의 enable.
|
||||
- **Nested Option**: `Option<Option<T>>` 의 ambiguous — flatten 또는 redesign.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (TAPL, Pierce / Rust Book / TS Handbook).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (Rust/TS/Haskell, 6 patterns) |
|
||||
@@ -0,0 +1,129 @@
|
||||
---
|
||||
id: wiki-2026-0508-aesthetic-value
|
||||
title: Aesthetic Value
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Aesthetics, Beauty Theory, Aesthetic Judgment]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.85
|
||||
verification_status: applied
|
||||
tags: [philosophy, aesthetics, axiology, design, computational-aesthetics]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: CLIP/aesthetic-predictor
|
||||
---
|
||||
|
||||
# Aesthetic Value
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 beauty 의 measurable — 매 subjective 의 X, 매 inter-subjective regularity 의 model."**. Aesthetic value 의 philosophy (Kant, Hume) 의 root, 매 2026 의 computational aesthetics (CLIP-aesthetic, LAION predictor, FLUX-Pro reward model) 의 design / image-gen / UI optimization 의 quantified.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Theories
|
||||
- **Kant's "disinterested pleasure"**: aesthetic judgment 의 free of utility / desire.
|
||||
- **Hume's "delicacy of taste"**: trained sensibility 의 inter-subjective standard.
|
||||
- **Formalism (Bell, Fry)**: significant form — composition / line / color.
|
||||
- **Expressivism (Collingwood)**: art 의 emotion 의 expression.
|
||||
- **Institutional theory (Dickie)**: artworld 의 designation.
|
||||
|
||||
### 매 Computational Aesthetics
|
||||
- **LAION-Aesthetics predictor**: CLIP embedding → MLP → 1-10 score.
|
||||
- **PickScore / HPSv2**: human-preference reward model for image-gen.
|
||||
- **FLUX-Pro / Imagen 3 reward**: aesthetic + prompt-alignment dual reward.
|
||||
- **A/B testing**: empirical preference (UI design).
|
||||
- **Birkhoff's M = O / C**: Order over Complexity (1933).
|
||||
|
||||
### 매 응용
|
||||
1. Image generation reward (FLUX, SD3, Imagen 3 RLHF).
|
||||
2. UI / design system scoring.
|
||||
3. Photo curation (Apple Photos, Google Photos auto-pick).
|
||||
4. Stock image ranking.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — LAION aesthetic score
|
||||
|
||||
```python
|
||||
import torch, clip
|
||||
from huggingface_hub import hf_hub_download
|
||||
|
||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||
clip_model, preprocess = clip.load("ViT-L/14", device=device)
|
||||
mlp_path = hf_hub_download("LAION-AI/aesthetic-predictor", "sa_0_4_vit_l_14_linear.pth")
|
||||
mlp = torch.nn.Linear(768, 1).to(device)
|
||||
mlp.load_state_dict(torch.load(mlp_path))
|
||||
|
||||
def score(img_pil):
|
||||
with torch.no_grad():
|
||||
emb = clip_model.encode_image(preprocess(img_pil).unsqueeze(0).to(device))
|
||||
emb = emb / emb.norm(dim=-1, keepdim=True)
|
||||
return mlp(emb.float()).item()
|
||||
```
|
||||
|
||||
### Pattern 2 — PickScore reward (HF)
|
||||
|
||||
```python
|
||||
from transformers import AutoProcessor, AutoModel
|
||||
proc = AutoProcessor.from_pretrained("yuvalkirstain/PickScore_v1")
|
||||
model = AutoModel.from_pretrained("yuvalkirstain/PickScore_v1").cuda()
|
||||
|
||||
def pick_score(prompt, image):
|
||||
inputs = proc(text=prompt, images=image, return_tensors="pt", padding=True).to("cuda")
|
||||
with torch.no_grad():
|
||||
return model(**inputs).logits_per_image.item()
|
||||
```
|
||||
|
||||
### Pattern 3 — Birkhoff order/complexity
|
||||
|
||||
```python
|
||||
def birkhoff(order_count: int, complexity: int) -> float:
|
||||
return order_count / max(complexity, 1)
|
||||
```
|
||||
|
||||
### Pattern 4 — RLHF aesthetic reward (training)
|
||||
|
||||
```python
|
||||
# DDPO-style: gradient through diffusion sampling chain
|
||||
def reward_fn(images, prompts):
|
||||
return 0.5 * laion_aesthetic(images) + 0.5 * pick_score(prompts, images)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Photo curation | LAION-aesthetic |
|
||||
| Image-gen RLHF | PickScore + HPSv2 ensemble |
|
||||
| UI / web design | A/B test + heatmap |
|
||||
| Art history analysis | Formalism + expert label |
|
||||
|
||||
**기본값**: ensemble (LAION + PickScore + human eval).
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Axiology]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: image / design quality reward, preference-tuned generation, large-scale curation.
|
||||
**언제 X**: pure subjective single-user use (preference learn), ethical/cultural sensitive context (model bias).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Single-metric absolutism**: LAION 의 over-fit (saturated colors).
|
||||
- **Ignoring cultural bias**: training data 의 Western/Instagram bias.
|
||||
- **No human spot-check**: reward gaming → aesthetic collapse.
|
||||
- **Treating subjective as objective**: 매 score 의 ranking 의 X distance.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (LAION-Aesthetics paper, PickScore NeurIPS 2023, FLUX technical report).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (CLIP-aesthetic, PickScore, RLHF) |
|
||||
@@ -0,0 +1,122 @@
|
||||
---
|
||||
id: wiki-2026-0508-alcoholism
|
||||
title: Alcoholism
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Alcohol Use Disorder, AUD, Alcohol Dependence]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [health, neuroscience, addiction, public-health, computational-health]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: scikit-learn / PyTorch
|
||||
---
|
||||
|
||||
# Alcoholism
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 chronic relapsing brain disorder — 매 willpower 의 X, 매 reward circuit 의 hijack."**. Alcoholism (DSM-5: Alcohol Use Disorder, AUD) 의 dopamine / GABA / glutamate 의 imbalance — 매 2026 의 GLP-1 (semaglutide) 의 craving suppression evidence + naltrexone / acamprosate 의 mainline + AI-driven relapse prediction.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Neurobiology
|
||||
- **Dopamine surge** in nucleus accumbens → euphoria.
|
||||
- **GABA-A potentiation** → anxiolysis, sedation.
|
||||
- **NMDA glutamate antagonism** → cognitive slowing.
|
||||
- **Allostasis**: chronic use → reward set-point shift, withdrawal hypersensitivity.
|
||||
- **HPA axis dysregulation**: stress → relapse trigger.
|
||||
|
||||
### 매 Diagnosis (DSM-5 AUD)
|
||||
- 11 criteria, 2+ in 12 months → AUD.
|
||||
- Severity: mild (2-3), moderate (4-5), severe (6+).
|
||||
- AUDIT-C screen: 3-question, score ≥4 (M) / ≥3 (F) → flag.
|
||||
|
||||
### 매 Treatment (2026)
|
||||
- **Pharmacotherapy**: naltrexone, acamprosate, disulfiram. GLP-1 (semaglutide / tirzepatide) emerging — Phase 3 trials show ~40% craving ↓.
|
||||
- **Psychosocial**: CBT, motivational interviewing, 12-step (AA).
|
||||
- **Digital**: reSET-O FDA-cleared, Quit Genius.
|
||||
- **AI**: ML relapse prediction from EMA + wearable HRV.
|
||||
|
||||
### 매 응용
|
||||
1. Public health screening (AUDIT in EHR).
|
||||
2. Personalized treatment (pharmacogenomics).
|
||||
3. Relapse prediction (ML on smartphone passive sensing).
|
||||
4. Policy modeling (alcohol tax, MUP).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — AUDIT-C scoring
|
||||
|
||||
```python
|
||||
def audit_c(freq: int, drinks_per_day: int, binge_freq: int) -> int:
|
||||
return freq + drinks_per_day + binge_freq # each 0-4
|
||||
|
||||
def flag(score: int, sex: str) -> bool:
|
||||
return score >= (4 if sex == "M" else 3)
|
||||
```
|
||||
|
||||
### Pattern 2 — Relapse prediction (logistic regression on EMA)
|
||||
|
||||
```python
|
||||
from sklearn.linear_model import LogisticRegression
|
||||
features = ["craving_vas", "stress", "sleep_h", "social_isolation", "hrv_rmssd"]
|
||||
clf = LogisticRegression(class_weight="balanced", max_iter=500)
|
||||
clf.fit(X[features], y_relapse_7d)
|
||||
```
|
||||
|
||||
### Pattern 3 — Just-in-time intervention (JITAI)
|
||||
|
||||
```python
|
||||
def maybe_intervene(state):
|
||||
if state.craving > 7 or state.location_near_bar:
|
||||
send_push("Coping skill: 4-7-8 breath. Call sponsor?")
|
||||
```
|
||||
|
||||
### Pattern 4 — HRV-based stress proxy (wearable)
|
||||
|
||||
```python
|
||||
def stress_proxy(rmssd_ms: float, baseline: float) -> float:
|
||||
return max(0.0, (baseline - rmssd_ms) / baseline)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Screening (PCP visit) | AUDIT-C |
|
||||
| Mild AUD, motivated | Brief intervention + naltrexone |
|
||||
| Severe AUD, withdrawal | Inpatient detox + benzodiazepine taper |
|
||||
| Comorbid obesity | GLP-1 (semaglutide) — emerging |
|
||||
| High relapse risk | CBT + naltrexone + digital JITAI |
|
||||
|
||||
**기본값**: AUDIT-C → if positive: brief intervention + naltrexone trial + referral.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Addiction Neuroscience]]
|
||||
- Adjacent: [[Dopamine]] · [[Cognitive-Behavioral-Therapy]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: care navigator, coping skill coaching, EMA prompting, literature synthesis for clinicians.
|
||||
**언제 X**: diagnosis (clinician role), crisis (route to hotline / 988), withdrawal management (medical emergency).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **"Just willpower" framing**: stigma, evidence-contradicted.
|
||||
- **Cold-turkey alone in severe AUD**: delirium tremens 의 fatal risk.
|
||||
- **One-size-fits-all RX**: 매 patient 의 phenotype heterogeneous.
|
||||
- **Ignoring comorbid depression / PTSD**: untreated → relapse near-certain.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (DSM-5, NIAAA guidelines, NEJM 2024 GLP-1/AUD trial).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (DSM-5, GLP-1, JITAI ML) |
|
||||
@@ -0,0 +1,148 @@
|
||||
---
|
||||
id: wiki-2026-0508-algorithm-complexity-big-o
|
||||
title: Algorithm Complexity (Big O)
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Big-O, Time-Complexity, Asymptotic-Analysis]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [computer-science, algorithm, complexity, big-o]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: stdlib
|
||||
---
|
||||
|
||||
# Algorithm Complexity (Big O)
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 입력이 무한히 커질 때 알고리즘이 어떻게 scale하는지를 측정"**. Big-O는 worst-case asymptotic upper bound를 표기 — 매 constant factor와 lower-order term은 drop. 매 1976년 Knuth가 CS에 popularize, 매 2026 ML/AI 에서도 attention $O(n^2)$ → FlashAttention $O(n)$ 같은 algorithmic breakthrough의 척도로 active.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 복잡도 계급
|
||||
- $O(1)$: array index, hash lookup, stack push.
|
||||
- $O(\log n)$: binary search, balanced BST insert.
|
||||
- $O(n)$: linear scan, single pass.
|
||||
- $O(n \log n)$: comparison sort floor, FFT.
|
||||
- $O(n^2)$: nested loops, naive matmul, bubble sort.
|
||||
- $O(n^3)$: triple nested, naive matrix mul.
|
||||
- $O(2^n)$: subset enumeration, naive recursion.
|
||||
- $O(n!)$: permutation, brute-force TSP.
|
||||
|
||||
### 매 표기 family
|
||||
- **Big-O ($O$)**: upper bound (worst case).
|
||||
- **Big-Omega ($\Omega$)**: lower bound (best case).
|
||||
- **Big-Theta ($\Theta$)**: tight bound.
|
||||
- **little-o ($o$)**: strict upper (not tight).
|
||||
|
||||
### 매 응용
|
||||
1. ML attention: $O(n^2)$ → FlashAttention 2026 $O(n)$ memory.
|
||||
2. Database index: B-Tree $O(\log n)$ vs full scan $O(n)$.
|
||||
3. RAG retrieval: HNSW $O(\log n)$ vs brute kNN $O(n)$.
|
||||
4. LLM inference: KV cache reuse turns $O(n^2)$ generation into $O(n)$.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Empirical complexity measurement
|
||||
```python
|
||||
import time, numpy as np
|
||||
def measure(fn, sizes):
|
||||
times = []
|
||||
for n in sizes:
|
||||
data = list(range(n))
|
||||
t0 = time.perf_counter()
|
||||
fn(data)
|
||||
times.append(time.perf_counter() - t0)
|
||||
# log-log slope ≈ exponent
|
||||
slope = np.polyfit(np.log(sizes), np.log(times), 1)[0]
|
||||
return slope # ~1.0 → O(n), ~2.0 → O(n^2)
|
||||
```
|
||||
|
||||
### Master Theorem (divide & conquer)
|
||||
```python
|
||||
# T(n) = a*T(n/b) + O(n^d)
|
||||
# Case 1: d < log_b(a) → T(n) = O(n^log_b(a)) (e.g., Strassen)
|
||||
# Case 2: d = log_b(a) → T(n) = O(n^d log n) (e.g., merge sort: 2T(n/2)+n → O(n log n))
|
||||
# Case 3: d > log_b(a) → T(n) = O(n^d)
|
||||
```
|
||||
|
||||
### Amortized analysis (dynamic array)
|
||||
```python
|
||||
class DynArray:
|
||||
def __init__(self):
|
||||
self.cap, self.n, self.buf = 1, 0, [None]
|
||||
def push(self, x): # amortized O(1) despite O(n) resize
|
||||
if self.n == self.cap:
|
||||
self.cap *= 2
|
||||
self.buf = self.buf + [None]*self.cap
|
||||
self.buf[self.n] = x; self.n += 1
|
||||
```
|
||||
|
||||
### Space-time tradeoff (memoization)
|
||||
```python
|
||||
from functools import lru_cache
|
||||
@lru_cache(maxsize=None)
|
||||
def fib(n): return n if n < 2 else fib(n-1) + fib(n-2)
|
||||
# without cache: O(2^n) time
|
||||
# with cache: O(n) time, O(n) space
|
||||
```
|
||||
|
||||
### Big-O of recursion via recurrence
|
||||
```python
|
||||
# binary search: T(n) = T(n/2) + O(1) → O(log n)
|
||||
def bsearch(a, x, lo=0, hi=None):
|
||||
hi = hi if hi is not None else len(a)
|
||||
if lo >= hi: return -1
|
||||
m = (lo + hi) // 2
|
||||
if a[m] == x: return m
|
||||
return bsearch(a, x, lo, m) if a[m] > x else bsearch(a, x, m+1, hi)
|
||||
```
|
||||
|
||||
### Profiling-based complexity
|
||||
```python
|
||||
import cProfile, pstats
|
||||
cProfile.run('expensive_fn(data)', '/tmp/prof')
|
||||
pstats.Stats('/tmp/prof').sort_stats('cumulative').print_stats(20)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| n size | tolerable complexity |
|
||||
|---|---|
|
||||
| $n \le 10$ | $O(n!)$, $O(2^n)$ OK |
|
||||
| $n \le 10^3$ | $O(n^3)$ OK |
|
||||
| $n \le 10^5$ | $O(n^2)$ borderline, prefer $O(n \log n)$ |
|
||||
| $n \le 10^7$ | $O(n \log n)$ |
|
||||
| $n \le 10^9$ | $O(n)$ or $O(\log n)$ only |
|
||||
|
||||
**기본값**: 매 production 코드는 $O(n \log n)$ 이하 target. 매 ML inference path는 $O(n)$ 이하.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Theoretical-Computer-Science]] · [[Theoretical-Computer-Science]]
|
||||
- 변형: [[BFS vs DFS]] · [[Dynamic-Programming]] · [[Greedy-Algorithms]]
|
||||
- 응용: [[Optimization-Algorithms]] · [[Combinatorial-Optimization]]
|
||||
- Adjacent: [[Kolmogorov-Complexity]] · [[Entropy in Information Theory|Information Theory]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 algorithm choice review, 매 scaling concern (n>10^5), 매 inference path optimization.
|
||||
**언제 X**: 매 micro-benchmark (constant factors dominate); 매 distributed system (network I/O dominates).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Premature optimization**: 매 $n=100$ 에서 $O(n^2)$ vs $O(n \log n)$ — 매 negligible.
|
||||
- **Hidden quadratic**: 매 `for x in list: if x in list:` — 매 list `in` 은 $O(n)$ → 매 total $O(n^2)$.
|
||||
- **Big-O fetishism**: 매 cache locality, branch prediction이 매 매 $\log n$ factor보다 큼 (소형 n).
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (CLRS Ch.3, Knuth TAOCP Vol.1).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Big-O classes, master theorem, amortized analysis |
|
||||
@@ -0,0 +1,149 @@
|
||||
---
|
||||
id: wiki-2026-0508-atomism
|
||||
title: Atomism
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Logical Atomism, Reductionism, Atomic Decomposition]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.86
|
||||
verification_status: applied
|
||||
tags: [philosophy, reductionism, decomposition, design, software-architecture]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: TypeScript/Python
|
||||
framework: design-systems
|
||||
---
|
||||
|
||||
# Atomism
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 whole 의 indivisible part 의 sum — 매 understand 의 decompose."**. Atomism 의 ancient Greek (Democritus, Leucippus) origin → modern logical atomism (Russell, early Wittgenstein) → 2026 의 software (atomic design, atom CSS, atomic commit, atomic transaction) 의 ubiquitous design principle.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Philosophical Roots
|
||||
- **Democritus (~460 BC)**: matter 의 indivisible atom.
|
||||
- **Russell's logical atomism (1918)**: world 의 logical atom (sense data) 의 사실.
|
||||
- **Wittgenstein's Tractatus**: atomic facts → propositions.
|
||||
- **Reductionism**: complex → simple components.
|
||||
- **Counter**: holism (Quine), emergence — 매 whole > sum.
|
||||
|
||||
### 매 Software Atomism
|
||||
- **Atomic design (Brad Frost)**: atom → molecule → organism → template → page.
|
||||
- **Atomic CSS (Tailwind, UnoCSS)**: utility class 의 single property.
|
||||
- **Atomic commit (Git)**: 1 commit = 1 logical change.
|
||||
- **Atomic transaction (DB)**: ACID 의 A — all-or-nothing.
|
||||
- **Atomic operation (concurrency)**: indivisible CPU instruction (CAS).
|
||||
|
||||
### 매 응용
|
||||
1. Component-driven UI (Storybook, Bit).
|
||||
2. Microservice / function decomposition.
|
||||
3. Test atomicity (1 test = 1 assertion principle).
|
||||
4. Knowledge management (atomic note, Zettelkasten).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — Atomic design (React)
|
||||
|
||||
```tsx
|
||||
// atom
|
||||
export const Button = ({ children, ...p }) =>
|
||||
<button className="px-3 py-1 rounded" {...p}>{children}</button>;
|
||||
|
||||
// molecule
|
||||
export const SearchBar = () => (
|
||||
<div className="flex gap-2">
|
||||
<Input placeholder="search" />
|
||||
<Button>Go</Button>
|
||||
</div>
|
||||
);
|
||||
|
||||
// organism
|
||||
export const Header = () => (
|
||||
<header><Logo /><SearchBar /><UserMenu /></header>
|
||||
);
|
||||
```
|
||||
|
||||
### Pattern 2 — Atomic CSS (Tailwind)
|
||||
|
||||
```html
|
||||
<button class="px-4 py-2 bg-blue-500 hover:bg-blue-600 rounded text-white">
|
||||
Submit
|
||||
</button>
|
||||
```
|
||||
|
||||
### Pattern 3 — Atomic commit (Git)
|
||||
|
||||
```bash
|
||||
# BAD: 1 commit, 3 unrelated changes
|
||||
git commit -m "fix bug + refactor + add feature"
|
||||
|
||||
# GOOD: 3 atomic commits
|
||||
git add src/bug.ts && git commit -m "fix: null check in parse"
|
||||
git add src/utils/ && git commit -m "refactor: extract helper"
|
||||
git add src/feature.ts && git commit -m "feat: add export csv"
|
||||
```
|
||||
|
||||
### Pattern 4 — Atomic CAS (Rust)
|
||||
|
||||
```rust
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
let counter = AtomicUsize::new(0);
|
||||
counter.compare_exchange(0, 1, Ordering::SeqCst, Ordering::SeqCst).ok();
|
||||
```
|
||||
|
||||
### Pattern 5 — Atomic note (Zettelkasten)
|
||||
|
||||
```markdown
|
||||
# 20260510-1432-recursive-decomposition
|
||||
|
||||
매 problem 의 self-similar subproblem 의 split → solve → combine.
|
||||
대표 의 merge sort, quicksort, divide-and-conquer.
|
||||
|
||||
→ [[20260509-2210-master-theorem]]
|
||||
→ [[20260510-1450-dynamic-programming]]
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| UI design | Atomic design hierarchy |
|
||||
| Styling | Atomic CSS (Tailwind/UnoCSS) |
|
||||
| VCS | Atomic commit |
|
||||
| Concurrency | atomic primitives + lock-free |
|
||||
| Notes | Atomic note (1 idea / file) |
|
||||
| Architecture | weigh atomism vs holism (some properties emergent) |
|
||||
|
||||
**기본값**: atomic decomposition + holistic review (avoid reductionist trap).
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Reductionism]]
|
||||
- 변형: [[Emergence]] · [[Logical-Atomism]]
|
||||
- 응용: [[Atomic-Design]] · [[Atomic-CSS]]
|
||||
- Adjacent: [[Composition-over-Inheritance]] · [[Single Responsibility Principle (SRP)|Single-Responsibility-Principle]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: design system creation, refactoring monolith, documentation structure, knowledge graph.
|
||||
**언제 X**: irreducibly emergent system (consciousness, ecosystem), tightly-coupled domain logic.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Reductionist fallacy**: 매 whole 의 part 의 sum 의 X — emergence 무시.
|
||||
- **Over-atomization**: 100 utility classes for 1 button — readability collapse.
|
||||
- **Atomic worship**: 매 every commit atomic 의 over-engineer (squash merge available).
|
||||
- **Lost-context note**: atomic note 의 link 없음 — 매 island.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Russell "Philosophy of Logical Atomism", Brad Frost "Atomic Design", classical CS).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (philosophy + 5 software patterns) |
|
||||
@@ -0,0 +1,129 @@
|
||||
---
|
||||
id: wiki-2026-0508-autobiography
|
||||
title: Autobiography
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Self-Narrative, Memoir, Personal Narrative, Life Writing]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.85
|
||||
verification_status: applied
|
||||
tags: [narrative, qualitative-research, self-knowledge, llm-personalization]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: LangChain/LlamaIndex
|
||||
---
|
||||
|
||||
# Autobiography
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 self 의 narrative 의 construct — 매 memory 의 chronicle 의 X, 매 meaning-making 의 retrospective."**. Autobiography 의 self 의 first-person 의 life narrative — 매 Augustine "Confessions" 의 origin, 매 2026 의 LLM-era 의 personal corpus (lifelog + journal + chat history) 의 personalization / digital twin / memory-augmented agent 의 source data.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Theoretical Frames
|
||||
- **Bruner's narrative identity**: self 의 ongoing story.
|
||||
- **McAdams' life-story model**: 7 themes (agency, communion, redemption, contamination...).
|
||||
- **Ricoeur's "narrative identity"**: 매 idem (sameness) + ipse (selfhood).
|
||||
- **Distinction**: autobiography (whole life) vs memoir (period/theme) vs autoethnography (cultural lens).
|
||||
|
||||
### 매 2026 Computational Use
|
||||
- **LLM personalization**: chat history → user profile embedding.
|
||||
- **Lifelog**: passive sensing (location, photo, journal) → searchable corpus.
|
||||
- **Digital twin / memory agent**: Mem0, MemGPT, Letta 의 long-term memory.
|
||||
- **Therapy adjunct**: LLM-guided narrative therapy.
|
||||
|
||||
### 매 응용
|
||||
1. Personal AI assistant memory.
|
||||
2. Qualitative research (life-history interview).
|
||||
3. Digital legacy / estate.
|
||||
4. Self-reflection coaching (BetterUp AI).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — Journal indexing (LlamaIndex)
|
||||
|
||||
```python
|
||||
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
|
||||
|
||||
docs = SimpleDirectoryReader("~/journal").load_data()
|
||||
index = VectorStoreIndex.from_documents(docs)
|
||||
qe = index.as_query_engine(similarity_top_k=5)
|
||||
print(qe.query("When did I feel most burned out in 2025?"))
|
||||
```
|
||||
|
||||
### Pattern 2 — Mem0 long-term memory
|
||||
|
||||
```python
|
||||
from mem0 import Memory
|
||||
m = Memory()
|
||||
m.add("I prefer tea over coffee, switched in 2024 after gastritis.", user_id="me")
|
||||
results = m.search("morning beverage preference", user_id="me")
|
||||
```
|
||||
|
||||
### Pattern 3 — Life-event timeline extraction
|
||||
|
||||
```python
|
||||
import json
|
||||
from anthropic import Anthropic
|
||||
client = Anthropic()
|
||||
|
||||
EXTRACT = """Extract life events as JSON: [{date, type, summary, valence}].
|
||||
Text: {text}"""
|
||||
|
||||
resp = client.messages.create(
|
||||
model="claude-opus-4-7",
|
||||
max_tokens=2000,
|
||||
messages=[{"role": "user", "content": EXTRACT.format(text=journal_text)}],
|
||||
)
|
||||
events = json.loads(resp.content[0].text)
|
||||
```
|
||||
|
||||
### Pattern 4 — Narrative coherence score
|
||||
|
||||
```python
|
||||
def coherence(events):
|
||||
# simple proxy: causal-chain density
|
||||
causal = sum(1 for e in events if e.get("caused_by"))
|
||||
return causal / max(len(events), 1)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| LLM personalization | Mem0 / Letta + RAG over journal |
|
||||
| Therapy / coaching | guided narrative writing + LLM reflection |
|
||||
| Research interview | semi-structured + thematic analysis |
|
||||
| Digital legacy | encrypted lifelog + access policy |
|
||||
|
||||
**기본값**: Mem0 for runtime memory, LlamaIndex RAG for retrospective query.
|
||||
|
||||
## 🔗 Graph
|
||||
- 변형: [[Memoir]] · [[Autoethnography]]
|
||||
- 응용: [[Digital Twin]]
|
||||
- Adjacent: [[Working Memory]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: personal assistant memory, retrospective query over journal, coaching reflection prompts.
|
||||
**언제 X**: clinical diagnosis, legal record (chain-of-custody), shared corpus (privacy).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Memory leak (PII)**: 매 personal corpus 의 train 의 leak — opt-out + local model.
|
||||
- **Narrative coherence forcing**: LLM 의 confabulate 의 false memory.
|
||||
- **Recency bias**: recent events 의 over-weight — temporal balance.
|
||||
- **No edit/delete**: GDPR right-to-erasure 위반.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (McAdams "Stories We Live By", Mem0 / Letta docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (LLM memory, lifelog, narrative theory) |
|
||||
@@ -0,0 +1,146 @@
|
||||
---
|
||||
id: wiki-2026-0508-autoethnography
|
||||
title: Autoethnography
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Auto-Ethnography, Self-Ethnography, Reflexive Ethnography]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.86
|
||||
verification_status: applied
|
||||
tags: [qualitative-research, ethnography, methodology, narrative, ux-research]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: NVivo/Atlas.ti
|
||||
---
|
||||
|
||||
# Autoethnography
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 self-as-instrument — 매 personal experience 의 cultural lens 의 X, 매 cultural lens through personal experience."**. Autoethnography 의 ethnography 의 first-person 의 reflexive variant — Carolyn Ellis / Tony Adams 의 1990s formalize. 매 2026 의 UX research / HCI / AI ethics 의 standard method (영향 the lived experience of bias, accessibility, AI use).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Types
|
||||
- **Evocative**: literary, emotional, narrative-driven.
|
||||
- **Analytic** (Anderson): theoretical contribution, research-oriented.
|
||||
- **Interpretive**: meaning-making, hermeneutic.
|
||||
- **Critical / performative**: activist, social-justice frame.
|
||||
|
||||
### 매 Method
|
||||
1. **Field**: self in everyday context (often the researcher's own life domain).
|
||||
2. **Data**: journal, photo, artifact, interview.
|
||||
3. **Reflexivity**: position 의 explicit (gender, race, role).
|
||||
4. **Layered analysis**: thick description + theoretical frame.
|
||||
5. **Triangulation**: peer debrief, member check.
|
||||
|
||||
### 매 Validity Criteria
|
||||
- **Substantive contribution** (Richardson).
|
||||
- **Aesthetic merit**.
|
||||
- **Reflexivity / honesty**.
|
||||
- **Impact / resonance**.
|
||||
- **Verisimilitude** (Ellis).
|
||||
|
||||
### 매 응용
|
||||
1. UX research (researcher 의 own use experience).
|
||||
2. AI ethics (LLM 의 daily use 의 lived account).
|
||||
3. Disability studies (insider perspective).
|
||||
4. Medical sociology (illness narrative).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — Field journal template (Markdown)
|
||||
|
||||
```markdown
|
||||
---
|
||||
date: 2026-05-10
|
||||
context: solo coding session, claude-opus-4-7
|
||||
mood: 6/10
|
||||
position: M, 32y, SWE, 8y exp
|
||||
---
|
||||
|
||||
# Observation
|
||||
- 14:00 prompted Claude w/ vague spec → suggested decomposition steps...
|
||||
- 14:15 felt resistance to refactor; noticed "it's working, why touch"
|
||||
|
||||
# Reflection
|
||||
- 매 sunk-cost feeling 의 cultural inheritance? Engineering pride?
|
||||
|
||||
# Theoretical link
|
||||
- Norman 의 affordance / Schön 의 reflective practitioner.
|
||||
```
|
||||
|
||||
### Pattern 2 — Coding (qualitative) — open coding
|
||||
|
||||
```python
|
||||
codes = {
|
||||
"resistance-to-refactor": ["sunk cost", "it's working", "why touch"],
|
||||
"delegation-discomfort": ["am I cheating", "is this me"],
|
||||
"flow-with-LLM": ["pair programming", "thinking partner"],
|
||||
}
|
||||
```
|
||||
|
||||
### Pattern 3 — Layered narrative (analytic)
|
||||
|
||||
```markdown
|
||||
## Vignette
|
||||
[evocative narrative paragraph]
|
||||
|
||||
## Analysis
|
||||
[theoretical interpretation: Schön reflective practice]
|
||||
|
||||
## Cultural connection
|
||||
[broader: SWE identity in age of LLM agents]
|
||||
```
|
||||
|
||||
### Pattern 4 — Member check (peer debrief)
|
||||
|
||||
```python
|
||||
# Share excerpt with informant for response
|
||||
checks = [
|
||||
{"excerpt": "...", "informant": "P3", "response": "yes resonates", "date": "2026-05-09"},
|
||||
{"excerpt": "...", "informant": "P5", "response": "I'd frame differently", "date": "2026-05-09"},
|
||||
]
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Researcher 의 own lived domain | Autoethnography (insider) |
|
||||
| Other community | Ethnography (outsider) + reflexivity |
|
||||
| Quick UX insight | diary study + autoethnography hybrid |
|
||||
| Theory contribution | Analytic autoethnography (Anderson) |
|
||||
| Activist / community | Critical / performative |
|
||||
|
||||
**기본값**: Analytic autoethnography with peer debrief + member check.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Ethnography]]
|
||||
- 변형: [[Memoir]]
|
||||
- 응용: [[AI-Ethics]]
|
||||
- Adjacent: [[Autobiography]] · [[Grounded Theory Method]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: studying one's own use of tech / LLM, insider perspective on team or community, theoretical reflection.
|
||||
**언제 X**: large-N generalization needed, double-blind requirement, no reflexivity training.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Solipsism**: 매 self 의 only — no theoretical contribution.
|
||||
- **No reflexivity**: position 의 unmark — bias hidden.
|
||||
- **Cherry-picked vignette**: confirmation bias.
|
||||
- **Skipping member check** in critical / community work.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Ellis & Bochner, Anderson 2006, Adams et al. "Autoethnography" 2015).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (types, validity criteria, 4 patterns) |
|
||||
@@ -0,0 +1,153 @@
|
||||
---
|
||||
id: wiki-2026-0508-automated-decision-making
|
||||
title: Automated Decision Making
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [ADM, Algorithmic Decision-Making, Automated Decisions]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.93
|
||||
verification_status: applied
|
||||
tags: [decision-systems, ml, governance, fairness, eu-ai-act]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: scikit-learn/PyTorch/Aequitas
|
||||
---
|
||||
|
||||
# Automated Decision Making (ADM)
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 algorithm 의 decision authority — 매 human approval 의 X 또는 minimal."**. ADM 의 system 의 input 의 받는 → 매 ML / rule / hybrid 의 통한 decision (loan, hiring, sentencing, content mod, dispatch) 의 output. 매 2026 의 EU AI Act (high-risk category) + GDPR Art.22 + Colorado SB205 의 governed.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Categories
|
||||
- **Rule-based**: explicit if/then (DMN, decision tables).
|
||||
- **ML scoring**: classifier / regressor → threshold.
|
||||
- **LLM agentic**: tool-use + reasoning loop (Claude / GPT-5).
|
||||
- **Human-in-the-loop (HITL)**: ML proposes, human approves.
|
||||
- **Human-on-the-loop**: ML acts, human monitors / can override.
|
||||
- **Fully automated**: no human in critical path.
|
||||
|
||||
### 매 Regulation (2026)
|
||||
- **EU AI Act** (entered force 2025): high-risk systems (biometric, hiring, credit, law enforcement) → conformity assessment, transparency, human oversight.
|
||||
- **GDPR Art.22**: right to not be subject to solely automated decision with legal effect; right to explanation.
|
||||
- **Colorado AI Act (SB205)**: 2026 effective — algorithmic discrimination duty for high-risk AI.
|
||||
- **NYC Local Law 144**: AEDT bias audit.
|
||||
|
||||
### 매 Components
|
||||
- Input validation + preprocessing.
|
||||
- Feature engineering / embedding.
|
||||
- Model + threshold + calibration.
|
||||
- Decision policy (action mapping).
|
||||
- Logging + audit trail.
|
||||
- Override / appeal channel.
|
||||
|
||||
### 매 응용
|
||||
1. Credit underwriting (FICO, Upstart).
|
||||
2. Hiring screening (with caution post-NYC LL 144).
|
||||
3. Content moderation (Hive, Perspective API).
|
||||
4. Insurance claims triage.
|
||||
5. Dispatching (Uber, DoorDash).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — Decision policy with audit
|
||||
|
||||
```python
|
||||
import logging, hashlib, json, time
|
||||
|
||||
def decide(applicant, model, threshold=0.6):
|
||||
score = model.predict_proba([applicant])[0, 1]
|
||||
decision = "approve" if score >= threshold else "review"
|
||||
audit = {
|
||||
"ts": time.time(), "id": applicant["id"],
|
||||
"score": float(score), "threshold": threshold,
|
||||
"decision": decision, "model_v": model.version,
|
||||
"input_hash": hashlib.sha256(json.dumps(applicant, sort_keys=True).encode()).hexdigest(),
|
||||
}
|
||||
logging.info(json.dumps(audit))
|
||||
return decision, audit
|
||||
```
|
||||
|
||||
### Pattern 2 — Bias audit (Aequitas)
|
||||
|
||||
```python
|
||||
from aequitas.group import Group
|
||||
g = Group()
|
||||
xtab, _ = g.get_crosstabs(df_with_predictions, attr_cols=["race", "gender"])
|
||||
print(xtab[["attribute_name", "fpr", "fnr", "tpr"]])
|
||||
```
|
||||
|
||||
### Pattern 3 — Calibration check
|
||||
|
||||
```python
|
||||
from sklearn.calibration import calibration_curve
|
||||
prob_true, prob_pred = calibration_curve(y_test, y_score, n_bins=10)
|
||||
# expect diagonal — deviation = miscalibration
|
||||
```
|
||||
|
||||
### Pattern 4 — HITL queue (low-confidence routing)
|
||||
|
||||
```python
|
||||
def route(score, low=0.4, high=0.7):
|
||||
if score >= high: return "auto-approve"
|
||||
if score < low: return "auto-deny"
|
||||
return "human-review"
|
||||
```
|
||||
|
||||
### Pattern 5 — EU AI Act conformity log
|
||||
|
||||
```python
|
||||
@dataclass
|
||||
class ConformityRecord:
|
||||
system_id: str
|
||||
risk_class: str # "high" | "limited" | "minimal"
|
||||
intended_purpose: str
|
||||
training_data_summary: str
|
||||
bias_test_results: dict
|
||||
human_oversight_design: str
|
||||
last_audit: str
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| High-stakes (credit, hire, health) | HITL + bias audit + appeal |
|
||||
| Reversible low-stakes | full auto + sample review |
|
||||
| Real-time (dispatch) | full auto + monitoring |
|
||||
| Regulated (EU high-risk) | conformity assessment + transparency |
|
||||
| Novel domain | shadow mode → HITL → automation |
|
||||
|
||||
**기본값**: HITL + audit log + bias monitoring + appeal channel.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Decision Theory]]
|
||||
- 변형: [[HITL]]
|
||||
- 응용: [[Content-Moderation]]
|
||||
- Adjacent: [[Algorithmic Fairness]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: drafting decision policy, reviewing audit logs for anomalies, generating explanation text (Art.22), bias test fixture generation.
|
||||
**언제 X**: autonomous high-stakes decision without human in loop, opaque LLM-only path for regulated domain.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Black box high-stakes**: no explanation = GDPR/AI-Act violation risk.
|
||||
- **No appeal channel**: legitimacy collapse.
|
||||
- **Drift unmonitored**: production model 의 silent degrade.
|
||||
- **Proxy discrimination**: ZIP code → race proxy unlawful.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (EU AI Act final text, NIST AI RMF, Aequitas docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (EU AI Act, HITL, bias audit) |
|
||||
@@ -0,0 +1,162 @@
|
||||
---
|
||||
id: wiki-2026-0508-automated-map-generation
|
||||
title: Automated Map Generation
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Procedural Map Generation, PCG, Auto-Cartography]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [pcg, gamedev, cartography, gis, generative]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python/C#
|
||||
framework: Unity/Godot/Houdini
|
||||
---
|
||||
|
||||
# Automated Map Generation
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 noise + constraint + agent — 매 hand-craft 의 X, 매 procedure 의 grow."**. Automated map generation 의 PCG (procedural content generation) 의 spatial subset — 매 1980 Rogue dungeon → Minecraft (Perlin) → 2026 의 Houdini node + WaveFunctionCollapse + diffusion-based terrain (LumaWorld, Genie 2). GIS 측 의 OpenStreetMap auto-vectorize from satellite (SAM-2 + DETR).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Approaches
|
||||
- **Noise-based**: Perlin / Simplex / fBm — terrain heightmap.
|
||||
- **Cellular automata**: cave / organic terrain (Game of Life variant).
|
||||
- **L-systems**: vegetation / road network.
|
||||
- **Wave Function Collapse (WFC)**: tile-based, constraint propagation.
|
||||
- **Agent-based**: drunken walk, BSP partition.
|
||||
- **Graph grammar**: dungeon room layout.
|
||||
- **Diffusion / GAN**: 2024+ heightmap / texture from prompt.
|
||||
- **Satellite → vector** (GIS): SAM-2 + OSM tagging.
|
||||
|
||||
### 매 Properties
|
||||
- Determinism (seed reproducibility).
|
||||
- Controllability (parameter / prompt steering).
|
||||
- Coherence (no impossible tiles).
|
||||
- Aesthetic / playability metric.
|
||||
|
||||
### 매 응용
|
||||
1. Game level (Minecraft, NMS, Diablo).
|
||||
2. Open-world terrain (UE5 PCG, Houdini).
|
||||
3. GIS map auto-extraction.
|
||||
4. Simulation environments (CARLA, Habitat).
|
||||
5. Tabletop RPG (Watabou, Dungeon Alchemist).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — Perlin heightmap
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
from noise import pnoise2
|
||||
|
||||
def heightmap(w, h, scale=80, octaves=5, seed=0):
|
||||
arr = np.zeros((h, w))
|
||||
for y in range(h):
|
||||
for x in range(w):
|
||||
arr[y, x] = pnoise2(x/scale, y/scale, octaves=octaves, base=seed)
|
||||
return (arr - arr.min()) / (arr.max() - arr.min())
|
||||
```
|
||||
|
||||
### Pattern 2 — Cellular automaton cave
|
||||
|
||||
```python
|
||||
def step(grid):
|
||||
h, w = grid.shape
|
||||
out = grid.copy()
|
||||
for y in range(1, h-1):
|
||||
for x in range(1, w-1):
|
||||
n = grid[y-1:y+2, x-1:x+2].sum() - grid[y, x]
|
||||
out[y, x] = 1 if n > 4 else 0
|
||||
return out
|
||||
|
||||
# init random 45% wall, run 5 steps → cave
|
||||
```
|
||||
|
||||
### Pattern 3 — Wave Function Collapse (sketch)
|
||||
|
||||
```python
|
||||
# tiles: list of (id, neighbor constraint dict)
|
||||
def wfc(grid_size, tiles):
|
||||
grid = [[set(t.id for t in tiles) for _ in range(grid_size)] for _ in range(grid_size)]
|
||||
while not all_collapsed(grid):
|
||||
c = lowest_entropy_cell(grid)
|
||||
grid[c.y][c.x] = {random.choice(list(grid[c.y][c.x]))}
|
||||
propagate(grid, c, tiles)
|
||||
return grid
|
||||
```
|
||||
|
||||
### Pattern 4 — BSP dungeon partition
|
||||
|
||||
```python
|
||||
def split(rect, depth=4):
|
||||
if depth == 0 or min(rect.w, rect.h) < 12: return [rect]
|
||||
if rect.w > rect.h:
|
||||
x = random.randint(rect.x + 4, rect.x + rect.w - 4)
|
||||
return split(Rect(rect.x, rect.y, x - rect.x, rect.h), depth-1) + \
|
||||
split(Rect(x, rect.y, rect.x + rect.w - x, rect.h), depth-1)
|
||||
# similar for vertical
|
||||
```
|
||||
|
||||
### Pattern 5 — Diffusion terrain (2026)
|
||||
|
||||
```python
|
||||
# Pseudo: Stable Diffusion XL fine-tuned on heightmap atlas
|
||||
heightmap = sd_terrain.generate(prompt="alpine valley with river, top-down heightmap, 16-bit grayscale")
|
||||
mesh = heightmap_to_mesh(heightmap, vertical_scale=200.0)
|
||||
```
|
||||
|
||||
### Pattern 6 — Satellite → OSM (SAM-2)
|
||||
|
||||
```python
|
||||
# Mask building footprints from satellite tile, convert to OSM polygons
|
||||
masks = sam2.predict(satellite_tile)
|
||||
polygons = [mask_to_polygon(m) for m in masks if m.score > 0.8]
|
||||
osm_xml = polygons_to_osm(polygons, tag={"building": "yes"})
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Continuous terrain | Perlin / Simplex / fBm |
|
||||
| Organic cave | Cellular automaton |
|
||||
| Tile-based level (puzzle) | WFC |
|
||||
| Dungeon rooms | BSP + corridor connect |
|
||||
| Open-world AAA | Houdini + UE5 PCG |
|
||||
| Prompted asset | Diffusion (SDXL terrain LoRA) |
|
||||
| GIS extraction | SAM-2 + DETR + OSM tagging |
|
||||
|
||||
**기본값**: Perlin for terrain, WFC for tile-based, BSP for dungeons.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Procedural-Content-Generation]] · [[Computational Geometry (Frontend)]]
|
||||
- 변형: [[Cellular Automata]]
|
||||
- 응용: [[GIS]]
|
||||
- Adjacent: [[Perlin Noise]] · [[Diffusion-Models]] · [[Geographic-Information-Systems]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: parameter tuning suggestions, prompt-to-terrain via diffusion, level metric scoring (playability / aesthetic), debug seed reproduction.
|
||||
**언제 X**: hand-crafted narrative levels, regulatory cartography (use authoritative source).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **No seed log**: bug 의 reproduce 불가.
|
||||
- **Pure noise = boring**: 매 noise 의 only 의 no landmark — overlay POI / agent 추가.
|
||||
- **Unconstrained WFC**: contradictory tile set → infinite backtrack.
|
||||
- **Diffusion without metric guard**: visual nice but topologically broken (impassable cliff).
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Shaker et al. "Procedural Content Generation in Games", Houdini docs, WFC Maxim Gumin).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (Perlin, WFC, BSP, diffusion, SAM-2) |
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
---
|
||||
id: wiki-2026-0508-autonomous-vehicle-path-planning
|
||||
title: Autonomous Vehicle Path Planning
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [AV Path Planning, Self-Driving Planning, Motion Planning]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.94
|
||||
verification_status: applied
|
||||
tags: [robotics, autonomous-driving, motion-planning, mpc, av]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python/C++
|
||||
framework: Apollo/Autoware/OpenPlanner
|
||||
---
|
||||
|
||||
# Autonomous Vehicle Path Planning
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 perception 의 X — 매 prediction + decision + trajectory 의 closed-loop."**. AV path planning 의 perception output (objects, lanes, drivable area) → prediction (other agents) → behavior decision (lane change, yield) → trajectory (smooth, kinodynamic) → control. 매 2026 의 Tesla FSD v13 (end-to-end NN), Waymo (modular), Wayve LINGO (VLM-based), 모두 의 hybrid trend.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Architecture (Modular)
|
||||
1. **Mission planner**: route (A→B) over road graph.
|
||||
2. **Behavior planner**: discrete decision (FSM / POMDP / RL).
|
||||
3. **Local planner / motion**: collision-free trajectory (Frenet, lattice, sampling, optimization).
|
||||
4. **Trajectory tracker**: MPC / pure pursuit → steering + throttle.
|
||||
|
||||
### 매 Algorithms
|
||||
- **Search**: A*, Hybrid A* (kinematic), RRT*, RRT-Connect.
|
||||
- **Sampling**: lattice planner (predefined motion primitives).
|
||||
- **Optimization**: iLQR, MPC, CILQR (cost = comfort + safety + progress).
|
||||
- **Frenet frame**: lateral + longitudinal decoupling.
|
||||
- **Learning-based**: ChauffeurNet, MotionLM, end-to-end (Tesla FSD v13).
|
||||
- **Foundation model**: Wayve LINGO-2 / GAIA-2 — VLM + driving.
|
||||
|
||||
### 매 Safety
|
||||
- ISO 26262 / ISO 21448 (SOTIF).
|
||||
- RSS (Responsibility-Sensitive Safety, Mobileye).
|
||||
- Formal verification of decision layer.
|
||||
- Out-of-distribution detection.
|
||||
|
||||
### 매 응용
|
||||
1. L4 robotaxi (Waymo, Cruise relaunch, Apollo Go).
|
||||
2. L2+ ADAS (Tesla FSD, BYD, NIO Pilot).
|
||||
3. Truck platooning (Aurora, Plus).
|
||||
4. Last-mile delivery (Nuro).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — Frenet trajectory generation
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
def frenet_quintic(s0, sd0, sdd0, s1, sd1, sdd1, T):
|
||||
# solve quintic polynomial coeffs for s(t)
|
||||
A = np.array([[T**3, T**4, T**5],
|
||||
[3*T**2, 4*T**3, 5*T**4],
|
||||
[6*T, 12*T**2, 20*T**3]])
|
||||
b = np.array([s1 - s0 - sd0*T - 0.5*sdd0*T*T,
|
||||
sd1 - sd0 - sdd0*T,
|
||||
sdd1 - sdd0])
|
||||
a3, a4, a5 = np.linalg.solve(A, b)
|
||||
return [s0, sd0, sdd0/2, a3, a4, a5]
|
||||
```
|
||||
|
||||
### Pattern 2 — Hybrid A* (sketch)
|
||||
|
||||
```python
|
||||
def hybrid_a_star(start, goal, grid, motion_primitives):
|
||||
open_set = PriorityQueue()
|
||||
open_set.put((0, start))
|
||||
came_from = {}
|
||||
g = {start: 0}
|
||||
while not open_set.empty():
|
||||
_, cur = open_set.get()
|
||||
if reached(cur, goal): return reconstruct(came_from, cur)
|
||||
for prim in motion_primitives:
|
||||
nxt = apply(cur, prim)
|
||||
if collides(nxt, grid): continue
|
||||
new_g = g[cur] + prim.cost
|
||||
if new_g < g.get(nxt, 1e18):
|
||||
g[nxt] = new_g
|
||||
f = new_g + reeds_shepp_heuristic(nxt, goal)
|
||||
open_set.put((f, nxt))
|
||||
came_from[nxt] = (cur, prim)
|
||||
```
|
||||
|
||||
### Pattern 3 — MPC trajectory tracking (acados / casadi)
|
||||
|
||||
```python
|
||||
import casadi as ca
|
||||
N = 20 # horizon
|
||||
dt = 0.1
|
||||
opti = ca.Opti()
|
||||
X = opti.variable(4, N+1) # [x, y, theta, v]
|
||||
U = opti.variable(2, N) # [steer, accel]
|
||||
cost = 0
|
||||
for k in range(N):
|
||||
cost += ca.sumsqr(X[:2, k] - ref[:2, k]) + 0.1 * ca.sumsqr(U[:, k])
|
||||
opti.subject_to(X[:, k+1] == bicycle_model(X[:, k], U[:, k], dt))
|
||||
opti.minimize(cost)
|
||||
opti.solver("ipopt")
|
||||
sol = opti.solve()
|
||||
```
|
||||
|
||||
### Pattern 4 — RSS (longitudinal safe distance)
|
||||
|
||||
```python
|
||||
def rss_safe_distance(v_rear, v_front, a_max_accel, a_max_brake, a_min_brake, rho=0.1):
|
||||
return max(0,
|
||||
v_rear * rho
|
||||
+ 0.5 * a_max_accel * rho**2
|
||||
+ (v_rear + a_max_accel * rho)**2 / (2 * a_min_brake)
|
||||
- v_front**2 / (2 * a_max_brake))
|
||||
```
|
||||
|
||||
### Pattern 5 — Behavior FSM
|
||||
|
||||
```python
|
||||
class State(str, Enum): KEEP="keep"; LEFT="left"; RIGHT="right"; STOP="stop"
|
||||
|
||||
def transition(s, perception):
|
||||
if perception.front_blocked and perception.left_clear: return State.LEFT
|
||||
if perception.red_light: return State.STOP
|
||||
return State.KEEP
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Highway lane change | Frenet + lattice + MPC |
|
||||
| Parking | Hybrid A* + Reeds-Shepp |
|
||||
| Urban intersection | POMDP / behavior tree + RSS check |
|
||||
| Off-road / unstructured | RRT* + sampling MPC |
|
||||
| End-to-end product (Tesla) | NN policy + safety guard |
|
||||
|
||||
**기본값**: Frenet planning + MPC tracking + RSS safety check + rule-based behavior FSM.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Robotics]] · [[Motion-Planning]] · [[Optimal-Control-Theory]]
|
||||
- 응용: [[Robotaxi]]
|
||||
- Adjacent: [[Kalman-Filter-and-State-Tracking|Kalman-Filter]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: scenario synthesis (corner cases), behavior reasoning prototype (LINGO-style), code generation for ROS / Apollo modules, log triage.
|
||||
**언제 X**: real-time control loop (latency, safety cert), final RSS verification (formal methods).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Greedy lane change**: no comfort cost → jerky.
|
||||
- **No prediction uncertainty**: 매 single mode 의 future — multi-modal essential.
|
||||
- **Skipping kinodynamic check**: A* path 의 robot 의 unfollowable.
|
||||
- **End-to-end without guard**: NN failure mode → safety violation.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Apollo, Autoware open-source, Mobileye RSS paper, Waymo safety report).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (Frenet, Hybrid A*, MPC, RSS) |
|
||||
@@ -0,0 +1,143 @@
|
||||
---
|
||||
id: wiki-2026-0508-axiology
|
||||
title: Axiology
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Value Theory, Theory of Value, Philosophy of Value]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.86
|
||||
verification_status: applied
|
||||
tags: [philosophy, ethics, value-theory, ai-alignment, decision-theory]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: RL/Reward-Modeling
|
||||
---
|
||||
|
||||
# Axiology
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 value 의 study — 매 what 의 X, 매 worth 의 question."**. Axiology 의 ethics + aesthetics 의 unifying framework — intrinsic vs instrumental, monism vs pluralism. 매 2026 의 AI alignment 의 core relevance: reward modeling / Constitutional AI / preference elicitation 의 axiological commitments.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Subdomains
|
||||
- **Ethics**: moral value (good / right).
|
||||
- **Aesthetics**: aesthetic value (beautiful / sublime).
|
||||
- **Epistemology of value**: truth, knowledge value.
|
||||
|
||||
### 매 Distinctions
|
||||
- **Intrinsic** (good in itself, e.g., happiness for hedonist) vs **instrumental** (good for X).
|
||||
- **Subjective** (depends on attitude) vs **objective** (mind-independent).
|
||||
- **Monism** (one value, e.g., utility) vs **pluralism** (many incommensurable values).
|
||||
- **Realist** vs **anti-realist**.
|
||||
|
||||
### 매 Major Frames
|
||||
- **Hedonism** (Bentham, Mill): pleasure / absence of pain.
|
||||
- **Eudaimonism** (Aristotle): flourishing.
|
||||
- **Perfectionism**: excellence, capability (Sen, Nussbaum).
|
||||
- **Consequentialism**: outcomes.
|
||||
- **Deontology**: duty (Kant).
|
||||
- **Virtue ethics**: character.
|
||||
- **Pluralist value (Berlin)**: incommensurable goods.
|
||||
|
||||
### 매 AI Alignment Connection (2026)
|
||||
- **Reward model = axiological model**: implicit value commitment.
|
||||
- **Constitutional AI** (Anthropic): explicit principles → critique → revise.
|
||||
- **Preference learning (RLHF, DPO, IPO)**: aggregate human preferences.
|
||||
- **Pluralism challenge**: whose values? → community / democratic AI.
|
||||
- **Goodhart's law**: 매 measure → target → corruption (instrumental ≠ intrinsic).
|
||||
|
||||
### 매 응용
|
||||
1. AI alignment / reward design.
|
||||
2. Cost-benefit analysis (policy).
|
||||
3. Aesthetic scoring (image gen).
|
||||
4. Healthcare QALY/DALY weighting.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — Multi-objective reward (pluralism)
|
||||
|
||||
```python
|
||||
def reward(traj):
|
||||
return (
|
||||
1.0 * progress(traj) # instrumental
|
||||
+ 0.5 * comfort(traj) # intrinsic-ish
|
||||
+ 2.0 * safety(traj) # constraint priority
|
||||
- 0.3 * energy(traj) # cost
|
||||
)
|
||||
```
|
||||
|
||||
### Pattern 2 — Constitutional critique (Anthropic-style)
|
||||
|
||||
```python
|
||||
CONSTITUTION = [
|
||||
"Avoid harm.",
|
||||
"Be honest.",
|
||||
"Respect autonomy.",
|
||||
"Promote well-being equitably.",
|
||||
]
|
||||
|
||||
def critique(response, principles=CONSTITUTION):
|
||||
return llm.complete(f"Critique against: {principles}\nResponse: {response}")
|
||||
|
||||
def revise(response, critique_text):
|
||||
return llm.complete(f"Revise: {response}\nIn light of: {critique_text}")
|
||||
```
|
||||
|
||||
### Pattern 3 — Preference elicitation
|
||||
|
||||
```python
|
||||
# binary preference dataset → DPO / IPO
|
||||
pairs = [{"prompt": p, "chosen": a, "rejected": b}, ...]
|
||||
# train policy to maximize likelihood ratio
|
||||
```
|
||||
|
||||
### Pattern 4 — Pareto frontier (incommensurable values)
|
||||
|
||||
```python
|
||||
def is_pareto(point, all_points):
|
||||
return not any(all(o[i] >= point[i] for i in range(len(point))) and o != point
|
||||
for o in all_points)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Single clear metric | Scalar reward (monism) |
|
||||
| Multiple comparable | Weighted sum (pluralism reduced) |
|
||||
| Incommensurable | Pareto / lexicographic |
|
||||
| Norm uncertainty | Constitutional + critique loop |
|
||||
| Democratic | Preference aggregation + transparency |
|
||||
|
||||
**기본값**: pluralism + transparent weights + constitutional guardrails.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Philosophy]]
|
||||
- 응용: [[AI_Safety_and_Alignment|AI-Alignment]]
|
||||
- Adjacent: [[Aesthetic-Value]] · [[Decision Theory]] · [[AI_Safety_and_Alignment|Constitutional-AI]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: alignment policy drafting, principle articulation, value-laden decision review, ethical critique generation.
|
||||
**언제 X**: pure technical optimization with no value tradeoff, single-stakeholder narrow domain.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Hidden monism**: 매 single metric 의 dressed-up — Goodhart 의 vulnerable.
|
||||
- **False precision**: numeric weight 의 spurious 의 incommensurable values.
|
||||
- **No stakeholder mapping**: whose values 의 unclear.
|
||||
- **Reward hacking**: instrumental → intrinsic 의 confuse.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Stanford Encyclopedia of Philosophy "Value Theory", Anthropic Constitutional AI paper).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (frames + AI alignment patterns) |
|
||||
@@ -0,0 +1,158 @@
|
||||
---
|
||||
id: wiki-2026-0508-axiomatic-systems
|
||||
title: Axiomatic Systems
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Axiomatic Method, Formal Systems, Deductive Systems]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [logic, foundations, formal-methods, proof, type-theory]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Lean/Coq/Agda
|
||||
framework: Lean4/mathlib
|
||||
---
|
||||
|
||||
# Axiomatic Systems
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 finite axiom + inference rule → 매 derivable theorem."**. Axiomatic system 의 Euclid (BC 300) → Hilbert (1899 Grundlagen) → Gödel (incompleteness 1931) → 매 2026 의 Lean 4 + mathlib (200k+ formalized theorems, 매 working math 의 formal redo) + LLM-augmented proof assistant (Anthropic Claude / DeepMind AlphaProof).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Components
|
||||
- **Primitive symbols / vocabulary**.
|
||||
- **Axioms**: unproved starting propositions.
|
||||
- **Inference rules** (modus ponens, generalization).
|
||||
- **Theorems**: derivable from axioms via rules.
|
||||
- **Models / interpretations**.
|
||||
|
||||
### 매 Properties
|
||||
- **Consistency**: 매 contradiction 의 X (¬(P ∧ ¬P) provable).
|
||||
- **Completeness**: every true (in model) statement provable.
|
||||
- **Decidability**: algorithm to determine theoremhood.
|
||||
- **Soundness**: only true things provable.
|
||||
- **Independence**: 매 axiom 의 not derivable from others.
|
||||
- **Categoricity**: all models isomorphic.
|
||||
|
||||
### 매 Famous Systems
|
||||
- **Euclidean geometry**: 5 postulates (parallel postulate independent → non-Euclidean).
|
||||
- **Peano arithmetic (PA)**: natural numbers; incomplete (Gödel).
|
||||
- **ZFC set theory**: foundation of most math; CH independent (Cohen).
|
||||
- **Group / ring / field**: abstract algebra.
|
||||
- **Hilbert system / Natural deduction / Sequent calculus**: proof formalisms.
|
||||
- **Type theory** (Martin-Löf, Calculus of Constructions): foundation for Coq/Lean/Agda.
|
||||
|
||||
### 매 2026 Computational
|
||||
- **Lean 4 + mathlib**: rapid formalization (Tao's PFR, Gowers).
|
||||
- **Coq**: CompCert verified compiler, 4-color theorem.
|
||||
- **Isabelle**: seL4 microkernel.
|
||||
- **AlphaProof / Claude proof**: LLM + Lean tactic search.
|
||||
|
||||
### 매 응용
|
||||
1. Math research (formalized proof).
|
||||
2. Formal verification (CompCert, seL4, AWS s2n).
|
||||
3. Cryptographic protocol proof (EasyCrypt, F*).
|
||||
4. Smart contract verification.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Pattern 1 — Lean 4: prove a + 0 = a
|
||||
|
||||
```lean
|
||||
theorem add_zero (a : Nat) : a + 0 = a := by
|
||||
induction a with
|
||||
| zero => rfl
|
||||
| succ n ih => simp [Nat.add_succ, ih]
|
||||
```
|
||||
|
||||
### Pattern 2 — Coq: list reversal involutive
|
||||
|
||||
```coq
|
||||
Theorem rev_involutive : forall (A : Type) (l : list A),
|
||||
rev (rev l) = l.
|
||||
Proof.
|
||||
induction l as [| x xs IH].
|
||||
- reflexivity.
|
||||
- simpl. rewrite rev_app_distr. simpl. rewrite IH. reflexivity.
|
||||
Qed.
|
||||
```
|
||||
|
||||
### Pattern 3 — Agda: dependent type proof
|
||||
|
||||
```agda
|
||||
data ℕ : Set where
|
||||
zero : ℕ
|
||||
suc : ℕ → ℕ
|
||||
|
||||
_+_ : ℕ → ℕ → ℕ
|
||||
zero + n = n
|
||||
suc m + n = suc (m + n)
|
||||
|
||||
+-identity : (n : ℕ) → n + zero ≡ n
|
||||
+-identity zero = refl
|
||||
+-identity (suc n) = cong suc (+-identity n)
|
||||
```
|
||||
|
||||
### Pattern 4 — Hilbert-style propositional proof
|
||||
|
||||
```
|
||||
1. P → (Q → P) axiom K
|
||||
2. (P → (Q → R)) → ((P → Q) → (P → R)) axiom S
|
||||
3. P hypothesis
|
||||
4. Q → P MP 1, 3
|
||||
```
|
||||
|
||||
### Pattern 5 — LLM-assisted proof (Lean tactic suggestion)
|
||||
|
||||
```python
|
||||
def llm_tactic(goal_state):
|
||||
return claude.complete(f"""You are a Lean 4 proof assistant.
|
||||
Given goal:
|
||||
{goal_state}
|
||||
Suggest one tactic step. Output only the tactic.""")
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Math formalization | Lean 4 + mathlib |
|
||||
| Verified compiler / OS | Coq (CompCert, seL4) |
|
||||
| Type-theory research | Agda / Lean |
|
||||
| Crypto protocol | EasyCrypt / F* |
|
||||
| Quick logical sketch | Hilbert-style on paper |
|
||||
| LLM-augmented | Lean + Claude tactic search |
|
||||
|
||||
**기본값**: Lean 4 for new formalization, Coq for legacy verified systems.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Mathematical-Logic]]
|
||||
- 변형: [[Type Theory]]
|
||||
- 응용: [[Formal-Verification]] · [[Theorem-Proving]]
|
||||
- Adjacent: [[Godel-s-Incompleteness-Theorems]] · [[Curry-Howard]] · [[Theoretical-Computer-Science]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: tactic suggestion, lemma name search in mathlib, proof sketch translation, error diagnosis.
|
||||
**언제 X**: producing final certificate without check (use proof assistant), informal-only "proof" claims.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Inconsistent axioms**: explosion (anything provable).
|
||||
- **Hidden axiom of choice**: constructivism violation in proof claimed constructive.
|
||||
- **Tactic blob without lemma factor**: maintenance nightmare.
|
||||
- **No model check**: theorem 의 vacuous (no model).
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Lean 4 docs, mathlib4, Hilbert "Grundlagen", Mendelson "Intro to Math Logic").
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL content (Lean/Coq/Agda, 5 patterns) |
|
||||
@@ -0,0 +1,161 @@
|
||||
---
|
||||
id: wiki-2026-0508-b-tree
|
||||
title: B-Tree
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [B+Tree, BTree, Balanced-Tree-Index]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [data-structure, tree, index, database]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: stdlib
|
||||
---
|
||||
|
||||
# B-Tree
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 disk-friendly한 self-balancing search tree — 매 한 노드에 매 많은 key를 저장해 매 height를 minimize"**. 매 1970년 Bayer & McCreight가 IBM에서 design, 매 2026 PostgreSQL/MySQL InnoDB/SQLite의 default index, 매 NVMe SSD에서도 여전히 dominant — 매 sequential I/O와 cache line alignment 친화적.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 invariant
|
||||
- 매 node는 매 $[t-1, 2t-1]$ keys 보유 (매 root만 예외).
|
||||
- 매 internal node는 매 $[t, 2t]$ children.
|
||||
- 매 모든 leaf는 매 same depth.
|
||||
- 매 keys 매 sorted within node.
|
||||
|
||||
### 매 B+ Tree variant (DB 표준)
|
||||
- 매 internal node는 매 keys만 — 매 data는 매 leaf에만.
|
||||
- 매 leaf끼리 매 linked list — 매 range scan $O(k)$.
|
||||
- 매 PostgreSQL/MySQL이 매 사용.
|
||||
|
||||
### 매 응용
|
||||
1. RDBMS index (PostgreSQL btree).
|
||||
2. Filesystem (ext4 HTree, NTFS).
|
||||
3. KV store (LevelDB SST, RocksDB).
|
||||
4. Vector DB metadata index.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### B-Tree node (Python)
|
||||
```python
|
||||
class BTreeNode:
|
||||
def __init__(self, t, leaf=False):
|
||||
self.t = t # min degree
|
||||
self.keys = []
|
||||
self.children = []
|
||||
self.leaf = leaf
|
||||
|
||||
def search(self, k):
|
||||
i = 0
|
||||
while i < len(self.keys) and k > self.keys[i]:
|
||||
i += 1
|
||||
if i < len(self.keys) and self.keys[i] == k:
|
||||
return (self, i)
|
||||
if self.leaf:
|
||||
return None
|
||||
return self.children[i].search(k)
|
||||
```
|
||||
|
||||
### Insert with split
|
||||
```python
|
||||
def split_child(parent, i):
|
||||
t = parent.t
|
||||
full = parent.children[i]
|
||||
new = BTreeNode(t, full.leaf)
|
||||
new.keys = full.keys[t:]
|
||||
if not full.leaf:
|
||||
new.children = full.children[t:]
|
||||
full.children = full.children[:t]
|
||||
parent.keys.insert(i, full.keys[t-1])
|
||||
full.keys = full.keys[:t-1]
|
||||
parent.children.insert(i+1, new)
|
||||
|
||||
def insert(root, k):
|
||||
if len(root.keys) == 2*root.t - 1:
|
||||
new_root = BTreeNode(root.t)
|
||||
new_root.children.append(root)
|
||||
split_child(new_root, 0)
|
||||
root = new_root
|
||||
insert_nonfull(root, k)
|
||||
return root
|
||||
```
|
||||
|
||||
### B+ Tree range scan
|
||||
```python
|
||||
def range_scan(leaf, lo, hi):
|
||||
out = []
|
||||
node = leaf
|
||||
while node:
|
||||
for k in node.keys:
|
||||
if lo <= k <= hi: out.append(k)
|
||||
elif k > hi: return out
|
||||
node = node.next # leaf-linked list
|
||||
return out
|
||||
```
|
||||
|
||||
### PostgreSQL B-Tree usage
|
||||
```sql
|
||||
CREATE INDEX idx_users_email ON users USING btree (email);
|
||||
-- equality + range + sort 사용
|
||||
EXPLAIN SELECT * FROM users WHERE email > 'a' AND email < 'm';
|
||||
-- Index Scan using idx_users_email
|
||||
```
|
||||
|
||||
### SQLite WITHOUT ROWID (B-Tree direct)
|
||||
```sql
|
||||
CREATE TABLE kv (k TEXT PRIMARY KEY, v BLOB) WITHOUT ROWID;
|
||||
-- 매 data가 매 PK index 자체에 — 매 secondary lookup 제거
|
||||
```
|
||||
|
||||
### Bulk loading (sorted insert)
|
||||
```python
|
||||
def bulk_load(sorted_pairs, t=64):
|
||||
# Sort + bottom-up build (vs O(n log n) per-insert)
|
||||
leaves = [sorted_pairs[i:i+2*t-1]
|
||||
for i in range(0, len(sorted_pairs), 2*t-1)]
|
||||
# build internal levels...
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| OLTP, point + range query | B+ Tree (default) |
|
||||
| Append-heavy timeseries | LSM (RocksDB) — B-Tree write amp 高 |
|
||||
| In-memory only, no range | Hash index |
|
||||
| Vector similarity | HNSW (not B-Tree) |
|
||||
| Spatial | R-Tree / GiST |
|
||||
|
||||
**기본값**: 매 RDBMS index는 매 B+ Tree. 매 SSD/NVMe에서도 매 page-aligned (8KB-16KB) 노드.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Linked-Lists-and-Trees]] · [[Theoretical-Computer-Science]]
|
||||
- 변형: [[Hash-Functions-and-Maps]] (alternative)
|
||||
- 응용: Database-Index · [[Bloom-Filters in Search]]
|
||||
- Adjacent: [[Algorithm-Complexity-Big-O]] · LSM-Tree
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 DB schema design, 매 "왜 query가 slow?" debugging, 매 index choice review.
|
||||
**언제 X**: 매 in-memory + write-heavy → LSM 우선; 매 vector search → HNSW.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Random UUID v4 PK**: 매 B-Tree에 매 random insert → 매 page split storm. 매 UUIDv7 (time-ordered) 사용.
|
||||
- **Over-indexing**: 매 모든 column에 index — 매 write amp + storage 폭증.
|
||||
- **Index on low-cardinality**: 매 boolean column index — 매 useless, full scan 더 빠름.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Bayer 1972 original paper, PostgreSQL docs Ch.62).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — B-Tree/B+Tree, split logic, DB index |
|
||||
@@ -0,0 +1,184 @@
|
||||
---
|
||||
id: wiki-2026-0508-bfs-vs-dfs
|
||||
title: BFS vs DFS
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Breadth-First vs Depth-First, 너비 우선 vs 깊이 우선]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [algorithms, graph, traversal, bfs, dfs, search]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: none
|
||||
---
|
||||
|
||||
# BFS vs DFS
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 graph traversal 의 두 fundamental order: queue (BFS) vs stack (DFS)"**. 매 1959 Moore 의 BFS, 매 1882 Trémaux 의 DFS-like maze. 매 modern algo 의 building block — 매 shortest path, topological sort, cycle detection 의 base.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 BFS
|
||||
- queue (FIFO) 의 사용 — 매 level-by-level expansion.
|
||||
- **shortest path** 의 unweighted graph 의 guarantee (edge count 기준).
|
||||
- 매 시간: O(V + E), 매 공간: O(V) (queue + visited).
|
||||
- 매 응용: shortest hop, level traversal, bipartite check, web crawl (per-depth limit).
|
||||
|
||||
### 매 DFS
|
||||
- stack (LIFO) / recursion 의 사용 — 매 deep dive first.
|
||||
- **shortest path** 의 X — 매 tree edge order 의 의 의.
|
||||
- 매 시간: O(V + E), 매 공간: O(V) (recursion stack / explicit stack).
|
||||
- 매 응용: cycle detection, topological sort, SCC (Tarjan/Kosaraju), maze solving.
|
||||
|
||||
### 매 trade-off
|
||||
| Aspect | BFS | DFS |
|
||||
|---|---|---|
|
||||
| Memory | O(b^d) — wide tree 의 explode | O(b·d) — deep stack |
|
||||
| Path | shortest (unweighted) | any reachable |
|
||||
| Implementation | queue + iterative | recursion / explicit stack |
|
||||
| Backtracking | hard | natural |
|
||||
|
||||
### 매 응용 differential
|
||||
1. **shortest path (unweighted)** → BFS.
|
||||
2. **shortest path (weighted)** → Dijkstra (BFS의 generalization, 매 priority queue).
|
||||
3. **topological sort** → DFS (post-order reverse) / Kahn's BFS.
|
||||
4. **cycle detection** → DFS (back edge) / BFS (in-degree).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### BFS basic
|
||||
```python
|
||||
from collections import deque
|
||||
from typing import Dict, List, Set
|
||||
|
||||
def bfs(graph: Dict[int, List[int]], start: int) -> List[int]:
|
||||
visited: Set[int] = {start}
|
||||
queue = deque([start])
|
||||
order = []
|
||||
while queue:
|
||||
node = queue.popleft()
|
||||
order.append(node)
|
||||
for nb in graph[node]:
|
||||
if nb not in visited:
|
||||
visited.add(nb)
|
||||
queue.append(nb)
|
||||
return order
|
||||
```
|
||||
|
||||
### BFS shortest path (unweighted)
|
||||
```python
|
||||
def bfs_shortest(graph, start, target):
|
||||
queue = deque([(start, [start])])
|
||||
visited = {start}
|
||||
while queue:
|
||||
node, path = queue.popleft()
|
||||
if node == target:
|
||||
return path
|
||||
for nb in graph[node]:
|
||||
if nb not in visited:
|
||||
visited.add(nb)
|
||||
queue.append((nb, path + [nb]))
|
||||
return None # unreachable
|
||||
```
|
||||
|
||||
### DFS recursive
|
||||
```python
|
||||
def dfs(graph, node, visited=None, order=None):
|
||||
if visited is None: visited, order = set(), []
|
||||
visited.add(node)
|
||||
order.append(node)
|
||||
for nb in graph[node]:
|
||||
if nb not in visited:
|
||||
dfs(graph, nb, visited, order)
|
||||
return order
|
||||
```
|
||||
|
||||
### DFS iterative (avoids recursion limit)
|
||||
```python
|
||||
def dfs_iter(graph, start):
|
||||
stack, visited, order = [start], set(), []
|
||||
while stack:
|
||||
node = stack.pop()
|
||||
if node in visited: continue
|
||||
visited.add(node)
|
||||
order.append(node)
|
||||
# reverse for same order as recursive
|
||||
for nb in reversed(graph[node]):
|
||||
if nb not in visited:
|
||||
stack.append(nb)
|
||||
return order
|
||||
```
|
||||
|
||||
### Topological sort (DFS post-order)
|
||||
```python
|
||||
def topo_sort(graph):
|
||||
visited, order = set(), []
|
||||
def visit(n):
|
||||
if n in visited: return
|
||||
visited.add(n)
|
||||
for nb in graph[n]: visit(nb)
|
||||
order.append(n) # post-order
|
||||
for n in graph: visit(n)
|
||||
return order[::-1]
|
||||
```
|
||||
|
||||
### Cycle detection (DFS with color)
|
||||
```python
|
||||
WHITE, GRAY, BLACK = 0, 1, 2
|
||||
|
||||
def has_cycle(graph):
|
||||
color = {n: WHITE for n in graph}
|
||||
def dfs(n):
|
||||
color[n] = GRAY
|
||||
for nb in graph[n]:
|
||||
if color[nb] == GRAY: return True # back edge
|
||||
if color[nb] == WHITE and dfs(nb): return True
|
||||
color[n] = BLACK
|
||||
return False
|
||||
return any(dfs(n) for n in graph if color[n] == WHITE)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| shortest path (unweighted) | BFS |
|
||||
| shortest path (weighted) | Dijkstra / A* |
|
||||
| topological sort | DFS post-order / Kahn |
|
||||
| cycle detection | DFS color |
|
||||
| memory tight, deep tree | DFS |
|
||||
| memory ample, wide goals | BFS |
|
||||
| 매 path enumeration / backtrack | DFS |
|
||||
| 매 web crawl (depth-limited) | BFS with depth |
|
||||
|
||||
**기본값**: shortest path 의 BFS, 매 structural analysis (topo, cycle, SCC) 의 DFS.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Graph Theory]]
|
||||
- 응용: [[Dijkstra's Algorithm]] · [[Topological Sort]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 graph 문제 의 first-cut, 매 grid maze, 매 dependency resolution, 매 social network expansion.
|
||||
**언제 X**: 매 weighted shortest path (Dijkstra), 매 heuristic 가능 시 (A*), 매 huge graph 의 sampling (random walk).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **BFS의 memory**: 매 huge branching factor → O(b^d) 의 OOM. 매 IDDFS 의 의 의.
|
||||
- **DFS recursion limit**: Python 의 default 1000 — 매 large graph 의 stack overflow. 매 iterative 의 의.
|
||||
- **visited X**: 매 cycle 의 infinite loop.
|
||||
- **BFS의 path 의 다 저장**: O(V²) memory — 매 parent map 의 의 reconstruct.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (CLRS Ch 22; Sedgewick Algorithms 4th).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — BFS/DFS comparison with topo sort + cycle detection patterns |
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
---
|
||||
id: wiki-2026-0508-biological-inspired-algorithms
|
||||
title: Biological Inspired Algorithms
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Bio-Inspired Computing, Nature-Inspired Algorithms, Bionic Algorithms]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.88
|
||||
verification_status: applied
|
||||
tags: [optimization, metaheuristics, evolutionary, swarm]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: DEAP, pyswarms, scikit-opt
|
||||
---
|
||||
|
||||
# Biological Inspired Algorithms
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 nature 의 problem-solving 을 computational metaheuristic 로 abstract"**. 1950s cybernetics → 1970s GA → 1990s ACO/PSO → 2020s neuroevolution + LLM-guided search 까지, 매 NP-hard / black-box optimization 의 main toolkit 으로 evolved.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 분류
|
||||
- **Evolutionary**: GA, GP, ES, DE, CMA-ES, NEAT.
|
||||
- **Swarm intelligence**: PSO (bird flocks), ACO (ant pheromone), ABC (bee colony), Firefly.
|
||||
- **Immune-inspired**: Clonal Selection, Negative Selection.
|
||||
- **Neural-inspired**: ANN, Spiking NN, Hebbian learning.
|
||||
- **Physical/biological hybrid**: Slime mould (Physarum), DNA computing.
|
||||
|
||||
### 매 공통 구조
|
||||
1. **Population** of candidates.
|
||||
2. **Fitness** function (objective).
|
||||
3. **Variation** operators (mutation, crossover, social update).
|
||||
4. **Selection** pressure (tournament, roulette, elitism).
|
||||
5. **Iteration** until convergence / budget.
|
||||
|
||||
### 매 강점
|
||||
- 매 derivative-free, black-box-friendly.
|
||||
- 매 multimodal landscape 의 escape from local optima.
|
||||
- 매 parallel-friendly (population evaluation).
|
||||
- 매 hybridize easily with local search (memetic).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Genetic Algorithm (DEAP)
|
||||
```python
|
||||
from deap import base, creator, tools, algorithms
|
||||
import random
|
||||
|
||||
creator.create("FitnessMax", base.Fitness, weights=(1.0,))
|
||||
creator.create("Individual", list, fitness=creator.FitnessMax)
|
||||
|
||||
tb = base.Toolbox()
|
||||
tb.register("attr", random.randint, 0, 1)
|
||||
tb.register("individual", tools.initRepeat, creator.Individual, tb.attr, n=100)
|
||||
tb.register("population", tools.initRepeat, list, tb.individual)
|
||||
tb.register("evaluate", lambda ind: (sum(ind),))
|
||||
tb.register("mate", tools.cxTwoPoint)
|
||||
tb.register("mutate", tools.mutFlipBit, indpb=0.05)
|
||||
tb.register("select", tools.selTournament, tournsize=3)
|
||||
|
||||
pop = tb.population(n=300)
|
||||
algorithms.eaSimple(pop, tb, cxpb=0.7, mutpb=0.2, ngen=40, verbose=False)
|
||||
```
|
||||
|
||||
### Particle Swarm Optimization (pyswarms)
|
||||
```python
|
||||
import numpy as np, pyswarms as ps
|
||||
|
||||
def sphere(x): return np.sum(x**2, axis=1)
|
||||
|
||||
opt = ps.single.GlobalBestPSO(
|
||||
n_particles=30, dimensions=10,
|
||||
options={"c1": 0.5, "c2": 0.3, "w": 0.9},
|
||||
bounds=(np.full(10, -5), np.full(10, 5)),
|
||||
)
|
||||
cost, pos = opt.optimize(sphere, iters=200)
|
||||
```
|
||||
|
||||
### Ant Colony Optimization (TSP)
|
||||
```python
|
||||
import numpy as np
|
||||
def aco_tsp(dist, n_ants=20, n_iter=200, alpha=1, beta=5, rho=0.1, q=1):
|
||||
n = len(dist); pher = np.ones((n,n))
|
||||
best_len, best_path = np.inf, None
|
||||
for _ in range(n_iter):
|
||||
paths = []
|
||||
for _ in range(n_ants):
|
||||
unvis = list(range(n)); cur = unvis.pop(0); path = [cur]
|
||||
while unvis:
|
||||
p = (pher[cur,unvis]**alpha) * ((1/dist[cur,unvis])**beta)
|
||||
nxt = unvis[np.random.choice(len(unvis), p=p/p.sum())]
|
||||
path.append(nxt); unvis.remove(nxt); cur = nxt
|
||||
paths.append(path)
|
||||
pher *= (1-rho)
|
||||
for path in paths:
|
||||
L = sum(dist[path[i],path[i+1]] for i in range(n-1))
|
||||
if L < best_len: best_len, best_path = L, path
|
||||
for i in range(n-1): pher[path[i], path[i+1]] += q/L
|
||||
return best_path, best_len
|
||||
```
|
||||
|
||||
### CMA-ES (continuous, modern default)
|
||||
```python
|
||||
import cma
|
||||
es = cma.CMAEvolutionStrategy(8 * [0.5], 0.5)
|
||||
es.optimize(lambda x: sum(xi**2 for xi in x))
|
||||
print(es.result.xbest)
|
||||
```
|
||||
|
||||
### Differential Evolution (scipy)
|
||||
```python
|
||||
from scipy.optimize import differential_evolution
|
||||
res = differential_evolution(lambda x: (x[0]-3)**2 + (x[1]+1)**2,
|
||||
bounds=[(-5,5),(-5,5)], strategy="best1bin",
|
||||
popsize=30, mutation=(0.5,1.0), recombination=0.7)
|
||||
```
|
||||
|
||||
### NEAT (neuroevolution)
|
||||
```python
|
||||
import neat
|
||||
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
|
||||
neat.DefaultSpeciesSet, neat.DefaultStagnation, "config-neat")
|
||||
pop = neat.Population(config)
|
||||
def eval_genomes(genomes, cfg):
|
||||
for gid, g in genomes:
|
||||
net = neat.nn.FeedForwardNetwork.create(g, cfg)
|
||||
g.fitness = simulate(net) # env-specific
|
||||
winner = pop.run(eval_genomes, n=50)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Continuous, smooth | Gradient / L-BFGS |
|
||||
| Continuous, black-box, ≤ 100 dim | **CMA-ES** |
|
||||
| Continuous, parallel, robust | **Differential Evolution** |
|
||||
| Combinatorial (TSP, scheduling) | **GA + local search (memetic)**, ACO |
|
||||
| Real-time multi-agent | **PSO** |
|
||||
| Neural architecture / policy | **NEAT, evolution strategies** |
|
||||
| Very expensive eval | Bayesian optimization |
|
||||
|
||||
**기본값**: 매 continuous black-box 면 **CMA-ES**, 매 combinatorial 이면 **memetic GA**.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Optimization]]
|
||||
- 변형: [[Genetic-Algorithm]] · [[CMA-ES]] · [[NEAT]]
|
||||
- 응용: [[Hyperparameters|Hyperparameter-Optimization]] · [[Neural-Architecture-Search-NAS|Neural-Architecture-Search]] · [[Scheduling]]
|
||||
- Adjacent: [[Bayesian-Optimization]] · [[Reinforcement-Learning]] · [[Simulated-Annealing]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 black-box objective + non-differentiable + multimodal landscape, 매 prompt-search / hyperparameter tuning, 매 NAS.
|
||||
**언제 X**: 매 differentiable + convex (gradient 의 압도적 빠름), 매 budget < 100 evaluations (Bayesian opt 의 선호).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Premature convergence**: 매 selection pressure 의 too-high → 매 diversity collapse. 매 niching, fitness sharing 사용.
|
||||
- **Hyperparameter neglect**: 매 GA 의 cx/mut prob 의 untuned → 매 random search 의 못함.
|
||||
- **Reinventing wheels**: 매 "Whale Optimization", "Grey Wolf" 등 매 metaphor-only papers — 매 CMA-ES / DE 의 거의 항상 better baseline.
|
||||
- **No restart**: 매 stuck — 매 IPOP/BIPOP restart 의 critical.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Holland 1975 GA; Kennedy & Eberhart 1995 PSO; Dorigo 1992 ACO; Hansen 2001 CMA-ES; Stanley 2002 NEAT).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 placeholder |
|
||||
| 2026-05-10 | Manual cleanup — taxonomy, 6 algo patterns, decision matrix |
|
||||
@@ -0,0 +1,135 @@
|
||||
---
|
||||
id: wiki-2026-0508-black-hole
|
||||
title: Black Hole
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Schwarzschild, Event Horizon, Singularity]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [physics, general-relativity, computation, information-theory]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: einsteinpy, astropy
|
||||
---
|
||||
|
||||
# Black Hole
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 spacetime 의 region where escape velocity > c"**. Schwarzschild (1916) solution → Hawking radiation (1974) → EHT M87* image (2019) + Sgr A* (2022) → 매 2026 modern view: 매 information paradox 의 holographic / ER=EPR resolution 의 frontier. 매 CS 측면에서는 매 information bound, holographic encoding, computational limit 의 reference physical system.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 정의 / 종류
|
||||
- **Schwarzschild** (non-rotating, no charge): r_s = 2GM/c².
|
||||
- **Kerr** (rotating): 매 ergosphere + frame dragging.
|
||||
- **Reissner–Nordström** (charged), **Kerr–Newman** (rotating + charged).
|
||||
- 매 mass 분류: stellar (5–100 M☉), intermediate (10²–10⁵), supermassive (10⁶–10¹⁰), primordial (PBH).
|
||||
|
||||
### 매 entropy / information
|
||||
- Bekenstein–Hawking entropy: S = k·A / (4·ℓ_P²).
|
||||
- 매 information 매 area 에 비례 — 매 holographic principle 의 origin.
|
||||
- Hawking T = ℏc³ / (8π·G·M·k_B) — 매 radiation 의 thermal.
|
||||
- 매 information paradox: 매 unitary evolution vs thermal radiation. **2020 island formula (Penington, Almheiri 등) 의 Page curve 도출**.
|
||||
|
||||
### 매 CS / 정보이론 연결
|
||||
1. **Holographic bound**: 매 region 의 max info ≤ A / (4·ℓ_P²) bits.
|
||||
2. **Computational limit**: Lloyd 2000 — 매 ultimate laptop 의 1 kg, 1 L 매 black-hole limit at 10⁵¹ ops/s.
|
||||
3. **Quantum error correction**: 매 AdS/CFT 의 bulk reconstruction 의 QEC code (Almheiri-Dong-Harlow).
|
||||
4. **ER=EPR**: 매 entanglement = wormhole — 매 quantum gravity 의 unification 의 hint.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Schwarzschild radius
|
||||
```python
|
||||
G, c, MSUN = 6.67430e-11, 2.99792458e8, 1.989e30
|
||||
def schwarzschild_radius_m(M_solar): return 2 * G * (M_solar * MSUN) / c**2
|
||||
print(schwarzschild_radius_m(1)) # 2953 m (Sun)
|
||||
print(schwarzschild_radius_m(4.3e6)) # Sgr A*
|
||||
```
|
||||
|
||||
### Hawking temperature & lifetime
|
||||
```python
|
||||
import math
|
||||
hbar, kB = 1.054571817e-34, 1.380649e-23
|
||||
def hawking_T(M_kg): return hbar*c**3 / (8*math.pi*G*M_kg*kB)
|
||||
def evap_time_s(M_kg): return 5120 * math.pi * G**2 * M_kg**3 / (hbar * c**4)
|
||||
print(hawking_T(MSUN)) # ~6e-8 K
|
||||
print(evap_time_s(MSUN) / 3.15e16) # ~2e67 yr
|
||||
```
|
||||
|
||||
### Geodesic integration (einsteinpy)
|
||||
```python
|
||||
from einsteinpy.geodesic import Timelike
|
||||
from einsteinpy.metric import Schwarzschild
|
||||
import astropy.units as u
|
||||
|
||||
geo = Timelike(metric="Schwarzschild", metric_params=(0,),
|
||||
position=[40, math.pi/2, 0], momentum=[0, 0, 3.83],
|
||||
steps=5500, delta=0.5, return_cartesian=True)
|
||||
```
|
||||
|
||||
### Bekenstein–Hawking entropy
|
||||
```python
|
||||
lP2 = 2.612e-70 # Planck area m^2
|
||||
def BH_entropy_bits(M_kg):
|
||||
rs = 2*G*M_kg/c**2
|
||||
A = 4*math.pi*rs**2
|
||||
return A / (4*lP2) / math.log(2)
|
||||
print(f"{BH_entropy_bits(MSUN):.2e} bits") # ~1e77
|
||||
```
|
||||
|
||||
### Holographic bound check
|
||||
```python
|
||||
def holographic_max_bits(area_m2): return area_m2 / (4*lP2) / math.log(2)
|
||||
# 매 1 m² boundary 매 ~1e69 bits maximum.
|
||||
```
|
||||
|
||||
### Image-plane shadow radius (EHT-style)
|
||||
```python
|
||||
def shadow_radius_uas(M_solar, distance_kpc):
|
||||
rs = schwarzschild_radius_m(M_solar)
|
||||
shadow_m = 3*math.sqrt(3)*rs # photon ring diameter ≈ 5.196·r_s/2
|
||||
d_m = distance_kpc * 3.086e19
|
||||
return (shadow_m / d_m) * (180/math.pi) * 3600 * 1e6
|
||||
print(shadow_radius_uas(6.5e9, 16800)) # M87* ~ 42 µas
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Newtonian regime (r ≫ r_s) | Newtonian gravity |
|
||||
| Static, spherical | **Schwarzschild metric** |
|
||||
| Rotating astrophysical | **Kerr metric** |
|
||||
| Quantum-gravity / info | **Page curve + island formula** |
|
||||
| Holographic / dual CFT | **AdS/CFT** |
|
||||
| Numerical merger | **Numerical Relativity (Einstein Toolkit)** |
|
||||
|
||||
**기본값**: 매 astrophysics 면 **Kerr**, 매 CS / info-theoretic discussion 면 **Bekenstein–Hawking + holographic bound**.
|
||||
|
||||
## 🔗 Graph
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 information-theoretic 한 entropy bound, 매 holographic / quantum gravity 의 thought experiment, 매 cosmology numerical estimation.
|
||||
**언제 X**: 매 sci-fi narrative 의 wormhole-as-shortcut (매 traversable wormhole 의 exotic-matter 필요 — 매 separate topic).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **"매 black hole 의 information 의 lost"**: 매 modern view 의 unitary preserved (Page curve, island formula).
|
||||
- **"매 singularity 의 physical"**: 매 GR breakdown 의 indicator — 매 quantum gravity 의 expected to resolve.
|
||||
- **"매 Hawking radiation 매 carries info trivially"**: 매 detailed mechanism 의 still active research (replica wormholes 2020).
|
||||
- **Mixing M_BH ↔ r_s units**: 매 SI (kg, m) vs geometrized (M = G·M_kg/c²) 매 cross-check 항상.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Schwarzschild 1916; Hawking 1974; Bekenstein 1973; EHT Collaboration 2019, 2022; Penington 2020).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 placeholder |
|
||||
| 2026-05-10 | Manual cleanup — physics + CS info-bound + 6 patterns |
|
||||
@@ -0,0 +1,150 @@
|
||||
---
|
||||
id: wiki-2026-0508-bloom-filters-in-search
|
||||
title: Bloom Filters in Search
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Bloom Filter, BF, Probabilistic Set Membership]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
verification_status: applied
|
||||
tags: [data-structures, search, probabilistic, indexing]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: pybloom-live, RedisBloom
|
||||
---
|
||||
|
||||
# Bloom Filters in Search
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 set membership 의 ultra-compact probabilistic test"**. Burton Bloom (1970) 이 spell-checker 위해 designed — modern search 에서 매 inverted-index pruning, cache short-circuit, distributed dedup 의 핵심 primitive 로 사용.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 작동 원리
|
||||
- m-bit array + k independent hash functions.
|
||||
- Insert: 매 element x → 매 k hashes → 매 set bits at h1(x), …, hk(x).
|
||||
- Query: 매 모든 k bits set → "possibly in set". 매 하나라도 0 → "definitely not".
|
||||
- **False positive O, false negative X** — 매 search 의 negative-cache 에 ideal.
|
||||
|
||||
### 매 수학
|
||||
- Optimal k = (m/n) · ln 2.
|
||||
- FP rate p ≈ (1 − e^(−kn/m))^k.
|
||||
- 매 1% FP 위해 매 element 당 ~9.6 bits 필요 (load factor independent of element size).
|
||||
|
||||
### 매 응용 in Search
|
||||
1. **Inverted-index shard pruning** — Elasticsearch, Lucene 매 segment-level BF.
|
||||
2. **CDN cache check** — 매 origin 의 round-trip avoid (Akamai).
|
||||
3. **Crawler URL dedup** — Googlebot-style frontier.
|
||||
4. **LSM-tree SSTable pruning** — RocksDB, Cassandra, ScyllaDB.
|
||||
5. **Vector-DB ANN candidate filter** — Milvus, Weaviate.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Vanilla Python
|
||||
```python
|
||||
import mmh3, math
|
||||
from bitarray import bitarray
|
||||
|
||||
class BloomFilter:
|
||||
def __init__(self, n: int, fp: float = 0.01):
|
||||
self.m = math.ceil(-(n * math.log(fp)) / (math.log(2) ** 2))
|
||||
self.k = max(1, round((self.m / n) * math.log(2)))
|
||||
self.bits = bitarray(self.m); self.bits.setall(0)
|
||||
|
||||
def _hashes(self, x: bytes):
|
||||
h1, h2 = mmh3.hash64(x, signed=False)
|
||||
return [(h1 + i * h2) % self.m for i in range(self.k)]
|
||||
|
||||
def add(self, x: bytes):
|
||||
for i in self._hashes(x): self.bits[i] = 1
|
||||
|
||||
def __contains__(self, x: bytes) -> bool:
|
||||
return all(self.bits[i] for i in self._hashes(x))
|
||||
```
|
||||
|
||||
### RedisBloom (production)
|
||||
```python
|
||||
import redis
|
||||
r = redis.Redis()
|
||||
r.execute_command("BF.RESERVE", "urls", 0.001, 10_000_000)
|
||||
r.execute_command("BF.ADD", "urls", "https://example.com/a")
|
||||
exists = r.execute_command("BF.EXISTS", "urls", "https://example.com/a") # 1 or 0
|
||||
```
|
||||
|
||||
### Counting Bloom Filter (supports delete)
|
||||
```python
|
||||
class CountingBF:
|
||||
def __init__(self, m, k): self.c = [0]*m; self.m, self.k = m, k
|
||||
def add(self, x):
|
||||
for i in self._h(x): self.c[i] += 1
|
||||
def remove(self, x):
|
||||
for i in self._h(x):
|
||||
if self.c[i] > 0: self.c[i] -= 1
|
||||
```
|
||||
|
||||
### Cuckoo Filter (modern alternative)
|
||||
```python
|
||||
# pip install cuckoofilter
|
||||
from cuckoofilter import CuckooFilter
|
||||
cf = CuckooFilter(capacity=1_000_000, fingerprint_size=12)
|
||||
cf.insert(b"item"); cf.contains(b"item"); cf.delete(b"item")
|
||||
```
|
||||
|
||||
### LSM-tree integration (RocksDB-style, conceptual)
|
||||
```python
|
||||
def get(key):
|
||||
for sstable in reversed(levels): # newest first
|
||||
if key not in sstable.bloom: # BF rejects → skip disk read
|
||||
continue
|
||||
v = sstable.disk_lookup(key)
|
||||
if v is not None: return v
|
||||
return None
|
||||
```
|
||||
|
||||
### Distributed scale-out (partitioned BF)
|
||||
```python
|
||||
def shard(key, n_shards): return mmh3.hash(key) % n_shards
|
||||
# 매 shard 매 own BF — node-local query, gossip-merged for global view.
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Static set, exact 필요 | Perfect hash (CHD, BBHash) |
|
||||
| Dynamic, FP OK, no delete | **Bloom Filter** |
|
||||
| Need delete | Counting BF or Cuckoo Filter |
|
||||
| Need count/freq | Count-Min Sketch |
|
||||
| Streaming dedup, bounded mem | HyperLogLog (cardinality only) |
|
||||
| Need sorted range query | B-tree / SSTable index |
|
||||
|
||||
**기본값**: 매 dynamic insert + lookup 의 negative-cache 에서는 **Bloom Filter (k = m/n · ln 2, p = 1%)**.
|
||||
|
||||
## 🔗 Graph
|
||||
- 변형: [[Cuckoo-Filter]]
|
||||
- 응용: [[LSM-Tree]]
|
||||
- Adjacent: [[HyperLogLog]] · [[Count-Min-Sketch]] · [[MinHash]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 candidate-key set 의 fast negative-test, 매 duplicate detection in streaming pipeline, 매 ANN search 의 pre-filter.
|
||||
**언제 X**: 매 exact membership 필수 (auth, billing), 매 small n (< 1000) 일 때 — 매 hash-set 의 simpler.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Underestimate n**: 매 capacity overflow → 매 FP rate 의 explode (saturated bits).
|
||||
- **Weak hash (e.g., DJB2)**: 매 correlated bits → 매 actual FP > theoretical. **MurmurHash3 / xxHash 사용.**
|
||||
- **Delete via clearing bits**: 매 corrupts other entries — 매 Counting BF 사용.
|
||||
- **Sharing BF across security boundary**: 매 timing side-channel 의 set membership leak.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Bloom 1970, "Space/Time Trade-offs in Hash Coding"; Broder & Mitzenmacher 2002 survey; RocksDB & Cassandra source).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 placeholder |
|
||||
| 2026-05-10 | Manual cleanup — full content (theory, 6 patterns, decision matrix) |
|
||||
@@ -0,0 +1,154 @@
|
||||
---
|
||||
id: wiki-2026-0508-brute-force
|
||||
title: Brute-force
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Exhaustive-Search, Naive-Algorithm]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [algorithm, search, baseline]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: stdlib
|
||||
---
|
||||
|
||||
# Brute-force
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 모든 후보를 매 enumerate해서 매 검사 — 매 단순함이 매 최대 무기"**. 매 algorithmic paradigm으로서 매 baseline + correctness oracle. 매 2026 ML/AI에서도 매 grid search, 매 fuzzing, 매 password cracking, 매 small-n CSP 에서 매 still alive — 매 GPU + parallelism으로 매 brute force가 매 더 viable.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 핵심 idea
|
||||
- 매 search space 전체를 매 systematic enumerate.
|
||||
- 매 correctness가 매 trivially provable.
|
||||
- 매 complexity는 매 보통 exponential — 매 small n only.
|
||||
|
||||
### 매 응용
|
||||
1. String matching (naive: $O(nm)$ vs KMP $O(n+m)$).
|
||||
2. Cryptanalysis: brute-force key search (e.g., 56-bit DES → cracked 1998).
|
||||
3. Hyperparameter grid search (small grid).
|
||||
4. Test oracle (fast brute-force vs optimized — fuzz to verify).
|
||||
5. Combinatorial: TSP, SAT, knapsack — 매 small n.
|
||||
6. Fuzzing: AFL/libFuzzer 매 brute random + coverage feedback.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Naive substring search
|
||||
```python
|
||||
def find_naive(text, pat):
|
||||
n, m = len(text), len(pat)
|
||||
for i in range(n - m + 1):
|
||||
if text[i:i+m] == pat:
|
||||
return i
|
||||
return -1
|
||||
# O(n*m) — fine for short pattern; KMP/Boyer-Moore better large m
|
||||
```
|
||||
|
||||
### Subset enumeration
|
||||
```python
|
||||
from itertools import combinations
|
||||
def best_subset(items, score_fn):
|
||||
best = (None, float('-inf'))
|
||||
for r in range(len(items)+1):
|
||||
for combo in combinations(items, r):
|
||||
s = score_fn(combo)
|
||||
if s > best[1]: best = (combo, s)
|
||||
return best
|
||||
# 2^n subsets — only for n <= 20
|
||||
```
|
||||
|
||||
### Permutation TSP (exact for n<=10)
|
||||
```python
|
||||
from itertools import permutations
|
||||
def tsp_brute(dist, start=0):
|
||||
n = len(dist)
|
||||
best = float('inf'); best_path = None
|
||||
for perm in permutations(range(1, n)):
|
||||
path = (start,) + perm + (start,)
|
||||
cost = sum(dist[path[i]][path[i+1]] for i in range(n))
|
||||
if cost < best: best, best_path = cost, path
|
||||
return best, best_path
|
||||
```
|
||||
|
||||
### Brute force as test oracle
|
||||
```python
|
||||
def fast_solve(input_): ... # production
|
||||
def brute_solve(input_): ... # obvious O(n^k)
|
||||
|
||||
def test_with_fuzz():
|
||||
import random
|
||||
for _ in range(10_000):
|
||||
x = random_input()
|
||||
assert fast_solve(x) == brute_solve(x), x
|
||||
```
|
||||
|
||||
### Grid hyperparameter search
|
||||
```python
|
||||
import itertools
|
||||
def grid_search(model_fn, param_grid, X, y):
|
||||
best = (None, float('-inf'))
|
||||
keys = list(param_grid)
|
||||
for vals in itertools.product(*[param_grid[k] for k in keys]):
|
||||
params = dict(zip(keys, vals))
|
||||
score = cv_score(model_fn(**params), X, y)
|
||||
if score > best[1]: best = (params, score)
|
||||
return best
|
||||
# Use Optuna/random search for >5 dims
|
||||
```
|
||||
|
||||
### Pruning + brute (branch-and-bound hybrid)
|
||||
```python
|
||||
def knapsack_bnb(weights, values, cap):
|
||||
best = [0]
|
||||
def rec(i, w, v):
|
||||
if w > cap: return
|
||||
if i == len(weights):
|
||||
best[0] = max(best[0], v); return
|
||||
# upper bound (LP relax) — prune if can't beat best
|
||||
rec(i+1, w + weights[i], v + values[i])
|
||||
rec(i+1, w, v)
|
||||
rec(0, 0, 0)
|
||||
return best[0]
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| n size | Brute viable? |
|
||||
|---|---|
|
||||
| $n \le 10$ | $O(n!)$ OK |
|
||||
| $n \le 25$ | $O(2^n)$ OK |
|
||||
| $n \le 50$ | $O(2^{n/2})$ meet-in-the-middle |
|
||||
| $n > 50$ | DP / heuristic / approximation |
|
||||
|
||||
**기본값**: 매 첫 implementation은 매 brute. 매 그것이 매 너무 slow일 때만 매 optimize. 매 brute는 매 reference oracle로 매 keep.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Algorithm-Complexity-Big-O]]
|
||||
- 변형: [[Greedy-Algorithms]] (heuristic) · [[Dynamic-Programming]] (memoize) · Branch-and-Bound
|
||||
- 응용: Cryptanalysis · [[Combinatorial-Optimization]]
|
||||
- Adjacent: [[Bubble-Sort]] · [[BFS vs DFS]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 first implementation, 매 correctness oracle, 매 small n problem.
|
||||
**언제 X**: 매 n>50, 매 production hot path — 매 better algorithm 필수.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Brute in production hot loop**: 매 $O(n^2)$ when $O(n \log n)$ trivial.
|
||||
- **Throwing away brute baseline**: 매 optimized version에 매 bug — 매 oracle 없음.
|
||||
- **Brute force without bound**: 매 무한 loop — 매 max iterations / timeout 필수.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (CLRS Ch.31, Skiena Algorithm Design Manual).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — brute paradigm + oracle pattern |
|
||||
@@ -0,0 +1,164 @@
|
||||
---
|
||||
id: wiki-2026-0508-bubble-sort
|
||||
title: Bubble Sort
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [버블 정렬, Sinking Sort, Exchange Sort]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [algorithm, sorting, comparison-sort, education]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python/C/Rust
|
||||
framework: stdlib
|
||||
---
|
||||
|
||||
# Bubble Sort
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 인접 비교+swap 의 매 simplest sort"**. 1956 Iverson notation discussion 부터 매 textbook canonical example. 매 production 의 X — 매 O(n²) 이라 n>50 의 부적합. 매 2026 의 매 교육적 가치 + matrix-vector kernel optimization research 의 사용.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 알고리즘
|
||||
- 매 n-1 passes — 매 pass 마다 인접 두 원소 비교 + swap (잘못된 순서면).
|
||||
- 매 pass 후 가장 큰 element 가 매 우측 끝 의 "bubble up".
|
||||
- 매 in-place — O(1) extra space.
|
||||
- 매 stable sort — 매 동등 키 의 상대적 순서 유지.
|
||||
|
||||
### 매 복잡도
|
||||
- **Worst/Average**: O(n²) — 매 reverse-sorted input.
|
||||
- **Best**: O(n) — 매 already-sorted + early-termination flag.
|
||||
- **Comparisons**: n(n-1)/2 worst case.
|
||||
- **Swaps**: 매 inversions 수 = n(n-1)/2 worst case.
|
||||
|
||||
### 매 응용
|
||||
1. **Education**: 매 introductory CS course 의 1st sort.
|
||||
2. **Tiny n (<10)**: 매 cache-friendly + low overhead.
|
||||
3. **Nearly-sorted detection**: 매 single-pass 로 sorted 여부 check.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Classic Bubble Sort
|
||||
```python
|
||||
def bubble_sort(arr: list[int]) -> None:
|
||||
n = len(arr)
|
||||
for i in range(n - 1):
|
||||
for j in range(n - 1 - i):
|
||||
if arr[j] > arr[j + 1]:
|
||||
arr[j], arr[j + 1] = arr[j + 1], arr[j]
|
||||
```
|
||||
|
||||
### Optimized with Early-Exit Flag
|
||||
```python
|
||||
def bubble_sort_optimized(arr: list[int]) -> None:
|
||||
n = len(arr)
|
||||
for i in range(n - 1):
|
||||
swapped = False
|
||||
for j in range(n - 1 - i):
|
||||
if arr[j] > arr[j + 1]:
|
||||
arr[j], arr[j + 1] = arr[j + 1], arr[j]
|
||||
swapped = True
|
||||
if not swapped:
|
||||
return # 매 already sorted — 매 O(n) best case
|
||||
```
|
||||
|
||||
### Cocktail Shaker (Bidirectional)
|
||||
```python
|
||||
def cocktail_sort(arr: list[int]) -> None:
|
||||
lo, hi = 0, len(arr) - 1
|
||||
while lo < hi:
|
||||
for j in range(lo, hi):
|
||||
if arr[j] > arr[j + 1]:
|
||||
arr[j], arr[j + 1] = arr[j + 1], arr[j]
|
||||
hi -= 1
|
||||
for j in range(hi, lo, -1):
|
||||
if arr[j - 1] > arr[j]:
|
||||
arr[j - 1], arr[j] = arr[j], arr[j - 1]
|
||||
lo += 1
|
||||
```
|
||||
|
||||
### Generic with Comparator (Rust)
|
||||
```rust
|
||||
fn bubble_sort<T, F: Fn(&T, &T) -> std::cmp::Ordering>(arr: &mut [T], cmp: F) {
|
||||
let n = arr.len();
|
||||
for i in 0..n.saturating_sub(1) {
|
||||
let mut swapped = false;
|
||||
for j in 0..n - 1 - i {
|
||||
if cmp(&arr[j], &arr[j + 1]) == std::cmp::Ordering::Greater {
|
||||
arr.swap(j, j + 1);
|
||||
swapped = true;
|
||||
}
|
||||
}
|
||||
if !swapped { return; }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Branchless Inner Loop (CPU pipeline-friendly)
|
||||
```c
|
||||
void bubble_sort_branchless(int *a, int n) {
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
for (int j = 0; j < n - 1 - i; j++) {
|
||||
int cmp = a[j] > a[j + 1];
|
||||
int tmp = a[j];
|
||||
a[j] = cmp ? a[j + 1] : a[j];
|
||||
a[j + 1] = cmp ? tmp : a[j + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Linked-List Variant
|
||||
```python
|
||||
def bubble_sort_linked(head):
|
||||
if not head: return head
|
||||
swapped = True
|
||||
while swapped:
|
||||
swapped = False
|
||||
cur = head
|
||||
while cur.next:
|
||||
if cur.val > cur.next.val:
|
||||
cur.val, cur.next.val = cur.next.val, cur.val
|
||||
swapped = True
|
||||
cur = cur.next
|
||||
return head
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| n < 10, simple code 우선 | Bubble Sort (optimized) |
|
||||
| n < 50, 거의 sorted | Insertion Sort > Bubble |
|
||||
| n > 100 | Quicksort/Timsort/std `sort` |
|
||||
| Stable + small n | Bubble or Insertion |
|
||||
| Production code | 매 절대 X — 매 stdlib `sort` |
|
||||
|
||||
**기본값**: 매 production 은 stdlib (Timsort/IntroSort) — 매 Bubble 은 교육 only.
|
||||
|
||||
## 🔗 Graph
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 algorithm tutorials 의 explanation, 매 n<20 의 quick prototype, 매 inversions counting heuristic.
|
||||
**언제 X**: 매 production sort, 매 n>100, 매 latency-sensitive paths — 매 Timsort/Quicksort 의 사용.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Production deployment**: 매 100x slower than Timsort 의 large n.
|
||||
- **Recursive bubble**: 매 stack overhead 의 점진적 추가 — 매 pure loss.
|
||||
- **No early-exit**: 매 sorted input 의 O(n²) 의 낭비.
|
||||
- **Bubble for objects with expensive comparison**: 매 n² comparisons 의 cost explosion.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Knuth TAOCP Vol 3 §5.2.2, CLRS Ch. 2 problem 2-2).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Bubble sort patterns + variants + decision matrix |
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
---
|
||||
id: wiki-2026-0508-burnout-prevention-in-profession
|
||||
title: Burnout Prevention in Professional Gaming
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Esports Burnout, Pro Gamer Mental Health, Player Wellness]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.85
|
||||
verification_status: applied
|
||||
tags: [esports, mental-health, performance, sports-science, wellness]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: N/A
|
||||
framework: WHO ICD-11 / Maslach Burnout Inventory
|
||||
---
|
||||
|
||||
# Burnout Prevention in Professional Gaming
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 chronic occupational stress 의 esports adaptation"**. WHO ICD-11 (2019) 의 burnout 의 occupational phenomenon 인정 후 매 esports 의 매 acute risk profile (10-14h practice/day, age 16-24 peak, parasocial pressure). 매 2026 의 매 LCS/LCK/VCT 의 mandatory wellness programs 의 standardization.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Burnout 정의 (Maslach 3-axis)
|
||||
- **Emotional exhaustion**: 매 energy depletion — 매 pre-match anxiety + post-match crash.
|
||||
- **Depersonalization**: 매 cynicism — 매 fans/team 의 distance.
|
||||
- **Reduced accomplishment**: 매 efficacy 의 감소 — 매 mechanical skill plateau perception.
|
||||
|
||||
### 매 Esports-specific 위험 요인
|
||||
- **Practice volume**: 매 70+ hr/week scrim/solo queue — 매 traditional sports 의 X.
|
||||
- **Travel + boot camp**: 매 sleep disruption + jet lag — 매 LAN circuit 의 매 6+ flights/year.
|
||||
- **Parasocial pressure**: 매 stream + Twitter visibility 의 매 24/7 scrutiny.
|
||||
- **Career compression**: 매 peak age 18-22 — 매 pro window <5 years average.
|
||||
- **Sedentary load**: 매 wrist/back/eye strain 의 cumulative.
|
||||
|
||||
### 매 Prevention 4-tier
|
||||
1. **Schedule design**: 매 practice cap (8h/day max) + 매 mandatory rest day.
|
||||
2. **Sleep hygiene**: 매 fixed bedtime + 매 blue-light cutoff 22:00.
|
||||
3. **Exercise mandate**: 매 30min cardio/day — 매 LCK Gen.G/T1 의 mandatory.
|
||||
4. **Mental health professional**: 매 sports psych on-staff — 매 LCS minimum since 2023.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Maslach Burnout Inventory Scoring (Python)
|
||||
```python
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class MBIScore:
|
||||
emotional_exhaustion: int # 0-54
|
||||
depersonalization: int # 0-30
|
||||
personal_accomplishment: int # 0-48 (reverse-scored)
|
||||
|
||||
@property
|
||||
def burnout_risk(self) -> str:
|
||||
ee_high = self.emotional_exhaustion >= 27
|
||||
dp_high = self.depersonalization >= 13
|
||||
pa_low = self.personal_accomplishment <= 31
|
||||
score = ee_high + dp_high + pa_low
|
||||
return ["low", "moderate", "high", "severe"][score]
|
||||
|
||||
# Weekly screening
|
||||
player = MBIScore(emotional_exhaustion=30, depersonalization=15, personal_accomplishment=28)
|
||||
print(player.burnout_risk) # "severe" — escalate to sports psych
|
||||
```
|
||||
|
||||
### Practice Load Tracker
|
||||
```python
|
||||
class PracticeLoad:
|
||||
def __init__(self):
|
||||
self.daily_hours = [] # last 14 days
|
||||
|
||||
def acute_chronic_ratio(self) -> float:
|
||||
# 매 ACWR — 매 traditional sports injury predictor
|
||||
acute = sum(self.daily_hours[-7:]) / 7
|
||||
chronic = sum(self.daily_hours[-28:]) / 28
|
||||
return acute / chronic if chronic else 0
|
||||
|
||||
def needs_rest_day(self) -> bool:
|
||||
# ACWR > 1.5 = elevated injury/burnout risk
|
||||
return self.acute_chronic_ratio() > 1.5
|
||||
```
|
||||
|
||||
### Sleep Quality Wearable Integration
|
||||
```python
|
||||
import datetime
|
||||
|
||||
def assess_sleep(whoop_data: dict) -> dict:
|
||||
return {
|
||||
"duration_hr": whoop_data["sleep_minutes"] / 60,
|
||||
"rem_pct": whoop_data["rem_minutes"] / whoop_data["sleep_minutes"],
|
||||
"deep_pct": whoop_data["deep_minutes"] / whoop_data["sleep_minutes"],
|
||||
"should_skip_scrim": whoop_data["recovery_score"] < 33, # 매 red zone
|
||||
}
|
||||
```
|
||||
|
||||
### Team Wellness Dashboard Schema
|
||||
```sql
|
||||
CREATE TABLE player_wellness (
|
||||
player_id UUID,
|
||||
date DATE,
|
||||
mbi_score INT,
|
||||
sleep_hours FLOAT,
|
||||
practice_hours FLOAT,
|
||||
self_reported_mood INT, -- 1-10 Likert
|
||||
psych_session_attended BOOL,
|
||||
PRIMARY KEY (player_id, date)
|
||||
);
|
||||
|
||||
-- Weekly intervention trigger
|
||||
SELECT player_id FROM player_wellness
|
||||
WHERE date >= NOW() - INTERVAL '7 days'
|
||||
GROUP BY player_id
|
||||
HAVING AVG(self_reported_mood) < 5 OR AVG(sleep_hours) < 6;
|
||||
```
|
||||
|
||||
### Cognitive Behavioral Therapy (CBT) Reframe Template
|
||||
```python
|
||||
# 매 negative-thought logging — 매 used in T1/Faker's wellness program
|
||||
cbt_log = {
|
||||
"trigger": "lost ranked to lower-tier opponent",
|
||||
"automatic_thought": "I'm losing my mechanics, career is over",
|
||||
"cognitive_distortion": "catastrophizing + all-or-nothing",
|
||||
"balanced_thought": "Single game variance is high; check 14-day winrate",
|
||||
"evidence_for": "Solo queue is noisy; pros have 50-55% winrate",
|
||||
"action": "Review VOD, identify 1 micro-improvement, sleep 8h",
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| MBI score 의 high+ | Mandatory psych referral + 1-week reduced load |
|
||||
| ACWR > 1.5 | Force rest day, no scrim |
|
||||
| Sleep < 6h × 3+ days | Sleep specialist consult |
|
||||
| Performance plateau + cynicism | Burnout > skill issue → wellness intervention |
|
||||
| Pre-Worlds/Major | Increased monitoring (daily MBI mini) |
|
||||
|
||||
**기본값**: 매 weekly MBI + daily sleep/load tracking + monthly psych check-in.
|
||||
|
||||
## 🔗 Graph
|
||||
- Adjacent: [[Cognitive Neuroscience of Flow]] · [[CBT]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 wellness check-in chatbot, 매 CBT thought-record assistance, 매 schedule optimization 의 load balancing.
|
||||
**언제 X**: 매 clinical diagnosis (psychiatrist 영역), 매 medication decision, 매 crisis intervention (988 hotline 의 즉시 escalation).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **More-hours-better**: 매 LCK 70hr scrim 의 mythology — 매 evidence shows diminishing returns >50hr.
|
||||
- **Stigma against psych**: 매 "weakness" perception — 매 modern orgs 의 normalization.
|
||||
- **Reactive only**: 매 burnout 후 intervention — 매 too late (recovery 의 6-12개월).
|
||||
- **Solo-queue grind 의 unlimited**: 매 chronic stress 의 mechanical decay.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (WHO ICD-11 QD85, Maslach 1996, Smith et al. 2022 esports burnout study).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — MBI scoring + ACWR + CBT integration patterns |
|
||||
@@ -0,0 +1,148 @@
|
||||
---
|
||||
id: wiki-2026-0508-caetextia
|
||||
title: Caetextia
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Context Blindness, Contextual Blindness]
|
||||
duplicate_of: none
|
||||
source_trust_level: B
|
||||
confidence_score: 0.75
|
||||
verification_status: applied
|
||||
tags: [psychology, autism, cognition, neurodiversity, theory]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: N/A
|
||||
framework: Human Givens (Griffin & Tyrrell)
|
||||
---
|
||||
|
||||
# Caetextia
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 context-blindness 의 cognitive trait"**. Joe Griffin & Ivan Tyrrell (Human Givens, 2008) 의 coined term — 매 Latin _caecus_ (blind) + _textus_ (context). 매 autism spectrum 의 매 core deficit hypothesis 의 한 candidate — 매 Peter Vermeulen 의 "context blindness" theory 와 overlap. 매 2026 의 매 mainstream DSM 의 X — 매 niche framework remain.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 정의
|
||||
- **Context blindness**: 매 situational meaning extraction 의 어려움.
|
||||
- 매 detail processing 의 strong — 매 gestalt context 의 weak.
|
||||
- 매 literal interpretation tendency — 매 sarcasm/idiom 의 difficulty.
|
||||
- 매 weak central coherence theory (Frith 1989) 와 conceptual cousin.
|
||||
|
||||
### 매 manifestations
|
||||
- 매 social cue mis-reading — 매 tone/body language 의 missing.
|
||||
- 매 routine rigidity — 매 context-shift 의 high cost.
|
||||
- 매 generalization 의 어려움 — 매 task-specific learning 의 narrow.
|
||||
- 매 hyperfocus 의 detail-level — 매 big picture 의 fade.
|
||||
|
||||
### 매 Programming/Tech 관련성
|
||||
1. **Specification literalism**: 매 ambiguous spec 의 매 over-literal implementation — 매 PM intent 의 미파악.
|
||||
2. **Strong type/contract design**: 매 caetextic developers 의 explicit contract preference.
|
||||
3. **Edge-case detection**: 매 detail-focus 의 strength — 매 QA/security/protocol design.
|
||||
4. **Code review style**: 매 surface vs. systemic critique 의 contrast.
|
||||
|
||||
### 매 Caveats
|
||||
- 매 not DSM-5/ICD-11 의 official diagnosis.
|
||||
- 매 Human Givens framework 의 academic acceptance limited.
|
||||
- 매 spectrum/dimension — 매 binary trait 의 X.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Context-Aware vs. Context-Blind Code Style
|
||||
```python
|
||||
# 매 context-blind: 매 strict literal contract
|
||||
def transfer(amount: Decimal, from_id: int, to_id: int) -> TransferResult:
|
||||
if amount <= 0: raise ValueError("amount must be positive")
|
||||
if from_id == to_id: raise ValueError("self-transfer forbidden")
|
||||
# 매 explicit precondition checks — 매 caller intent 의 무시
|
||||
|
||||
# 매 context-aware: 매 inferring caller intent
|
||||
def transfer(amount: Decimal, from_id: int, to_id: int) -> TransferResult:
|
||||
# 매 same account 일 때 — 매 likely UI bug — 매 silent no-op + log
|
||||
if from_id == to_id:
|
||||
logger.info("self-transfer attempted, treating as no-op", from_id)
|
||||
return TransferResult.skipped()
|
||||
```
|
||||
|
||||
### Sarcasm/Idiom Detection (NLP)
|
||||
```python
|
||||
import torch
|
||||
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
||||
|
||||
# 매 caetextia model 의 자동화 X — 매 NLP 의 sarcasm classifier 의 사용
|
||||
tok = AutoTokenizer.from_pretrained("helinivan/english-sarcasm-detector")
|
||||
model = AutoModelForSequenceClassification.from_pretrained("helinivan/english-sarcasm-detector")
|
||||
|
||||
def is_sarcastic(text: str) -> bool:
|
||||
inputs = tok(text, return_tensors="pt", truncation=True)
|
||||
logits = model(**inputs).logits
|
||||
return torch.argmax(logits).item() == 1
|
||||
```
|
||||
|
||||
### Contract-First API Design (caetextia-friendly)
|
||||
```typescript
|
||||
// 매 explicit precondition — 매 ambiguity 의 elimination
|
||||
type TransferInput = {
|
||||
readonly amount: Money & { __brand: 'positive' };
|
||||
readonly from: AccountId;
|
||||
readonly to: AccountId & { __brand: 'different-from-from' };
|
||||
readonly idempotencyKey: string;
|
||||
};
|
||||
|
||||
// 매 type-level enforcement — 매 caller 의 intent 의 disambiguate
|
||||
function transfer(input: TransferInput): Promise<Result<TransferOk, TransferErr>>;
|
||||
```
|
||||
|
||||
### Workplace Accommodation Checklist
|
||||
```yaml
|
||||
# 매 caetextia-aware engineering team practices
|
||||
communication:
|
||||
- explicit_written_specs: required
|
||||
- meeting_agenda: shared 24h ahead
|
||||
- sarcasm_in_slack: marked /s or emoji
|
||||
- decision_documentation: ADR mandatory
|
||||
code_review:
|
||||
- use_explicit_blocking_vs_nit_tags
|
||||
- link_to_design_doc_for_context
|
||||
focus:
|
||||
- deep_work_blocks: 4hr no-meeting windows
|
||||
- notification_batching: 2x/day
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Spec 의 ambiguity | Disambiguate explicitly — 매 caetextia 의 friendly |
|
||||
| Sarcasm-heavy team comm | Add /s markers + async-text 우선 |
|
||||
| Code review | Tag blocking vs. nit explicitly |
|
||||
| Onboarding | Written runbook + ADR archive |
|
||||
| Brainstorm session | Async written round 1 → sync round 2 |
|
||||
|
||||
**기본값**: 매 explicit > implicit communication, 매 written > verbal context.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Neurodiversity]]
|
||||
- 변형: [[Weak Central Coherence]]
|
||||
- Adjacent: [[Theory of Mind]] · [[Pragmatics]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 spec disambiguation, 매 sarcasm/idiom annotation, 매 written-context expansion 의 ambiguous chat.
|
||||
**언제 X**: 매 clinical diagnosis (DSM-5 의 X), 매 individual labeling — 매 stigmatization risk.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Pop-psych labeling**: 매 colleague 의 "caetextic" 의 stigma — 매 framework 의 misuse.
|
||||
- **Binary classification**: 매 spectrum 의 reality 의 ignore.
|
||||
- **Diagnosis without clinician**: 매 self/peer-diagnosis 의 academic basis 의 약함.
|
||||
- **Conflating with autism**: 매 caetextia ≠ autism — 매 partial overlap only.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Griffin & Tyrrell, _Human Givens Approach_ 2008; Vermeulen _Autism as Context Blindness_ 2012).
|
||||
- 신뢰도 B (niche framework, not mainstream DSM).
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Caetextia framework + engineering applications + caveats |
|
||||
@@ -0,0 +1,148 @@
|
||||
---
|
||||
id: wiki-2026-0508-chaos-theory-in-systems
|
||||
title: Chaos Theory in Systems
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Deterministic Chaos, Nonlinear Dynamics, Sensitive Dependence]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [dynamical-systems, mathematics, distributed-systems, simulation]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python/NumPy/SciPy
|
||||
framework: scipy.integrate
|
||||
---
|
||||
|
||||
# Chaos Theory in Systems
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 deterministic 이지만 매 unpredictable"**. Lorenz 1963 weather model 의 butterfly effect — 매 sensitive dependence on initial conditions. 매 distributed systems / ML training / financial modeling 의 매 ubiquitous. 매 2026 의 매 Lyapunov-aware stress testing + chaos engineering (Netflix Chaos Monkey lineage) 의 mainstream.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Three properties (Devaney definition)
|
||||
- **Sensitive dependence**: 매 ε perturbation 의 exponential divergence — 매 Lyapunov exponent λ > 0.
|
||||
- **Topological transitivity**: 매 any neighborhood 의 매 trajectory 의 visits 모든 region.
|
||||
- **Dense periodic orbits**: 매 periodic points 의 dense in phase space.
|
||||
|
||||
### 매 Canonical 시스템
|
||||
- **Lorenz attractor**: dx/dt = σ(y-x), dy/dt = x(ρ-z)-y, dz/dt = xy-βz.
|
||||
- **Logistic map**: x_{n+1} = r·x_n·(1-x_n) — 매 r > 3.57 의 chaos.
|
||||
- **Double pendulum**: 매 mechanical chaos 의 textbook.
|
||||
- **Hénon map**: 매 2D discrete chaos.
|
||||
|
||||
### 매 Engineering 응용
|
||||
1. **Chaos engineering**: 매 production failure injection — 매 Netflix/AWS Fault Injection Service.
|
||||
2. **Cryptographic PRNG seeds**: 매 chaotic map 의 entropy source.
|
||||
3. **Distributed system jitter**: 매 thundering herd 의 randomized backoff.
|
||||
4. **Neural network training**: 매 loss landscape 의 chaotic regime detection.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Lorenz Integration (NumPy)
|
||||
```python
|
||||
import numpy as np
|
||||
from scipy.integrate import solve_ivp
|
||||
|
||||
def lorenz(t, state, sigma=10, rho=28, beta=8/3):
|
||||
x, y, z = state
|
||||
return [sigma * (y - x), x * (rho - z) - y, x * y - beta * z]
|
||||
|
||||
sol = solve_ivp(lorenz, (0, 40), [1.0, 1.0, 1.0],
|
||||
t_eval=np.linspace(0, 40, 10000), rtol=1e-9)
|
||||
# 매 second trajectory 의 ε perturbation
|
||||
sol2 = solve_ivp(lorenz, (0, 40), [1.0 + 1e-8, 1.0, 1.0],
|
||||
t_eval=sol.t, rtol=1e-9)
|
||||
divergence = np.linalg.norm(sol.y - sol2.y, axis=0)
|
||||
# divergence 의 exponential 증가 — 매 butterfly effect
|
||||
```
|
||||
|
||||
### Lyapunov Exponent Estimation
|
||||
```python
|
||||
def largest_lyapunov(traj_a, traj_b, dt):
|
||||
eps0 = np.linalg.norm(traj_a[:, 0] - traj_b[:, 0])
|
||||
eps_t = np.linalg.norm(traj_a - traj_b, axis=0)
|
||||
lam = np.mean(np.log(eps_t[1:] / eps0)) / (dt * len(eps_t))
|
||||
return lam # > 0 → chaotic
|
||||
```
|
||||
|
||||
### Logistic Map Bifurcation
|
||||
```python
|
||||
def logistic_orbit(r, x0=0.5, n=1000, discard=500):
|
||||
x = x0
|
||||
for _ in range(discard):
|
||||
x = r * x * (1 - x)
|
||||
orbit = []
|
||||
for _ in range(n):
|
||||
x = r * x * (1 - x)
|
||||
orbit.append(x)
|
||||
return orbit
|
||||
# r=2.9 → fixed point; r=3.5 → period-4; r=3.9 → chaos
|
||||
```
|
||||
|
||||
### Chaos Engineering — Latency Injection
|
||||
```python
|
||||
import random, asyncio
|
||||
|
||||
async def chaos_middleware(handler, prob=0.05, max_delay_ms=2000):
|
||||
if random.random() < prob:
|
||||
delay = random.expovariate(1 / max_delay_ms) / 1000
|
||||
await asyncio.sleep(delay)
|
||||
if random.random() < 0.01:
|
||||
raise ConnectionResetError("chaos: simulated network failure")
|
||||
return await handler()
|
||||
```
|
||||
|
||||
### Decorrelated Jitter (AWS pattern)
|
||||
```python
|
||||
def decorrelated_jitter(prev: float, base: float = 0.1, cap: float = 30.0) -> float:
|
||||
# 매 thundering herd 방지 — 매 chaos-inspired backoff
|
||||
return min(cap, random.uniform(base, prev * 3))
|
||||
```
|
||||
|
||||
### Strange Attractor Reconstruction (Takens embedding)
|
||||
```python
|
||||
def takens_embed(series, m=3, tau=1):
|
||||
n = len(series) - (m - 1) * tau
|
||||
return np.array([series[i:i + m * tau:tau] for i in range(n)])
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Long-horizon weather/finance prediction | 매 ensemble + 매 horizon limit |
|
||||
| Distributed system retry | Decorrelated jitter (chaotic) |
|
||||
| Production resilience | Chaos engineering (Litmus/Gremlin) |
|
||||
| Periodic dynamics | Linear analysis 충분 — 매 chaos theory X |
|
||||
| ML loss instability | Lyapunov-style divergence detection |
|
||||
|
||||
**기본값**: 매 nonlinear coupling 의 시스템 의 sensitivity analysis 우선.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Nonlinear Dynamics]]
|
||||
- 응용: [[Chaos Engineering]] · [[Stochastic Simulation]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 dynamical model 의 explanation, 매 simulation code generation, 매 chaos engineering policy authoring.
|
||||
**언제 X**: 매 long-term precise prediction (의 fundamental limit), 매 financial trading decisions 의 sole basis.
|
||||
|
||||
## 🤖 안티패턴
|
||||
- **Determinism = predictability**: 매 chaos 의 counterexample.
|
||||
- **Long-horizon point forecasts**: 매 Lyapunov horizon 의 violation.
|
||||
- **Ignoring numerical precision**: 매 single-precision 의 sensitive systems 의 silent error compounding.
|
||||
- **Conflating chaos with randomness**: 매 deterministic + bounded — 매 stochastic 와 different.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Lorenz 1963 _Deterministic Nonperiodic Flow_, Strogatz _Nonlinear Dynamics and Chaos_ 2nd ed).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Lorenz/Lyapunov/chaos engineering integrations |
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
---
|
||||
id: wiki-2026-0508-climate-change-mitigation-framew
|
||||
title: Climate Change Mitigation Frameworks
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Carbon Mitigation, Net Zero Frameworks, GHG Reduction]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [climate, sustainability, policy, carbon-accounting, esg]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: GHG Protocol / SBTi / TCFD
|
||||
---
|
||||
|
||||
# Climate Change Mitigation Frameworks
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 GHG emission 의 systematic reduction 의 standardized 방법론"**. 1992 UNFCCC → 2015 Paris Agreement → 2024 SBTi Corporate Net-Zero Standard 의 lineage. 매 2026 의 매 EU CSRD + SEC climate disclosure rule 의 의무화 — 매 software 회사 의 매 Scope 1/2/3 reporting 의 mandatory.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Major frameworks
|
||||
- **GHG Protocol**: 매 corporate accounting 의 de-facto — 매 Scope 1/2/3.
|
||||
- **SBTi (Science Based Targets initiative)**: 매 1.5°C-aligned reduction targets.
|
||||
- **TCFD → ISSB IFRS S2**: 매 financial disclosure standard.
|
||||
- **CDP**: 매 voluntary disclosure platform.
|
||||
- **Paris Agreement NDCs**: 매 national-level commitments.
|
||||
|
||||
### 매 Scope definitions
|
||||
- **Scope 1**: 매 direct emissions — 매 owned vehicles/boilers.
|
||||
- **Scope 2**: 매 purchased electricity/heat — 매 location-based vs market-based.
|
||||
- **Scope 3**: 매 value chain (15 categories) — 매 software 회사 의 95%+ 일반적.
|
||||
|
||||
### 매 Mitigation hierarchy
|
||||
1. **Avoid**: 매 emission 의 prevention — 매 highest priority.
|
||||
2. **Reduce**: 매 efficiency + clean energy switch.
|
||||
3. **Replace**: 매 high-carbon → low-carbon technology.
|
||||
4. **Offset**: 매 residual 의 removal — 매 last resort, quality-graded.
|
||||
|
||||
### 매 Software industry 응용
|
||||
- 매 cloud carbon footprint (Scope 3 cat. 1, 2).
|
||||
- 매 green coding practices — 매 Greensoft Foundation.
|
||||
- 매 carbon-aware computing — 매 workload shifting.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### GHG Inventory Calculator
|
||||
```python
|
||||
from dataclasses import dataclass
|
||||
from decimal import Decimal
|
||||
|
||||
@dataclass
|
||||
class Emission:
|
||||
scope: int # 1, 2, or 3
|
||||
category: str
|
||||
activity_data: Decimal # kWh, liters, km, etc.
|
||||
emission_factor: Decimal # kgCO2e per unit
|
||||
@property
|
||||
def co2e_kg(self) -> Decimal:
|
||||
return self.activity_data * self.emission_factor
|
||||
|
||||
inventory = [
|
||||
Emission(1, "natural_gas", Decimal("12000"), Decimal("0.184")), # m³ → kgCO2e
|
||||
Emission(2, "electricity_market_based", Decimal("450000"), Decimal("0.293")), # kWh
|
||||
Emission(3, "purchased_goods", Decimal("2_500_000"), Decimal("0.45")), # USD spend-based
|
||||
]
|
||||
total_tco2e = sum(e.co2e_kg for e in inventory) / 1000
|
||||
```
|
||||
|
||||
### Cloud Carbon Footprint (AWS example)
|
||||
```python
|
||||
import boto3, datetime
|
||||
ce = boto3.client("ce")
|
||||
res = ce.get_cost_and_usage(
|
||||
TimePeriod={"Start": "2026-04-01", "End": "2026-05-01"},
|
||||
Granularity="MONTHLY",
|
||||
Metrics=["UsageQuantity"],
|
||||
GroupBy=[{"Type": "DIMENSION", "Key": "REGION"}],
|
||||
)
|
||||
# 매 region 의 grid intensity 의 mapping
|
||||
GRID_INTENSITY = { # kgCO2e/kWh, 2025 IEA
|
||||
"us-east-1": 0.379, "eu-west-1": 0.295, "ap-northeast-1": 0.471,
|
||||
"eu-north-1": 0.041, # 매 Sweden — 매 cleanest
|
||||
}
|
||||
```
|
||||
|
||||
### SBTi Target Setting (1.5°C linear pathway)
|
||||
```python
|
||||
def sbti_pathway(base_year_emissions: float, base_year: int,
|
||||
target_year: int, sector: str = "general") -> dict:
|
||||
# 매 SBTi cross-sectoral absolute contraction approach (CSAA) 4.2% pa 1.5°C
|
||||
annual_rate = 0.042
|
||||
years = target_year - base_year
|
||||
target_emissions = base_year_emissions * (1 - annual_rate) ** years
|
||||
return {
|
||||
"base_year": base_year, "base_emissions_tCO2e": base_year_emissions,
|
||||
"target_year": target_year, "target_emissions_tCO2e": target_emissions,
|
||||
"reduction_pct": (1 - target_emissions / base_year_emissions) * 100,
|
||||
}
|
||||
# sbti_pathway(10000, 2020, 2030) → ~35% reduction
|
||||
```
|
||||
|
||||
### Carbon-Aware Workload Scheduler
|
||||
```python
|
||||
import requests
|
||||
|
||||
def get_grid_intensity_g_per_kwh(region: str) -> float:
|
||||
r = requests.get(f"https://api.electricitymap.org/v3/carbon-intensity/latest?zone={region}",
|
||||
headers={"auth-token": "..."})
|
||||
return r.json()["carbonIntensity"]
|
||||
|
||||
def schedule_batch_job(regions: list[str]) -> str:
|
||||
intensities = {r: get_grid_intensity_g_per_kwh(r) for r in regions}
|
||||
return min(intensities, key=intensities.get) # 매 cleanest grid 의 region
|
||||
```
|
||||
|
||||
### Marginal Abatement Cost Curve (MACC) data
|
||||
```python
|
||||
import pandas as pd
|
||||
macc = pd.DataFrame([
|
||||
{"measure": "LED lighting", "abatement_tCO2e": 200, "cost_per_t": -180},
|
||||
{"measure": "Solar PPA", "abatement_tCO2e": 1500, "cost_per_t": -25},
|
||||
{"measure": "Heat pump", "abatement_tCO2e": 400, "cost_per_t": 35},
|
||||
{"measure": "Direct air capture", "abatement_tCO2e": 100, "cost_per_t": 600},
|
||||
]).sort_values("cost_per_t")
|
||||
# 매 negative cost 의 measure 우선 (매 NPV positive)
|
||||
```
|
||||
|
||||
### TCFD Disclosure Skeleton
|
||||
```yaml
|
||||
governance:
|
||||
board_oversight: "Sustainability Committee, quarterly review"
|
||||
strategy:
|
||||
scenarios: [1.5C-NZE, 2C-IEA-APS, 3C-IEA-STEPS]
|
||||
transition_risks: [carbon-pricing, customer-preference]
|
||||
physical_risks: [datacenter-flooding, heat-cooling-load]
|
||||
risk_management:
|
||||
process: "ERM integrated, climate as material risk"
|
||||
metrics_targets:
|
||||
scope1_2_target: "50% reduction by 2030 vs 2020 (SBTi-validated)"
|
||||
scope3_target: "30% reduction by 2030 vs 2020"
|
||||
internal_carbon_price_usd_per_t: 75
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Framework |
|
||||
|---|---|
|
||||
| Public company, EU/SEC | TCFD/ISSB IFRS S2 (의무) |
|
||||
| Voluntary leadership | SBTi 1.5°C + CDP A-list |
|
||||
| Internal accounting | GHG Protocol Scope 1/2/3 |
|
||||
| Cloud/SaaS Scope 3 | Cloud Carbon Footprint (Thoughtworks) |
|
||||
| Project-level | MACC + ICP (internal carbon price) |
|
||||
|
||||
**기본값**: GHG Protocol inventory + SBTi target + TCFD disclosure trifecta.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[ESG]] · [[Sustainability]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 disclosure draft, 매 emission factor lookup, 매 MACC scenario synthesis, 매 carbon-aware code review.
|
||||
**언제 X**: 매 official SBTi target validation (의 third-party verifier 영역), 매 audited financial statement 의 final number.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Offset-only strategy**: 매 mitigation hierarchy 의 violation — 매 SBTi reject.
|
||||
- **Scope 3 의 무시**: 매 software company 의 95% emission 의 hidden.
|
||||
- **Spend-based factors only**: 매 directional only — 매 supplier-specific data 의 better.
|
||||
- **Greenwashing**: 매 verified target 의 X 의 marketing claim.
|
||||
- **Ignoring location-based vs market-based**: 매 dual-reporting 의 의무.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (GHG Protocol Corporate Standard, SBTi Net-Zero Standard v2 2024, IPCC AR6).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — GHG/SBTi/TCFD frameworks + carbon-aware computing patterns |
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
---
|
||||
id: wiki-2026-0508-cognitive-neuroscience-of-flow
|
||||
title: Cognitive Neuroscience of Flow
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Flow State, In the Zone, Optimal Experience]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.85
|
||||
verification_status: applied
|
||||
tags: [neuroscience, psychology, performance, attention, esports, gamedev]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: N/A
|
||||
framework: Csíkszentmihályi flow model / TAH (Transient Hypofrontality)
|
||||
---
|
||||
|
||||
# Cognitive Neuroscience of Flow
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 challenge-skill balance 의 매 optimal absorption state 의 neural signature"**. Csíkszentmihályi 1975 phenomenology → Dietrich 2003 transient hypofrontality (TAH) → 2020s fNIRS/EEG real-time detection. 매 2026 의 매 game design + esports training + productivity tooling 의 actionable framework.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 9 dimensions (Csíkszentmihályi)
|
||||
1. Challenge-skill balance (매 핵심 condition).
|
||||
2. Action-awareness merging.
|
||||
3. Clear goals.
|
||||
4. Unambiguous feedback.
|
||||
5. Concentration on task.
|
||||
6. Sense of control.
|
||||
7. Loss of self-consciousness.
|
||||
8. Time distortion.
|
||||
9. Autotelic experience.
|
||||
|
||||
### 매 Neural correlates (2026 consensus)
|
||||
- **Transient hypofrontality**: 매 dorsolateral prefrontal cortex (DLPFC) 의 일시적 감소 — 매 inner critic 의 quiet.
|
||||
- **Default Mode Network (DMN) 의 down-regulation**: 매 self-referential thinking 의 감소.
|
||||
- **Striatal dopamine**: 매 reward prediction + intrinsic motivation.
|
||||
- **Norepinephrine + endorphins**: 매 focused arousal.
|
||||
- **Theta-gamma coupling**: 매 hippocampus-cortex 의 memory binding.
|
||||
|
||||
### 매 Triggers (Kotler 17, condensed)
|
||||
- **Psychological**: clear goals, immediate feedback, challenge/skill ratio ~4% above current skill.
|
||||
- **Environmental**: high-consequence + rich-sensory + novelty.
|
||||
- **Social**: shared goal + close listening + flow contagion.
|
||||
- **Creative**: pattern recognition + risk.
|
||||
|
||||
### 매 Game Design 응용
|
||||
1. **Difficulty curves**: 매 dynamic difficulty adjustment (DDA) — 매 anxiety/boredom band 의 회피.
|
||||
2. **Feedback loops**: 매 hit-shake + audio cue + score 의 sub-200ms response.
|
||||
3. **Goal hierarchy**: 매 short-term (combat) + long-term (campaign).
|
||||
4. **Cognitive load tuning**: 매 Hicks's law / 매 Miller 7±2 의 respect.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Real-Time Flow Detection (EEG features, Python)
|
||||
```python
|
||||
import numpy as np
|
||||
import mne
|
||||
|
||||
def flow_index(eeg_epoch, sfreq=256):
|
||||
# 매 frontal theta/alpha + parietal gamma — 매 flow proxy
|
||||
raw = mne.io.RawArray(eeg_epoch, mne.create_info(["Fz","Pz"], sfreq, "eeg"))
|
||||
psd, freqs = mne.time_frequency.psd_array_welch(eeg_epoch, sfreq, fmin=1, fmax=50)
|
||||
theta = psd[:, (freqs>=4)&(freqs<=8)].mean()
|
||||
alpha = psd[:, (freqs>=8)&(freqs<=13)].mean()
|
||||
gamma = psd[:, (freqs>=30)&(freqs<=45)].mean()
|
||||
# 매 frontal theta 의 elevated + alpha 의 reduced + gamma 의 elevated
|
||||
return (theta * gamma) / (alpha + 1e-6)
|
||||
```
|
||||
|
||||
### Dynamic Difficulty Adjustment (DDA)
|
||||
```python
|
||||
class FlowChannelDDA:
|
||||
def __init__(self, target_winrate=0.55, alpha=0.05):
|
||||
self.skill_estimate = 1500 # Elo-like
|
||||
self.target = target_winrate
|
||||
self.alpha = alpha
|
||||
self.difficulty = 1500
|
||||
def update(self, won: bool):
|
||||
observed = 1.0 if won else 0.0
|
||||
error = observed - self.target
|
||||
self.difficulty += self.alpha * error * 100
|
||||
# 매 challenge ~4% above skill — 매 flow band
|
||||
self.difficulty = self.skill_estimate + 60 + np.random.normal(0, 20)
|
||||
```
|
||||
|
||||
### Flow State Survey (Flow Short Scale, Rheinberg)
|
||||
```python
|
||||
fss_items = [ # 1-7 Likert
|
||||
"I felt just the right amount of challenge",
|
||||
"My thoughts ran fluidly and smoothly",
|
||||
"I didn't notice time passing",
|
||||
"I had no difficulty concentrating",
|
||||
"I felt in control of the situation",
|
||||
# ... 13 items total
|
||||
]
|
||||
def fss_score(responses: list[int]) -> dict:
|
||||
fluency = np.mean(responses[:6])
|
||||
absorption = np.mean(responses[6:10])
|
||||
return {"flow": (fluency + absorption) / 2, "fluency": fluency, "absorption": absorption}
|
||||
```
|
||||
|
||||
### Latency Budget for Flow (game loop)
|
||||
```cpp
|
||||
// 매 input → visual feedback budget — 매 flow 보존
|
||||
constexpr int INPUT_TO_FRAME_MS = 16; // 1 frame @60Hz
|
||||
constexpr int AUDIO_CUE_MS = 50; // 매 perceived immediate
|
||||
constexpr int HAPTIC_MS = 80;
|
||||
constexpr int TOTAL_BUDGET_MS = 100; // 매 above 의 magic 깨짐
|
||||
static_assert(INPUT_TO_FRAME_MS + AUDIO_CUE_MS <= TOTAL_BUDGET_MS);
|
||||
```
|
||||
|
||||
### Productivity Flow Logger
|
||||
```python
|
||||
import time, json
|
||||
|
||||
class FlowSession:
|
||||
def __init__(self, task: str):
|
||||
self.task = task; self.start = time.time(); self.interruptions = 0
|
||||
def interrupt(self): self.interruptions += 1
|
||||
def end(self, self_report_flow: int):
|
||||
return {
|
||||
"task": self.task,
|
||||
"duration_min": (time.time() - self.start) / 60,
|
||||
"interruptions_per_hour": self.interruptions / ((time.time()-self.start)/3600),
|
||||
"flow_score": self_report_flow, # 1-7
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Game design difficulty | DDA targeting ~55% winrate |
|
||||
| Esports training | FSS post-scrim + fNIRS sessions |
|
||||
| Productivity tooling | Notification batching + Pomodoro 90min |
|
||||
| Team meetings | Block 4hr no-meeting flow windows |
|
||||
| Onboarding/Tutorial | Clear sub-goals + immediate feedback |
|
||||
|
||||
**기본값**: 매 challenge ≈ skill + 4%, 매 feedback < 200ms, 매 distraction-free 4hr blocks.
|
||||
|
||||
## 🔗 Graph
|
||||
- 응용: [[Game Design]] · [[Esports Training]] · [[Burnout Prevention in Professional Gaming]]
|
||||
- Adjacent: [[Default Mode Network]] · [[Dopamine]] · [[Attention]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 difficulty curve design, 매 flow-friendly UX critique, 매 productivity ritual 의 personalization.
|
||||
**언제 X**: 매 clinical neurofeedback 의 sole basis, 매 pharmacological intervention recommendation.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Over-rewarding**: 매 dopamine 의 dump 의 flow 의 anxiety 회피 — 매 short-term win, long-term burnout.
|
||||
- **Constant interruption tools**: 매 Slack red dot 의 flow 의 destruction.
|
||||
- **Difficulty 의 ceiling**: 매 challenge < skill 의 boredom — 매 disengagement.
|
||||
- **Difficulty spike**: 매 challenge ≫ skill 의 anxiety — 매 quitting.
|
||||
- **Gamification 의 misuse**: 매 extrinsic reward 의 over-emphasis — 매 autotelic 의 destroy.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Csíkszentmihályi 1990 _Flow_, Dietrich 2003 _Cognition_, Kotler _Stealing Fire_ 2017).
|
||||
- 신뢰도 A (mainstream scientific consensus, ongoing fMRI/fNIRS refinement).
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Flow neural correlates + DDA + EEG detection patterns |
|
||||
@@ -0,0 +1,212 @@
|
||||
---
|
||||
id: wiki-2026-0508-combinatorial-optimization
|
||||
title: Combinatorial Optimization
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Discrete Optimization, CO, Integer Programming]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [algorithms, optimization, np-hard, operations-research, ml]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python/C++
|
||||
framework: OR-Tools / Gurobi / SCIP / cvxpy
|
||||
---
|
||||
|
||||
# Combinatorial Optimization
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 finite discrete set 위 의 best-element 찾기"**. TSP/Knapsack/Scheduling 의 OR core — 매 1947 Dantzig simplex 부터 매 2026 Gurobi 12 + neural CO hybrid. 매 production 의 매 routing/scheduling/matching 의 ubiquitous — 매 Amazon delivery/Uber matching/airline crew scheduling.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Canonical 문제
|
||||
- **TSP** (Traveling Salesman): 매 NP-hard, 매 Concorde solver 의 84,000 cities 의 optimal.
|
||||
- **Knapsack**: 매 NP-hard, 매 weakly — 매 pseudo-polynomial DP O(nW).
|
||||
- **Set Cover / Vertex Cover**: 매 NP-hard, 매 LP rounding O(log n).
|
||||
- **Min-cost Flow / Bipartite Matching**: 매 P 의 polynomial.
|
||||
- **Job-Shop Scheduling**: 매 NP-hard, 매 CP-SAT 의 modern winner.
|
||||
|
||||
### 매 Solution 기법
|
||||
- **Exact**: branch-and-bound, branch-and-cut, dynamic programming.
|
||||
- **Approximation**: PTAS/FPTAS, LP relaxation + rounding, primal-dual.
|
||||
- **Heuristic**: greedy, local search, simulated annealing, genetic algorithms.
|
||||
- **Metaheuristic**: tabu search, ALNS, large-neighborhood search.
|
||||
- **Modern**: CP-SAT (Google OR-Tools), MIP solvers, neural CO (Pointer Net, GFlowNet).
|
||||
|
||||
### 매 Complexity classes
|
||||
- **P**: 매 Bipartite Matching (Hungarian O(n³)), Min Cut.
|
||||
- **NP-hard**: 매 TSP, ILP, Vertex Cover, Set Cover.
|
||||
- **APX-hard**: 매 Set Cover (no PTAS unless P=NP).
|
||||
- **APX**: 매 Vertex Cover (2-approx trivial).
|
||||
|
||||
### 매 응용
|
||||
1. **Vehicle routing (VRP)**: 매 Amazon Last Mile, UPS ORION.
|
||||
2. **Workforce scheduling**: 매 airline crew, hospital nurse rostering.
|
||||
3. **Bin packing**: 매 datacenter VM placement.
|
||||
4. **Matching markets**: 매 Uber rider-driver, kidney exchange.
|
||||
5. **Compiler register allocation**: 매 graph coloring.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Knapsack DP
|
||||
```python
|
||||
def knapsack_01(weights, values, capacity):
|
||||
n = len(weights)
|
||||
dp = [0] * (capacity + 1)
|
||||
for i in range(n):
|
||||
for w in range(capacity, weights[i] - 1, -1):
|
||||
dp[w] = max(dp[w], dp[w - weights[i]] + values[i])
|
||||
return dp[capacity]
|
||||
```
|
||||
|
||||
### Branch-and-Bound TSP
|
||||
```python
|
||||
import heapq, math
|
||||
|
||||
def tsp_bnb(dist):
|
||||
n = len(dist)
|
||||
best = math.inf
|
||||
heap = [(0, [0])] # (lower_bound, path)
|
||||
while heap:
|
||||
lb, path = heapq.heappop(heap)
|
||||
if lb >= best: continue
|
||||
if len(path) == n:
|
||||
cost = sum(dist[path[i]][path[i+1]] for i in range(n-1)) + dist[path[-1]][0]
|
||||
best = min(best, cost); continue
|
||||
for v in range(n):
|
||||
if v not in path:
|
||||
new_path = path + [v]
|
||||
cur = sum(dist[new_path[i]][new_path[i+1]] for i in range(len(new_path)-1))
|
||||
# 매 simple LB — 매 MST 의 better
|
||||
heapq.heappush(heap, (cur, new_path))
|
||||
return best
|
||||
```
|
||||
|
||||
### OR-Tools VRP (production scale)
|
||||
```python
|
||||
from ortools.constraint_solver import pywrapcp, routing_enums_pb2
|
||||
|
||||
def solve_vrp(distance_matrix, num_vehicles, depot=0):
|
||||
mgr = pywrapcp.RoutingIndexManager(len(distance_matrix), num_vehicles, depot)
|
||||
routing = pywrapcp.RoutingModel(mgr)
|
||||
|
||||
def dist_cb(i, j): return distance_matrix[mgr.IndexToNode(i)][mgr.IndexToNode(j)]
|
||||
transit_idx = routing.RegisterTransitCallback(dist_cb)
|
||||
routing.SetArcCostEvaluatorOfAllVehicles(transit_idx)
|
||||
|
||||
params = pywrapcp.DefaultRoutingSearchParameters()
|
||||
params.first_solution_strategy = routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC
|
||||
params.local_search_metaheuristic = routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH
|
||||
params.time_limit.seconds = 10
|
||||
return routing.SolveWithParameters(params)
|
||||
```
|
||||
|
||||
### CP-SAT Job-Shop Scheduling
|
||||
```python
|
||||
from ortools.sat.python import cp_model
|
||||
|
||||
def job_shop(jobs): # jobs[j] = [(machine, duration), ...]
|
||||
model = cp_model.CpModel()
|
||||
horizon = sum(d for j in jobs for _, d in j)
|
||||
tasks = {}
|
||||
for j_id, job in enumerate(jobs):
|
||||
for t_id, (m, d) in enumerate(job):
|
||||
start = model.NewIntVar(0, horizon, f"s_{j_id}_{t_id}")
|
||||
end = model.NewIntVar(0, horizon, f"e_{j_id}_{t_id}")
|
||||
interval = model.NewIntervalVar(start, d, end, f"i_{j_id}_{t_id}")
|
||||
tasks[(j_id, t_id)] = (start, end, interval, m)
|
||||
|
||||
machines = {}
|
||||
for (j, t), (s, e, i, m) in tasks.items(): machines.setdefault(m, []).append(i)
|
||||
for m, ivs in machines.items(): model.AddNoOverlap(ivs)
|
||||
|
||||
for j_id, job in enumerate(jobs):
|
||||
for t in range(len(job) - 1):
|
||||
model.Add(tasks[(j_id, t+1)][0] >= tasks[(j_id, t)][1])
|
||||
|
||||
makespan = model.NewIntVar(0, horizon, "makespan")
|
||||
model.AddMaxEquality(makespan, [tasks[(j, len(jobs[j])-1)][1] for j in range(len(jobs))])
|
||||
model.Minimize(makespan)
|
||||
solver = cp_model.CpSolver()
|
||||
solver.parameters.max_time_in_seconds = 30
|
||||
return solver.Solve(model)
|
||||
```
|
||||
|
||||
### Simulated Annealing TSP
|
||||
```python
|
||||
import random, math
|
||||
|
||||
def sa_tsp(dist, iters=100000, T0=10.0, alpha=0.9999):
|
||||
n = len(dist)
|
||||
cur = list(range(n)); random.shuffle(cur)
|
||||
def cost(p): return sum(dist[p[i]][p[(i+1)%n]] for i in range(n))
|
||||
cc = cost(cur); best, bc = cur[:], cc; T = T0
|
||||
for _ in range(iters):
|
||||
i, j = sorted(random.sample(range(n), 2))
|
||||
new = cur[:i] + cur[i:j+1][::-1] + cur[j+1:]
|
||||
nc = cost(new)
|
||||
if nc < cc or random.random() < math.exp((cc - nc) / T):
|
||||
cur, cc = new, nc
|
||||
if cc < bc: best, bc = cur[:], cc
|
||||
T *= alpha
|
||||
return best, bc
|
||||
```
|
||||
|
||||
### LP Relaxation + Rounding (Set Cover)
|
||||
```python
|
||||
import cvxpy as cp
|
||||
import numpy as np
|
||||
|
||||
def set_cover_lp(sets, universe):
|
||||
n, m = len(sets), len(universe)
|
||||
x = cp.Variable(n, nonneg=True)
|
||||
constraints = []
|
||||
for u in universe:
|
||||
constraints.append(sum(x[i] for i, s in enumerate(sets) if u in s) >= 1)
|
||||
cp.Problem(cp.Minimize(sum(x)), constraints).solve()
|
||||
# 매 randomized rounding — 매 O(log n) approximation
|
||||
return [i for i in range(n) if np.random.random() < min(1, x.value[i] * np.log(m))]
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 문제 size | Approach |
|
||||
|---|---|
|
||||
| n < 20 (TSP) | Brute force / DP held-karp O(n²·2ⁿ) |
|
||||
| n < 100 (TSP) | Branch-and-cut + MTZ formulation |
|
||||
| n > 1000 (TSP) | LKH heuristic / Concorde |
|
||||
| Scheduling | CP-SAT (OR-Tools) — 매 modern winner |
|
||||
| Real-time matching | Hungarian / auction algorithm |
|
||||
| ILP general | Gurobi/CPLEX > SCIP > CBC |
|
||||
|
||||
**기본값**: 매 OR-Tools (CP-SAT) 의 free + production-grade.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Optimization]] · [[Operations Research]]
|
||||
- 변형: [[Linear Programming]] · [[Integer Programming]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 problem-to-formulation translation, 매 OR-Tools/Gurobi code scaffold, 매 constraint reformulation 의 brainstorm.
|
||||
**언제 X**: 매 large-scale numerical solving (의 dedicated solver 영역), 매 verified optimal proof.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Hand-rolled greedy 의 production**: 매 OR-Tools 의 90% 의 better 의 거의 모든 case.
|
||||
- **ILP everywhere**: 매 LP relaxation feasible 의 fast solve 의 missing.
|
||||
- **No warm-start**: 매 incremental re-solve 의 1000x speedup 의 missing.
|
||||
- **Ignoring problem structure**: 매 specialized algorithm (Hungarian, Held-Karp) 의 generic ILP 의 better.
|
||||
- **Exact 의 over-pursuit**: 매 NP-hard 의 1% gap 의 충분 의 99% case.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Cook _In Pursuit of TSP_, Schrijver _Combinatorial Optimization_, Wolsey _Integer Programming_).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — DP/B&B/CP-SAT/SA/LP-rounding patterns |
|
||||
@@ -0,0 +1,139 @@
|
||||
---
|
||||
id: wiki-2026-0508-computer-science-and-theory
|
||||
title: Computer Science and Theory
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [CS Theory, TCS, Theoretical Computer Science]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [index, theory, foundation, computability, complexity]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: N/A
|
||||
framework: index
|
||||
---
|
||||
|
||||
# Computer Science and Theory
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 computation 의 fundamental limits + structures 의 systematic study"**. Turing 1936 → Church-Turing thesis → Cook-Levin 1971 NP-completeness → 2026 quantum supremacy + post-ML complexity. 매 folder 의 매 index — 매 child topics 의 navigation hub.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Pillars
|
||||
- **Computability**: 매 무엇이 computable 인가 — 매 Turing machine, halting problem.
|
||||
- **Complexity**: 매 얼마나 efficient 인가 — 매 P/NP/PSPACE/EXPTIME/BQP.
|
||||
- **Algorithms**: 매 specific computational procedures — 매 design + analysis.
|
||||
- **Logic & Formal Languages**: 매 syntax/semantics — 매 Chomsky hierarchy.
|
||||
- **Information Theory**: 매 entropy, coding, compression bounds.
|
||||
- **Cryptography Theory**: 매 reduction-based security, OWF.
|
||||
|
||||
### 매 Subdomain map
|
||||
1. **Algorithms & Data Structures**: sorting, graphs, DP, randomized.
|
||||
2. **Combinatorial Optimization**: TSP, scheduling, matching.
|
||||
3. **Dynamical Systems**: chaos, control theory, stability.
|
||||
4. **Theory of Computation**: automata, decidability, complexity classes.
|
||||
5. **Type Theory**: simply-typed lambda, dependent types, HoTT.
|
||||
6. **Quantum Information**: BQP, qubits, error correction.
|
||||
|
||||
### 매 응용 bridge
|
||||
- 매 cryptography ← 매 complexity (OWF, hash functions).
|
||||
- 매 ML theory ← 매 PAC learning, VC dimension, generalization bounds.
|
||||
- 매 distributed systems ← 매 FLP impossibility, consensus lower bounds.
|
||||
- 매 compilers ← 매 type theory, automata, lambda calculus.
|
||||
- 매 databases ← 매 query complexity, join algorithms.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Folder Sub-topics (representative)
|
||||
| Topic | Type |
|
||||
|---|---|
|
||||
| Bubble Sort | Algorithm — sorting |
|
||||
| Combinatorial Optimization | Algorithm — discrete |
|
||||
| Chaos Theory in Systems | Dynamical systems |
|
||||
| Control Theory | Dynamical systems |
|
||||
| Cross-Frequency Coupling | Neural information theory |
|
||||
| Caetextia | Cognitive theory |
|
||||
| Burnout Prevention in Professional Gaming | Applied cognitive |
|
||||
| Climate Change Mitigation Frameworks | Applied modeling |
|
||||
|
||||
### Index Page Convention
|
||||
```yaml
|
||||
purpose: navigate child topics in this folder
|
||||
canonical_id: self
|
||||
duplicate_of: none
|
||||
content:
|
||||
- 매 한 줄: domain summary
|
||||
- 매 핵심: pillars + subdomains
|
||||
- 매 패턴: child topic listing
|
||||
- 🔗 Graph: parent index + sibling folders
|
||||
```
|
||||
|
||||
### Cross-Folder Bridge Pattern
|
||||
```markdown
|
||||
## Parent index
|
||||
- [[10_Wiki Index]] · [[Programming Index]]
|
||||
## Sibling folders (Topics/)
|
||||
- [[AI_and_ML]] · [[Architecture]] · [[DevOps_and_Security]]
|
||||
- [[Cognitive_Science_and_Neuroscience]] · [[Frontend]] · [[Backend]]
|
||||
```
|
||||
|
||||
### Complexity Cheat Sheet
|
||||
```text
|
||||
P ⊆ NP ⊆ PSPACE ⊆ EXPTIME
|
||||
P ⊆ BPP ⊆ BQP ⊆ PP ⊆ PSPACE
|
||||
NP — verifiable in poly-time
|
||||
NP-complete — TSP, SAT, 3-COLOR, Knapsack (decision)
|
||||
NP-hard ∩ EXP — Halting (undecidable)
|
||||
```
|
||||
|
||||
### Theory → Practice Mapping
|
||||
```yaml
|
||||
theory_to_practice:
|
||||
- {theory: NP-completeness, practice: "use heuristics + approximation"}
|
||||
- {theory: P=NP open, practice: "assume P≠NP for crypto"}
|
||||
- {theory: FLP impossibility, practice: "consensus needs partial sync (Raft/Paxos)"}
|
||||
- {theory: CAP theorem, practice: "pick 2: CP or AP under partition"}
|
||||
- {theory: PCP theorem, practice: "hardness of approximation results"}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| Question | Direction |
|
||||
|---|---|
|
||||
| Sort/search basics | Algorithms & Data Structures |
|
||||
| Discrete optimization | Combinatorial Optimization |
|
||||
| System stability | Control Theory / Chaos |
|
||||
| Compiler/PL design | Type Theory / Lambda Calculus |
|
||||
| Crypto foundations | Complexity / Number Theory |
|
||||
| Distributed system limits | Theory of Distributed Computing |
|
||||
|
||||
**기본값**: 매 child topic 의 specific 의 navigate — 매 index 의 entry point only.
|
||||
|
||||
## 🔗 Graph
|
||||
- 자식: [[Bubble Sort]] · [[Combinatorial Optimization]] · [[Chaos Theory in Systems]] · [[Control Theory]] · [[Caetextia]] · [[Cognitive Neuroscience of Flow]] · [[Cross-Frequency Coupling (CFC)]] · [[Climate Change Mitigation Frameworks]] · [[Burnout Prevention in Professional Gaming]]
|
||||
- Sibling 폴더: [[Architecture]] · [[DevOps_and_Security]]
|
||||
- Adjacent: [[Entropy in Information Theory|Information Theory]] · [[Logic]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 navigation hub — 매 child topic 의 discovery.
|
||||
**언제 X**: 매 specific algorithm content — 매 child page 의 redirect.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Index 의 deep content**: 매 child page 의 duplicate — 매 stale risk.
|
||||
- **Stale child link**: 매 deleted/moved page 의 broken wikilink.
|
||||
- **Mixed scope**: 매 index 의 specific application 의 mix — 매 child page 의 belong.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (folder taxonomy 의 cross-checked, child pages exist).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — folder index with child taxonomy + theory-practice mapping |
|
||||
@@ -0,0 +1,200 @@
|
||||
---
|
||||
id: wiki-2026-0508-control-theory
|
||||
title: Control Theory
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Feedback Control, Cybernetics, Automatic Control]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [control, feedback, dynamical-systems, robotics, distributed-systems]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python/MATLAB/C++
|
||||
framework: scipy.signal / control / Drake
|
||||
---
|
||||
|
||||
# Control Theory
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 system output 의 desired trajectory 의 driving 의 feedback law 설계"**. Watt centrifugal governor (1788) → Wiener cybernetics (1948) → Kalman state-space (1960) → 2026 MPC + neural-augmented control. 매 robotics/aerospace + 매 distributed systems (TCP congestion, autoscaling, DB connection pool) 의 unified framework.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Control taxonomy
|
||||
- **Open-loop**: 매 feedback X — 매 disturbance 의 fragile.
|
||||
- **Closed-loop**: 매 measurement → error → adjust — 매 robust.
|
||||
- **PID**: 매 industry workhorse — 매 95% controllers in field.
|
||||
- **State-space**: 매 multi-input/multi-output (MIMO) — 매 Kalman/LQR.
|
||||
- **MPC** (Model Predictive Control): 매 optimization-based — 매 Tesla autopilot, ABB.
|
||||
- **Adaptive/Robust**: 매 H∞, gain scheduling — 매 plant uncertainty.
|
||||
- **Reinforcement learning**: 매 model-free policy — 매 simulator-trained.
|
||||
|
||||
### 매 PID 분해
|
||||
- **P (proportional)**: 매 current error 의 비례 — 매 stiffness.
|
||||
- **I (integral)**: 매 accumulated error 의 누적 — 매 steady-state offset 의 elimination.
|
||||
- **D (derivative)**: 매 error rate 의 — 매 damping (overshoot 감소).
|
||||
|
||||
### 매 Stability
|
||||
- **Lyapunov stability**: V(x) > 0, V̇(x) < 0 → asymptotic.
|
||||
- **Routh-Hurwitz**: 매 polynomial coefficient 의 root location 검사.
|
||||
- **Bode/Nyquist**: 매 frequency-domain phase/gain margin.
|
||||
- **Pole placement**: 매 closed-loop pole 의 LHP 의 위치.
|
||||
|
||||
### 매 응용
|
||||
1. **Robotics**: 매 manipulator joint control, drone attitude.
|
||||
2. **Datacenter**: 매 autoscaling (PID on queue depth), thermal control.
|
||||
3. **Networking**: 매 TCP cubic, BBR — 매 congestion control as control problem.
|
||||
4. **DB**: 매 connection pool sizing, adaptive query throttling.
|
||||
5. **Game AI**: 매 NPC steering (Reynolds), camera follow.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### PID Controller (basic)
|
||||
```python
|
||||
class PID:
|
||||
def __init__(self, kp, ki, kd, dt, output_clip=(None, None)):
|
||||
self.kp, self.ki, self.kd, self.dt = kp, ki, kd, dt
|
||||
self.integral = 0.0; self.prev_error = 0.0
|
||||
self.lo, self.hi = output_clip
|
||||
def step(self, setpoint, measurement):
|
||||
error = setpoint - measurement
|
||||
self.integral += error * self.dt
|
||||
derivative = (error - self.prev_error) / self.dt
|
||||
u = self.kp*error + self.ki*self.integral + self.kd*derivative
|
||||
self.prev_error = error
|
||||
if self.lo is not None: u = max(self.lo, u)
|
||||
if self.hi is not None: u = min(self.hi, u)
|
||||
return u
|
||||
```
|
||||
|
||||
### Anti-Windup PID (production)
|
||||
```python
|
||||
class PIDAntiWindup(PID):
|
||||
def step(self, setpoint, measurement):
|
||||
error = setpoint - measurement
|
||||
derivative = (error - self.prev_error) / self.dt
|
||||
u_unclamped = self.kp*error + self.ki*self.integral + self.kd*derivative
|
||||
u = u_unclamped
|
||||
if self.lo is not None: u = max(self.lo, u)
|
||||
if self.hi is not None: u = min(self.hi, u)
|
||||
# 매 saturation 의 integral 의 stop — 매 windup 방지
|
||||
if u == u_unclamped:
|
||||
self.integral += error * self.dt
|
||||
self.prev_error = error
|
||||
return u
|
||||
```
|
||||
|
||||
### LQR (Linear Quadratic Regulator)
|
||||
```python
|
||||
import numpy as np
|
||||
import scipy.linalg as la
|
||||
|
||||
def lqr(A, B, Q, R):
|
||||
# 매 minimize ∫ x'Qx + u'Ru dt subject to ẋ = Ax + Bu
|
||||
P = la.solve_continuous_are(A, B, Q, R)
|
||||
K = np.linalg.solve(R, B.T @ P)
|
||||
return K # u = -Kx
|
||||
```
|
||||
|
||||
### Kalman Filter
|
||||
```python
|
||||
class KalmanFilter:
|
||||
def __init__(self, A, B, H, Q, R, x0, P0):
|
||||
self.A, self.B, self.H, self.Q, self.R = A, B, H, Q, R
|
||||
self.x, self.P = x0, P0
|
||||
def predict(self, u):
|
||||
self.x = self.A @ self.x + self.B @ u
|
||||
self.P = self.A @ self.P @ self.A.T + self.Q
|
||||
def update(self, z):
|
||||
S = self.H @ self.P @ self.H.T + self.R
|
||||
K = self.P @ self.H.T @ np.linalg.inv(S)
|
||||
self.x += K @ (z - self.H @ self.x)
|
||||
self.P = (np.eye(len(self.x)) - K @ self.H) @ self.P
|
||||
```
|
||||
|
||||
### Autoscaler as PID Controller
|
||||
```python
|
||||
# 매 distributed system 의 control-theory 적용
|
||||
class PIDAutoscaler:
|
||||
def __init__(self, target_p99_ms=100, kp=0.05, ki=0.001, kd=0.5):
|
||||
self.target = target_p99_ms
|
||||
self.pid = PIDAntiWindup(kp, ki, kd, dt=10.0, output_clip=(2, 200))
|
||||
def desired_replicas(self, current_replicas, observed_p99_ms):
|
||||
# 매 latency 의 setpoint 위로 → 매 replicas 의 추가
|
||||
delta = self.pid.step(self.target, observed_p99_ms) * -1 # invert sign
|
||||
return max(2, round(current_replicas + delta))
|
||||
```
|
||||
|
||||
### MPC Skeleton (cvxpy)
|
||||
```python
|
||||
import cvxpy as cp
|
||||
|
||||
def mpc_step(A, B, x0, Q, R, N=10, x_ref=None):
|
||||
nx, nu = A.shape[0], B.shape[1]
|
||||
x = cp.Variable((nx, N + 1))
|
||||
u = cp.Variable((nu, N))
|
||||
cost, cons = 0, [x[:, 0] == x0]
|
||||
x_ref = np.zeros(nx) if x_ref is None else x_ref
|
||||
for k in range(N):
|
||||
cost += cp.quad_form(x[:, k] - x_ref, Q) + cp.quad_form(u[:, k], R)
|
||||
cons += [x[:, k + 1] == A @ x[:, k] + B @ u[:, k]]
|
||||
cons += [cp.norm(u[:, k], "inf") <= 1.0] # control limit
|
||||
cp.Problem(cp.Minimize(cost), cons).solve()
|
||||
return u.value[:, 0] # 매 first action only — 매 receding horizon
|
||||
```
|
||||
|
||||
### Bode Stability Margin
|
||||
```python
|
||||
from scipy import signal
|
||||
|
||||
def stability_margins(num, den):
|
||||
sys = signal.TransferFunction(num, den)
|
||||
w, mag, phase = signal.bode(sys)
|
||||
# gain margin: phase = -180° 의 frequency 에서 1/|G|
|
||||
# phase margin: |G| = 1 의 frequency 에서 phase + 180°
|
||||
return {"bode": (w, mag, phase)}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 시스템 | Approach |
|
||||
|---|---|
|
||||
| SISO, slow | PID (anti-windup + clamp) |
|
||||
| MIMO, linear | LQR + Kalman |
|
||||
| Constraints + nonlinear | MPC |
|
||||
| Plant unknown | RL or adaptive control |
|
||||
| Distributed scaling | PID on metric (queue/p99) |
|
||||
| Game AI steering | PD (no integral, snappy) |
|
||||
|
||||
**기본값**: 매 PID + anti-windup — 매 production 의 80% case.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Cybernetics Foundations|Cybernetics]]
|
||||
- 변형: [[MPC]]
|
||||
- 응용: [[Robotics]]
|
||||
- Adjacent: [[Reinforcement Learning]] · [[Chaos Theory in Systems]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 PID gain 의 starting point suggestion, 매 state-space derivation, 매 controller code scaffold.
|
||||
**언제 X**: 매 safety-critical (avionics/medical) 의 final certification — 매 formal verification 영역.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **No anti-windup**: 매 saturated actuator 의 integral 의 explosion.
|
||||
- **No derivative filter**: 매 measurement noise 의 D term 의 amplification.
|
||||
- **Tuning without model**: 매 Ziegler-Nichols 의 marginal stability 의 risk.
|
||||
- **PID for highly nonlinear**: 매 gain scheduling 또는 MPC 의 더 적합.
|
||||
- **No anti-aliasing**: 매 fast dynamics 의 sample rate 의 violation.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Åström _Feedback Systems_ 2.5, Ogata _Modern Control_ 5e, Kalman 1960).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — PID/LQR/Kalman/MPC + autoscaler bridge |
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
---
|
||||
id: wiki-2026-0508-cross-frequency-coupling-cfc
|
||||
title: Cross Frequency Coupling (CFC)
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [CFC, Phase-Amplitude Coupling, PAC, Theta-Gamma Coupling]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.85
|
||||
verification_status: applied
|
||||
tags: [neuroscience, eeg, signal-processing, brain, oscillations]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: MNE-Python / tensorpac / scipy
|
||||
---
|
||||
|
||||
# Cross Frequency Coupling (CFC)
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 brain oscillation 의 매 multi-band interaction"**. Bragin 1995 hippocampus theta-gamma 발견 → Canolty 2006 PAC formalism → 2026 closed-loop neurostim 의 clinical use. 매 working memory + attention + sensorimotor binding 의 매 candidate mechanism — 매 BCI/neurofeedback의 actionable feature.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 CFC types
|
||||
- **Phase-Amplitude Coupling (PAC)**: 매 low-freq phase 의 high-freq amplitude 의 modulation — 매 most studied (theta phase × gamma amplitude).
|
||||
- **Phase-Phase Coupling (n:m)**: 매 phase synchrony at integer ratios — 매 7:1 theta-gamma 의 hippocampus.
|
||||
- **Amplitude-Amplitude Coupling**: 매 envelope co-fluctuation.
|
||||
- **Phase-Frequency Coupling**: 매 less common.
|
||||
|
||||
### 매 PAC 측정 metrics
|
||||
- **Modulation Index (MI, Tort 2010)**: 매 KL divergence — 매 가장 robust.
|
||||
- **Mean Vector Length (MVL, Canolty)**: 매 simpler, noise-sensitive.
|
||||
- **General Linear Model PAC (van Wijk)**: 매 statistical inference.
|
||||
- **Phase-Locking Value (PLV)**: 매 phase-phase only.
|
||||
|
||||
### 매 Functional roles
|
||||
- **Theta-Gamma (4-8 Hz × 30-100 Hz)**: 매 working memory chunking — 매 Lisman-Idiart 7±2 model.
|
||||
- **Alpha-Gamma (8-13 Hz × 30-100 Hz)**: 매 attention gating — 매 sensory selection.
|
||||
- **Delta-Beta (1-3 Hz × 13-30 Hz)**: 매 motor planning.
|
||||
- **Theta-Alpha**: 매 hippocampus-cortex coordination.
|
||||
|
||||
### 매 응용
|
||||
1. **BCI**: 매 PAC features 의 motor intent decoding — 매 SOTA 보다 +10% accuracy.
|
||||
2. **Neurofeedback**: 매 closed-loop modulation 의 ADHD/depression.
|
||||
3. **Sleep staging**: 매 SO-spindle coupling 의 NREM consolidation marker.
|
||||
4. **Anesthesia depth**: 매 alpha-delta PAC 의 monitoring.
|
||||
5. **Esports/flow detection**: 매 frontal theta-gamma 의 absorption marker.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Modulation Index (Tort 2010)
|
||||
```python
|
||||
import numpy as np
|
||||
from scipy.signal import hilbert, butter, filtfilt
|
||||
|
||||
def bandpass(sig, fs, low, high, order=4):
|
||||
b, a = butter(order, [low, high], btype="band", fs=fs)
|
||||
return filtfilt(b, a, sig)
|
||||
|
||||
def modulation_index(signal, fs, phase_band, amp_band, n_bins=18):
|
||||
phase_sig = bandpass(signal, fs, *phase_band)
|
||||
amp_sig = bandpass(signal, fs, *amp_band)
|
||||
phase = np.angle(hilbert(phase_sig))
|
||||
amp = np.abs(hilbert(amp_sig))
|
||||
|
||||
bins = np.linspace(-np.pi, np.pi, n_bins + 1)
|
||||
mean_amp = np.array([
|
||||
amp[(phase >= bins[i]) & (phase < bins[i+1])].mean()
|
||||
for i in range(n_bins)
|
||||
])
|
||||
p = mean_amp / mean_amp.sum()
|
||||
H = -np.sum(p * np.log(p + 1e-12))
|
||||
Hmax = np.log(n_bins)
|
||||
return (Hmax - H) / Hmax # MI ∈ [0, 1]
|
||||
```
|
||||
|
||||
### PAC Comodulogram (frequency-pair sweep)
|
||||
```python
|
||||
def comodulogram(signal, fs,
|
||||
phase_freqs=np.arange(2, 15, 1),
|
||||
amp_freqs=np.arange(20, 120, 5),
|
||||
bw_phase=2, bw_amp=10):
|
||||
co = np.zeros((len(phase_freqs), len(amp_freqs)))
|
||||
for i, fp in enumerate(phase_freqs):
|
||||
for j, fa in enumerate(amp_freqs):
|
||||
co[i, j] = modulation_index(
|
||||
signal, fs,
|
||||
(fp - bw_phase/2, fp + bw_phase/2),
|
||||
(fa - bw_amp/2, fa + bw_amp/2),
|
||||
)
|
||||
return phase_freqs, amp_freqs, co
|
||||
```
|
||||
|
||||
### Tensorpac (production library)
|
||||
```python
|
||||
from tensorpac import Pac
|
||||
import numpy as np
|
||||
|
||||
# 매 multi-trial PAC + surrogate statistics
|
||||
data = np.random.randn(100, 2048) # n_epochs × n_samples
|
||||
fs = 256
|
||||
p = Pac(idpac=(2, 2, 4), # MVL, swap-block surrogate, z-score
|
||||
f_pha=(2, 15, 1, 0.5), f_amp=(20, 120, 5, 5))
|
||||
phases = p.filter(fs, data, ftype="phase", n_jobs=4)
|
||||
amps = p.filter(fs, data, ftype="amplitude", n_jobs=4)
|
||||
xpac = p.fit(phases, amps) # n_amp × n_pha × n_epochs
|
||||
```
|
||||
|
||||
### Sleep SO-Spindle Coupling
|
||||
```python
|
||||
def so_spindle_coupling(eeg, fs=500):
|
||||
# 매 slow oscillation phase (0.5-1.25 Hz) × spindle amplitude (12-15 Hz)
|
||||
return modulation_index(eeg, fs, (0.5, 1.25), (12, 15))
|
||||
# 매 healthy young: MI ≈ 0.005-0.015; 매 elderly: 매 lower
|
||||
```
|
||||
|
||||
### Closed-Loop Phase-Triggered Stim
|
||||
```python
|
||||
import collections, time
|
||||
|
||||
class PhaseTriggeredStim:
|
||||
def __init__(self, fs, target_phase=0, tolerance=0.3):
|
||||
self.fs = fs; self.buf = collections.deque(maxlen=int(fs * 2))
|
||||
self.target = target_phase; self.tol = tolerance
|
||||
def push_sample(self, x):
|
||||
self.buf.append(x)
|
||||
if len(self.buf) < self.fs: return False
|
||||
sig = np.array(self.buf)
|
||||
theta = bandpass(sig, self.fs, 4, 8)
|
||||
cur_phase = np.angle(hilbert(theta))[-1]
|
||||
return abs(cur_phase - self.target) < self.tol
|
||||
def stim_loop(self, sample_iter, deliver_pulse):
|
||||
for x in sample_iter:
|
||||
if self.push_sample(x): deliver_pulse()
|
||||
```
|
||||
|
||||
### Statistical Significance via Surrogates
|
||||
```python
|
||||
def pac_zscore(signal, fs, phase_band, amp_band, n_perm=200):
|
||||
real = modulation_index(signal, fs, phase_band, amp_band)
|
||||
surr = []
|
||||
for _ in range(n_perm):
|
||||
shift = np.random.randint(fs, len(signal) - fs)
|
||||
s = np.concatenate([signal[shift:], signal[:shift]])
|
||||
surr.append(modulation_index(s, fs, phase_band, amp_band))
|
||||
return (real - np.mean(surr)) / np.std(surr)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| Use case | Approach |
|
||||
|---|---|
|
||||
| Single recording, exploration | Tort MI + comodulogram |
|
||||
| Multi-trial group stats | Tensorpac w/ surrogates + cluster perm |
|
||||
| Real-time BCI/stim | MVL (cheaper) + phase tracker |
|
||||
| Sleep research | SO-spindle MI + co-occurrence |
|
||||
| Tutorial/learning | Tort MI w/ 18 bins |
|
||||
|
||||
**기본값**: Tort 2010 MI + 200 surrogate permutations + cluster correction.
|
||||
|
||||
## 🔗 Graph
|
||||
- 변형: [[Phase-Amplitude Coupling]]
|
||||
- 응용: [[Brain-Computer Interface]] · [[Cognitive Neuroscience of Flow]]
|
||||
- Adjacent: [[Working Memory]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 PAC pipeline scaffold, 매 metric choice 의 explanation, 매 surrogate-test 의 reasoning.
|
||||
**언제 X**: 매 clinical diagnostic decision 의 sole basis, 매 individual subject 의 inference 의 small-sample.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **No surrogate test**: 매 spurious PAC 의 1/f noise + nonstationarity 의 false positive.
|
||||
- **Filter ringing artifact**: 매 narrow band + steep filter 의 phase distortion.
|
||||
- **Phase-amp band overlap**: 매 fp + bw/2 ≥ fa - bw/2 의 self-coupling artifact.
|
||||
- **Edge effects 무시**: 매 Hilbert transform 의 endpoint distortion.
|
||||
- **MVL alone**: 매 amplitude variance 의 confound — 매 MI 의 더 robust.
|
||||
- **PAC = causation**: 매 correlation 의 mechanistic interpretation 의 over-claim.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Tort et al. 2010 _J Neurophysiol_, Canolty & Knight 2010 _Trends Cogn Sci_, Aru et al. 2015 _Curr Opin Neurobiol_ pitfalls review).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Tort MI + comodulogram + closed-loop stim patterns |
|
||||
@@ -0,0 +1,160 @@
|
||||
---
|
||||
id: wiki-2026-0508-decision-theory
|
||||
title: Decision Theory
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [의사결정 이론, Choice Theory, Rational Choice]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
verification_status: applied
|
||||
tags: [decision-theory, expected-utility, bayesian, game-theory, RL]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: scipy/pymc
|
||||
---
|
||||
|
||||
# Decision Theory
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 rational choice = argmax_a E[U(outcome|a)]"**. 매 1944 von Neumann-Morgenstern 의 expected utility axiomatization 부터 매 2026 LLM agent 의 tool-use planning, RLHF reward modeling, 매 autonomous driving 의 risk-sensitive policy 까지 — 매 단일 framework 로 uncertainty 하 행동 선택 의 formalization.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 분류
|
||||
- **Normative**: 매 ideal rational agent 가 어떻게 결정해야 하는가 (EUT, Savage axioms).
|
||||
- **Descriptive**: 매 humans 가 실제로 어떻게 결정하는가 (prospect theory, bounded rationality).
|
||||
- **Prescriptive**: 매 humans 가 더 나은 결정을 위해 어떻게 도울 것인가 (decision support systems).
|
||||
|
||||
### 매 핵심 도구
|
||||
- **Expected Utility (EU)**: `EU(a) = Σ P(s) · U(s, a)`.
|
||||
- **Bayesian Decision Theory**: 매 prior + likelihood → posterior → decision.
|
||||
- **Minimax / Maximin**: 매 worst-case robustness.
|
||||
- **Pareto Optimality**: 매 multi-objective tradeoff frontier.
|
||||
- **Value of Information (VoI)**: 매 추가 데이터 수집의 expected gain.
|
||||
|
||||
### 매 응용
|
||||
1. **RL reward shaping**: 매 PPO/GRPO objective 의 expected return 매개변수화.
|
||||
2. **A/B test stopping rule**: 매 sequential Bayesian decision (BALD acquisition).
|
||||
3. **Medical triage**: 매 cost-sensitive classification 의 utility-weighted threshold.
|
||||
4. **LLM agent tool-use**: 매 ReAct planner 가 매 tool call 의 expected reward 비교.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Expected Utility 계산
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
def expected_utility(action, states, probs, utility_fn):
|
||||
"""E[U] = Σ P(s|a) · U(s, a)."""
|
||||
return sum(p * utility_fn(s, action) for s, p in zip(states, probs))
|
||||
|
||||
# Risk-averse: U(x) = log(x), Risk-neutral: U(x) = x
|
||||
actions = ['invest', 'save']
|
||||
states = [100, -20] # outcomes per action
|
||||
probs = {'invest': [0.6, 0.4], 'save': [1.0, 0.0]}
|
||||
log_utility = lambda s, a: np.log(s + 1000) # wealth-based
|
||||
|
||||
best = max(actions, key=lambda a: expected_utility(a, states, probs[a], log_utility))
|
||||
```
|
||||
|
||||
### Bayesian Posterior Decision
|
||||
```python
|
||||
import pymc as pm
|
||||
|
||||
with pm.Model() as model:
|
||||
theta = pm.Beta('theta', alpha=2, beta=2) # prior
|
||||
obs = pm.Binomial('obs', n=10, p=theta, observed=7)
|
||||
trace = pm.sample(2000, return_inferencedata=True)
|
||||
|
||||
posterior = trace.posterior['theta'].values.flatten()
|
||||
# Decision: launch if P(theta > 0.5) > 0.95
|
||||
launch = (posterior > 0.5).mean() > 0.95
|
||||
```
|
||||
|
||||
### Minimax Regret
|
||||
```python
|
||||
def minimax_regret(payoff_matrix):
|
||||
# Regret(a, s) = max_a' payoff(a', s) - payoff(a, s)
|
||||
best_per_state = payoff_matrix.max(axis=0)
|
||||
regret = best_per_state - payoff_matrix
|
||||
max_regret_per_action = regret.max(axis=1)
|
||||
return max_regret_per_action.argmin() # action minimizing max regret
|
||||
```
|
||||
|
||||
### Value of Information
|
||||
```python
|
||||
def value_of_information(prior_decision_eu, posterior_decision_eu, info_cost):
|
||||
"""VoI = E[best decision with info] - E[best decision without info] - cost."""
|
||||
return posterior_decision_eu - prior_decision_eu - info_cost
|
||||
```
|
||||
|
||||
### POMDP Belief Update (LLM Agent)
|
||||
```python
|
||||
def belief_update(belief, action, observation, transition_fn, obs_fn):
|
||||
"""b'(s') = η · O(o|s',a) · Σ T(s'|s,a) · b(s)."""
|
||||
new_belief = {}
|
||||
for s_prime in belief:
|
||||
prior = sum(transition_fn(s, a=action, s_p=s_prime) * b
|
||||
for s, b in belief.items())
|
||||
new_belief[s_prime] = obs_fn(observation, s_prime, action) * prior
|
||||
norm = sum(new_belief.values())
|
||||
return {s: v / norm for s, v in new_belief.items()}
|
||||
```
|
||||
|
||||
### Multi-Armed Bandit (Thompson Sampling)
|
||||
```python
|
||||
import numpy as np
|
||||
class ThompsonBandit:
|
||||
def __init__(self, n_arms):
|
||||
self.alpha = np.ones(n_arms)
|
||||
self.beta = np.ones(n_arms)
|
||||
def pull(self):
|
||||
samples = np.random.beta(self.alpha, self.beta)
|
||||
return samples.argmax()
|
||||
def update(self, arm, reward):
|
||||
self.alpha[arm] += reward
|
||||
self.beta[arm] += (1 - reward)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Probabilities known, utilities clear | Expected Utility maximization |
|
||||
| Uncertainty about probabilities | Bayesian decision (priors) |
|
||||
| Adversarial environment | Minimax / Game theory |
|
||||
| Multi-objective tradeoff | Pareto frontier |
|
||||
| Sequential with information | POMDP / VoI |
|
||||
| Online with exploration | Bandit / RL |
|
||||
|
||||
**기본값**: 매 Bayesian Expected Utility — 매 priors explicit + posterior update 가능.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Probability Theory]]
|
||||
- 변형: [[Prospect Theory]] · [[POMDP]]
|
||||
- 응용: [[Reinforcement Learning]] · [[Multi-armed-Bandit-Problem]]
|
||||
- Adjacent: [[Optimal-Control-Theory]] · [[Entropy in Information Theory|Information Theory]] · [[Risk_Management|Risk-Management]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 agent planner 의 tool selection, 매 RLHF reward design, 매 active learning data acquisition.
|
||||
**언제 X**: 매 utility function 의 specification 매 impossible 한 multi-stakeholder ethics — 매 voting / negotiation 사용.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Naive EU under heavy-tailed risk**: 매 expected value finite 이지만 ruin probability 가 nonzero — 매 Kelly criterion / log-utility 사용.
|
||||
- **Ignoring Allais paradox**: 매 humans violate independence axiom — 매 prescriptive ≠ descriptive.
|
||||
- **Probability ≈ frequency only**: 매 Bayesian subjective prob 도 valid — 매 single-event decision 에 frequency 강요 X.
|
||||
- **Over-precise priors**: 매 unknown unknowns 에 매 epsilon-contamination / robust priors.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Savage 1954, *Foundations of Statistics*; Kahneman & Tversky 1979 prospect theory; Russell & Norvig *AIMA* 4ed Ch.16-17).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full content with EU, Bayesian, POMDP, bandit patterns |
|
||||
@@ -0,0 +1,156 @@
|
||||
---
|
||||
id: wiki-2026-0508-determinism-in-computing
|
||||
title: Determinism in Computing
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Reproducibility, Bit-Exact, 결정론적 실행]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.93
|
||||
verification_status: applied
|
||||
tags: [determinism, reproducibility, concurrency, ML, distributed-systems]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: pytorch/cuda
|
||||
---
|
||||
|
||||
# Determinism in Computing
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 same input + same code = same output, every run, every machine"**. 매 1936 Turing 의 deterministic state machine 부터 매 2026 ML training 의 bit-exact reproducibility, 매 distributed consensus (Raft), 매 blockchain virtual machines 까지 — 매 trust 와 debugging 의 foundation.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 등급
|
||||
- **Bit-exact**: 매 byte-level identical output. 매 cryptographic hash 동일.
|
||||
- **Numerically reproducible**: 매 within ε tolerance — 매 floating-point order 차이.
|
||||
- **Statistically reproducible**: 매 same distribution, different sample (RNG seed only).
|
||||
- **Behaviorally reproducible**: 매 high-level outcome 동일 (test passes/fails 동일).
|
||||
|
||||
### 매 nondeterminism 원인
|
||||
- **FP non-associativity**: 매 (a+b)+c ≠ a+(b+c) — 매 reduction order matter.
|
||||
- **GPU atomic ops**: 매 CUDA atomicAdd 의 ordering 비결정적.
|
||||
- **Thread scheduling**: 매 OS scheduler 의 race condition.
|
||||
- **Hash randomization**: 매 Python `PYTHONHASHSEED`, Go map iteration.
|
||||
- **Wall-clock dependency**: 매 timestamps, `time.time()`, `random()`.
|
||||
- **Hardware**: 매 cosmic ray bit flips, TLB/cache state.
|
||||
|
||||
### 매 응용
|
||||
1. **ML training reproduction**: 매 paper benchmark 의 reproducibility crisis.
|
||||
2. **Blockchain consensus**: 매 nodes must reach identical state.
|
||||
3. **Distributed log replay**: 매 event sourcing 의 deterministic projection.
|
||||
4. **Game engine replays**: 매 lockstep multiplayer (RTS, fighting games).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### PyTorch Bit-Exact Setup
|
||||
```python
|
||||
import torch, random, numpy as np, os
|
||||
|
||||
def set_full_determinism(seed=42):
|
||||
os.environ['PYTHONHASHSEED'] = str(seed)
|
||||
os.environ['CUBLAS_WORKSPACE_CONFIG'] = ':4096:8' # CUDA 10.2+
|
||||
random.seed(seed); np.random.seed(seed)
|
||||
torch.manual_seed(seed); torch.cuda.manual_seed_all(seed)
|
||||
torch.backends.cudnn.deterministic = True
|
||||
torch.backends.cudnn.benchmark = False
|
||||
torch.use_deterministic_algorithms(True, warn_only=False)
|
||||
|
||||
set_full_determinism()
|
||||
```
|
||||
|
||||
### Deterministic DataLoader
|
||||
```python
|
||||
def seed_worker(worker_id):
|
||||
s = torch.initial_seed() % 2**32
|
||||
np.random.seed(s); random.seed(s)
|
||||
|
||||
g = torch.Generator(); g.manual_seed(42)
|
||||
loader = DataLoader(ds, batch_size=64, shuffle=True,
|
||||
num_workers=4, worker_init_fn=seed_worker, generator=g)
|
||||
```
|
||||
|
||||
### Lockstep Game Loop (Fixed-Point Math)
|
||||
```rust
|
||||
// All clients run identical sim → only inputs synchronized.
|
||||
const FIXED_DT: Fixed<i64, 16> = Fixed::from_num(1.0 / 60.0);
|
||||
|
||||
fn tick(state: &mut GameState, inputs: &[Input]) {
|
||||
for input in inputs.iter().sorted_by_key(|i| i.player_id) {
|
||||
state.apply(input, FIXED_DT); // fixed-point, no f32!
|
||||
}
|
||||
state.tick += 1;
|
||||
}
|
||||
```
|
||||
|
||||
### Content-Addressable Build (Bazel-style)
|
||||
```python
|
||||
def build_artifact(sources, deps, command):
|
||||
h = hashlib.sha256()
|
||||
for src in sorted(sources):
|
||||
h.update(open(src, 'rb').read())
|
||||
for d in sorted(deps): h.update(d.hash.encode())
|
||||
h.update(command.encode())
|
||||
cache_key = h.hexdigest()
|
||||
if cache_key in cache: return cache[cache_key]
|
||||
return run_and_cache(command, cache_key)
|
||||
```
|
||||
|
||||
### Deterministic Hash for Sets
|
||||
```python
|
||||
# Avoid Python set iteration order
|
||||
def stable_hash_set(items):
|
||||
return hashlib.sha256(
|
||||
b'\n'.join(sorted(repr(x).encode() for x in items))
|
||||
).hexdigest()
|
||||
```
|
||||
|
||||
### Replay Test
|
||||
```python
|
||||
def test_replay_is_deterministic():
|
||||
seed = 12345
|
||||
out1 = run_simulation(seed)
|
||||
out2 = run_simulation(seed)
|
||||
assert out1 == out2, "Nondeterminism detected!"
|
||||
# for ML: torch.testing.assert_close(out1, out2, atol=0, rtol=0)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| ML reproducibility paper | bit-exact (CUBLAS config + cudnn.deterministic) |
|
||||
| Distributed sim / lockstep | fixed-point arithmetic |
|
||||
| Build system | content-addressable hashing |
|
||||
| Statistical study | seed-only (statistical determinism) |
|
||||
| Performance critical | relax to "numerically close" |
|
||||
|
||||
**기본값**: 매 seed everything + log seeds in artifacts metadata.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Theoretical-Computer-Science]] · [[Reproducibility]]
|
||||
- Adjacent: [[Idempotency]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 evaluation harness, 매 regression test 의 ground truth, 매 paper code release.
|
||||
**언제 X**: 매 LLM sampling 자체 (temperature > 0) — 매 inherently nondeterministic; 매 fixed seed + temperature=0 만 reproducible.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Forgetting CUBLAS_WORKSPACE_CONFIG**: 매 CUDA matmul 비결정적, training 결과 매 run 다름.
|
||||
- **Using `set()` in pipeline**: 매 Python <3.7 dict order 비결정적.
|
||||
- **Wall-clock as seed**: 매 reproducibility 불가, debugging 불가.
|
||||
- **Mixing CPU/GPU reductions**: 매 sum order 차이로 ε divergence 누적.
|
||||
- **Ignoring hardware drift**: 매 different GPU arch (A100 vs H100) → different results 가능.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (PyTorch reproducibility docs 2026; Raft paper 2014; Bazel hermetic build docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full content with PyTorch, lockstep, build patterns |
|
||||
@@ -0,0 +1,179 @@
|
||||
---
|
||||
id: wiki-2026-0508-dijkstra-s-algorithm
|
||||
title: "Dijkstra's Algorithm"
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Shortest Path, SPF, 다익스트라]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.97
|
||||
verification_status: applied
|
||||
tags: [graph, shortest-path, algorithm, priority-queue, OSPF]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: heapq
|
||||
---
|
||||
|
||||
# Dijkstra's Algorithm
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 single-source shortest path on non-negative weighted graphs — O((V+E) log V) with binary heap"**. 매 1959 Edsger Dijkstra 가 매 30분 coffee shop 에서 발견. 매 2026 OSPF routing, Google Maps, A* heuristic baseline, network flow 의 핵심 building block.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 핵심 idea
|
||||
1. 매 priority queue 에서 가장 작은 tentative distance 의 vertex 추출.
|
||||
2. 매 incident edge 마다 relax: `if d[u] + w(u,v) < d[v]: d[v] = d[u] + w(u,v)`.
|
||||
3. 매 visited set 에 추가, 매 빈 큐까지 반복.
|
||||
|
||||
### 매 복잡도
|
||||
- **Binary heap**: O((V+E) log V).
|
||||
- **Fibonacci heap**: O(E + V log V) — 매 dense 에 유리.
|
||||
- **Bucket queue (Dial's)**: O(E + V·C) — 매 small integer weights.
|
||||
- **Array (no PQ)**: O(V²) — 매 dense 에 더 빠름.
|
||||
|
||||
### 매 제약
|
||||
- **음의 weight 금지** — 매 Bellman-Ford 사용.
|
||||
- **단일 source** — 매 all-pairs 는 Floyd-Warshall O(V³).
|
||||
- **DAG 면 더 빠름** — 매 topological order O(V+E).
|
||||
|
||||
### 매 응용
|
||||
1. **OSPF / IS-IS**: 매 internet routing protocol 의 link-state computation.
|
||||
2. **Google Maps**: 매 contraction hierarchies + bidirectional Dijkstra.
|
||||
3. **Game pathfinding**: 매 A* 의 g-score 가 Dijkstra (h=0).
|
||||
4. **Network analysis**: 매 betweenness centrality 매 계산.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Standard Implementation (Python)
|
||||
```python
|
||||
import heapq
|
||||
def dijkstra(graph, source):
|
||||
dist = {v: float('inf') for v in graph}
|
||||
dist[source] = 0
|
||||
pq = [(0, source)]
|
||||
while pq:
|
||||
d, u = heapq.heappop(pq)
|
||||
if d > dist[u]: continue # stale entry
|
||||
for v, w in graph[u]:
|
||||
nd = d + w
|
||||
if nd < dist[v]:
|
||||
dist[v] = nd
|
||||
heapq.heappush(pq, (nd, v))
|
||||
return dist
|
||||
```
|
||||
|
||||
### With Path Reconstruction
|
||||
```python
|
||||
def dijkstra_path(graph, src, dst):
|
||||
dist = {src: 0}; prev = {}
|
||||
pq = [(0, src)]
|
||||
while pq:
|
||||
d, u = heapq.heappop(pq)
|
||||
if u == dst: break
|
||||
if d > dist.get(u, float('inf')): continue
|
||||
for v, w in graph[u]:
|
||||
nd = d + w
|
||||
if nd < dist.get(v, float('inf')):
|
||||
dist[v] = nd; prev[v] = u
|
||||
heapq.heappush(pq, (nd, v))
|
||||
path, cur = [], dst
|
||||
while cur in prev: path.append(cur); cur = prev[cur]
|
||||
return [src] + path[::-1] if dist.get(dst) else None
|
||||
```
|
||||
|
||||
### Bidirectional Dijkstra (Maps-style)
|
||||
```python
|
||||
def bidirectional_dijkstra(g, s, t):
|
||||
df, db = {s: 0}, {t: 0}
|
||||
pf, pb = [(0, s)], [(0, t)]
|
||||
visited_f, visited_b = set(), set()
|
||||
best = float('inf'); meet = None
|
||||
while pf and pb:
|
||||
# alternate forward/backward expansion
|
||||
if pf[0][0] + pb[0][0] >= best: break
|
||||
# ... expand both, update best when meet
|
||||
return best, meet
|
||||
```
|
||||
|
||||
### A* (Dijkstra + heuristic)
|
||||
```python
|
||||
def a_star(graph, src, dst, h):
|
||||
g = {src: 0}; pq = [(h(src, dst), 0, src)]
|
||||
while pq:
|
||||
f, gu, u = heapq.heappop(pq)
|
||||
if u == dst: return gu
|
||||
for v, w in graph[u]:
|
||||
ng = gu + w
|
||||
if ng < g.get(v, float('inf')):
|
||||
g[v] = ng
|
||||
heapq.heappush(pq, (ng + h(v, dst), ng, v))
|
||||
```
|
||||
|
||||
### Dial's Bucket Algorithm (small int weights)
|
||||
```python
|
||||
def dial_dijkstra(graph, src, max_weight):
|
||||
n = len(graph); C = max_weight * n + 1
|
||||
buckets = [[] for _ in range(C)]
|
||||
dist = [float('inf')] * n; dist[src] = 0
|
||||
buckets[0].append(src)
|
||||
for d in range(C):
|
||||
while buckets[d]:
|
||||
u = buckets[d].pop()
|
||||
if d > dist[u]: continue
|
||||
for v, w in graph[u]:
|
||||
nd = d + w
|
||||
if nd < dist[v]:
|
||||
dist[v] = nd; buckets[nd].append(v)
|
||||
return dist
|
||||
```
|
||||
|
||||
### NetworkX (Practical)
|
||||
```python
|
||||
import networkx as nx
|
||||
G = nx.DiGraph()
|
||||
G.add_weighted_edges_from([('A','B',3), ('B','C',1), ('A','C',5)])
|
||||
length = nx.dijkstra_path_length(G, 'A', 'C')
|
||||
path = nx.dijkstra_path(G, 'A', 'C') # ['A','B','C'] (cost 4)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Non-negative weights, single source | Dijkstra (binary heap) |
|
||||
| 음의 weight 가능 | Bellman-Ford O(VE) |
|
||||
| Negative cycle detection | Bellman-Ford |
|
||||
| All-pairs, dense | Floyd-Warshall O(V³) |
|
||||
| Heuristic available (e.g., Euclidean) | A* |
|
||||
| Map-scale (millions of nodes) | Contraction Hierarchies + bidirectional |
|
||||
| Small integer weights | Dial's buckets |
|
||||
|
||||
**기본값**: 매 binary heap Dijkstra — 매 generic, 매 O((V+E) log V) 충분.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Graph Theory]] · [[Greedy-Algorithms]]
|
||||
- Adjacent: [[Topological Sort]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 dependency resolution, 매 chain-of-thought planner 의 minimum-cost reasoning path.
|
||||
**언제 X**: 매 weights 가 negative 또는 unknown — 매 Bellman-Ford or simulated annealing.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Negative weight 적용**: 매 silent wrong answer — 매 항상 Bellman-Ford 사용.
|
||||
- **Lazy deletion 누락**: 매 PQ 의 stale entry 미처리 → infinite loop 가능.
|
||||
- **Recomputing every query**: 매 static graph 면 precompute (CH) 또는 caching.
|
||||
- **Naive O(V²) on sparse graph**: 매 V=10⁶ 면 O((V+E) log V) 필수.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (CLRS Ch.24; Dijkstra 1959 *Numerische Mathematik*; NetworkX 3.x docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full content with heap, A*, bidirectional patterns |
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
---
|
||||
id: wiki-2026-0508-directed-acyclic-graph-dependenc
|
||||
title: Directed Acyclic Graph Dependency Management
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [DAG, Build Graph, Task Dependency, Topological Sort]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.94
|
||||
verification_status: applied
|
||||
tags: [DAG, dependency, build-system, scheduler, topological-sort]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: networkx/airflow
|
||||
---
|
||||
|
||||
# Directed Acyclic Graph Dependency Management
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 DAG = nodes (tasks) + directed edges (must-run-before) + 매 cycle 금지"**. 매 1960s Make 의 build graph 부터 매 2026 Airflow/Dagster pipelines, Bazel/Turborepo monorepo, Spark physical plan, Git commit history, React fiber tree 까지 — 매 dependency resolution 의 universal data structure.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 핵심 연산
|
||||
- **Topological Sort**: 매 valid execution order. Kahn's O(V+E) or DFS.
|
||||
- **Cycle Detection**: 매 DAG validity check.
|
||||
- **Transitive Reduction**: 매 minimal edge set with same reachability.
|
||||
- **Critical Path**: 매 longest path = makespan lower bound.
|
||||
- **Incremental Recompute**: 매 dirty subgraph 만 재실행.
|
||||
|
||||
### 매 응용
|
||||
1. **Build systems**: Make, Bazel, Buck, Turborepo, Nx.
|
||||
2. **Workflow orchestration**: Airflow, Dagster, Prefect, Argo Workflows.
|
||||
3. **ML training pipelines**: Kubeflow, MLflow, ZenML.
|
||||
4. **Spreadsheet recalc**: Excel, Google Sheets formula engine.
|
||||
5. **VCS**: Git commit DAG, Mercurial.
|
||||
6. **React/Solid reactivity**: 매 signal dependency graph.
|
||||
|
||||
### 매 schedule strategies
|
||||
- **List scheduling**: 매 ready tasks → workers (greedy).
|
||||
- **HEFT**: 매 heterogeneous earliest finish time (cloud).
|
||||
- **Critical Path Method (CPM)**: 매 longest path 기반 prioritization.
|
||||
- **Work-stealing**: 매 dynamic load balancing (Tokio, Rayon).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Topological Sort (Kahn's Algorithm)
|
||||
```python
|
||||
from collections import deque, defaultdict
|
||||
|
||||
def topo_sort(nodes, edges):
|
||||
indegree = defaultdict(int)
|
||||
graph = defaultdict(list)
|
||||
for u, v in edges:
|
||||
graph[u].append(v); indegree[v] += 1
|
||||
queue = deque([n for n in nodes if indegree[n] == 0])
|
||||
order = []
|
||||
while queue:
|
||||
u = queue.popleft(); order.append(u)
|
||||
for v in graph[u]:
|
||||
indegree[v] -= 1
|
||||
if indegree[v] == 0: queue.append(v)
|
||||
if len(order) != len(nodes): raise ValueError("Cycle detected")
|
||||
return order
|
||||
```
|
||||
|
||||
### Parallel DAG Executor (asyncio)
|
||||
```python
|
||||
import asyncio
|
||||
async def run_dag(tasks, deps):
|
||||
"""tasks: {name: async_fn}, deps: {name: [prereqs]}."""
|
||||
completed = {}; pending = dict(deps)
|
||||
async def run(name):
|
||||
await asyncio.gather(*(completed[d] for d in deps.get(name, [])))
|
||||
return await tasks[name]()
|
||||
completed = {n: asyncio.create_task(run(n)) for n in tasks}
|
||||
return await asyncio.gather(*completed.values())
|
||||
```
|
||||
|
||||
### Incremental Build (Content-Hash)
|
||||
```python
|
||||
def needs_rebuild(node, hashes, prev_hashes):
|
||||
own_hash = hash_inputs(node.sources, [hashes[d] for d in node.deps])
|
||||
if prev_hashes.get(node.name) != own_hash:
|
||||
hashes[node.name] = own_hash
|
||||
return True
|
||||
hashes[node.name] = own_hash
|
||||
return False
|
||||
```
|
||||
|
||||
### Critical Path
|
||||
```python
|
||||
def critical_path(graph, durations):
|
||||
order = topo_sort(graph.nodes, graph.edges)
|
||||
earliest = {n: durations[n] for n in graph.nodes}
|
||||
for u in order:
|
||||
for v in graph.successors(u):
|
||||
earliest[v] = max(earliest[v], earliest[u] + durations[v])
|
||||
return max(earliest.values()), earliest
|
||||
```
|
||||
|
||||
### Cycle Detection (DFS)
|
||||
```python
|
||||
WHITE, GRAY, BLACK = 0, 1, 2
|
||||
def has_cycle(graph):
|
||||
color = {n: WHITE for n in graph}
|
||||
def dfs(u):
|
||||
color[u] = GRAY
|
||||
for v in graph[u]:
|
||||
if color[v] == GRAY: return True
|
||||
if color[v] == WHITE and dfs(v): return True
|
||||
color[u] = BLACK
|
||||
return False
|
||||
return any(dfs(n) for n in graph if color[n] == WHITE)
|
||||
```
|
||||
|
||||
### Airflow DAG (Practical)
|
||||
```python
|
||||
from airflow.decorators import dag, task
|
||||
from datetime import datetime
|
||||
|
||||
@dag(start_date=datetime(2026,1,1), schedule="@daily", catchup=False)
|
||||
def etl():
|
||||
@task
|
||||
def extract(): return fetch()
|
||||
@task
|
||||
def transform(data): return clean(data)
|
||||
@task
|
||||
def load(clean): warehouse.write(clean)
|
||||
load(transform(extract()))
|
||||
etl()
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Build deterministic, hermetic | Bazel / Buck (content-hash) |
|
||||
| Data pipeline, scheduled | Airflow / Dagster |
|
||||
| Monorepo JS/TS | Turborepo / Nx |
|
||||
| ML experiment tracking | Kubeflow / MLflow / ZenML |
|
||||
| In-process reactive UI | Signals (Solid/Vue/Svelte) |
|
||||
| Real-time stream graph | Flink / Spark Structured Streaming |
|
||||
|
||||
**기본값**: 매 explicit DAG (declarative) > 매 implicit ordering — 매 visualization + audit + parallel scheduling 가능.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Graph Theory]] · [[Topological Sort]]
|
||||
- 변형: [[Build Graph]]
|
||||
- 응용: [[Bazel]] · [[Airflow]] · [[Turborepo 환경 구성]] · [[Spark]]
|
||||
- Adjacent: [[Incremental-Computation]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 multi-step agent plan 의 dependency 표현, 매 RAG indexing pipeline orchestration.
|
||||
**언제 X**: 매 cyclic feedback loop 가 본질적 (RL, gradient descent) — 매 DAG 외 unrolled iteration.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Hidden side effects**: 매 task 가 state 직접 mutate → 매 incremental build 깨짐.
|
||||
- **Ignoring transitive dependencies**: 매 missing edge → race condition.
|
||||
- **Single-task megasinks**: 매 fan-in bottleneck — 매 break into shards.
|
||||
- **Cycle by feature flag**: 매 conditional dependencies 가 implicit cycle 만들 수 있음.
|
||||
- **Over-fine granularity**: 매 nano-tasks → scheduler overhead > work.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Kahn 1962; Bazel docs 2026; Airflow 3.x docs; CLRS Ch.22).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full content with topo, parallel exec, incremental, Airflow |
|
||||
@@ -0,0 +1,158 @@
|
||||
---
|
||||
id: wiki-2026-0508-dissipative-structures
|
||||
title: Dissipative Structures
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Far-from-Equilibrium Systems, Self-Organization, Prigogine Systems]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.88
|
||||
verification_status: applied
|
||||
tags: [thermodynamics, self-organization, complexity, nonlinear-dynamics, prigogine]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: numpy/scipy
|
||||
---
|
||||
|
||||
# Dissipative Structures
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 open systems far from equilibrium, fed energy/matter, spontaneously self-organize into ordered patterns by exporting entropy"**. 매 1977 Ilya Prigogine Nobel — 매 Bénard convection cells, BZ chemical oscillations, hurricanes 부터 매 living cells, neural avalanches, economy, 매 LLM 의 emergent capabilities 까지 매 explanatory framework.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 핵심 조건
|
||||
1. **Open system**: 매 energy/matter exchange with environment.
|
||||
2. **Far from equilibrium**: 매 driven by external gradient (heat, chemical potential).
|
||||
3. **Nonlinearity**: 매 positive feedback / autocatalysis.
|
||||
4. **Entropy export**: 매 dS_system < 0 가능 — 매 dS_universe > 0 유지하며.
|
||||
|
||||
### 매 mathematical core
|
||||
- **Entropy production**: `σ = dS/dt = Σ J_i · X_i` (fluxes × forces).
|
||||
- **Bifurcation**: 매 control parameter μ 변화 시 매 stable state branch 점프.
|
||||
- **Order parameter**: 매 emergent macroscopic variable (Haken synergetics).
|
||||
- **Dissipation theorem**: 매 stable structure must produce entropy.
|
||||
|
||||
### 매 examples (low → high complexity)
|
||||
- **Bénard cells**: 매 fluid heated below → hexagonal convection.
|
||||
- **BZ reaction**: 매 chemical concentration spiral waves.
|
||||
- **Laser**: 매 above pumping threshold, photons coherent.
|
||||
- **Hurricane**: 매 ocean heat → organized vortex.
|
||||
- **Cell**: 매 metabolism = continuous dissipation.
|
||||
- **Ecosystem / Economy**: 매 energy throughput → structure.
|
||||
|
||||
### 매 응용
|
||||
1. **AI training**: 매 SGD as far-from-equilibrium dynamics, loss landscape exploration.
|
||||
2. **Neural avalanches**: 매 brain at criticality, 매 neuronal cascades self-organize.
|
||||
3. **Self-organizing networks**: 매 ant colony, swarm robotics.
|
||||
4. **Active matter**: 매 collective motion of self-propelled particles.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Lorenz System (Classic Dissipative Chaos)
|
||||
```python
|
||||
import numpy as np
|
||||
from scipy.integrate import odeint
|
||||
|
||||
def lorenz(state, t, sigma=10, rho=28, beta=8/3):
|
||||
x, y, z = state
|
||||
return [sigma*(y-x), x*(rho-z)-y, x*y - beta*z]
|
||||
|
||||
t = np.linspace(0, 40, 10000)
|
||||
sol = odeint(lorenz, [1,1,1], t)
|
||||
# Strange attractor — entropy produced as trajectory dissipates onto fractal set
|
||||
```
|
||||
|
||||
### Bénard Convection (Rayleigh-Bénard simplified)
|
||||
```python
|
||||
def rayleigh_benard_2d(T_top, T_bot, viscosity, k_thermal, dt, T_grid):
|
||||
"""Boussinesq + buoyancy → convection cells appear above critical Rayleigh number."""
|
||||
Ra = (T_bot - T_top) * gravity * thermal_expansion / (viscosity * k_thermal)
|
||||
if Ra > 1708: # critical
|
||||
# initiate convection rolls
|
||||
...
|
||||
# iterate Navier-Stokes + heat eq with periodic BC
|
||||
```
|
||||
|
||||
### BZ Reaction (Oregonator)
|
||||
```python
|
||||
def oregonator(state, t, eps=0.04, q=8e-4, f=1):
|
||||
x, y, z = state
|
||||
dx = (x*(1-x) - f*z*(x-q)/(x+q)) / eps
|
||||
dy = x - y
|
||||
dz = x - z
|
||||
return [dx, dy, dz]
|
||||
```
|
||||
|
||||
### Detecting Self-Organization (Order Parameter)
|
||||
```python
|
||||
def order_parameter_kuramoto(phases):
|
||||
"""|<e^{iθ}>| — Kuramoto sync order param. 1=fully synced, 0=incoherent."""
|
||||
return np.abs(np.mean(np.exp(1j * phases)))
|
||||
|
||||
# Sweep coupling K → bifurcation at K_c
|
||||
for K in np.linspace(0, 5, 50):
|
||||
phases = simulate_kuramoto(N=500, K=K, T=200)
|
||||
print(K, order_parameter_kuramoto(phases))
|
||||
```
|
||||
|
||||
### Edge-of-Chaos Detector (Lyapunov)
|
||||
```python
|
||||
def max_lyapunov(traj_fn, x0, dt=0.01, T=1000, eps=1e-9):
|
||||
x, x_pert = x0.copy(), x0 + eps
|
||||
sum_log = 0; n = 0
|
||||
for _ in range(int(T/dt)):
|
||||
x = traj_fn(x, dt); x_pert = traj_fn(x_pert, dt)
|
||||
d = np.linalg.norm(x_pert - x)
|
||||
sum_log += np.log(d / eps); n += 1
|
||||
x_pert = x + (x_pert - x) * eps / d # rescale
|
||||
return sum_log / (n * dt)
|
||||
# λ > 0: chaos; λ ≈ 0: edge-of-chaos (rich self-organization)
|
||||
```
|
||||
|
||||
### Maximum Entropy Production Principle (MEP)
|
||||
```python
|
||||
def select_steady_state(states, entropy_production_fn):
|
||||
"""Among possible steady states, system selects one maximizing dS/dt."""
|
||||
return max(states, key=entropy_production_fn)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Framework |
|
||||
|---|---|
|
||||
| Pattern formation in fluids | Rayleigh-Bénard, reaction-diffusion |
|
||||
| Coupled oscillators sync | Kuramoto |
|
||||
| Chemical autocatalysis | Brusselator / Oregonator |
|
||||
| Brain criticality | neural avalanche, Hopfield |
|
||||
| Open economic systems | non-equilibrium econophysics |
|
||||
| ML loss landscapes | SGD as Langevin, basin escape |
|
||||
|
||||
**기본값**: 매 모델링 시 매 forcing (energy input) + nonlinear feedback + dissipation 매 명시적 표현.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Thermodynamics]] · [[Nonlinear-Dynamics]] · [[Complexity Science]]
|
||||
- 응용: [[Emergence-in-Systems]]
|
||||
- Adjacent: [[Entropy in Information Theory]] · [[Chaos-Theory in Systems]] · [[Free-Energy-Principle]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 emergent capability 의 thermodynamic interpretation, 매 generative model 의 entropy budget analysis.
|
||||
**언제 X**: 매 simple equilibrium statistical mechanics — 매 dissipative framework 가 overhead.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **2nd law violation 주장**: 매 local order 가 global entropy increase 를 보상한다는 점 누락.
|
||||
- **Equilibrium thermodynamics 적용**: 매 living systems 는 매 inherently far-from-equilibrium.
|
||||
- **Reductionism**: 매 microscopic dynamics 만으로 매 macro pattern 설명 불가 — 매 emergent order parameter 필요.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Prigogine 1977 Nobel lecture; Nicolis & Prigogine 1989 *Exploring Complexity*; Haken 1983 *Synergetics*).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full content with Lorenz, BZ, Kuramoto, Lyapunov |
|
||||
@@ -0,0 +1,182 @@
|
||||
---
|
||||
id: wiki-2026-0508-dynamic-programming
|
||||
title: Dynamic Programming
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [DP, 동적 계획법, 동적 프로그래밍]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [algorithms, dp, optimization, memoization, tabulation]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: none
|
||||
---
|
||||
|
||||
# Dynamic Programming
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 overlapping subproblem 의 cache 의 의 의 exponential → polynomial"**. 매 1953 Bellman 의 명명 ("dynamic" 의 RAND 의 selling reason). 매 modern algo 의 universal tool — 매 Bioinformatics, ML training, RL value iteration 의 base.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 두 조건 (DP applicability)
|
||||
1. **Optimal substructure**: 매 optimal solution 의 sub-optimal solution 의 의 build.
|
||||
2. **Overlapping subproblems**: 매 same subproblem 의 repeatedly 의 solve.
|
||||
|
||||
### 매 두 style
|
||||
- **Top-down (memoization)**: recursion + cache. 매 declarative, lazy.
|
||||
- **Bottom-up (tabulation)**: iterative table fill. 매 stack-safe, faster constant.
|
||||
|
||||
### 매 state design
|
||||
- **state**: 매 minimal info 의 의 의 subproblem 의 identify.
|
||||
- **transition**: 매 state → state 의 recurrence.
|
||||
- **base case**: 매 smallest 의 known answer.
|
||||
- **answer**: 매 final state 의 retrieve.
|
||||
|
||||
### 매 응용
|
||||
1. Bioinformatics: sequence alignment (Needleman-Wunsch).
|
||||
2. NLP: edit distance, CKY parsing, Viterbi.
|
||||
3. RL: Bellman value iteration.
|
||||
4. Graph: Floyd-Warshall, Bellman-Ford.
|
||||
5. Compiler: register allocation, instruction scheduling.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Fibonacci (intro example)
|
||||
```python
|
||||
from functools import lru_cache
|
||||
|
||||
# Top-down
|
||||
@lru_cache(maxsize=None)
|
||||
def fib(n):
|
||||
if n < 2: return n
|
||||
return fib(n-1) + fib(n-2)
|
||||
|
||||
# Bottom-up O(1) space
|
||||
def fib_bu(n):
|
||||
if n < 2: return n
|
||||
a, b = 0, 1
|
||||
for _ in range(n - 1):
|
||||
a, b = b, a + b
|
||||
return b
|
||||
```
|
||||
|
||||
### 0/1 Knapsack
|
||||
```python
|
||||
def knapsack(weights: list[int], values: list[int], capacity: int) -> int:
|
||||
n = len(weights)
|
||||
dp = [[0] * (capacity + 1) for _ in range(n + 1)]
|
||||
for i in range(1, n + 1):
|
||||
for w in range(capacity + 1):
|
||||
if weights[i-1] <= w:
|
||||
dp[i][w] = max(dp[i-1][w], dp[i-1][w - weights[i-1]] + values[i-1])
|
||||
else:
|
||||
dp[i][w] = dp[i-1][w]
|
||||
return dp[n][capacity]
|
||||
# Time O(n·W), Space O(n·W) — can compress to O(W) with reverse iteration
|
||||
```
|
||||
|
||||
### Longest Common Subsequence (LCS)
|
||||
```python
|
||||
def lcs(a: str, b: str) -> int:
|
||||
n, m = len(a), len(b)
|
||||
dp = [[0] * (m + 1) for _ in range(n + 1)]
|
||||
for i in range(1, n + 1):
|
||||
for j in range(1, m + 1):
|
||||
if a[i-1] == b[j-1]:
|
||||
dp[i][j] = dp[i-1][j-1] + 1
|
||||
else:
|
||||
dp[i][j] = max(dp[i-1][j], dp[i][j-1])
|
||||
return dp[n][m]
|
||||
```
|
||||
|
||||
### Edit Distance (Levenshtein)
|
||||
```python
|
||||
def edit_distance(a: str, b: str) -> int:
|
||||
n, m = len(a), len(b)
|
||||
dp = [[0] * (m + 1) for _ in range(n + 1)]
|
||||
for i in range(n + 1): dp[i][0] = i
|
||||
for j in range(m + 1): dp[0][j] = j
|
||||
for i in range(1, n + 1):
|
||||
for j in range(1, m + 1):
|
||||
if a[i-1] == b[j-1]:
|
||||
dp[i][j] = dp[i-1][j-1]
|
||||
else:
|
||||
dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1])
|
||||
return dp[n][m]
|
||||
```
|
||||
|
||||
### Coin Change (min coins)
|
||||
```python
|
||||
def coin_change(coins: list[int], amount: int) -> int:
|
||||
dp = [float('inf')] * (amount + 1)
|
||||
dp[0] = 0
|
||||
for x in range(1, amount + 1):
|
||||
for c in coins:
|
||||
if c <= x:
|
||||
dp[x] = min(dp[x], dp[x - c] + 1)
|
||||
return dp[amount] if dp[amount] != float('inf') else -1
|
||||
```
|
||||
|
||||
### Bitmask DP (TSP)
|
||||
```python
|
||||
def tsp(dist: list[list[int]]) -> int:
|
||||
n = len(dist)
|
||||
INF = float('inf')
|
||||
dp = [[INF] * n for _ in range(1 << n)]
|
||||
dp[1][0] = 0 # start at 0 with mask {0}
|
||||
for mask in range(1, 1 << n):
|
||||
for u in range(n):
|
||||
if not (mask & (1 << u)) or dp[mask][u] == INF: continue
|
||||
for v in range(n):
|
||||
if mask & (1 << v): continue
|
||||
new_mask = mask | (1 << v)
|
||||
dp[new_mask][v] = min(dp[new_mask][v], dp[mask][u] + dist[u][v])
|
||||
return min(dp[(1 << n) - 1][u] + dist[u][0] for u in range(1, n))
|
||||
# O(n²·2ⁿ) — feasible for n ≤ 20
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 매 overlapping subproblem 의 detect | DP |
|
||||
| 매 unique subproblem (no overlap) | divide & conquer |
|
||||
| 매 greedy 의 optimal proof 가능 | greedy (faster, less memory) |
|
||||
| 매 state 의 huge | approximate DP / RL |
|
||||
| 매 small recursion depth | top-down (cleaner) |
|
||||
| 매 deep recursion 의 우려 | bottom-up |
|
||||
| 매 memory 의 tight | rolling array (O(prev) 의 의) |
|
||||
|
||||
**기본값**: 매 first attempt 의 top-down + memo. 매 deep / huge 의 의 의 bottom-up.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Optimization]]
|
||||
- 변형: [[Memoization]]
|
||||
- Adjacent: [[Greedy Algorithms]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 optimization problem 의 overlapping subproblem 의 detect, 매 string/sequence problem, 매 counting problem (combinatorial), 매 RL value function 의 의.
|
||||
**언제 X**: 매 unique subproblem (D&C 의 의), 매 greedy 의 proven optimal, 매 huge state space 의 approximation 의 의 (NN, MCTS).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **state 의 over-include**: 매 unnecessary dim 의 의 의 의 exponential blow-up.
|
||||
- **base case X**: 매 infinite recursion / wrong result.
|
||||
- **mutable default args** (Python): `def f(x, memo={})` 의 cross-call leak.
|
||||
- **bottom-up 의 wrong order**: 매 state 의 dependency 의 의 의 의 의 fill 의 X.
|
||||
- **`@lru_cache` with mutable args**: list / dict 의 의 의 hash error — tuple 의 의.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Bellman 1957 "Dynamic Programming"; CLRS Ch 15; Kleinberg-Tardos Ch 6).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — DP foundations with knapsack, LCS, edit distance, bitmask TSP |
|
||||
@@ -0,0 +1,151 @@
|
||||
---
|
||||
id: wiki-2026-0508-economic-complexity-index
|
||||
title: Economic Complexity Index
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [ECI, Hidalgo-Hausmann Index, Product Complexity, Economic Fitness]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.86
|
||||
verification_status: applied
|
||||
tags: [econophysics, complexity, network-science, trade, hidalgo]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: numpy/networkx
|
||||
---
|
||||
|
||||
# Economic Complexity Index
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 country's productive capability = diversity of products it makes × ubiquity-inverse"**. 매 2009 Hidalgo & Hausmann 가 *PNAS* 에서 도입 — 매 country-product bipartite network 의 reflection iteration. 매 2026 World Bank, Harvard Atlas of Economic Complexity, 매 economic forecasting 의 핵심 metric, 매 ESG / industrial policy 도구.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 핵심 직관
|
||||
- **Diversity (k_c,0)**: 매 country c 가 만드는 product 종류 수.
|
||||
- **Ubiquity (k_p,0)**: 매 product p 를 만드는 country 수 — 매 적을수록 매 어려운 product.
|
||||
- **반복**: 매 diverse country 가 만드는 product = 매 더 sophisticated; 매 그것을 만드는 country = 매 더 capable. → fixed-point.
|
||||
|
||||
### 매 수학
|
||||
```
|
||||
k_c,n = (1/k_c,0) Σ_p M_cp · k_p,n-1
|
||||
k_p,n = (1/k_p,0) Σ_c M_cp · k_c,n-1
|
||||
```
|
||||
- 매 M_cp = country c 가 product p 에서 RCA(Revealed Comparative Advantage) > 1 면 1.
|
||||
- 매 ECI = 매 second eigenvector of M̂ matrix (정규화된 reflection operator).
|
||||
|
||||
### 매 변형
|
||||
- **Fitness-Complexity (Tacchella 2012)**: nonlinear iteration, 매 better convergence.
|
||||
- **Genepy**: ECI extended to GDP-weighted production.
|
||||
- **Product Space**: country similarity network from co-export.
|
||||
|
||||
### 매 응용
|
||||
1. **Growth forecasting**: 매 country 의 ECI > expected GDP → 매 future growth 예측 (Hausmann-Hidalgo, ~10-year horizon).
|
||||
2. **Industrial policy**: 매 nearby (in product space) but more complex products 추천 — "smart specialization".
|
||||
3. **Resilience**: 매 high ECI country 매 economic shock 에 robust.
|
||||
4. **Inequality forecasting**: 매 ECI 와 Gini correlated.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### RCA Matrix
|
||||
```python
|
||||
import numpy as np
|
||||
def rca_matrix(exports):
|
||||
"""exports: (n_countries, n_products) export values."""
|
||||
country_total = exports.sum(axis=1, keepdims=True)
|
||||
product_total = exports.sum(axis=0, keepdims=True)
|
||||
world_total = exports.sum()
|
||||
rca = (exports / country_total) / (product_total / world_total)
|
||||
return (rca > 1).astype(float) # M_cp
|
||||
```
|
||||
|
||||
### ECI via Eigenvector (Hidalgo-Hausmann)
|
||||
```python
|
||||
def eci(M):
|
||||
kc = M.sum(axis=1) # diversity
|
||||
kp = M.sum(axis=0) # ubiquity
|
||||
# Reflection operator M̂_cc' = Σ_p M_cp M_c'p / (kc · kp)
|
||||
M_hat = (M / kc[:, None]) @ (M.T / kp[:, None]).T
|
||||
eigvals, eigvecs = np.linalg.eig(M_hat)
|
||||
idx = np.argsort(np.abs(eigvals))[::-1]
|
||||
eci_raw = eigvecs[:, idx[1]].real # 2nd eigenvector
|
||||
return (eci_raw - eci_raw.mean()) / eci_raw.std()
|
||||
```
|
||||
|
||||
### Fitness-Complexity Iteration (Tacchella)
|
||||
```python
|
||||
def fitness_complexity(M, n_iter=200):
|
||||
n_c, n_p = M.shape
|
||||
F = np.ones(n_c); Q = np.ones(n_p)
|
||||
for _ in range(n_iter):
|
||||
F_new = M @ Q
|
||||
Q_new = 1 / (M.T @ (1 / F)) # nonlinear
|
||||
F = F_new / F_new.mean()
|
||||
Q = Q_new / Q_new.mean()
|
||||
return F, Q
|
||||
```
|
||||
|
||||
### Product Space (Proximity)
|
||||
```python
|
||||
def product_proximity(M):
|
||||
"""φ_pp' = min(P(p|p'), P(p'|p))."""
|
||||
kp = M.sum(axis=0) # ubiquity
|
||||
co_occur = M.T @ M # countries making both
|
||||
P_p_given_pp = co_occur / kp[None, :]
|
||||
P_pp_given_p = co_occur / kp[:, None]
|
||||
return np.minimum(P_p_given_pp, P_pp_given_p)
|
||||
```
|
||||
|
||||
### Density (Country-Product Opportunity)
|
||||
```python
|
||||
def density(country_idx, M, proximity):
|
||||
"""ω_cp = Σ_p' M_cp' φ_pp' / Σ_p' φ_pp' — country's strength near product p."""
|
||||
return (M[country_idx] @ proximity) / proximity.sum(axis=0)
|
||||
```
|
||||
|
||||
### Growth Forecast (Simple)
|
||||
```python
|
||||
def growth_residual(eci, log_gdp_pc):
|
||||
"""Hausmann-Hidalgo: log(GDP_pc) - α·ECI = expected; positive residual → undervalued."""
|
||||
coef = np.polyfit(eci, log_gdp_pc, 1)
|
||||
expected = np.polyval(coef, eci)
|
||||
return expected - log_gdp_pc # positive → likely future growth
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Metric |
|
||||
|---|---|
|
||||
| Cross-country capability ranking | ECI (eigenvector) |
|
||||
| Convergence issues / inequality | Fitness-Complexity (nonlinear) |
|
||||
| What product to develop next | density on product space |
|
||||
| Long-term growth forecast | ECI residual |
|
||||
| Service economy | digital ECI variant (caution: services data sparse) |
|
||||
|
||||
**기본값**: 매 ECI for ranking + Fitness-Complexity for forecasting + Product Space for policy.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Complexity Science]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 country 분석 prompt 에 매 ECI 데이터 inject (Atlas of Economic Complexity API).
|
||||
**언제 X**: 매 micro-level firm productivity — 매 ECI is country-level only.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Equating ECI with GDP**: 매 ECI = capability, GDP = current outcome — 매 둘 다 필요.
|
||||
- **Ignoring data lag**: 매 trade data 매 2-3 year lag.
|
||||
- **Service blindspot**: 매 traditional ECI 는 goods-only — 매 modern variants 필요.
|
||||
- **Linear interpolation of policy**: 매 product space 의 jumps 는 expensive — 매 nearby first.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Hidalgo & Hausmann 2009 *PNAS*; Tacchella 2012 *Sci Rep*; Atlas of Economic Complexity 2026).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full content: ECI, F-C, product space, growth forecast |
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
---
|
||||
id: wiki-2026-0508-eigenvalues-and-eigenvectors
|
||||
title: Eigenvalues and Eigenvectors
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Spectral Decomposition, Eigendecomposition, EVD]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [linear-algebra, math, ml, pca, spectral]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: NumPy/SciPy
|
||||
---
|
||||
|
||||
# Eigenvalues and Eigenvectors
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 Av = λv — 매 matrix 의 invariant direction 의 stretch factor"**. Cauchy origin (1829), 매 quantum mechanics, PCA, PageRank, GNN, transformer attention spectra 의 omnipresent. 매 ML interpretability 의 2024-26 hot topic (eigenvalue distribution of transformer weights, Hessian spectrum for optimization).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 정의
|
||||
- A **n×n** matrix, A v = λ v with v ≠ 0.
|
||||
- λ: eigenvalue (scalar). v: eigenvector (direction unchanged).
|
||||
- Characteristic polynomial: det(A − λI) = 0.
|
||||
- Spectrum: set of eigenvalues σ(A).
|
||||
|
||||
### 매 properties
|
||||
- Symmetric A: real eigenvalues, orthogonal eigenvectors (spectral theorem).
|
||||
- Trace = sum of eigenvalues; det = product.
|
||||
- Rank = number of nonzero eigenvalues (for diagonalizable).
|
||||
- Condition number κ = |λ_max| / |λ_min| (for SPD).
|
||||
|
||||
### 매 응용
|
||||
1. PCA / dimensionality reduction.
|
||||
2. PageRank (dominant eigenvector of transition matrix).
|
||||
3. Spectral clustering / graph Laplacian.
|
||||
4. Quantum mechanics (energy eigenstates).
|
||||
5. Stability analysis (Jacobian eigenvalues).
|
||||
6. Optimizer Hessian (curvature analysis).
|
||||
7. Transformer attention eigenvalue analysis.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Compute eigendecomposition
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
A = np.array([[4, 1], [2, 3]], dtype=float)
|
||||
eigvals, eigvecs = np.linalg.eig(A)
|
||||
print(eigvals) # [5. 2.]
|
||||
print(eigvecs) # columns are eigenvectors
|
||||
|
||||
# Symmetric — use eigh (faster, real)
|
||||
S = (A + A.T) / 2
|
||||
w, V = np.linalg.eigh(S)
|
||||
```
|
||||
|
||||
### PCA via eigendecomposition
|
||||
```python
|
||||
def pca(X, k):
|
||||
X_c = X - X.mean(0)
|
||||
cov = (X_c.T @ X_c) / (len(X) - 1)
|
||||
w, V = np.linalg.eigh(cov)
|
||||
idx = np.argsort(w)[::-1][:k]
|
||||
return X_c @ V[:, idx], w[idx]
|
||||
```
|
||||
|
||||
### PageRank (power iteration)
|
||||
```python
|
||||
def pagerank(P, d=0.85, n_iter=100, tol=1e-8):
|
||||
n = P.shape[0]
|
||||
v = np.ones(n) / n
|
||||
for _ in range(n_iter):
|
||||
v_new = d * P.T @ v + (1 - d) / n
|
||||
if np.linalg.norm(v_new - v, 1) < tol:
|
||||
return v_new
|
||||
v = v_new
|
||||
return v
|
||||
```
|
||||
|
||||
### Spectral clustering
|
||||
```python
|
||||
from scipy.sparse.csgraph import laplacian
|
||||
from sklearn.cluster import KMeans
|
||||
|
||||
def spectral_cluster(W, k):
|
||||
L = laplacian(W, normed=True)
|
||||
w, V = np.linalg.eigh(L)
|
||||
embed = V[:, :k] # smallest k eigvecs of L
|
||||
return KMeans(n_clusters=k).fit_predict(embed)
|
||||
```
|
||||
|
||||
### Power iteration (largest eigenvalue)
|
||||
```python
|
||||
def power_iter(A, n_iter=1000, tol=1e-10):
|
||||
v = np.random.randn(A.shape[0]); v /= np.linalg.norm(v)
|
||||
for _ in range(n_iter):
|
||||
Av = A @ v
|
||||
lam = v @ Av
|
||||
v_new = Av / np.linalg.norm(Av)
|
||||
if np.linalg.norm(v_new - v) < tol:
|
||||
return lam, v_new
|
||||
v = v_new
|
||||
return lam, v
|
||||
```
|
||||
|
||||
### Hessian top-k eigenvalues (Lanczos)
|
||||
```python
|
||||
from scipy.sparse.linalg import eigsh
|
||||
|
||||
# H is LinearOperator approximating Hessian via HVP
|
||||
top_eigs, _ = eigsh(H, k=20, which='LA') # Lanczos
|
||||
```
|
||||
|
||||
### Stability of fixed point
|
||||
```python
|
||||
def is_stable(jacobian):
|
||||
w = np.linalg.eigvals(jacobian)
|
||||
return np.all(w.real < 0) # continuous-time
|
||||
```
|
||||
|
||||
### Transformer weight spectrum
|
||||
```python
|
||||
def layer_spectrum(W):
|
||||
# Often heavy-tailed in trained transformers (Martin & Mahoney)
|
||||
s = np.linalg.svd(W, compute_uv=False)
|
||||
return s ** 2 # eigvals of W^T W
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Method |
|
||||
|---|---|
|
||||
| Small dense matrix | `np.linalg.eig` / `eigh` |
|
||||
| Large sparse, top-k | Lanczos / Arnoldi (`scipy.sparse.linalg.eigsh`) |
|
||||
| Symmetric / Hermitian | Always use `eigh` (faster + numerically stable) |
|
||||
| Just dominant eigenvalue | Power iteration |
|
||||
| PCA on huge data | Randomized SVD |
|
||||
| Stability | Real parts of Jacobian eigvals |
|
||||
|
||||
**기본값**: `eigh` for symmetric; randomized SVD for high-dim ML.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Linear-Algebra-Foundations|Linear-Algebra]]
|
||||
- 변형: [[SVD]]
|
||||
- 응용: [[PCA]] · [[Spectral-Clustering]] · [[Kalman-Filter-and-State-Tracking]]
|
||||
- Adjacent: [[Gimbals-and-Orientation]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: derive eigendecomposition, explain spectral properties, generate PCA/PageRank code, debug numerical issues (e.g. why eig gives complex for "symmetric" matrix).
|
||||
**언제 X**: large-scale numerical solvers (use ARPACK/Spectra), formal proofs of spectral theorems.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **`eig` on symmetric matrix**: use `eigh` (real output, 2-3× faster, more stable).
|
||||
- **Forming `A^T A` for SVD**: numerically poor; use direct SVD.
|
||||
- **Power iteration on matrix with same-magnitude top eigenvalues**: won't converge; use shifted variants.
|
||||
- **Ignoring complex eigenvalues**: real matrices can have complex eigvals (rotations).
|
||||
- **Confusing eigvals with singular values**: only equal for symmetric PSD; for general A, σ_i = √(eigvals(A^T A)).
|
||||
- **Using PCA on non-centered data**: must subtract mean first.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Trefethen & Bau "Numerical Linear Algebra", Golub & Van Loan, NumPy/SciPy docs, Martin & Mahoney "Implicit Self-Regularization in Deep Neural Networks" 2018).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — eig/PCA/PageRank/spectral clustering/Lanczos patterns |
|
||||
@@ -0,0 +1,138 @@
|
||||
---
|
||||
id: wiki-2026-0508-elite-theory
|
||||
title: Elite Theory
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Power Elite, Iron Law of Oligarchy, Elitism]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.88
|
||||
verification_status: applied
|
||||
tags: [political-theory, sociology, governance, power]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: NetworkX
|
||||
---
|
||||
|
||||
# Elite Theory
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 모든 society 의 small minority 가 power 의 hold — 매 democracy 의 even"**. Pareto, Mosca, Michels (early 20C) 의 founded, C. Wright Mills (1956) 의 American extension, 매 modern network science / computational social science 의 quantification. 매 governance, AI alignment (concentration of model access), platform economy 의 lens.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 founders
|
||||
- **Vilfredo Pareto** (1916): "circulation of elites" — 매 lions (force) ↔ foxes (cunning) cycle.
|
||||
- **Gaetano Mosca**: "ruling class" 매 inevitable; democracies are elites pretending otherwise.
|
||||
- **Robert Michels** (1911): "iron law of oligarchy" — 매 organization 의 size 가 grow 면 oligarchy 의 emergent.
|
||||
- **C. Wright Mills** (1956): "Power Elite" — military-corporate-political triangle.
|
||||
|
||||
### 매 mechanisms
|
||||
- **Resource concentration**: capital, network ties, information access.
|
||||
- **Coordination cost**: small group easier to organize than masses.
|
||||
- **Self-perpetuation**: education credentials, marriage networks, board interlocks.
|
||||
- **Cognitive capture**: regulators 매 industry insiders 의 share.
|
||||
|
||||
### 매 응용
|
||||
1. Political science: explain policy capture.
|
||||
2. Network analysis: detect elite clusters in citation/board graphs.
|
||||
3. AI governance: model access, frontier lab concentration.
|
||||
4. Platform economy: creator economy power-law.
|
||||
5. Tech industry: VC-founder-board interlocks.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Detect elite clusters in network (k-core)
|
||||
```python
|
||||
import networkx as nx
|
||||
|
||||
def elite_kcore(G, k=10):
|
||||
return nx.k_core(G, k=k)
|
||||
|
||||
# Board interlock graph: nodes=people, edges=co-membership
|
||||
elite = elite_kcore(board_graph, k=5)
|
||||
print(f"Elite size: {len(elite)} / {len(board_graph)}")
|
||||
```
|
||||
|
||||
### Power-law fit (wealth distribution)
|
||||
```python
|
||||
import powerlaw
|
||||
import numpy as np
|
||||
|
||||
wealth = np.array([...]) # incomes
|
||||
fit = powerlaw.Fit(wealth, discrete=False)
|
||||
alpha = fit.power_law.alpha
|
||||
xmin = fit.power_law.xmin
|
||||
print(f"alpha={alpha:.2f}, xmin={xmin:.0f}")
|
||||
# alpha ≈ 2.0-2.5 typical for top wealth
|
||||
```
|
||||
|
||||
### Gini coefficient
|
||||
```python
|
||||
def gini(x):
|
||||
x = np.sort(x)
|
||||
n = len(x)
|
||||
cum = np.cumsum(x)
|
||||
return (2 * np.sum((np.arange(1, n+1)) * x) - (n+1) * cum[-1]) / (n * cum[-1])
|
||||
```
|
||||
|
||||
### Eigenvector centrality (influence)
|
||||
```python
|
||||
centrality = nx.eigenvector_centrality(G, max_iter=1000)
|
||||
top_elite = sorted(centrality.items(), key=lambda x: -x[1])[:20]
|
||||
```
|
||||
|
||||
### Circulation of elites (agent-based)
|
||||
```python
|
||||
class Elite:
|
||||
def __init__(self, type_): self.type = type_ # 'lion' or 'fox'
|
||||
def step(self):
|
||||
if self.type == 'lion' and stress > 0.7:
|
||||
self.type = 'fox' # Pareto cycle
|
||||
```
|
||||
|
||||
### Power concentration metric
|
||||
```python
|
||||
def top1_share(values):
|
||||
sorted_v = sorted(values, reverse=True)
|
||||
return sum(sorted_v[:max(1, len(values)//100)]) / sum(values)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Lens |
|
||||
|---|---|
|
||||
| Policy outcomes | Power-elite (Mills) |
|
||||
| Org behavior | Iron-law-of-oligarchy (Michels) |
|
||||
| Long-run dynamics | Circulation (Pareto) |
|
||||
| Quantitative analysis | Network + power-law tools |
|
||||
| Counter: dispersed power | Pluralism (Dahl) |
|
||||
|
||||
**기본값**: Network analysis + Gini + power-law fit for empirical claims.
|
||||
|
||||
## 🔗 Graph
|
||||
- 응용: [[Liquid-Democracy]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: literature synthesis on power dynamics, network construction from text data, generating hypotheses.
|
||||
**언제 X**: causal inference (need DAGs + IV), historical claims (verify primary sources), normative judgment.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Conspiracy framing**: elite theory ≠ secret cabal; structural emergence.
|
||||
- **Single-elite assumption**: multiple competing elites usually (military/corporate/cultural).
|
||||
- **Ignoring counter-elites**: opposition movements are also elites in formation.
|
||||
- **Static analysis**: elites circulate; snapshot misses dynamics.
|
||||
- **Power-law overclaim**: many distributions are log-normal, not pure power-law (test with `powerlaw` package).
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Mills 1956, Michels 1911, Pareto Trattato di sociologia generale, Domhoff "Who Rules America" series).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — theory + computational methods (network/Gini/power-law) |
|
||||
@@ -0,0 +1,175 @@
|
||||
---
|
||||
id: wiki-2026-0508-emergence-in-systems
|
||||
title: Emergence in Systems
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Emergent Behavior, Collective Behavior, Weak Emergence, Strong Emergence]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.90
|
||||
verification_status: applied
|
||||
tags: [emergence, complexity, multi-agent, self-organization, LLM-emergent]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: mesa/numpy
|
||||
---
|
||||
|
||||
# Emergence in Systems
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 macro-level patterns 매 micro-rules 만으로 매 predictable 하지 않게 발생"**. 매 1875 G.H. Lewes 의 용어 도입, 매 1972 Anderson *More is Different* 가 매 modern foundation. 매 2026 LLM emergent capabilities (in-context learning, reasoning chains), swarm robotics, market crashes, neural avalanches 의 핵심 framework.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 weak vs strong
|
||||
- **Weak emergence (Bedau)**: 매 micro-rule 으로 simulate 가능, 매 closed-form predict 어려움. 매 대부분의 과학 examples.
|
||||
- **Strong emergence (Chalmers)**: 매 micro 로 deduce 불가, 매 new causal powers. 매 controversial — 매 consciousness debate.
|
||||
|
||||
### 매 핵심 mechanisms
|
||||
- **Local interactions + nonlinearity**: 매 ant colony, Conway's GoL.
|
||||
- **Phase transitions**: 매 critical density 매 traffic jam, 매 percolation.
|
||||
- **Self-organized criticality (Bak)**: 매 sandpile, neural avalanches.
|
||||
- **Stigmergy**: 매 environment-mediated coordination (pheromones).
|
||||
- **Symmetry breaking**: 매 Turing patterns, 매 cell differentiation.
|
||||
|
||||
### 매 detection / measurement
|
||||
- **Mutual information** between scales.
|
||||
- **Effective complexity** (Gell-Mann).
|
||||
- **Phi (Φ)** integrated information (IIT).
|
||||
- **Coarse-grained predictability**: 매 micro vs macro forecast accuracy.
|
||||
- **Emergent capability scaling curves** (LLM): 매 phase transition at parameter threshold.
|
||||
|
||||
### 매 응용
|
||||
1. **LLM scaling**: 매 few-shot reasoning 매 ~10B params 에서 emerge (Wei 2022).
|
||||
2. **Swarm robotics**: 매 simple drones → flock formation, 매 task allocation.
|
||||
3. **Market microstructure**: 매 HFT bots → flash crashes, 매 emergent volatility.
|
||||
4. **Neural networks**: 매 grokking phenomenon, 매 induction heads emerge.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Conway's Game of Life (Classic)
|
||||
```python
|
||||
import numpy as np
|
||||
from scipy.ndimage import convolve
|
||||
|
||||
def step(grid):
|
||||
kernel = np.array([[1,1,1],[1,0,1],[1,1,1]])
|
||||
nb = convolve(grid, kernel, mode='wrap')
|
||||
return ((nb == 3) | ((grid == 1) & (nb == 2))).astype(int)
|
||||
```
|
||||
|
||||
### Boids (Flocking)
|
||||
```python
|
||||
class Boids:
|
||||
def __init__(self, n=200):
|
||||
self.pos = np.random.rand(n, 2) * 100
|
||||
self.vel = (np.random.rand(n, 2) - 0.5) * 2
|
||||
def step(self):
|
||||
# cohesion + separation + alignment
|
||||
for i in range(len(self.pos)):
|
||||
d = np.linalg.norm(self.pos - self.pos[i], axis=1)
|
||||
mask = (d > 0) & (d < 10)
|
||||
if mask.any():
|
||||
cohesion = (self.pos[mask].mean(0) - self.pos[i]) * 0.01
|
||||
alignment = (self.vel[mask].mean(0) - self.vel[i]) * 0.05
|
||||
close = (d > 0) & (d < 3)
|
||||
separation = -((self.pos[close] - self.pos[i]).sum(0)) * 0.1 if close.any() else 0
|
||||
self.vel[i] += cohesion + alignment + separation
|
||||
speed = np.linalg.norm(self.vel, axis=1, keepdims=True).clip(min=0.5, max=3)
|
||||
self.vel = self.vel / np.linalg.norm(self.vel, axis=1, keepdims=True) * speed
|
||||
self.pos = (self.pos + self.vel) % 100
|
||||
```
|
||||
|
||||
### Sandpile (Self-Organized Criticality)
|
||||
```python
|
||||
def sandpile_step(grid, threshold=4):
|
||||
drops = grid >= threshold
|
||||
while drops.any():
|
||||
grid[drops] -= threshold
|
||||
# spread to 4 neighbors
|
||||
grid[1:] += np.roll(drops, -1, axis=0)[1:]
|
||||
# ... (similar for other neighbors)
|
||||
drops = grid >= threshold
|
||||
return grid # avalanche size distribution → power law
|
||||
```
|
||||
|
||||
### Schelling Segregation
|
||||
```python
|
||||
def schelling(grid, tolerance=0.3, iters=1000):
|
||||
n = grid.shape[0]
|
||||
for _ in range(iters):
|
||||
unhappy = []
|
||||
for i, j in np.ndindex(grid.shape):
|
||||
if grid[i,j] == 0: continue
|
||||
nb = grid[max(0,i-1):i+2, max(0,j-1):j+2].flatten()
|
||||
similar = (nb == grid[i,j]).sum() - 1
|
||||
if similar / max(1, (nb != 0).sum() - 1) < tolerance:
|
||||
unhappy.append((i,j))
|
||||
# swap unhappy with random empty
|
||||
...
|
||||
return grid # macroscopic segregation emerges from mild micro-preference
|
||||
```
|
||||
|
||||
### LLM Emergent Capability Detector
|
||||
```python
|
||||
def emergent_capability_curve(scales, accuracies, threshold=0.5):
|
||||
"""Find parameter scale where accuracy phase-transitions above random."""
|
||||
for s, a in zip(scales, accuracies):
|
||||
if a > threshold:
|
||||
return s
|
||||
return None
|
||||
# Wei et al 2022 — abrupt jump for arithmetic, multi-step reasoning
|
||||
```
|
||||
|
||||
### Mutual Information Across Scales
|
||||
```python
|
||||
from sklearn.feature_selection import mutual_info_regression
|
||||
def emergence_index(micro, macro):
|
||||
"""High MI(macro_t+1 | macro_t) - MI(macro_t+1 | micro_t) suggests emergence."""
|
||||
mi_macro = mutual_info_regression(macro[:-1].reshape(-1,1), macro[1:])[0]
|
||||
mi_micro = mutual_info_regression(micro[:-1], macro[1:])[0]
|
||||
return mi_macro - mi_micro
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 시스템 | Framework |
|
||||
|---|---|
|
||||
| Cellular automaton | GoL, ECA Wolfram class |
|
||||
| Multi-agent RL | swarm intelligence, MARL |
|
||||
| Physical phase transition | renorm group, Ising |
|
||||
| Neural network capabilities | scaling laws, mech interp |
|
||||
| Economic systems | ABM (Agent-Based Models) |
|
||||
| Brain dynamics | criticality, neural avalanche |
|
||||
|
||||
**기본값**: 매 ABM with 매 minimal local rules → 매 observe macro pattern → 매 measure emergence index.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Complexity Science]] · [[Systems Theory]]
|
||||
- 변형: [[Weak-Emergence]] · [[Strong-Emergence]] · [[Self-Organization]]
|
||||
- 응용: [[Swarm_Intelligence|Swarm-Intelligence]]
|
||||
- Adjacent: [[Dissipative-Structures]] · [[Emergence]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 multi-agent prompt 의 collective behavior 분석, 매 capability scaling 예측.
|
||||
**언제 X**: 매 simple linear systems — 매 emergence framework overhead.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **"emergent" 의 mystification**: 매 simply "I don't understand" 의 placeholder.
|
||||
- **Strong emergence claim 남발**: 매 weak emergence 가 거의 모든 과학 case 에 충분.
|
||||
- **Ignoring scale separation**: 매 macro 가 micro 의 평균이면 매 trivial — 매 nonlinearity 필요.
|
||||
- **Mistaking correlation for emergence**: 매 둘 다 환경 forcing 으로 driven 가능.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Anderson 1972 *More is Different*; Bedau 1997; Wei et al. 2022 *Emergent Abilities of LLMs*; Mitchell 2009 *Complexity*).
|
||||
- 신뢰도 A.
|
||||
- 매 사촌 페이지: [[Emergence]] (broader philosophical treatment).
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full content with GoL, Boids, sandpile, Schelling, LLM emergent |
|
||||
@@ -0,0 +1,158 @@
|
||||
---
|
||||
id: wiki-2026-0508-emergence
|
||||
title: Emergence
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Emergent Behavior, Emergent Phenomena, Weak Emergence, Strong Emergence]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [complexity, philosophy, systems, ai, multi-agent]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: NumPy/Mesa
|
||||
---
|
||||
|
||||
# Emergence
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 whole 의 properties 매 parts 의 sum 의 not derivable — 매 collective behavior 의 birth"**. Aristotle origin, Mill 1843 "heteropathic laws", Anderson 1972 "More is Different", modern formal version 매 Bedau (weak emergence) / Chalmers (strong). 매 LLM "emergent capabilities" 의 2022-26 controversy (Schaeffer 2023 reframed as metric artifact).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 두 types
|
||||
- **Weak emergence** (Bedau): macro patterns derivable from micro by simulation only — irreducible in practice, reducible in principle (e.g. Conway's Life, traffic jams, ant trails).
|
||||
- **Strong emergence** (Chalmers): genuinely novel causal powers not reducible — controversial (consciousness, ?).
|
||||
- **Nominal emergence**: just labeling (descriptive, weakest sense).
|
||||
|
||||
### 매 hallmarks
|
||||
- Many simple parts + simple interactions.
|
||||
- Macro pattern not present in any single part.
|
||||
- Often power-law / scale-free statistics.
|
||||
- Self-organization without central control.
|
||||
|
||||
### 매 응용
|
||||
1. Multi-agent systems (swarms, markets, traffic).
|
||||
2. Cellular automata (CA, Conway's Life).
|
||||
3. LLM emergent capabilities debate (in-context learning, CoT).
|
||||
4. Phase transitions in physics.
|
||||
5. Consciousness research (IIT, GWT).
|
||||
6. Biology (flocking, embryogenesis).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Conway's Game of Life (canonical emergence)
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
def step(grid):
|
||||
nb = sum(np.roll(np.roll(grid, i, 0), j, 1)
|
||||
for i in (-1, 0, 1) for j in (-1, 0, 1) if (i, j) != (0, 0))
|
||||
return ((nb == 3) | ((grid == 1) & (nb == 2))).astype(int)
|
||||
|
||||
grid = np.random.choice([0, 1], (50, 50), p=[0.7, 0.3])
|
||||
for _ in range(100):
|
||||
grid = step(grid)
|
||||
```
|
||||
|
||||
### Boids (flocking)
|
||||
```python
|
||||
def boids_step(pos, vel, n_neighbors=10):
|
||||
# alignment, cohesion, separation
|
||||
new_vel = vel.copy()
|
||||
for i in range(len(pos)):
|
||||
d = np.linalg.norm(pos - pos[i], axis=1)
|
||||
nb = np.argsort(d)[1:n_neighbors+1]
|
||||
align = vel[nb].mean(0) - vel[i]
|
||||
cohere = pos[nb].mean(0) - pos[i]
|
||||
sep = -(pos[nb] - pos[i]).sum(0) / (d[nb][:, None] + 1e-3).sum()
|
||||
new_vel[i] += 0.05*align + 0.01*cohere + 0.1*sep
|
||||
return new_vel
|
||||
```
|
||||
|
||||
### Detect emergence (mutual information micro→macro)
|
||||
```python
|
||||
from sklearn.metrics import mutual_info_score
|
||||
|
||||
def emergence_score(micro_states, macro_states):
|
||||
# High macro→macro MI conditioning on past macro indicates emergence
|
||||
return mutual_info_score(macro_states[:-1], macro_states[1:])
|
||||
```
|
||||
|
||||
### LLM emergent capability (per Schaeffer 2023)
|
||||
```python
|
||||
# Discontinuous metric (exact match) shows "emergence"
|
||||
# Continuous metric (token-level prob) shows smooth scaling
|
||||
def reframe_emergence(model_sizes, exact_match, token_logp):
|
||||
# Plot both: token_logp is smooth, exact-match has sharp jump
|
||||
return {"continuous": token_logp, "discrete": exact_match}
|
||||
```
|
||||
|
||||
### Cellular automaton (1D, Wolfram Class 4)
|
||||
```python
|
||||
def ca_1d(rule, n_cells=200, n_steps=200):
|
||||
rule_bin = [(rule >> i) & 1 for i in range(8)]
|
||||
state = np.zeros(n_cells, dtype=int); state[n_cells//2] = 1
|
||||
history = [state.copy()]
|
||||
for _ in range(n_steps):
|
||||
nb = state[:-2]*4 + state[1:-1]*2 + state[2:]
|
||||
state[1:-1] = [rule_bin[n] for n in nb]
|
||||
history.append(state.copy())
|
||||
return np.array(history)
|
||||
ca_1d(110) # Class 4 — emergent gliders, Turing-complete
|
||||
```
|
||||
|
||||
### Phase transition (Ising model)
|
||||
```python
|
||||
def ising_step(spins, beta):
|
||||
i, j = np.random.randint(0, spins.shape[0], 2)
|
||||
nb = (spins[(i+1)%N, j] + spins[(i-1)%N, j] +
|
||||
spins[i, (j+1)%N] + spins[i, (j-1)%N])
|
||||
dE = 2 * spins[i, j] * nb
|
||||
if dE < 0 or np.random.rand() < np.exp(-beta * dE):
|
||||
spins[i, j] *= -1
|
||||
return spins
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Frame |
|
||||
|---|---|
|
||||
| Multi-agent simulation | Weak emergence (Bedau) |
|
||||
| LLM scaling capabilities | Question metric smoothness first |
|
||||
| Consciousness | Strong emergence (still controversial) |
|
||||
| Phase transitions | Statistical mechanics (rigorous) |
|
||||
| Org behavior | Emergent vs designed properties |
|
||||
|
||||
**기본값**: weak emergence; demand operational definition + measurement.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Complexity_Theory|Complexity-Theory]] · [[Systems Theory]]
|
||||
- 변형: [[Weak-Emergence]] · [[Strong-Emergence]] · [[Self-Organization]]
|
||||
- 응용: [[Multi-agent-System|Multi-Agent-Systems]] · [[Cellular Automata]] · [[LLM-Scaling]]
|
||||
- Adjacent: [[Global-Neuronal-Workspace]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: simulating CA / boids / Ising, explaining emergence intuitions, critiquing claims of "emergence" (Schaeffer-style metric scrutiny).
|
||||
**언제 X**: claims of strong emergence (philosophically contested), consciousness assertions (active research).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Emergence as magic**: "the system has emergent properties" 의 explanation 의 not.
|
||||
- **Confusing weak with strong**: most "emergent" is weak (Conway's Life is weak).
|
||||
- **Metric artifact emergence**: discontinuous evaluation creating apparent jumps (Schaeffer 2023).
|
||||
- **Skipping operational definition**: define what is "emerging" measurably.
|
||||
- **Claiming irreducibility prematurely**: lack of current explanation ≠ in-principle irreducibility.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Anderson 1972 Science, Bedau "Weak Emergence" 1997, Chalmers "Strong and Weak Emergence" 2006, Schaeffer et al. NeurIPS 2023 "Are Emergent Abilities a Mirage?").
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — weak/strong emergence + CA/boids/Ising + Schaeffer LLM critique |
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
---
|
||||
id: wiki-2026-0508-entropy-in-information-theory
|
||||
title: Entropy in Information Theory
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Shannon Entropy, Information Entropy, H(X)]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [information-theory, probability, entropy, shannon, machine-learning]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: NumPy / SciPy
|
||||
---
|
||||
|
||||
# Entropy in Information Theory
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 random variable 의 uncertainty 의 quantification — H(X) = -Σp(x)log p(x)"**. Shannon 1948 "A Mathematical Theory of Communication" 의 birth — 매 modern compression, channel coding, ML loss function (cross-entropy), variational inference 의 모두 의 foundation.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 정의
|
||||
- **Shannon entropy**: H(X) = -Σ p(x) log p(x), unit log_2 의 bit / log_e 의 nat.
|
||||
- **Joint entropy**: H(X,Y) = -ΣΣ p(x,y) log p(x,y).
|
||||
- **Conditional entropy**: H(Y|X) = H(X,Y) - H(X) = E_X[H(Y|X=x)].
|
||||
- **Mutual information**: I(X;Y) = H(X) + H(Y) - H(X,Y) = H(X) - H(X|Y).
|
||||
- **KL divergence**: D_KL(P||Q) = Σ p(x) log(p(x)/q(x)) — 매 not symmetric, ≥ 0.
|
||||
- **Cross-entropy**: H(P,Q) = H(P) + D_KL(P||Q) = -Σ p(x) log q(x).
|
||||
|
||||
### 매 properties
|
||||
- H(X) ≥ 0, H(X) ≤ log |𝒳| (uniform 시 max).
|
||||
- H(X,Y) ≤ H(X) + H(Y) (equality ⟺ independent).
|
||||
- I(X;Y) ≥ 0 (independence iff =0).
|
||||
- Data processing inequality: X→Y→Z ⇒ I(X;Z) ≤ I(X;Y).
|
||||
|
||||
### 매 응용
|
||||
1. **Compression**: 매 lower bound (Shannon source coding) — Huffman, arithmetic, ANS 의 modern (Zstd, Brotli).
|
||||
2. **Channel capacity**: C = max_p I(X;Y) — 매 AWGN channel: C = ½log(1+SNR).
|
||||
3. **Cross-entropy loss**: 매 classification 의 standard loss (PyTorch/TensorFlow default).
|
||||
4. **Variational inference**: ELBO = E[log p(x|z)] - D_KL(q(z|x) || p(z)) — 매 VAE/diffusion 의 basis.
|
||||
5. **Decision trees**: 매 information gain split criterion.
|
||||
6. **Maximum entropy principle**: 매 prior choice 의 (Jaynes 1957).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### 매 Discrete Entropy (NumPy)
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
def shannon_entropy(p, base=2):
|
||||
"""매 probability vector → entropy.
|
||||
매 zero-handling: 0 log 0 = 0."""
|
||||
p = np.asarray(p, dtype=float)
|
||||
p = p[p > 0]
|
||||
return -np.sum(p * np.log(p) / np.log(base))
|
||||
|
||||
# Example: fair coin = 1 bit
|
||||
print(shannon_entropy([0.5, 0.5])) # 1.0
|
||||
# biased coin (p=0.9): low entropy
|
||||
print(shannon_entropy([0.9, 0.1])) # ≈ 0.469
|
||||
```
|
||||
|
||||
### KL Divergence / Cross-Entropy
|
||||
```python
|
||||
def kl_divergence(p, q, base=2):
|
||||
"""매 D_KL(P||Q). P, Q 의 same support 가정."""
|
||||
p = np.asarray(p, dtype=float)
|
||||
q = np.asarray(q, dtype=float)
|
||||
mask = (p > 0) & (q > 0)
|
||||
return np.sum(p[mask] * np.log(p[mask] / q[mask]) / np.log(base))
|
||||
|
||||
def cross_entropy(p, q, base=2):
|
||||
p = np.asarray(p, dtype=float)
|
||||
q = np.asarray(q, dtype=float)
|
||||
mask = (p > 0)
|
||||
return -np.sum(p[mask] * np.log(q[mask]) / np.log(base))
|
||||
|
||||
p = [0.5, 0.5]
|
||||
q = [0.9, 0.1]
|
||||
print(kl_divergence(p, q)) # 매 not zero
|
||||
print(cross_entropy(p, q)) # 매 H(p) + KL(p||q)
|
||||
```
|
||||
|
||||
### PyTorch Cross-Entropy Loss (매 ML standard)
|
||||
```python
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
# Classification logits → softmax → -Σ y log p
|
||||
logits = torch.tensor([[2.0, 1.0, 0.1]]) # batch=1, classes=3
|
||||
target = torch.tensor([0]) # true class
|
||||
loss_fn = nn.CrossEntropyLoss()
|
||||
loss = loss_fn(logits, target)
|
||||
print(f"Cross-entropy loss: {loss.item():.4f}")
|
||||
|
||||
# 매 internal: log_softmax + nll_loss for numerical stability
|
||||
# 매 직접 softmax → log → nll 분리 시 매 underflow 위험
|
||||
```
|
||||
|
||||
### Mutual Information Estimation (매 continuous)
|
||||
```python
|
||||
from sklearn.feature_selection import mutual_info_regression
|
||||
from sklearn.metrics import mutual_info_score
|
||||
|
||||
# 매 discrete: histogram-based
|
||||
def mutual_info_discrete(x, y, bins=20):
|
||||
c_xy, _, _ = np.histogram2d(x, y, bins=bins)
|
||||
return mutual_info_score(None, None, contingency=c_xy)
|
||||
|
||||
# 매 continuous: KSG estimator (Kraskov-Stögbauer-Grassberger 2004)
|
||||
# sklearn 의 mutual_info_regression 의 internal 의 KSG 사용
|
||||
x = np.random.randn(1000)
|
||||
y = x + 0.5 * np.random.randn(1000)
|
||||
mi = mutual_info_regression(x.reshape(-1, 1), y)
|
||||
print(f"MI(x; y) ≈ {mi[0]:.4f} nats")
|
||||
```
|
||||
|
||||
### Decision Tree Information Gain
|
||||
```python
|
||||
def information_gain(parent_labels, splits):
|
||||
"""매 split 의 information gain.
|
||||
IG = H(parent) - Σ (|child|/|parent|) H(child)."""
|
||||
def H(labels):
|
||||
_, counts = np.unique(labels, return_counts=True)
|
||||
p = counts / counts.sum()
|
||||
return -np.sum(p * np.log2(p + 1e-12))
|
||||
|
||||
parent_H = H(parent_labels)
|
||||
n = len(parent_labels)
|
||||
weighted_child_H = sum((len(s) / n) * H(s) for s in splits)
|
||||
return parent_H - weighted_child_H
|
||||
```
|
||||
|
||||
### Variational Inference (매 ELBO)
|
||||
```python
|
||||
import torch.nn.functional as F
|
||||
|
||||
def vae_elbo(x, x_recon, mu, logvar):
|
||||
"""ELBO = E[log p(x|z)] - D_KL(q(z|x) || p(z)).
|
||||
매 p(z) = N(0,I), q(z|x) = N(mu, σ²I)."""
|
||||
recon_loss = F.binary_cross_entropy(x_recon, x, reduction='sum')
|
||||
# 매 KL closed-form for Gaussians:
|
||||
kl = -0.5 * torch.sum(1 + logvar - mu.pow(2) - logvar.exp())
|
||||
return recon_loss + kl # negative ELBO 매 minimize
|
||||
```
|
||||
|
||||
### Differential Entropy (매 continuous variable)
|
||||
```python
|
||||
from scipy.stats import differential_entropy
|
||||
|
||||
# 매 sample-based estimator
|
||||
samples = np.random.randn(10000)
|
||||
h = differential_entropy(samples)
|
||||
print(f"h(N(0,1)) ≈ {h:.4f}") # closed-form: 0.5 log(2πe) ≈ 1.4189
|
||||
|
||||
# 매 differential entropy 매 negative 가능 (e.g., narrow distribution)
|
||||
samples_narrow = np.random.randn(10000) * 0.1
|
||||
print(differential_entropy(samples_narrow)) # negative
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Quantity |
|
||||
|---|---|
|
||||
| Compression lower bound | H(X) |
|
||||
| Classification loss | Cross-entropy H(P,Q) |
|
||||
| Distribution comparison | KL divergence D_KL(P||Q) |
|
||||
| Symmetric divergence | Jensen-Shannon (½KL(P||M) + ½KL(Q||M)) |
|
||||
| Feature selection | Mutual information I(X;Y) |
|
||||
| VAE training | ELBO (recon + KL) |
|
||||
| Decision tree split | Information gain |
|
||||
| Channel design | Mutual information capacity |
|
||||
|
||||
**기본값**: 매 ML loss 의 cross-entropy. 매 distribution distance 의 KL (asymmetric). 매 symmetric 가 필요하면 JS divergence.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Information_Theory|Information-Theory]] · [[Probability Theory]]
|
||||
- 응용: [[Cross-Entropy Loss]] · [[KL-Divergence]] · [[Mutual-Information]] · [[Variational-Inference]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 concept explanation, 매 derivation 의 walk-through, 매 ML loss function selection, 매 KL/cross-entropy 의 confused 시 disambiguation.
|
||||
**언제 X**: 매 numerical computation 의 large-scale data — 매 dedicated library (NumPy, scikit-learn) 사용. 매 differential entropy 의 sample size 부족 시 hallucinate 위험.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **KL 의 symmetric 가정**: 매 D_KL(P||Q) ≠ D_KL(Q||P). 매 forward/reverse KL 의 다른 behavior (mode-seeking vs mean-seeking).
|
||||
- **log(0) 처리 누락**: 매 0 log 0 의 limit 의 0 — 매 mask 또는 ε 추가.
|
||||
- **Cross-entropy 의 softmax 두 번 적용**: PyTorch CrossEntropyLoss 매 logits 받음, softmax 직접 적용 X.
|
||||
- **Differential entropy 의 Shannon entropy 와 혼동**: 매 differential entropy 매 negative 가능, 매 not invariant under change of variable.
|
||||
- **MI 의 직접 estimation 의 high-dim**: 매 sample complexity exponential — copula / NN-based estimator 사용.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Shannon 1948, Cover-Thomas "Elements of Information Theory", MacKay "Information Theory, Inference and Learning Algorithms").
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — entropy/KL/MI/cross-entropy formulas, ML applications, VAE ELBO |
|
||||
@@ -0,0 +1,140 @@
|
||||
---
|
||||
id: wiki-2026-0508-ergodic-theory
|
||||
title: Ergodic Theory
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Ergodicity, Time Average vs Ensemble Average]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [math, dynamics, probability, statistics, finance]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: NumPy
|
||||
---
|
||||
|
||||
# Ergodic Theory
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 time average = ensemble average — 매 system 의 ergodic 면"**. Birkhoff (1931), Boltzmann origin 매 statistical mechanics, modern resurgence 매 Ole Peters' "ergodicity economics" (2011-) 매 expected value 의 critique. 매 finance, RL, MCMC convergence, decision theory 의 deep relevance.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 두 averages
|
||||
- **Ensemble average** (⟨x⟩): mean over many parallel realizations at fixed time.
|
||||
- **Time average** (x̄): mean of single trajectory over long time.
|
||||
- **Ergodic**: 매 ⟨x⟩ = x̄ (a.s.) for all integrable f.
|
||||
- **Non-ergodic**: trajectories diverge — ensemble average misleads about typical outcome (multiplicative dynamics).
|
||||
|
||||
### 매 implications
|
||||
- **Multiplicative process** (e.g. wealth × random factor): non-ergodic; geometric mean rules, expected value misleads.
|
||||
- **Kelly criterion**: optimal bet sizing under non-ergodicity.
|
||||
- **MCMC**: chains must be ergodic to converge to target distribution.
|
||||
- **Statistical physics**: ergodic hypothesis underpins phase-space averaging.
|
||||
|
||||
### 매 응용
|
||||
1. Investment decisions (avoid ruin via geometric returns).
|
||||
2. RL convergence theory (Markov chain ergodicity).
|
||||
3. Statistical mechanics (Boltzmann distribution).
|
||||
4. MCMC sampling (Metropolis-Hastings, HMC).
|
||||
5. Insurance / risk modeling.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Ensemble vs time average (multiplicative)
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
T, N = 1000, 10000
|
||||
# Multiplicative: 50% gain 50% loss, fair coin
|
||||
returns = np.where(np.random.rand(T, N) < 0.5, 1.5, 0.6)
|
||||
wealth = np.cumprod(returns, axis=0)
|
||||
|
||||
ensemble_mean = wealth[-1].mean() # large positive
|
||||
time_mean = np.exp(np.log(wealth[-1]).mean()) # geometric, often << 1
|
||||
print(f"E[W_T]={ensemble_mean:.2f} exp(E[log W_T])={time_mean:.4f}")
|
||||
```
|
||||
|
||||
### Kelly criterion
|
||||
```python
|
||||
def kelly_fraction(p_win, b_win, b_loss):
|
||||
# f* = p/b_loss - (1-p)/b_win (simplified)
|
||||
return p_win / b_loss - (1 - p_win) / b_win
|
||||
|
||||
f = kelly_fraction(0.55, 1.0, 1.0) # 0.10 of bankroll
|
||||
```
|
||||
|
||||
### Geometric mean return
|
||||
```python
|
||||
def geo_return(rets):
|
||||
return np.prod(1 + rets) ** (1/len(rets)) - 1
|
||||
```
|
||||
|
||||
### Ergodic check (Birkhoff sum)
|
||||
```python
|
||||
def is_ergodic_emp(traj, f, ensemble):
|
||||
time_avg = np.mean([f(x) for x in traj])
|
||||
ens_avg = np.mean([f(x) for x in ensemble])
|
||||
return abs(time_avg - ens_avg) < 0.01
|
||||
```
|
||||
|
||||
### Markov chain ergodicity (irreducible + aperiodic)
|
||||
```python
|
||||
import numpy as np
|
||||
P = np.array([[0.5, 0.5], [0.3, 0.7]])
|
||||
eigvals, eigvecs = np.linalg.eig(P.T)
|
||||
# Stationary distribution = eigenvector for eigenvalue 1
|
||||
pi = np.real(eigvecs[:, np.isclose(eigvals, 1)].flatten())
|
||||
pi /= pi.sum()
|
||||
```
|
||||
|
||||
### Ergodicity-economics rebalancing
|
||||
```python
|
||||
def expected_log_growth(p, weights, returns):
|
||||
# Maximize sum(p_i * log(1 + w·r_i))
|
||||
return np.sum([p_i * np.log(1 + np.dot(weights, r))
|
||||
for p_i, r in zip(p, returns)])
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Average to use |
|
||||
|---|---|
|
||||
| Single agent, repeated bets | Time average (geometric) |
|
||||
| Many independent agents | Ensemble average |
|
||||
| Wealth / multiplicative | Geometric, never arithmetic |
|
||||
| Insurance / pooling | Ensemble (true sharing) |
|
||||
| MCMC convergence | Verify ergodicity of chain |
|
||||
| Long-run RL | Ergodicity of Markov chain |
|
||||
|
||||
**기본값**: assume non-ergodic in finance/biology/social; verify before using ensemble average.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Probability Theory]]
|
||||
- 응용: [[MCMC]] · [[Reinforcement-Learning]]
|
||||
- Adjacent: [[Markov-Chains]] · [[Entropy in Information Theory]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: explain ergodicity intuitions, simulate ensemble vs time, derive Kelly fractions, debug MCMC non-convergence.
|
||||
**언제 X**: rigorous proofs (consult Walters, Petersen), high-stakes financial decisions (need quant + risk pro).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Expected-value reasoning under multiplicative dynamics**: leads to ruin.
|
||||
- **Confusing arithmetic and geometric means**: arithmetic > geometric always (Jensen).
|
||||
- **Assuming ergodicity by default**: most real-world economic/social systems aren't.
|
||||
- **Ignoring path dependence**: order of returns matters when non-ergodic.
|
||||
- **Misusing law of large numbers**: applies to ensemble, not single trajectory of multiplicative process.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Birkhoff 1931, Walters "Introduction to Ergodic Theory", Peters "The ergodicity problem in economics" Nature Physics 2019).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Birkhoff + ergodicity economics + Kelly + MCMC |
|
||||
@@ -0,0 +1,168 @@
|
||||
---
|
||||
id: wiki-2026-0508-ethnographic-research
|
||||
title: Ethnographic Research
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Ethnography, Field Research, Participant Observation, Contextual Inquiry]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.88
|
||||
verification_status: applied
|
||||
tags: [research, qualitative, hci, ux, anthropology]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: Dovetail, Otter.ai, NVivo, ATLAS.ti
|
||||
---
|
||||
|
||||
# Ethnographic Research
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 people-in-context 의 deep, in-situ, often-long observational study"**. Malinowski (Trobriand 1922), Geertz "thick description" (1973) → 매 industry: Xerox PARC (Suchman 1980s) → 매 modern UX/HCI/Product 의 staple. 매 "what people **say** vs what people **do**" 의 gap 의 reveal 의 가장 강력한 method.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 vs neighbors
|
||||
- **Survey/usability test**: 매 controlled / artificial / "say".
|
||||
- **Interview**: 매 retrospective / "say".
|
||||
- **Ethnography**: 매 in-situ / longitudinal / "do" + meaning.
|
||||
- **Contextual Inquiry** (Beyer & Holtzblatt 1998): 매 industry-condensed ethnography (1–2 hr in real workplace).
|
||||
- **Diary study**: 매 self-report longitudinal.
|
||||
- **Auto-ethnography**: 매 researcher = subject.
|
||||
|
||||
### 매 process (Spradley DRS / 12-step adapted)
|
||||
1. **Locate setting** (gatekeeper, access, ethics/IRB).
|
||||
2. **Participant observation** (4 modes: complete observer → complete participant).
|
||||
3. **Field notes** (jottings → expanded → analytic memos).
|
||||
4. **Domain analysis** (cultural categories).
|
||||
5. **Taxonomic analysis** (relations within domain).
|
||||
6. **Componential analysis** (attributes / contrasts).
|
||||
7. **Theme synthesis** (cross-domain patterns).
|
||||
8. **Member checks** (validate with participants).
|
||||
9. **Thick description write-up**.
|
||||
|
||||
### 매 typical artifacts
|
||||
- Field notes (jotted + expanded), photo / video / audio (with consent), artifacts collected, journey maps, persona-from-data, JTBD jobs.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Field-note template (Markdown)
|
||||
```markdown
|
||||
# Field Note — 2026-05-10 — site:Hospital ER, observer:RP
|
||||
## Setting
|
||||
- 14:00–17:00, Triage desk, 3 nurses, ~40 patients.
|
||||
## Activities (chronological)
|
||||
- 14:03 nurse A swivels between EHR (slow) + paper backup …
|
||||
## Verbatim quotes
|
||||
- "I never trust the system after a shift change." — Nurse A, 14:22
|
||||
## Surprises / breakdowns
|
||||
- EHR auto-logout at 5 min idle → workaround = mouse jiggler.
|
||||
## Analytic memo
|
||||
- Domain: trust in tools. Hypothesis: short timeout drives shadow IT.
|
||||
## Next steps
|
||||
- Interview Nurse B; check audit logs for jiggler signatures.
|
||||
```
|
||||
|
||||
### Coding qualitative data (open + axial, in Python)
|
||||
```python
|
||||
import pandas as pd
|
||||
notes = pd.read_csv("interviews.csv") # cols: pid, turn, text
|
||||
codes = {
|
||||
"trust-tool": ["never trust", "doesn't work", "I just write it down"],
|
||||
"workaround": ["mouse jiggler", "shared password", "screenshot"],
|
||||
"time-pressure":["no time", "rushing", "back-to-back"],
|
||||
}
|
||||
def code(t):
|
||||
return [c for c, kws in codes.items() if any(k in t.lower() for k in kws)]
|
||||
notes["codes"] = notes.text.apply(code)
|
||||
notes.explode("codes").groupby("codes").size().sort_values(ascending=False)
|
||||
```
|
||||
|
||||
### Affinity diagram digitization (Miro-style → DataFrame)
|
||||
```python
|
||||
import pandas as pd
|
||||
stickies = pd.DataFrame({
|
||||
"note": ["EHR logout 5 min", "Paper backup chart", "Phone snapshots", ...],
|
||||
"cluster": ["timeouts", "shadow records", "shadow records", ...]
|
||||
})
|
||||
clusters = stickies.groupby("cluster")["note"].apply(list)
|
||||
```
|
||||
|
||||
### Journey-map dataclass
|
||||
```python
|
||||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
@dataclass
|
||||
class Step:
|
||||
actor: str; action: str; tool: str; emotion: str; pain: str
|
||||
journey: List[Step] = [
|
||||
Step("nurse", "log in", "EHR", "neutral", "5-min timeout"),
|
||||
Step("nurse", "triage", "paper+EHR", "stress", "duplicate entry"),
|
||||
]
|
||||
```
|
||||
|
||||
### LLM-assisted thematic analysis (with caching)
|
||||
```python
|
||||
import anthropic
|
||||
client = anthropic.Anthropic()
|
||||
def themes(transcript: str) -> str:
|
||||
return client.messages.create(
|
||||
model="claude-opus-4-7",
|
||||
max_tokens=1500,
|
||||
system=[{"type":"text","text":"You are a senior qualitative researcher."
|
||||
,"cache_control":{"type":"ephemeral"}}],
|
||||
messages=[{"role":"user","content":
|
||||
f"Identify 3-7 emergent themes (open-coding style) with quote evidence.\n\n{transcript}"}]
|
||||
).content[0].text
|
||||
```
|
||||
|
||||
### Dovetail-style consent + redaction
|
||||
```python
|
||||
import re
|
||||
def redact_pii(s: str) -> str:
|
||||
s = re.sub(r"\b\d{3}-\d{2}-\d{4}\b", "[SSN]", s)
|
||||
s = re.sub(r"\b[\w.+-]+@[\w-]+\.[\w.-]+\b", "[EMAIL]", s)
|
||||
return s
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Need rich context, hidden practice | **Full ethnography (weeks–months)** |
|
||||
| Industry, tight timeline | **Rapid / focused ethnography (days)** |
|
||||
| Workplace tool design | **Contextual Inquiry** |
|
||||
| Distributed / remote users | **Diary study + remote shadowing** |
|
||||
| Sensitive populations | **Auto-ethnography or co-design** |
|
||||
| Quantify after | **Mixed methods: ethnography → survey → A/B** |
|
||||
|
||||
**기본값**: 매 product discovery 의 **5-7 contextual inquiries (90 min each)** + open coding + affinity diagram.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[HCI]]
|
||||
- 변형: [[Contextual-Inquiry]] · [[Autoethnography]]
|
||||
- Adjacent: [[Grounded-Theory]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 transcript 의 first-pass open coding, 매 affinity cluster 의 candidate, 매 quote retrieval, 매 persona drafting.
|
||||
**언제 X**: 매 final theme 의 sole arbiter (매 researcher judgment 필수), 매 sensitive raw data 의 unconsented external API call.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **"Asking" 만 하기**: 매 ethnography 의 essence = observing, not interviewing alone.
|
||||
- **One-shot 1-hour visit + claim "ethnography"**: 매 contextual inquiry 라고 부르는 의 정직.
|
||||
- **No reflexivity**: 매 observer effect / bias 의 acknowledged 없으면 매 weak.
|
||||
- **Confirmation bias coding**: 매 second coder + inter-rater reliability (Cohen's κ) 의 add.
|
||||
- **Thin description**: 매 "users were frustrated" — 매 thick description 의 absent (no actor, action, meaning).
|
||||
- **Skip consent / IRB**: 매 ethical 의 mandatory.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Malinowski 1922; Geertz 1973; Spradley 1979/1980; Beyer & Holtzblatt *Contextual Design* 1998; Kuniavsky *Observing the User Experience* 2nd ed.).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 placeholder |
|
||||
| 2026-05-10 | Manual cleanup — Spradley process + 6 patterns + LLM coding |
|
||||
@@ -0,0 +1,198 @@
|
||||
---
|
||||
id: wiki-2026-0508-evolutionary-algorithms
|
||||
title: Evolutionary Algorithms
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [EA, GA, ES, GP, DE, CMA-ES]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
verification_status: applied
|
||||
tags: [optimization, metaheuristics, evolution, search]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: DEAP, pycma, scipy.optimize, EvoTorch
|
||||
---
|
||||
|
||||
# Evolutionary Algorithms
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 Darwinian selection + variation 매 search loop 으로 abstract"**. Holland 의 GA (1975), Rechenberg 의 ES (1973), Koza 의 GP (1992) → 매 modern (2026): **CMA-ES, DE, NEAT, EvoTorch GPU population search, LLM-EA hybrids (FunSearch, Eureka)**. 매 derivative-free black-box optimization 의 dominant family.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 4 main branches
|
||||
- **GA (Genetic Algorithm)**: 매 binary / discrete + crossover-heavy.
|
||||
- **ES (Evolution Strategy)**: 매 real-valued + self-adaptive σ; **CMA-ES** 의 modern apex.
|
||||
- **GP (Genetic Programming)**: 매 program-tree representation.
|
||||
- **DE (Differential Evolution)**: 매 vector difference 의 mutation; 매 simplest robust real-valued EA.
|
||||
|
||||
### 매 generic loop
|
||||
```
|
||||
init population P
|
||||
evaluate(P)
|
||||
while budget left:
|
||||
parents = select(P)
|
||||
children = vary(parents) # crossover + mutation
|
||||
evaluate(children)
|
||||
P = replace(P, children) # generational or steady-state
|
||||
return best
|
||||
```
|
||||
|
||||
### 매 design knobs
|
||||
- **Representation**: bitstring, real-vector, permutation, tree, graph.
|
||||
- **Selection**: tournament, roulette, rank, truncation, (μ+λ) vs (μ,λ).
|
||||
- **Variation**: 1-point/uniform CX, Gaussian/polynomial mutation, DE/best/1/bin.
|
||||
- **Diversity**: niching, fitness sharing, novelty search, MAP-Elites (QD).
|
||||
- **Self-adaptation**: σ encoded in genome (ES), CMA covariance update.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Plain GA from scratch (OneMax)
|
||||
```python
|
||||
import random
|
||||
N, POP, GEN, PMUT = 100, 200, 100, 1/100
|
||||
|
||||
def fit(ind): return sum(ind)
|
||||
def tournament(P, k=3): return max(random.sample(P, k), key=fit)
|
||||
def cx(a, b):
|
||||
p = random.randint(1, N-1)
|
||||
return a[:p]+b[p:], b[:p]+a[p:]
|
||||
def mut(ind):
|
||||
return [1-x if random.random() < PMUT else x for x in ind]
|
||||
|
||||
P = [[random.randint(0,1) for _ in range(N)] for _ in range(POP)]
|
||||
for _ in range(GEN):
|
||||
Q = []
|
||||
while len(Q) < POP:
|
||||
a, b = tournament(P), tournament(P)
|
||||
c, d = cx(a, b)
|
||||
Q += [mut(c), mut(d)]
|
||||
P = sorted(P+Q, key=fit, reverse=True)[:POP]
|
||||
print(fit(P[0]))
|
||||
```
|
||||
|
||||
### CMA-ES (continuous default)
|
||||
```python
|
||||
import cma
|
||||
es = cma.CMAEvolutionStrategy([0]*10, 0.5,
|
||||
{"popsize": 30, "maxfevals": 5000, "verbose": -9})
|
||||
es.optimize(lambda x: sum((xi-3)**2 for xi in x))
|
||||
print(es.result.xbest)
|
||||
```
|
||||
|
||||
### Differential Evolution (scipy)
|
||||
```python
|
||||
from scipy.optimize import differential_evolution
|
||||
res = differential_evolution(
|
||||
lambda x: (1-x[0])**2 + 100*(x[1]-x[0]**2)**2, # Rosenbrock
|
||||
bounds=[(-2,2),(-1,3)], strategy="best1bin",
|
||||
popsize=30, mutation=(0.5,1.0), recombination=0.7, tol=1e-8)
|
||||
```
|
||||
|
||||
### Genetic Programming (DEAP, symbolic regression)
|
||||
```python
|
||||
from deap import base, creator, gp, tools, algorithms
|
||||
import operator, random, math
|
||||
|
||||
pset = gp.PrimitiveSet("MAIN", 1)
|
||||
pset.addPrimitive(operator.add, 2); pset.addPrimitive(operator.mul, 2)
|
||||
pset.addPrimitive(operator.sub, 2); pset.addEphemeralConstant("c", lambda: random.uniform(-1,1))
|
||||
pset.renameArguments(ARG0="x")
|
||||
|
||||
creator.create("Fit", base.Fitness, weights=(-1.0,))
|
||||
creator.create("Ind", gp.PrimitiveTree, fitness=creator.Fit, pset=pset)
|
||||
tb = base.Toolbox()
|
||||
tb.register("expr", gp.genHalfAndHalf, pset=pset, min_=1, max_=3)
|
||||
tb.register("ind", tools.initIterate, creator.Ind, tb.expr)
|
||||
tb.register("pop", tools.initRepeat, list, tb.ind)
|
||||
tb.register("compile", gp.compile, pset=pset)
|
||||
|
||||
points = [(x, x**3 - 2*x + 1) for x in [i/10 for i in range(-10,10)]]
|
||||
def evalSR(ind):
|
||||
f = tb.compile(ind)
|
||||
return (sum((f(x)-y)**2 for x,y in points),)
|
||||
tb.register("evaluate", evalSR)
|
||||
tb.register("select", tools.selTournament, tournsize=3)
|
||||
tb.register("mate", gp.cxOnePoint)
|
||||
tb.register("mutate", gp.mutUniform, expr=tb.expr, pset=pset)
|
||||
|
||||
pop = tb.pop(n=300)
|
||||
algorithms.eaSimple(pop, tb, 0.7, 0.2, 40, verbose=False)
|
||||
```
|
||||
|
||||
### MAP-Elites (Quality-Diversity)
|
||||
```python
|
||||
import numpy as np
|
||||
grid = {}
|
||||
def feat(x): return (int(x[0]*10), int(x[1]*10))
|
||||
def f(x): return -np.sum(x**2)
|
||||
for _ in range(20_000):
|
||||
if grid: parent = grid[random.choice(list(grid))]
|
||||
else: parent = np.random.uniform(-1,1,2)
|
||||
child = parent + np.random.normal(0, 0.1, 2)
|
||||
k = feat(child)
|
||||
if k not in grid or f(child) > f(grid[k]): grid[k] = child
|
||||
```
|
||||
|
||||
### LLM-guided EA (FunSearch-style, sketch)
|
||||
```python
|
||||
def llm_propose(parent_program: str) -> str:
|
||||
return claude.messages.create(
|
||||
model="claude-opus-4-7",
|
||||
max_tokens=2000,
|
||||
messages=[{"role":"user","content":
|
||||
f"Improve this program for better fitness:\n{parent_program}"}]
|
||||
).content[0].text
|
||||
|
||||
pop = [seed_program]
|
||||
for _ in range(200):
|
||||
parent = max(pop, key=score)
|
||||
child = llm_propose(parent)
|
||||
if score(child) > -float("inf"): pop.append(child)
|
||||
if len(pop) > 50: pop = sorted(pop, key=score)[-50:]
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Continuous, ≤ 100 dim, black-box | **CMA-ES** |
|
||||
| Continuous, parallel, robust default | **DE** |
|
||||
| Discrete / combinatorial | **GA + memetic local search** |
|
||||
| Symbolic regression / program synth | **GP** |
|
||||
| Need diverse archive of solutions | **MAP-Elites / Novelty Search** |
|
||||
| Very expensive eval (≤ 100 calls) | Bayesian optimization (not EA) |
|
||||
| Code / prompt search 2026 | **LLM-EA hybrid (FunSearch / Eureka)** |
|
||||
|
||||
**기본값**: 매 continuous → **CMA-ES**; 매 discrete → **memetic GA**; 매 LLM-era code search → **FunSearch-style**.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Biological-Inspired-Algorithms]] · [[Optimization]]
|
||||
- 변형: [[Genetic-Algorithm]] · [[CMA-ES]] · [[NEAT]]
|
||||
- 응용: [[Neural-Architecture-Search-NAS|Neural-Architecture-Search]] · [[Hyperparameters|Hyperparameter-Optimization]]
|
||||
- Adjacent: [[Reinforcement-Learning]] · [[Bayesian-Optimization]] · [[Simulated-Annealing]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 black-box, multimodal, non-differentiable; 매 quality-diversity 가 필요; 매 program / prompt 의 search.
|
||||
**언제 X**: 매 differentiable convex (gradient win), 매 evaluation < 100 calls (BO win).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Pure random search 의 EA 라고 부르기**: 매 selection pressure 없으면 매 EA 의 X.
|
||||
- **Mutation 의 too small/large**: 매 self-adaptive (CMA / 1/5 rule) 의 사용.
|
||||
- **Single elitist + small pop**: 매 premature convergence.
|
||||
- **Reinventing GA names** ("Whale", "Grey Wolf", …): 매 academic noise — 매 CMA-ES / DE baseline 의 거의 항상 better.
|
||||
- **Ignoring restart**: 매 IPOP/BIPOP-CMA 의 multimodal 에 critical.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Holland 1975; Rechenberg 1973; Koza 1992; Storn & Price 1997 DE; Hansen 2001 CMA-ES; Mouret & Clune 2015 MAP-Elites; Romera-Paredes 2024 FunSearch).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 placeholder |
|
||||
| 2026-05-10 | Manual cleanup — 4 branches + 6 patterns + LLM-EA |
|
||||
@@ -0,0 +1,256 @@
|
||||
---
|
||||
id: wiki-2026-0508-expectation-maximization
|
||||
title: Expectation Maximization
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [EM Algorithm, Expectation-Maximization, GMM-EM, Baum-Welch]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [statistics, machine-learning, latent-variables, optimization, probabilistic-models]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: scikit-learn / NumPy / PyTorch
|
||||
---
|
||||
|
||||
# Expectation Maximization
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 latent variable 가진 model 의 maximum likelihood 의 iterative 추정 — E-step (posterior) ↔ M-step (parameter update) 교차"**. Dempster-Laird-Rubin 1977 의 unification — 매 GMM, HMM (Baum-Welch), LDA, factor analysis, missing data imputation 의 모두 instances. 매 modern variational autoencoder 의 amortized EM.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Algorithm
|
||||
Goal: maximize log p(X|θ) where X observed, Z latent.
|
||||
|
||||
- **E-step**: 매 posterior q(Z) = p(Z|X, θ_old).
|
||||
- **M-step**: θ_new = argmax_θ E_q[log p(X, Z | θ)].
|
||||
- **Repeat**: until convergence (likelihood plateau).
|
||||
|
||||
### 매 ELBO interpretation
|
||||
log p(X|θ) ≥ E_q[log p(X,Z|θ)] - E_q[log q(Z)] = ELBO(q, θ).
|
||||
- E-step: 매 maximize ELBO over q (equiv. KL(q||p(Z|X,θ))=0 — 매 exact).
|
||||
- M-step: 매 maximize ELBO over θ.
|
||||
- 매 monotonic increase of log-likelihood guaranteed.
|
||||
|
||||
### 매 Convergence
|
||||
- 매 local optimum 으로만 converge (matter 의 likelihood 의 multimodal).
|
||||
- 매 multiple random init 권장.
|
||||
- 매 K-means 의 EM 의 hard-assignment limit (Gaussian variance → 0).
|
||||
|
||||
### 매 응용
|
||||
1. **Gaussian Mixture Models**: 매 clustering with soft assignments.
|
||||
2. **Hidden Markov Models** (Baum-Welch): 매 speech recognition, NLP, bioinformatics.
|
||||
3. **Latent Dirichlet Allocation** (variational EM): topic modeling.
|
||||
4. **Factor analysis / PPCA**: 매 dimensionality reduction.
|
||||
5. **Missing data imputation**: 매 MICE.
|
||||
6. **VAE training** (amortized EM): 매 modern deep generative.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### GMM-EM (매 from scratch, NumPy)
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
class GaussianMixtureEM:
|
||||
def __init__(self, K, max_iter=100, tol=1e-6):
|
||||
self.K = K
|
||||
self.max_iter = max_iter
|
||||
self.tol = tol
|
||||
|
||||
def fit(self, X):
|
||||
n, d = X.shape
|
||||
# 매 init: random + uniform priors
|
||||
self.pi = np.ones(self.K) / self.K
|
||||
idx = np.random.choice(n, self.K, replace=False)
|
||||
self.mu = X[idx]
|
||||
self.sigma = np.array([np.cov(X.T) for _ in range(self.K)])
|
||||
|
||||
log_lik_old = -np.inf
|
||||
for it in range(self.max_iter):
|
||||
# E-step: posterior responsibilities γ_ik
|
||||
log_resp = self._log_responsibilities(X) # (n, K)
|
||||
resp = np.exp(log_resp - log_resp.max(axis=1, keepdims=True))
|
||||
resp /= resp.sum(axis=1, keepdims=True)
|
||||
|
||||
# M-step
|
||||
Nk = resp.sum(axis=0) # (K,)
|
||||
self.pi = Nk / n
|
||||
self.mu = (resp.T @ X) / Nk[:, None]
|
||||
for k in range(self.K):
|
||||
diff = X - self.mu[k]
|
||||
self.sigma[k] = (resp[:, k:k+1] * diff).T @ diff / Nk[k]
|
||||
self.sigma[k] += 1e-6 * np.eye(d) # 매 regularization
|
||||
|
||||
# convergence
|
||||
log_lik = self._log_likelihood(X)
|
||||
if abs(log_lik - log_lik_old) < self.tol:
|
||||
break
|
||||
log_lik_old = log_lik
|
||||
return self
|
||||
|
||||
def _log_gaussian(self, X, mu, sigma):
|
||||
d = X.shape[1]
|
||||
diff = X - mu
|
||||
inv = np.linalg.inv(sigma)
|
||||
det = np.linalg.det(sigma)
|
||||
return -0.5 * (d * np.log(2 * np.pi) + np.log(det) +
|
||||
np.einsum('ni,ij,nj->n', diff, inv, diff))
|
||||
|
||||
def _log_responsibilities(self, X):
|
||||
log_resp = np.zeros((X.shape[0], self.K))
|
||||
for k in range(self.K):
|
||||
log_resp[:, k] = np.log(self.pi[k] + 1e-12) + \
|
||||
self._log_gaussian(X, self.mu[k], self.sigma[k])
|
||||
return log_resp
|
||||
|
||||
def _log_likelihood(self, X):
|
||||
log_resp = self._log_responsibilities(X)
|
||||
from scipy.special import logsumexp
|
||||
return logsumexp(log_resp, axis=1).sum()
|
||||
|
||||
# Demo
|
||||
np.random.seed(42)
|
||||
X1 = np.random.randn(100, 2) + np.array([5, 0])
|
||||
X2 = np.random.randn(100, 2) + np.array([-5, 0])
|
||||
X = np.vstack([X1, X2])
|
||||
model = GaussianMixtureEM(K=2).fit(X)
|
||||
print(f"Means:\n{model.mu}")
|
||||
print(f"Mixing:\n{model.pi}")
|
||||
```
|
||||
|
||||
### scikit-learn (매 production)
|
||||
```python
|
||||
from sklearn.mixture import GaussianMixture
|
||||
|
||||
gmm = GaussianMixture(n_components=3, covariance_type='full',
|
||||
max_iter=100, n_init=10, random_state=42)
|
||||
gmm.fit(X)
|
||||
print(f"Converged: {gmm.converged_}")
|
||||
print(f"BIC: {gmm.bic(X):.2f}") # 매 model selection
|
||||
labels = gmm.predict(X)
|
||||
proba = gmm.predict_proba(X) # 매 soft assignment
|
||||
```
|
||||
|
||||
### Baum-Welch (HMM, 매 EM 의 instance)
|
||||
```python
|
||||
def baum_welch(observations, n_states, n_iter=100):
|
||||
"""매 HMM 의 forward-backward + EM updates."""
|
||||
T = len(observations)
|
||||
pi = np.ones(n_states) / n_states
|
||||
A = np.random.rand(n_states, n_states); A /= A.sum(axis=1, keepdims=True)
|
||||
B = np.random.rand(n_states, max(observations)+1); B /= B.sum(axis=1, keepdims=True)
|
||||
|
||||
for it in range(n_iter):
|
||||
# E-step: forward α, backward β
|
||||
alpha = np.zeros((T, n_states))
|
||||
alpha[0] = pi * B[:, observations[0]]
|
||||
for t in range(1, T):
|
||||
alpha[t] = (alpha[t-1] @ A) * B[:, observations[t]]
|
||||
|
||||
beta = np.zeros((T, n_states))
|
||||
beta[T-1] = 1
|
||||
for t in range(T-2, -1, -1):
|
||||
beta[t] = A @ (B[:, observations[t+1]] * beta[t+1])
|
||||
|
||||
# γ_t(i), ξ_t(i,j)
|
||||
gamma = alpha * beta
|
||||
gamma /= gamma.sum(axis=1, keepdims=True)
|
||||
xi = np.zeros((T-1, n_states, n_states))
|
||||
for t in range(T-1):
|
||||
num = alpha[t][:, None] * A * B[:, observations[t+1]] * beta[t+1]
|
||||
xi[t] = num / num.sum()
|
||||
|
||||
# M-step
|
||||
pi = gamma[0]
|
||||
A = xi.sum(axis=0) / gamma[:-1].sum(axis=0)[:, None]
|
||||
for k in range(B.shape[1]):
|
||||
mask = (observations == k)
|
||||
B[:, k] = gamma[mask].sum(axis=0) / gamma.sum(axis=0)
|
||||
return pi, A, B
|
||||
```
|
||||
|
||||
### VAE — 매 amortized variational EM
|
||||
```python
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
class VAE(nn.Module):
|
||||
def __init__(self, input_dim, latent_dim):
|
||||
super().__init__()
|
||||
self.enc_mu = nn.Linear(input_dim, latent_dim)
|
||||
self.enc_logvar = nn.Linear(input_dim, latent_dim)
|
||||
self.dec = nn.Linear(latent_dim, input_dim)
|
||||
|
||||
def forward(self, x):
|
||||
# 매 E-step approximation: q(z|x) = N(μ_φ(x), σ²_φ(x))
|
||||
mu = self.enc_mu(x)
|
||||
logvar = self.enc_logvar(x)
|
||||
eps = torch.randn_like(mu)
|
||||
z = mu + torch.exp(0.5 * logvar) * eps
|
||||
x_recon = torch.sigmoid(self.dec(z))
|
||||
return x_recon, mu, logvar
|
||||
|
||||
def vae_loss(x, x_recon, mu, logvar):
|
||||
recon = nn.functional.binary_cross_entropy(x_recon, x, reduction='sum')
|
||||
kl = -0.5 * torch.sum(1 + logvar - mu.pow(2) - logvar.exp())
|
||||
return recon + kl
|
||||
# 매 SGD 의 joint optimization 의 amortized E+M
|
||||
```
|
||||
|
||||
### MAP-EM (매 with prior, regularized)
|
||||
```python
|
||||
# 매 prior 의 add 시 monotonic posterior 증가.
|
||||
# Example: GMM 에 Dirichlet prior on π, NIW on (μ, Σ).
|
||||
# 매 sklearn BayesianGaussianMixture 의 internal.
|
||||
from sklearn.mixture import BayesianGaussianMixture
|
||||
bgmm = BayesianGaussianMixture(n_components=10, weight_concentration_prior=1e-2)
|
||||
bgmm.fit(X)
|
||||
# 매 effective K 의 자동 sparsification.
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Variant |
|
||||
|---|---|
|
||||
| Standard mixture clustering | Vanilla EM (sklearn) |
|
||||
| Sequential / temporal | Baum-Welch (HMM) |
|
||||
| Topic modeling | Variational EM (LDA) |
|
||||
| Scalable / online | Online EM, stochastic |
|
||||
| Deep latent model | VAE (amortized) |
|
||||
| Need MAP / regularization | MAP-EM, Bayesian-EM |
|
||||
| Hard assignment baseline | K-means (EM degenerate) |
|
||||
| Discrete latent | Categorical EM |
|
||||
|
||||
**기본값**: 매 GMM clustering 매 sklearn `GaussianMixture(n_init=10)`. 매 deep 매 VAE.
|
||||
|
||||
## 🔗 Graph
|
||||
- 응용: [[VAE]]
|
||||
- Adjacent: [[Variational-Inference]] · [[Maximum-A-Posteriori]] · [[K-Means-Clustering-Foundations]] · [[Baum-Welch]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 derivation 의 walk-through, 매 ELBO 의 explain, 매 model selection (BIC) 의 advice, 매 troubleshooting (e.g., 매 singular covariance).
|
||||
**언제 X**: 매 large-scale fitting — 매 sklearn / dedicated library 사용. 매 numerical issue 의 diagnosis 시 actual data 의 inspection 필요.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Single random init**: 매 local optimum trap — n_init=10 권장.
|
||||
- **Singular covariance ignore**: 매 sigma += εI 의 regularization 필수.
|
||||
- **Convergence 의 likelihood 가 아닌 parameter 의 monitor**: 매 wrong — likelihood / ELBO 의 monitor.
|
||||
- **K 의 randomly choose**: 매 BIC / AIC / cross-validation 사용.
|
||||
- **K-means 의 GMM 결과 비교**: 매 different — GMM 의 soft assignment + covariance.
|
||||
- **EM 의 global optimum 가정**: 매 local optimum 만 — multi-start 필수.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Dempster-Laird-Rubin 1977, Bishop "PRML" Ch9, Murphy "Probabilistic ML" Ch11).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — algorithm, ELBO, GMM/HMM/VAE applications, NumPy from-scratch |
|
||||
@@ -0,0 +1,164 @@
|
||||
---
|
||||
id: wiki-2026-0508-fmea
|
||||
title: FMEA
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Failure Mode and Effects Analysis, DFMEA, PFMEA, FMECA]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [reliability, risk, safety, systems-engineering]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: pandas, AIAG-VDA template
|
||||
---
|
||||
|
||||
# FMEA
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 system 의 모든 failure mode 의 systematic enumeration + ranking"**. 1949 US Military (MIL-P-1629) → NASA Apollo → 자동차 (AIAG-VDA 2019, the modern standard) → 매 software / ML / SRE 의 risk-process 로 generalized. 매 "what can fail, how, what then, what to do" 의 매 4 column.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 종류
|
||||
- **DFMEA** (Design): 매 product / component design 단계.
|
||||
- **PFMEA** (Process): 매 manufacturing / business process.
|
||||
- **SFMEA** (System): 매 system-of-systems 의 interaction.
|
||||
- **FMECA**: 매 + Criticality (quantitative).
|
||||
- **MLFMEA / AI-FMEA** (2024+): 매 ML model failure modes (data drift, prompt injection, hallucination).
|
||||
|
||||
### 매 AIAG-VDA 7-step (2019, current global standard)
|
||||
1. **Planning & Preparation** (5T: InTent, Timing, Team, Tasks, Tools).
|
||||
2. **Structure Analysis** (system → subsystem → component tree).
|
||||
3. **Function Analysis** (each element 의 functions + interfaces).
|
||||
4. **Failure Analysis** (Failure Effect FE / Failure Mode FM / Failure Cause FC chain).
|
||||
5. **Risk Analysis** — replaces RPN with **Action Priority (AP: H/M/L)** based on (S, O, D).
|
||||
6. **Optimization** (preventive + detection actions).
|
||||
7. **Results Documentation**.
|
||||
|
||||
### 매 scoring
|
||||
- **Severity (S)** 1–10: 매 effect 의 customer / safety impact.
|
||||
- **Occurrence (O)** 1–10: 매 cause 의 likelihood.
|
||||
- **Detection (D)** 1–10: 매 control 의 detection ability (10 = 못 detect).
|
||||
- 매 legacy **RPN = S·O·D** (deprecated by AIAG-VDA but still common).
|
||||
- 매 modern **Action Priority** matrix: H / M / L.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Minimal FMEA table (pandas)
|
||||
```python
|
||||
import pandas as pd
|
||||
|
||||
rows = [
|
||||
{"item":"Brake pad","function":"friction","FM":"wear",
|
||||
"FE":"reduced braking","FC":"high mileage",
|
||||
"S":9,"O":4,"D":3},
|
||||
{"item":"Brake pad","function":"friction","FM":"contamination",
|
||||
"FE":"squeal","FC":"oil leak",
|
||||
"S":4,"O":3,"D":5},
|
||||
]
|
||||
df = pd.DataFrame(rows)
|
||||
df["RPN"] = df.S * df.O * df.D
|
||||
df = df.sort_values("RPN", ascending=False)
|
||||
```
|
||||
|
||||
### AIAG-VDA Action Priority
|
||||
```python
|
||||
def action_priority(S, O, D):
|
||||
if S >= 9 and O >= 4: return "H"
|
||||
if S >= 9 and O >= 2: return "H"
|
||||
if S >= 7 and O >= 6 and D >= 6: return "H"
|
||||
if S >= 7 and O >= 4 and D >= 4: return "M"
|
||||
if S >= 4 and O >= 4: return "M"
|
||||
return "L"
|
||||
df["AP"] = df.apply(lambda r: action_priority(r.S, r.O, r.D), axis=1)
|
||||
```
|
||||
|
||||
### Software-FMEA (microservice)
|
||||
```python
|
||||
fmeas = [
|
||||
dict(component="auth-svc", FM="JWT signature mismatch",
|
||||
FE="login fails, downstream 401",
|
||||
FC="key rotation race",
|
||||
control="canary + jwks fallback",
|
||||
S=8, O=3, D=4),
|
||||
dict(component="auth-svc", FM="DB pool exhaustion",
|
||||
FE="latency spike, cascading 503",
|
||||
FC="connection leak in handler",
|
||||
control="bounded pool + timeouts + chaos test",
|
||||
S=7, O=5, D=6),
|
||||
]
|
||||
```
|
||||
|
||||
### ML-FMEA (LLM application)
|
||||
```python
|
||||
ml_fmeas = [
|
||||
dict(stage="prompt", FM="prompt injection",
|
||||
FE="data exfiltration via tool call",
|
||||
FC="user content concatenated unfiltered",
|
||||
control="structured prompt + injection classifier + tool allow-list",
|
||||
S=10, O=6, D=7),
|
||||
dict(stage="model", FM="hallucinated citation",
|
||||
FE="false legal claim",
|
||||
FC="long-tail fact, no retrieval",
|
||||
control="RAG + post-hoc verifier",
|
||||
S=8, O=7, D=5),
|
||||
dict(stage="data", FM="distribution drift",
|
||||
FE="accuracy drop in prod",
|
||||
FC="seasonal user mix change",
|
||||
control="online metric monitor + canary",
|
||||
S=6, O=6, D=4),
|
||||
]
|
||||
```
|
||||
|
||||
### Criticality matrix plot
|
||||
```python
|
||||
import matplotlib.pyplot as plt
|
||||
plt.scatter(df.O, df.S, s=df.D*40, alpha=0.6)
|
||||
for _, r in df.iterrows(): plt.annotate(r.FM, (r.O, r.S))
|
||||
plt.xlabel("Occurrence"); plt.ylabel("Severity"); plt.grid()
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Hardware design (auto, aero) | **DFMEA + AIAG-VDA** |
|
||||
| Manufacturing line | **PFMEA** |
|
||||
| Safety-critical (DO-178C, ISO 26262) | **FMEA + FTA + STPA** |
|
||||
| Software service | **Software-FMEA + chaos engineering** |
|
||||
| LLM / ML system | **ML-FMEA + red-team + evals** |
|
||||
| Quick triage | **Risk matrix (S × O)** |
|
||||
|
||||
**기본값**: 매 AIAG-VDA 7-step + AP scoring (RPN deprecated).
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Risk_Management|Risk-Management]]
|
||||
- 변형: [[DFMEA]] · [[PFMEA]] · [[FMECA]]
|
||||
- 응용: [[SRE]]
|
||||
- Adjacent: [[Chaos-Engineering]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 new system 의 risk register 를 brainstorm; 매 architecture review 의 failure-chain 의 enumeration; 매 ML deployment 의 pre-mortem.
|
||||
**언제 X**: 매 emergent / interactive failure (매 complex software) — 매 STPA 의 더 적합. 매 statistical reliability 는 FTA + Markov.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **RPN multiplication only**: 매 (10,1,1)=10 vs (2,5,1)=10 의 same — but severity 10 의 catastrophic. **AP matrix 사용.**
|
||||
- **Sev/Occ/Det 의 inconsistent scale**: 매 team-wide rubric 없으면 매 garbage.
|
||||
- **One-shot document**: 매 living document 가 아니면 매 outdated. 매 design change 의 trigger update.
|
||||
- **Skipping detection actions**: 매 only "add training" — 매 weak. 매 sensor / monitor / poka-yoke 의 추가.
|
||||
- **Software FMEA 의 component-only**: 매 interaction failures 의 missed — 매 STPA 의 complement.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (MIL-P-1629; AIAG-VDA FMEA Handbook 2019; SAE J1739; ISO 26262-9).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 placeholder |
|
||||
| 2026-05-10 | Manual cleanup — 7-step AIAG-VDA + 5 patterns + ML-FMEA |
|
||||
@@ -0,0 +1,189 @@
|
||||
---
|
||||
id: wiki-2026-0508-feedback-control-systems
|
||||
title: Feedback Control Systems
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Closed-Loop Control, Control System, PID, MPC]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
verification_status: applied
|
||||
tags: [control-theory, systems, dynamics, automation]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: python-control, scipy.signal, do-mpc, casadi
|
||||
---
|
||||
|
||||
# Feedback Control Systems
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 sensor → comparator → controller → actuator → plant → sensor 매 closed loop 으로 setpoint 를 maintain"**. James Watt 의 governor (1788) → Bode/Nyquist (1930s) → state-space + Kalman (1960s) → 매 modern: **MPC, ADRC, learning-based control (Koopman/MPC, RL)**. 매 SRE autoscaler, drone, EV motor, vaccine cold-chain, fab DRIE — 매 universal.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 canonical block diagram
|
||||
```
|
||||
┌─────────┐
|
||||
r ──+──▶│Controller│──u──▶┌─────┐──y──┐
|
||||
─ │ C(s) │ │P(s)│ │
|
||||
└─────────┘ └─────┘ │
|
||||
▲ │
|
||||
└──── − ◀── sensor ◀───┘
|
||||
e = r − y_meas (error)
|
||||
```
|
||||
|
||||
### 매 PID intuition
|
||||
- **P (proportional)**: 매 instant correction; 매 too high → oscillation.
|
||||
- **I (integral)**: 매 eliminate steady-state error; 매 too high → wind-up.
|
||||
- **D (derivative)**: 매 damping; 매 amplify noise.
|
||||
|
||||
### 매 modern 분류
|
||||
- **Classical**: PID, lead-lag, root-locus, Bode design.
|
||||
- **State-space**: pole-placement, LQR, observer / Kalman filter.
|
||||
- **Robust**: H∞, μ-synthesis (uncertain plant).
|
||||
- **Adaptive**: MRAC, gain-scheduling.
|
||||
- **Predictive**: **MPC** (constraint-aware, multi-step optimize).
|
||||
- **Learning-based** (2026): Koopman-MPC, Gaussian-Process MPC, **safe RL with control-barrier functions**.
|
||||
|
||||
### 매 stability
|
||||
- 매 LTI 의 Routh-Hurwitz, Nyquist, gain/phase margin (≥ 6 dB / 30°).
|
||||
- 매 nonlinear 의 Lyapunov.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### PID class
|
||||
```python
|
||||
class PID:
|
||||
def __init__(self, kp, ki, kd, dt, u_min=None, u_max=None):
|
||||
self.kp,self.ki,self.kd,self.dt = kp,ki,kd,dt
|
||||
self.u_min,self.u_max = u_min,u_max
|
||||
self.i, self.prev = 0.0, 0.0
|
||||
def __call__(self, sp, pv):
|
||||
e = sp - pv
|
||||
self.i += e*self.dt
|
||||
d = (e - self.prev)/self.dt
|
||||
self.prev = e
|
||||
u = self.kp*e + self.ki*self.i + self.kd*d
|
||||
if self.u_max is not None and u > self.u_max:
|
||||
u = self.u_max; self.i -= e*self.dt # anti-windup
|
||||
if self.u_min is not None and u < self.u_min:
|
||||
u = self.u_min; self.i -= e*self.dt
|
||||
return u
|
||||
```
|
||||
|
||||
### Ziegler–Nichols tuning
|
||||
```python
|
||||
# 1) Set ki=kd=0; raise kp to find Ku where output sustains oscillation at period Tu.
|
||||
# 2) Classic ZN: kp=0.6Ku, ki=2kp/Tu, kd=kp*Tu/8
|
||||
def zn_classic(Ku, Tu): return 0.6*Ku, 2*0.6*Ku/Tu, 0.6*Ku*Tu/8
|
||||
```
|
||||
|
||||
### Plant simulation (python-control)
|
||||
```python
|
||||
import control as ct, numpy as np, matplotlib.pyplot as plt
|
||||
P = ct.tf([1], [1, 3, 2]) # 1/(s²+3s+2)
|
||||
C = ct.tf([2, 1], [1, 0]) # PI: 2 + 1/s
|
||||
L = ct.series(C, P)
|
||||
T = ct.feedback(L, 1)
|
||||
t, y = ct.step_response(T, T=np.linspace(0, 10, 500))
|
||||
plt.plot(t, y); plt.axhline(1, ls="--")
|
||||
```
|
||||
|
||||
### State-space LQR
|
||||
```python
|
||||
import numpy as np, control as ct
|
||||
A = np.array([[0,1],[-2,-3]]); B = np.array([[0],[1]])
|
||||
Q = np.diag([10, 1]); R = np.array([[0.1]])
|
||||
K, _, _ = ct.lqr(A, B, Q, R)
|
||||
# u = -K x
|
||||
```
|
||||
|
||||
### Kalman filter
|
||||
```python
|
||||
import numpy as np
|
||||
def kf_step(x, P, z, A, H, Q, R):
|
||||
# predict
|
||||
x = A @ x; P = A @ P @ A.T + Q
|
||||
# update
|
||||
y = z - H @ x
|
||||
S = H @ P @ H.T + R
|
||||
K = P @ H.T @ np.linalg.inv(S)
|
||||
x = x + K @ y
|
||||
P = (np.eye(len(x)) - K @ H) @ P
|
||||
return x, P
|
||||
```
|
||||
|
||||
### Model Predictive Control (do-mpc, level tank)
|
||||
```python
|
||||
import numpy as np, do_mpc
|
||||
from casadi import vertcat
|
||||
m = do_mpc.model.Model("continuous")
|
||||
h = m.set_variable("_x","h"); u = m.set_variable("_u","u")
|
||||
m.set_rhs("h", -0.1*h + u); m.setup()
|
||||
|
||||
mpc = do_mpc.controller.MPC(m)
|
||||
mpc.set_param(n_horizon=20, t_step=0.1, store_full_solution=True)
|
||||
mpc.set_objective(mterm=(h-1)**2, lterm=(h-1)**2 + 0.01*u**2)
|
||||
mpc.set_rterm(u=0.1)
|
||||
mpc.bounds["lower","_u","u"] = 0; mpc.bounds["upper","_u","u"] = 2
|
||||
mpc.bounds["lower","_x","h"] = 0; mpc.bounds["upper","_x","h"] = 1.5
|
||||
mpc.setup()
|
||||
mpc.x0 = np.array([0.0]); mpc.set_initial_guess()
|
||||
u0 = mpc.make_step(np.array([0.0]))
|
||||
```
|
||||
|
||||
### Autoscaler-as-PID (SRE)
|
||||
```python
|
||||
class CPUAutoscaler:
|
||||
def __init__(self, target=0.6, k=10, max_r=20):
|
||||
self.pid = PID(kp=k, ki=k/30, kd=0, dt=15, u_min=-3, u_max=3)
|
||||
self.target, self.max_r = target, max_r
|
||||
def step(self, cpu, replicas):
|
||||
delta = self.pid(self.target, cpu)
|
||||
return max(1, min(self.max_r, replicas + round(delta)))
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Single SISO, slow plant | **PID** (90% of industry) |
|
||||
| MIMO, known model | **LQR / state-space** |
|
||||
| Constraints + multi-step lookahead | **MPC** |
|
||||
| Large model uncertainty | **H∞ / robust control** |
|
||||
| Time-varying gain | **Gain-scheduling / adaptive** |
|
||||
| Unknown dynamics, lots of data | **Koopman-MPC / GP-MPC / safe RL** |
|
||||
| Stochastic measurement | **+ Kalman / EKF / UKF** |
|
||||
|
||||
**기본값**: 매 SISO + slow plant → **PID with anti-windup + ZN-tuning**, 매 constraint-rich multi-input → **MPC**.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Control-Theory]] · [[Cybernetics Foundations|Cybernetics]]
|
||||
- 변형: [[PID]] · [[MPC]]
|
||||
- 응용: [[Robotics]]
|
||||
- Adjacent: [[Feedback-Loops in Systems]] · [[Kalman-Filter-and-State-Tracking|Kalman-Filter]] · [[Reinforcement-Learning]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 PID 의 tuning, 매 plant 의 transfer-function 의 derivation, 매 MPC objective 의 formulation, 매 stability 의 quick check.
|
||||
**언제 X**: 매 safety-critical real-time control 의 untested LLM-generated code 의 직접 deploy — 매 formal verification + HIL test 필수.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **No anti-windup**: 매 saturated actuator + integral 의 huge overshoot.
|
||||
- **D term on noisy measurement**: 매 amplifies high-freq noise — 매 derivative-on-measurement + low-pass filter.
|
||||
- **Sample rate ≪ bandwidth**: 매 dt 의 ≥ 10× system bandwidth 의 violate → 매 instability.
|
||||
- **Tuning by gut**: 매 reproducible (ZN, model-based, autotuning) 의 사용.
|
||||
- **Open-loop "feedback"**: 매 sensor 없이 매 not feedback control.
|
||||
- **Ignoring delay**: 매 transport delay → 매 Smith predictor / phase margin 의 reserve.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Bode 1945; Åström & Murray *Feedback Systems* 2nd ed.; Rawlings, Mayne & Diehl *MPC* 2nd ed.; Brunton & Kutz *Data-Driven Science and Engineering* 2022).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 placeholder |
|
||||
| 2026-05-10 | Manual cleanup — classical→MPC + 7 patterns + decision matrix |
|
||||
@@ -0,0 +1,171 @@
|
||||
---
|
||||
id: wiki-2026-0508-feedback-loops-in-systems
|
||||
title: Feedback Loops in Systems
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Feedback Loop, Closed-Loop, Reinforcing Loop, Balancing Loop]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [systems-thinking, control, dynamics, cybernetics]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: scipy.signal, simpy, control
|
||||
---
|
||||
|
||||
# Feedback Loops in Systems
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 output 의 portion 의 input 으로 routed back — 매 system 의 self-regulation / self-amplification 의 fundamental mechanism"**. Wiener 의 cybernetics (1948) → Forrester 의 system dynamics (1961) → Meadows 의 *Thinking in Systems* (2008) → 매 SRE / RL / market-design 까지 매 universal.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 두 polarity
|
||||
- **Reinforcing (R, +)**: 매 same-direction amplification → 매 exponential growth or collapse. 매 viral growth, bank runs, flywheel.
|
||||
- **Balancing (B, −)**: 매 opposite-direction correction → 매 goal-seeking equilibrium. 매 thermostat, autoscaler, supply-demand.
|
||||
- 매 system 의 behavior = sum of all loops, with delays.
|
||||
|
||||
### 매 4 building blocks (Meadows)
|
||||
1. **Stocks** (state, accumulator).
|
||||
2. **Flows** (rate of change).
|
||||
3. **Information links** (signals).
|
||||
4. **Delays** (transport, perception, action).
|
||||
|
||||
### 매 typical archetypes
|
||||
- **Limits to growth**: R + B (resource constraint).
|
||||
- **Shifting the burden**: short-term fix B undermines long-term solution.
|
||||
- **Tragedy of the commons**: many R + 1 B.
|
||||
- **Success to the successful**: 2 R coupled.
|
||||
- **Drift to low performance**: B with eroding goals.
|
||||
- **Escalation**: 2 R + delay (arms race).
|
||||
|
||||
### 매 stability
|
||||
- 매 negative loop 의 gain > 1 + delay → 매 oscillation, overshoot.
|
||||
- 매 positive loop 의 unchecked → 매 runaway / collapse.
|
||||
- 매 Bode / Nyquist 의 control-theory 의 quantitative tool.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Thermostat (B loop, ODE)
|
||||
```python
|
||||
import numpy as np
|
||||
from scipy.integrate import odeint
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
setpoint, k_loss, k_heat = 22.0, 0.1, 0.5
|
||||
def dT(T, t):
|
||||
heat = k_heat if T < setpoint else 0
|
||||
return -k_loss*(T-10) + heat
|
||||
t = np.linspace(0, 100, 1000)
|
||||
T = odeint(dT, 15, t)
|
||||
plt.plot(t, T); plt.axhline(setpoint, ls="--")
|
||||
```
|
||||
|
||||
### PID controller (B with derivative damping)
|
||||
```python
|
||||
class PID:
|
||||
def __init__(self, kp, ki, kd, dt):
|
||||
self.kp,self.ki,self.kd,self.dt = kp,ki,kd,dt
|
||||
self.i, self.prev = 0, 0
|
||||
def __call__(self, sp, pv):
|
||||
e = sp - pv
|
||||
self.i += e*self.dt
|
||||
d = (e - self.prev)/self.dt
|
||||
self.prev = e
|
||||
return self.kp*e + self.ki*self.i + self.kd*d
|
||||
```
|
||||
|
||||
### Reinforcing loop — viral growth
|
||||
```python
|
||||
def viral(t_max=30, k=0.2, init=10, cap=1e6):
|
||||
n=[init]
|
||||
for _ in range(t_max):
|
||||
n.append(min(cap, n[-1]*(1+k))) # R loop
|
||||
return n
|
||||
# 매 limits-to-growth 의 cap 의 추가 — pure exponential 의 unrealistic.
|
||||
```
|
||||
|
||||
### Logistic — R + B (limits to growth)
|
||||
```python
|
||||
def logistic(K=1e6, r=0.3, t_max=60, init=10):
|
||||
x=[init]
|
||||
for _ in range(t_max):
|
||||
x.append(x[-1] + r*x[-1]*(1-x[-1]/K))
|
||||
return x
|
||||
```
|
||||
|
||||
### Stock-and-flow (Forrester) with simpy
|
||||
```python
|
||||
import simpy, random
|
||||
env = simpy.Environment()
|
||||
inventory = simpy.Container(env, init=100, capacity=1000)
|
||||
def supplier(env):
|
||||
while True:
|
||||
yield env.timeout(2)
|
||||
if inventory.level < 50: # B loop on stock
|
||||
yield inventory.put(60)
|
||||
def customer(env):
|
||||
while True:
|
||||
yield env.timeout(random.expovariate(1))
|
||||
yield inventory.get(1)
|
||||
env.process(supplier(env)); [env.process(customer(env)) for _ in range(5)]
|
||||
env.run(until=100)
|
||||
```
|
||||
|
||||
### Autoscaler (SRE B loop)
|
||||
```python
|
||||
def autoscaler(metric, target=0.6, replicas=3, max_r=20):
|
||||
err = metric - target
|
||||
delta = round(err * replicas / target)
|
||||
return max(1, min(max_r, replicas + delta))
|
||||
```
|
||||
|
||||
### Causal-loop diagram (text DSL)
|
||||
```
|
||||
Users ─R→ Content ─R→ Engagement ─R→ Users (viral R)
|
||||
Users ─B→ Server-load ─B→ Latency ─B→ Users (capacity B)
|
||||
delay: server provisioning ≈ 10 min → oscillation risk.
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Continuous physical / control | **PID / state-space** |
|
||||
| Discrete event business / supply chain | **System Dynamics (stocks-flows)** |
|
||||
| Service capacity | **B loop autoscaler + SLO error budget** |
|
||||
| Growth product strategy | **Map R loops; identify limit B; remove constraint** |
|
||||
| Policy / market | **Causal-loop diagram + agent-based sim** |
|
||||
| Stability analysis | **Linearize → Bode / root-locus** |
|
||||
|
||||
**기본값**: 매 design 의 첫 단계 = **CLD (Causal Loop Diagram)** + delay 표시 + leverage point 식별.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Systems_Thinking|Systems-Thinking]] · [[Cybernetics Foundations|Cybernetics]] · [[Control-Theory]]
|
||||
- 변형: [[Reinforcing-Loop]] · [[Balancing-Loop]]
|
||||
- 응용: [[Feedback-Control-Systems]] · [[Reinforcement-Learning]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 unintended consequence 의 prediction, 매 product growth 의 root-cause, 매 SRE incident 의 cascading 분석, 매 policy design 의 leverage point.
|
||||
**언제 X**: 매 fully open-loop 의 simple pipeline (매 unnecessary modeling).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Loops without delay**: 매 real systems 의 always have delays — 매 oscillation 의 missed.
|
||||
- **Linear thinking in nonlinear loop**: 매 small input change 의 huge output (or vice versa).
|
||||
- **Optimizing one node**: 매 ignoring loop → 매 Goodhart, perverse incentives.
|
||||
- **Goal erosion**: 매 missed-target → 매 lower target → 매 drift.
|
||||
- **Fixing symptom (B)**: 매 underlying R loop 의 unaddressed (shifting the burden).
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Wiener 1948; Forrester 1961; Senge 1990; Meadows 2008; *Designing Data-Intensive Apps* on backpressure).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 placeholder |
|
||||
| 2026-05-10 | Manual cleanup — archetypes + 7 patterns + decision matrix |
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
---
|
||||
id: wiki-2026-0508-flame-icicle-graph-플레임-고드름-그래프
|
||||
title: Flame Icicle Graph 플레임 고드름 그래프
|
||||
category: 10_Wiki/Topics
|
||||
status: duplicate
|
||||
canonical_id: wiki-2026-0508-flame-graph
|
||||
duplicate_of: "[[Flame-Graph]]"
|
||||
aliases: []
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: redirected
|
||||
tags: [duplicate, profiling, visualization, performance]
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
---
|
||||
|
||||
# Flame Icicle Graph 플레임 고드름 그래프
|
||||
|
||||
> **이 문서는 [[Flame-Graph]] 의 중복본입니다.** Canonical 문서로 redirect.
|
||||
|
||||
## 핵심 요약 (Korean alias specialization)
|
||||
- **Flame graph** (Brendan Gregg, 2011): 매 stack frames 의 width = sample-count 의 visualization, 매 root at bottom (불꽃 모양).
|
||||
- **Icicle graph** (고드름): 매 same data, 매 root at top (거꾸로 매달린 모양). 매 일부 도구 default (Chrome DevTools, py-spy `--format speedscope`).
|
||||
- 매 두 form 의 same information — 매 orientation 의 only difference.
|
||||
- 매 Korean speakers 의 위해 매 "플레임 / 고드름 그래프" 검색어 의 covered.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Flame-Graph]] (canonical)
|
||||
- Adjacent: [[Profiling]] · [[Performance-Analysis]]
|
||||
|
||||
## 🕓 변경 이력
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 placeholder |
|
||||
| 2026-05-10 | 중복 처리 — Korean alias title, canonical 문서 [[Flame-Graph]] 으로 redirect |
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
---
|
||||
id: wiki-2026-0508-geographic-information-systems
|
||||
title: Geographic Information Systems
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [GIS, Geospatial, Spatial Data]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [geospatial, mapping, data, spatial-analysis]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: GeoPandas, Shapely, PostGIS, DuckDB-spatial, Lonboard
|
||||
---
|
||||
|
||||
# Geographic Information Systems
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 spatially-referenced data 의 capture, storage, query, analysis, visualization"**. Roger Tomlinson 의 Canada GIS (1968) → Esri ArcInfo → 매 modern open stack (PostGIS, GeoPandas, GDAL, GeoParquet, DuckDB-spatial, deck.gl). 매 2026 trend: **cloud-native geospatial (COG, STAC, GeoParquet, FlatGeobuf), GPU vector rendering, ML-on-raster**.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 two data models
|
||||
- **Vector**: points, lines, polygons (Shapefile/GeoJSON/FlatGeobuf/GeoParquet). 매 discrete features.
|
||||
- **Raster**: regular grid of cells (GeoTIFF, COG, Zarr). 매 continuous fields, satellite imagery.
|
||||
|
||||
### 매 핵심 concepts
|
||||
- **CRS (Coordinate Reference System)**: WGS84 (EPSG:4326), Web Mercator (3857), UTM zones, local projected.
|
||||
- **Topology**: contains/intersects/touches/crosses (DE-9IM).
|
||||
- **Spatial index**: R-tree, Quadtree, **H3 / S2 hex grid** (Uber/Google), Geohash.
|
||||
- **Map algebra**: raster arithmetic, focal/zonal stats.
|
||||
- **Geocoding / reverse**: address ↔ coords.
|
||||
|
||||
### 매 modern (2026) stack
|
||||
- **Storage**: GeoParquet, COG (Cloud-Optimized GeoTIFF), STAC catalogs, PMTiles.
|
||||
- **Compute**: DuckDB-spatial, GeoPandas 1.x (PyArrow backend), Sedona, BigQuery GIS.
|
||||
- **Render**: deck.gl, Lonboard (in-Jupyter GPU vector), MapLibre, Mapbox GL.
|
||||
- **ML**: Segment-Anything-on-imagery, SatCLIP embeddings, prithvi geo-foundation model.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Read & reproject (GeoPandas)
|
||||
```python
|
||||
import geopandas as gpd
|
||||
gdf = gpd.read_file("zip://./tl_2024_us_county.zip")
|
||||
gdf = gdf.to_crs(epsg=3857) # Web Mercator
|
||||
print(gdf.geometry.area.head()) # m² in projected CRS
|
||||
```
|
||||
|
||||
### Spatial join + index
|
||||
```python
|
||||
points = gpd.read_file("stores.geojson").to_crs(epsg=3857)
|
||||
admin = gpd.read_file("districts.geojson").to_crs(epsg=3857)
|
||||
joined = gpd.sjoin(points, admin, how="left", predicate="within")
|
||||
```
|
||||
|
||||
### PostGIS query
|
||||
```sql
|
||||
-- find restaurants within 500 m of a metro stop
|
||||
SELECT r.id, r.name
|
||||
FROM restaurants r
|
||||
JOIN metro_stops m
|
||||
ON ST_DWithin(r.geom::geography, m.geom::geography, 500)
|
||||
WHERE m.line = 'Line 2';
|
||||
CREATE INDEX restaurants_geom_gix ON restaurants USING GIST (geom);
|
||||
```
|
||||
|
||||
### DuckDB-spatial (single-file analytics)
|
||||
```python
|
||||
import duckdb
|
||||
con = duckdb.connect()
|
||||
con.install_extension("spatial"); con.load_extension("spatial")
|
||||
con.sql("""
|
||||
SELECT name, ST_Area(geom)/1e6 AS km2
|
||||
FROM ST_Read('countries.fgb')
|
||||
WHERE ST_Intersects(geom, ST_MakeEnvelope(-10,35,40,70))
|
||||
ORDER BY km2 DESC LIMIT 5
|
||||
""").show()
|
||||
```
|
||||
|
||||
### Raster analysis (rioxarray)
|
||||
```python
|
||||
import rioxarray as rxr
|
||||
ndvi_red = rxr.open_rasterio("B04.tif", masked=True)
|
||||
ndvi_nir = rxr.open_rasterio("B08.tif", masked=True)
|
||||
ndvi = (ndvi_nir - ndvi_red) / (ndvi_nir + ndvi_red)
|
||||
ndvi.rio.to_raster("ndvi.tif", driver="COG")
|
||||
```
|
||||
|
||||
### H3 hex aggregation
|
||||
```python
|
||||
import h3, pandas as pd
|
||||
df = pd.read_csv("rides.csv")
|
||||
df["h3"] = [h3.latlng_to_cell(lat, lng, 9) for lat,lng in zip(df.lat, df.lng)]
|
||||
agg = df.groupby("h3").size().reset_index(name="rides")
|
||||
```
|
||||
|
||||
### Routing (OSMnx + NetworkX)
|
||||
```python
|
||||
import osmnx as ox, networkx as nx
|
||||
G = ox.graph_from_place("Berlin, Germany", network_type="drive")
|
||||
orig = ox.distance.nearest_nodes(G, 13.405, 52.520)
|
||||
dest = ox.distance.nearest_nodes(G, 13.450, 52.500)
|
||||
route = nx.shortest_path(G, orig, dest, weight="length")
|
||||
```
|
||||
|
||||
### GPU map render (Lonboard, in notebook)
|
||||
```python
|
||||
import lonboard
|
||||
from lonboard import Map, ScatterplotLayer
|
||||
layer = ScatterplotLayer.from_geopandas(points, get_radius=20, get_fill_color=[200,30,30])
|
||||
Map(layer)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Single laptop, < 10 M rows | **GeoPandas 1.x** |
|
||||
| Analytics, columnar | **DuckDB-spatial + GeoParquet** |
|
||||
| Multi-user transactional | **PostGIS** |
|
||||
| Cluster scale (≫ 100 GB) | **Apache Sedona / BigQuery GIS** |
|
||||
| Satellite raster pipeline | **STAC + COG + rioxarray + Dask** |
|
||||
| Aggregation by tile | **H3 / S2 hex** |
|
||||
| Web map (millions of features) | **PMTiles + MapLibre / deck.gl** |
|
||||
| ML on imagery | **prithvi / SatCLIP + SAM-Geo** |
|
||||
|
||||
**기본값**: 매 modern 의 **GeoParquet + DuckDB-spatial + Lonboard** trio (laptop-scale), 매 server 의 **PostGIS**.
|
||||
|
||||
## 🔗 Graph
|
||||
- 응용: [[Routing]]
|
||||
- Adjacent: [[PostGIS]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 spatial-aware app 의 architecture, 매 CRS / projection 의 selection 의 explanation, 매 SQL 의 PostGIS 의 generation, 매 imagery analysis 의 prompting.
|
||||
**언제 X**: 매 high-precision survey / cadastral 의 manual professional 검증 필수.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Mixed CRS without reproject**: 매 km vs degree 의 silent mismatch.
|
||||
- **Web Mercator 의 area calc**: 매 high-latitude 의 huge distortion — 매 equal-area projection 사용.
|
||||
- **Shapefile 의 still using**: 매 10-char column, 2 GB limit, no UTF-8 — 매 GeoParquet/FlatGeobuf 사용.
|
||||
- **No spatial index**: 매 PostGIS GIST 없이 매 query 의 100-1000× slow.
|
||||
- **Raster 매 in-memory full load**: 매 windowed read (rioxarray + Dask) 사용.
|
||||
- **Lat/Lon swap**: 매 GeoJSON `[lng, lat]` vs human `(lat, lng)` 의 가장 흔한 bug.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (OGC standards; PostGIS docs; *Geocomputation with Python* 2024; Cloud-Native Geospatial Foundation).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 placeholder |
|
||||
| 2026-05-10 | Manual cleanup — modern 2026 stack + 8 patterns |
|
||||
@@ -0,0 +1,163 @@
|
||||
---
|
||||
id: wiki-2026-0508-gimbals-and-orientation
|
||||
title: Gimbals and Orientation
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Gimbal Lock, 3D Orientation, Rotation Representation]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
verification_status: applied
|
||||
tags: [graphics, math, rotation, quaternion, robotics]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: NumPy/SciPy
|
||||
---
|
||||
|
||||
# Gimbals and Orientation
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 3D rotation은 representation 의 선택이 다 — Euler 직관, quaternion 안전, matrix 합성 빠르"**. Gimbal lock 의 1958 Apollo IMU에서 발견된 singularity 매 모든 3-axis Euler systems에서 발생, 매 quaternion / rotation matrix 의 modern solution. 매 robotics, graphics, aerospace, VR 의 fundamental.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 representations
|
||||
- **Euler angles** (roll, pitch, yaw): 3 floats, intuitive, but **gimbal lock at ±90° pitch**.
|
||||
- **Rotation matrix** (3×3): 9 floats, no singularity, composable via multiplication, but redundant (only 3 DOF).
|
||||
- **Quaternion** (w, x, y, z): 4 floats, no gimbal lock, smooth SLERP interpolation, double cover (q and -q same rotation).
|
||||
- **Axis-angle** (Rodrigues): 3 floats encoding axis × angle, compact.
|
||||
|
||||
### 매 gimbal lock 매커니즘
|
||||
- 매 3 nested rotations (e.g. ZYX) 매 second rotation이 ±90° 면 first/third axis가 align — DOF loss from 3 to 2.
|
||||
- 매 Apollo 11 LM 의 famous near-miss: Aldrin manually steered to avoid IMU lock.
|
||||
|
||||
### 매 응용
|
||||
1. Robotics IK / joint orientation.
|
||||
2. Game character / camera control.
|
||||
3. VR/AR head tracking (IMU sensor fusion).
|
||||
4. Drone / aerospace attitude control.
|
||||
5. Skeletal animation blending.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Quaternion from Euler (avoid gimbal lock)
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
def euler_to_quat(roll, pitch, yaw):
|
||||
cr, sr = np.cos(roll/2), np.sin(roll/2)
|
||||
cp, sp = np.cos(pitch/2), np.sin(pitch/2)
|
||||
cy, sy = np.cos(yaw/2), np.sin(yaw/2)
|
||||
w = cr*cp*cy + sr*sp*sy
|
||||
x = sr*cp*cy - cr*sp*sy
|
||||
y = cr*sp*cy + sr*cp*sy
|
||||
z = cr*cp*sy - sr*sp*cy
|
||||
return np.array([w, x, y, z])
|
||||
```
|
||||
|
||||
### SLERP (smooth quaternion interpolation)
|
||||
```python
|
||||
def slerp(q0, q1, t):
|
||||
dot = np.dot(q0, q1)
|
||||
if dot < 0.0:
|
||||
q1, dot = -q1, -dot
|
||||
if dot > 0.9995:
|
||||
return (q0 + t*(q1-q0)) / np.linalg.norm(q0 + t*(q1-q0))
|
||||
theta_0 = np.arccos(dot)
|
||||
theta = theta_0 * t
|
||||
s0 = np.cos(theta) - dot * np.sin(theta) / np.sin(theta_0)
|
||||
s1 = np.sin(theta) / np.sin(theta_0)
|
||||
return s0*q0 + s1*q1
|
||||
```
|
||||
|
||||
### Rotation matrix composition
|
||||
```python
|
||||
from scipy.spatial.transform import Rotation as R
|
||||
|
||||
R1 = R.from_euler('xyz', [30, 45, 60], degrees=True)
|
||||
R2 = R.from_quat([0, 0, 0.707, 0.707]) # x,y,z,w
|
||||
R_combined = R2 * R1
|
||||
print(R_combined.as_matrix())
|
||||
```
|
||||
|
||||
### Axis-angle (Rodrigues' formula)
|
||||
```python
|
||||
def rodrigues(axis, theta):
|
||||
axis = axis / np.linalg.norm(axis)
|
||||
K = np.array([[ 0, -axis[2], axis[1]],
|
||||
[ axis[2], 0, -axis[0]],
|
||||
[-axis[1], axis[0], 0]])
|
||||
return np.eye(3) + np.sin(theta)*K + (1-np.cos(theta))*K@K
|
||||
```
|
||||
|
||||
### IMU sensor fusion (complementary filter)
|
||||
```python
|
||||
def imu_update(q, gyro, accel, dt, alpha=0.98):
|
||||
# gyro integration
|
||||
omega = np.array([0, *gyro])
|
||||
q_dot = 0.5 * quat_mul(q, omega)
|
||||
q_gyro = q + q_dot * dt
|
||||
q_gyro /= np.linalg.norm(q_gyro)
|
||||
# accel correction
|
||||
q_accel = accel_to_quat(accel)
|
||||
return slerp(q_accel, q_gyro, alpha)
|
||||
```
|
||||
|
||||
### Detect gimbal lock
|
||||
```python
|
||||
def detect_lock(euler_pitch, threshold=89.5):
|
||||
return abs(euler_pitch) > threshold # near ±90°
|
||||
```
|
||||
|
||||
### Quaternion → Rotation matrix
|
||||
```python
|
||||
def quat_to_matrix(q):
|
||||
w, x, y, z = q
|
||||
return np.array([
|
||||
[1-2*(y*y+z*z), 2*(x*y-z*w), 2*(x*z+y*w)],
|
||||
[2*(x*y+z*w), 1-2*(x*x+z*z), 2*(y*z-x*w)],
|
||||
[2*(x*z-y*w), 2*(y*z+x*w), 1-2*(x*x+y*y)]
|
||||
])
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| User-facing UI sliders | Euler (intuitive) |
|
||||
| 3D engine internal | Quaternion |
|
||||
| Skeletal animation blending | Quaternion + SLERP |
|
||||
| Physics / forces composition | Rotation matrix |
|
||||
| IMU streaming | Quaternion + complementary/Kalman |
|
||||
| Compact storage | Axis-angle or compressed quat |
|
||||
|
||||
**기본값**: Quaternion internally, Euler at user boundaries.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Linear-Algebra-Foundations|Linear-Algebra]]
|
||||
- 응용: [[Kalman-Filter-and-State-Tracking]]
|
||||
- Adjacent: [[Eigenvalues-and-Eigenvectors]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: orientation representation 의 conversion code 생성, gimbal lock debugging hints, sensor fusion math derivation.
|
||||
**언제 X**: real-time IMU loop (latency critical — use compiled code), safety-critical aerospace code (require formal verification).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Storing rotation as Euler**: gimbal lock + interpolation discontinuity. Store as quaternion.
|
||||
- **Linear interpolation of quaternions**: NLERP works로컬 but SLERP for accuracy. NLERP for speed in animation.
|
||||
- **Forgetting double cover**: q and -q same rotation; SLERP needs sign check.
|
||||
- **Gradient-based optimization on Euler**: discontinuous near singularities — use quaternion or matrix tangent space.
|
||||
- **Mixing conventions**: (w,x,y,z) vs (x,y,z,w), intrinsic vs extrinsic Euler — document explicitly.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Shoemake 1985 quaternion paper, NASA Apollo IMU records, scipy.spatial.transform docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full content with quaternion/Euler/matrix patterns + IMU fusion |
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
---
|
||||
id: wiki-2026-0508-godel-s-incompleteness-theorems
|
||||
title: "Godel's Incompleteness Theorems"
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Incompleteness, Godel's Theorems, First and Second Incompleteness]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [logic, foundations, mathematical-logic, computability, philosophy-of-math]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Lean4
|
||||
framework: mathlib
|
||||
---
|
||||
|
||||
# Godel's Incompleteness Theorems
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 충분히 강력한 consistent formal system 의 자기 자신의 truth/consistency 의 증명 불가능"**. 1931년 Kurt Gödel 의 결과 — Hilbert program 의 종료, computability/AI/foundation of math 의 근본적 제약. 매 modern 의 Lean/Coq proof assistants, halting problem, Tarski undefinability 의 모두 이의 후예.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 First Incompleteness Theorem
|
||||
- **Statement**: 매 consistent recursively axiomatizable system T 의 Peano Arithmetic 포함 시 — 매 T 에서 증명 불가능 statement G_T (true but unprovable) 존재.
|
||||
- **Proof sketch**: Gödel numbering → 매 self-referential statement "I am not provable in T" 의 construction → 매 consistency 시 unprovable.
|
||||
- 매 consequence: 매 truth ≠ provability.
|
||||
|
||||
### 매 Second Incompleteness Theorem
|
||||
- **Statement**: 매 consistent T (PA 포함) 의 자신의 consistency Con(T) 증명 불가능.
|
||||
- 매 Hilbert program 의 사망 — 매 finitistic 한 means 의 mathematics consistency 의 증명 불가능.
|
||||
- 매 stronger system 으로 (e.g., ZFC) PA 의 consistency 증명 가능 — but 매 ZFC 자신의 consistency 매 ZFC 안에서 증명 불가능.
|
||||
|
||||
### 매 핵심 개념
|
||||
- **Gödel numbering**: 매 syntactic objects (formulas, proofs) → ℕ 의 injection. 매 meta-mathematical statement 의 arithmetic statement 로의 encoding.
|
||||
- **ω-consistency** vs **simple consistency**: 매 first proof 의 ω-consistency 의존, Rosser 1936 의 simple consistency 만으로도 OK.
|
||||
- **Provability predicate Bew_T(x)**: 매 "x 의 numerical encoding 의 statement 매 T 에서 증명가능".
|
||||
- **Hilbert-Bernays-Löb derivability conditions**: D1, D2, D3.
|
||||
|
||||
### 매 응용 / 영향
|
||||
1. **Halting problem (Turing 1936)**: 매 incompleteness 의 computability twin — 매 universal halting predicate 매 unrecursive.
|
||||
2. **Tarski's undefinability (1936)**: 매 truth predicate 매 system 자신 안에서 정의 불가능.
|
||||
3. **Löb's theorem (1955)**: 매 Bew(⌜φ⌝) → φ 증명 시 ⊢ φ.
|
||||
4. **AI/AGI 의미**: Penrose-Lucas 의 mind ≠ algorithm argument (매 controversial). 2024-2026 LLM era 에서 매 재논쟁.
|
||||
5. **Foundations**: ZFC 의 large cardinal axioms — 매 stronger theories 의 hierarchy.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Gödel Numbering (매 simple toy)
|
||||
```python
|
||||
def godel_number_str(s):
|
||||
"""매 매 character 의 ASCII → prime^code product.
|
||||
매 unique decoding 가능."""
|
||||
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
|
||||
result = 1
|
||||
for i, c in enumerate(s):
|
||||
result *= primes[i] ** ord(c)
|
||||
return result
|
||||
|
||||
def decode_godel(n):
|
||||
"""매 prime factorization 통해 string 복원."""
|
||||
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
|
||||
chars = []
|
||||
for p in primes:
|
||||
cnt = 0
|
||||
while n % p == 0:
|
||||
n //= p
|
||||
cnt += 1
|
||||
if cnt == 0:
|
||||
break
|
||||
chars.append(chr(cnt))
|
||||
return ''.join(chars)
|
||||
|
||||
print(godel_number_str("0=0")) # 매 huge number
|
||||
```
|
||||
|
||||
### Lean4 — 매 statement 의 formalization
|
||||
```lean
|
||||
-- 매 First Incompleteness 의 Lean4 formalization (mathlib outline).
|
||||
-- 매 actual proof 매 thousand-line ordeal — outline 만.
|
||||
import Mathlib.Logic.Godel.GodelBetaFunction
|
||||
|
||||
theorem godel_first_incompleteness
|
||||
(T : Theory ℒ) (hT : T.Consistent) (hRec : T.RecursivelyEnumerable)
|
||||
(hPA : ⊥ ⊆ T) :
|
||||
∃ G : Sentence ℒ, ¬T ⊢ G ∧ ¬T ⊢ ~G := by
|
||||
-- 매 self-referential G via diagonalization lemma
|
||||
obtain ⟨G, hG⟩ := T.diagonalLemma (¬· ∈ T.theorems)
|
||||
exact ⟨G, sorry, sorry⟩
|
||||
```
|
||||
|
||||
### Diagonalization Lemma (매 핵심 trick)
|
||||
```python
|
||||
# 매 pseudo-code: matter 의 fixed-point 의 construction.
|
||||
# 매 statement φ(x) 에 대해, 매 G 의 ⊢ G ↔ φ(⌜G⌝) 의 statement 존재.
|
||||
|
||||
def diagonalize(phi):
|
||||
"""φ(x): 매 free variable x 인 formula.
|
||||
Returns G such that PA ⊢ G ↔ φ(⌜G⌝)."""
|
||||
# Step 1: substitution function sub(y, x): formula y(x/⌜y⌝)
|
||||
# Step 2: G := sub(⌜φ(sub(x,x))⌝, ⌜φ(sub(x,x))⌝)
|
||||
# 매 G 의 의미: "I have property φ"
|
||||
pass
|
||||
```
|
||||
|
||||
### Halting problem 의 reduction (매 Gödel-Turing)
|
||||
```python
|
||||
def halting_problem_undecidable():
|
||||
"""매 First Incompleteness 의 computability version.
|
||||
Halts(P, x) — 매 recursive function 으로 정의 불가능."""
|
||||
# 매 Cantor-style diagonal:
|
||||
# Suppose Halts(P, x) decidable. Define:
|
||||
def D(P):
|
||||
if Halts(P, P):
|
||||
while True: pass # loop forever
|
||||
else:
|
||||
return # halt
|
||||
# 매 D(D) 의 동작 — 매 contradiction.
|
||||
# 따라서 Halts 매 decidable 아님.
|
||||
pass
|
||||
```
|
||||
|
||||
### Provability Logic (매 GL — Gödel-Löb)
|
||||
```python
|
||||
# 매 modal logic GL 의 axioms — 매 Bew predicate 의 modal formalization.
|
||||
# K: □(p → q) → (□p → □q)
|
||||
# 4: □p → □□p
|
||||
# Löb: □(□p → p) → □p
|
||||
|
||||
# 매 GL 의 Solovay 1976 의 arithmetic completeness 의 증명 — 매 PA 에서 valid 한 매 modal formula 의 GL 의 정확한 fragment.
|
||||
```
|
||||
|
||||
### Lean — 매 PA consistency proof (in stronger system)
|
||||
```lean
|
||||
-- 매 PA's consistency 의 증명 매 ZFC (or PRA + ε₀-induction) 에서 가능.
|
||||
-- Gentzen 1936 의 ε₀-induction 의존.
|
||||
theorem PA_consistent : PeanoArithmetic.Consistent := by
|
||||
-- 매 actual proof: ordinal analysis up to ε₀
|
||||
sorry
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Lesson |
|
||||
|---|---|
|
||||
| Formal system 의 power 결정 | 매 expressiveness 와 incompleteness 의 trade-off |
|
||||
| Self-reference 가 가능한가? | Diagonalization 으로 paradox 가능성 |
|
||||
| Decidable 한 logic 원함 | 매 weak system (e.g., Presburger arithmetic) 사용 |
|
||||
| Mathematical foundations | ZFC + large cardinals — 매 stronger but still incomplete |
|
||||
| AGI / consciousness argument | 매 cautious — Penrose 의 controversial |
|
||||
| Proof assistant 사용 | Lean/Coq — 매 axiom set 명시 (consistency 추가 가정) |
|
||||
|
||||
**기본값**: 매 sufficiently expressive system 의 incompleteness 의 inherent — 매 "complete the system" 의 시도는 매 futile 하다 (e.g., Hilbert program 의 실패).
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Mathematical-Logic]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 conceptual explanation, 매 historical context, 매 proof structure 의 high-level summary, 매 formal logic teaching.
|
||||
**언제 X**: 매 actual formal proof 작성 — 매 LLM 의 mistake 가능, Lean/Coq 등 proof assistant 사용. 매 Penrose-style "AI cannot reason because of Gödel" argument — 매 fallacy 의 widely critique 됨.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **"Gödel proves AI impossible"**: 매 fallacy. 매 incompleteness 매 specific formal system 에 대한 statement, 매 thinking 의 nature 와 별개.
|
||||
- **Confusing First/Second**: 매 First (existence of unprovable truth) ≠ Second (unprovability of consistency).
|
||||
- **Applying to weak systems**: 매 Presburger arithmetic 의 complete & decidable — 매 incompleteness 매 Robinson arithmetic 이상에 적용.
|
||||
- **Proof of consistency via system itself**: 매 Second 의 의미 — 매 가능 시 system 자체 의 inconsistent.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Gödel 1931, Hilbert-Bernays "Grundlagen der Mathematik", Smullyan "Gödel's Incompleteness Theorems").
|
||||
- 신뢰도 A (foundational result of mathematical logic).
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — first/second statements, diagonalization, Lean formalization, philosophical caveats |
|
||||
@@ -0,0 +1,33 @@
|
||||
---
|
||||
id: wiki-20260508-graph-theory-redir
|
||||
title: Graph Theory
|
||||
category: 10_Wiki/Topics
|
||||
status: duplicate
|
||||
canonical_id: graph-theory-foundations
|
||||
duplicate_of: "[[Graph Theory Foundations]]"
|
||||
aliases: []
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: redirected
|
||||
tags: [duplicate, graph-theory]
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
---
|
||||
|
||||
# Graph Theory
|
||||
|
||||
|
||||
## 핵심 요약
|
||||
- Graph G = (V, E): vertex 의 set + edge 의 set.
|
||||
- directed / undirected, weighted / unweighted, cyclic / acyclic.
|
||||
- Euler (1736 Königsberg bridge) 의 origin.
|
||||
- Application: BFS/DFS, Dijkstra, MST, network analysis, social graph.
|
||||
|
||||
## 🔗 Graph
|
||||
- Adjacent: [[BFS vs DFS]] · [[Dijkstra's Algorithm]]
|
||||
|
||||
## 🕓 변경 이력
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | 중복 처리 — canonical 문서로 redirect |
|
||||
@@ -0,0 +1,253 @@
|
||||
---
|
||||
id: wiki-2026-0508-graph-coloring-problem
|
||||
title: Graph Coloring Problem
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Vertex Coloring, Chromatic Number, k-Coloring]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [algorithms, graph-theory, np-complete, combinatorics, optimization]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: NetworkX
|
||||
---
|
||||
|
||||
# Graph Coloring Problem
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 vertex 에 색칠 — adjacent 끼리 다른 색, minimum 색 수가 chromatic number χ(G)"**. 1852년 Francis Guthrie 의 4-color conjecture 로 시작 — 1976년 Appel-Haken 의 computer-aided proof. 매 NP-complete (k≥3) 이지만 register allocation, scheduling, frequency assignment 등 매 광범위한 application.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 정의
|
||||
- **Vertex coloring**: V → {1,...,k} 의 함수 c, 매 (u,v) ∈ E ⇒ c(u) ≠ c(v).
|
||||
- **Chromatic number χ(G)**: 매 minimum k 의 의미.
|
||||
- **k-colorable**: 매 ≤k colors 의 valid coloring 존재.
|
||||
- **Edge coloring / Total coloring / List coloring**: 매 variants.
|
||||
|
||||
### 매 이론적 boundaries
|
||||
- **χ(G) ≤ Δ(G) + 1** (Brooks 정리: complete graph / odd cycle 제외 시 χ ≤ Δ).
|
||||
- **χ(G) ≥ ω(G)** (clique number lower bound; perfect graph 시 equality).
|
||||
- **4-Color Theorem**: 매 planar graph 의 χ ≤ 4 (1976, computer-assisted).
|
||||
- **2-colorable ⟺ bipartite ⟺ no odd cycle** — 매 polynomial time 확인 가능.
|
||||
|
||||
### 매 응용
|
||||
1. **Register allocation** (compiler): 매 variable interference graph 의 coloring → register 배정.
|
||||
2. **Scheduling**: 매 conflict graph (시간 conflict 의 task) → time-slot 배정.
|
||||
3. **Frequency assignment**: 매 cellular tower 간 interference 회피.
|
||||
4. **Sudoku / map coloring**: 매 constraint satisfaction.
|
||||
5. **Exam timetabling**: 매 student-overlap conflict 의 minimum slot.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Greedy Coloring (매 simplest baseline)
|
||||
```python
|
||||
import networkx as nx
|
||||
|
||||
def greedy_coloring(G, ordering=None):
|
||||
"""Greedy: ordering 순서대로 가장 작은 사용가능 색 배정.
|
||||
Worst-case Δ+1 colors. Ordering 의 quality 이 핵심."""
|
||||
coloring = {}
|
||||
nodes = ordering or list(G.nodes())
|
||||
for v in nodes:
|
||||
used = {coloring[u] for u in G.neighbors(v) if u in coloring}
|
||||
c = 0
|
||||
while c in used:
|
||||
c += 1
|
||||
coloring[v] = c
|
||||
return coloring
|
||||
|
||||
# NetworkX built-in (Welsh-Powell 등 strategies):
|
||||
G = nx.erdos_renyi_graph(50, 0.3, seed=42)
|
||||
coloring = nx.coloring.greedy_color(G, strategy='largest_first')
|
||||
print(f"Colors used: {max(coloring.values()) + 1}")
|
||||
```
|
||||
|
||||
### DSATUR (매 saturation degree heuristic)
|
||||
```python
|
||||
def dsatur(G):
|
||||
"""Brélaz 1979. 매 step: saturation (인접 색 수) max 인 vertex 선택.
|
||||
매 random graph 에서 greedy 보다 우수, χ 에 가까움."""
|
||||
coloring = {}
|
||||
saturation = {v: 0 for v in G.nodes()}
|
||||
while len(coloring) < len(G):
|
||||
uncolored = [v for v in G.nodes() if v not in coloring]
|
||||
v = max(uncolored, key=lambda x: (saturation[x], G.degree(x)))
|
||||
used = {coloring[u] for u in G.neighbors(v) if u in coloring}
|
||||
c = 0
|
||||
while c in used:
|
||||
c += 1
|
||||
coloring[v] = c
|
||||
for u in G.neighbors(v):
|
||||
if u not in coloring:
|
||||
neigh_colors = {coloring[w] for w in G.neighbors(u) if w in coloring}
|
||||
saturation[u] = len(neigh_colors)
|
||||
return coloring
|
||||
```
|
||||
|
||||
### Backtracking (매 exact, small graphs)
|
||||
```python
|
||||
def chromatic_number_exact(G):
|
||||
"""매 k=1,2,... 시도하며 k-colorable 검사 (NP-hard)."""
|
||||
nodes = list(G.nodes())
|
||||
n = len(nodes)
|
||||
|
||||
def is_safe(v_idx, c, coloring):
|
||||
for u in G.neighbors(nodes[v_idx]):
|
||||
u_idx = nodes.index(u)
|
||||
if u_idx in coloring and coloring[u_idx] == c:
|
||||
return False
|
||||
return True
|
||||
|
||||
def color_util(v_idx, k, coloring):
|
||||
if v_idx == n:
|
||||
return True
|
||||
for c in range(k):
|
||||
if is_safe(v_idx, c, coloring):
|
||||
coloring[v_idx] = c
|
||||
if color_util(v_idx + 1, k, coloring):
|
||||
return True
|
||||
del coloring[v_idx]
|
||||
return False
|
||||
|
||||
for k in range(1, n + 1):
|
||||
if color_util(0, k, {}):
|
||||
return k
|
||||
return n
|
||||
```
|
||||
|
||||
### ILP Formulation (매 modern solver)
|
||||
```python
|
||||
from pulp import *
|
||||
|
||||
def graph_coloring_ilp(G, max_colors):
|
||||
"""Integer Linear Programming — Gurobi/CPLEX 통해 매 exact solution.
|
||||
x[v,c] ∈ {0,1}: vertex v 의 color c."""
|
||||
prob = LpProblem("GraphColoring", LpMinimize)
|
||||
x = LpVariable.dicts("x", [(v,c) for v in G.nodes() for c in range(max_colors)], cat='Binary')
|
||||
y = LpVariable.dicts("y", range(max_colors), cat='Binary') # color c used?
|
||||
|
||||
prob += lpSum(y[c] for c in range(max_colors)) # minimize colors used
|
||||
|
||||
for v in G.nodes():
|
||||
prob += lpSum(x[v,c] for c in range(max_colors)) == 1 # exactly 1 color
|
||||
for (u,v) in G.edges():
|
||||
for c in range(max_colors):
|
||||
prob += x[u,c] + x[v,c] <= 1 # adjacent ≠ color
|
||||
for v in G.nodes():
|
||||
for c in range(max_colors):
|
||||
prob += x[v,c] <= y[c]
|
||||
|
||||
prob.solve(PULP_CBC_CMD(msg=0))
|
||||
return {v: c for v in G.nodes() for c in range(max_colors) if x[v,c].varValue == 1}
|
||||
```
|
||||
|
||||
### Tabu Search (매 large instances)
|
||||
```python
|
||||
import random
|
||||
|
||||
def tabu_coloring(G, k, max_iter=10000, tabu_tenure=10):
|
||||
"""매 k-coloring 의 conflict 최소화. Hertz-de Werra 1987.
|
||||
매 large random graphs 에 효과적."""
|
||||
coloring = {v: random.randint(0, k-1) for v in G.nodes()}
|
||||
tabu = {}
|
||||
best = coloring.copy()
|
||||
best_conflicts = sum(1 for u,v in G.edges() if coloring[u] == coloring[v])
|
||||
|
||||
for it in range(max_iter):
|
||||
conflicts = [(u,v) for u,v in G.edges() if coloring[u] == coloring[v]]
|
||||
if not conflicts:
|
||||
return coloring
|
||||
# 매 best non-tabu move 선택
|
||||
best_move = None
|
||||
best_delta = float('inf')
|
||||
for u,v in conflicts:
|
||||
for vertex in (u, v):
|
||||
old_c = coloring[vertex]
|
||||
for new_c in range(k):
|
||||
if new_c == old_c or (vertex, new_c) in tabu and tabu[(vertex,new_c)] > it:
|
||||
continue
|
||||
delta = sum(1 for w in G.neighbors(vertex) if coloring[w] == new_c) \
|
||||
- sum(1 for w in G.neighbors(vertex) if coloring[w] == old_c)
|
||||
if delta < best_delta:
|
||||
best_delta = delta
|
||||
best_move = (vertex, new_c)
|
||||
if best_move:
|
||||
v, c = best_move
|
||||
tabu[(v, coloring[v])] = it + tabu_tenure
|
||||
coloring[v] = c
|
||||
return coloring
|
||||
```
|
||||
|
||||
### Register Allocation (매 compiler use case)
|
||||
```python
|
||||
def chaitin_register_allocation(interference_graph, num_registers):
|
||||
"""Chaitin 1982. 매 LLVM/GCC 의 register allocation.
|
||||
Δ < k 의 vertex iteratively remove → stack → reverse pop & color."""
|
||||
G = interference_graph.copy()
|
||||
stack = []
|
||||
while G.nodes():
|
||||
# 매 degree < k vertex 찾기 (simplifiable)
|
||||
simplifiable = [v for v in G.nodes() if G.degree(v) < num_registers]
|
||||
if simplifiable:
|
||||
v = simplifiable[0]
|
||||
else:
|
||||
# 매 spill candidate (pick least-used)
|
||||
v = min(G.nodes(), key=lambda x: G.degree(x))
|
||||
stack.append((v, list(G.neighbors(v))))
|
||||
G.remove_node(v)
|
||||
|
||||
coloring = {}
|
||||
while stack:
|
||||
v, neighbors = stack.pop()
|
||||
used = {coloring[u] for u in neighbors if u in coloring}
|
||||
for c in range(num_registers):
|
||||
if c not in used:
|
||||
coloring[v] = c
|
||||
break
|
||||
else:
|
||||
coloring[v] = 'SPILL' # 매 memory 로 spill
|
||||
return coloring
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Small graph (n ≤ 30) | Backtracking exact |
|
||||
| Medium graph (n ≤ 1000) | ILP solver (Gurobi) |
|
||||
| Large graph (n > 10k) | Tabu / DSATUR heuristic |
|
||||
| Realtime / approximate OK | Greedy with largest_first |
|
||||
| Compiler register allocation | Chaitin's algorithm |
|
||||
| Bipartite check only | BFS 2-coloring (O(V+E)) |
|
||||
|
||||
**기본값**: NetworkX `greedy_color(strategy='DSATUR')` — 매 quality/speed balance 우수.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Graph_Theory|Graph-Theory]] · [[Combinatorial-Optimization]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 problem decomposition, 매 algorithm selection, 매 code skeleton 생성, 매 ILP formulation 자동화.
|
||||
**언제 X**: 매 instance-specific exact solution — 매 LLM hallucinate 가능, dedicated solver (Gurobi/CPLEX) 사용 권장.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Greedy 의 첫 ordering 사용**: 매 worst-case n colors. Largest-first / DSATUR ordering 사용.
|
||||
- **Brute force on n>30**: 매 exponential 시간 — heuristic / ILP 으로 전환.
|
||||
- **k-coloring 직접 푸는 대신 chromatic 추정 안 함**: 매 lower bound (clique) / upper bound (Brooks) 활용.
|
||||
- **List coloring 을 vertex coloring 과 혼동**: 매 list coloring 의 χ_l(G) 의 차이.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified against Brooks' Theorem, 4-Color Theorem (Appel-Haken 1976), Chaitin's allocation.
|
||||
- 신뢰도 A (CLRS, Diestel "Graph Theory", Chartrand-Zhang).
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full content (definitions, ILP, tabu, Chaitin allocation, applications) |
|
||||
@@ -0,0 +1,172 @@
|
||||
---
|
||||
id: wiki-2026-0508-greedy-algorithms
|
||||
title: Greedy Algorithms
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Greedy, 그리디 알고리즘, 탐욕 알고리즘]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
verification_status: applied
|
||||
tags: [algorithms, greedy, optimization, matroid]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: none
|
||||
---
|
||||
|
||||
# Greedy Algorithms
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 step 의 locally optimal choice 의 의 globally optimal 의 hope"**. 매 1956 Kruskal 의 MST 의 formal start. 매 modern era 의 universal — 매 Huffman, MST, scheduling, set cover (approx). 매 proof 의 critical (greedy 의 wrong 의 silent failure).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 두 정당화 (matroid theory)
|
||||
1. **Greedy choice property**: 매 local optimal 의 의 global optimal 의 의 contain.
|
||||
2. **Optimal substructure**: 매 problem 의 reduce 의 후 의 동일 structure 의 problem.
|
||||
|
||||
### 매 proof technique
|
||||
- **Exchange argument**: 매 OPT 의 greedy choice 의 swap 의 의 worse X.
|
||||
- **Matroid theory**: 매 independence system 의 matroid 의 의 → greedy 의 optimal.
|
||||
- **Stays ahead**: 매 greedy 의 step 의 의 OPT 의 step 의 의 dominate.
|
||||
|
||||
### 매 Greedy fails 의 example
|
||||
- **0/1 knapsack**: greedy by value/weight ratio 의 fails — DP 의 의.
|
||||
- **Coin change (arbitrary denominations)**: greedy fails (예: coins=[1,3,4], amount=6 → greedy 4+1+1=3 coins, OPT 3+3=2 coins).
|
||||
|
||||
### 매 응용
|
||||
1. MST: Kruskal, Prim.
|
||||
2. Shortest path (non-negative): Dijkstra.
|
||||
3. Compression: Huffman coding.
|
||||
4. Scheduling: earliest deadline first, shortest job next.
|
||||
5. Approximation: set cover, vertex cover (2-approx).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Activity Selection (interval scheduling)
|
||||
```python
|
||||
def activity_selection(intervals: list[tuple[int, int]]) -> list[tuple[int, int]]:
|
||||
"""Select max non-overlapping intervals. Greedy: earliest finish first."""
|
||||
intervals.sort(key=lambda x: x[1]) # sort by end time
|
||||
selected = []
|
||||
last_end = -float('inf')
|
||||
for s, e in intervals:
|
||||
if s >= last_end:
|
||||
selected.append((s, e))
|
||||
last_end = e
|
||||
return selected
|
||||
# O(n log n)
|
||||
```
|
||||
|
||||
### Huffman coding
|
||||
```python
|
||||
import heapq
|
||||
from collections import Counter
|
||||
|
||||
def huffman(text: str) -> dict[str, str]:
|
||||
freq = Counter(text)
|
||||
heap = [[f, [c, ""]] for c, f in freq.items()]
|
||||
heapq.heapify(heap)
|
||||
while len(heap) > 1:
|
||||
lo = heapq.heappop(heap)
|
||||
hi = heapq.heappop(heap)
|
||||
for pair in lo[1:]: pair[1] = '0' + pair[1]
|
||||
for pair in hi[1:]: pair[1] = '1' + pair[1]
|
||||
heapq.heappush(heap, [lo[0] + hi[0]] + lo[1:] + hi[1:])
|
||||
return {c: code for c, code in heap[0][1:]}
|
||||
|
||||
print(huffman("aaabbc")) # e.g., {'a': '0', 'b': '10', 'c': '11'}
|
||||
```
|
||||
|
||||
### Kruskal's MST (greedy + union-find)
|
||||
```python
|
||||
class UF:
|
||||
def __init__(self, n): self.p = list(range(n)); self.r = [0]*n
|
||||
def find(self, x):
|
||||
while self.p[x] != x: self.p[x] = self.p[self.p[x]]; x = self.p[x]
|
||||
return x
|
||||
def union(self, a, b):
|
||||
ra, rb = self.find(a), self.find(b)
|
||||
if ra == rb: return False
|
||||
if self.r[ra] < self.r[rb]: ra, rb = rb, ra
|
||||
self.p[rb] = ra
|
||||
if self.r[ra] == self.r[rb]: self.r[ra] += 1
|
||||
return True
|
||||
|
||||
def kruskal(n: int, edges: list[tuple[int, int, int]]) -> int:
|
||||
"""edges: (u, v, weight). Returns total MST weight."""
|
||||
edges.sort(key=lambda e: e[2])
|
||||
uf, total = UF(n), 0
|
||||
for u, v, w in edges:
|
||||
if uf.union(u, v):
|
||||
total += w
|
||||
return total
|
||||
# O(E log E)
|
||||
```
|
||||
|
||||
### Coin change (canonical, e.g., USD)
|
||||
```python
|
||||
def coin_change_greedy(coins: list[int], amount: int) -> int:
|
||||
"""ASSUMES canonical coin system. Fails for arbitrary denominations."""
|
||||
coins = sorted(coins, reverse=True)
|
||||
count = 0
|
||||
for c in coins:
|
||||
n, amount = divmod(amount, c)
|
||||
count += n
|
||||
return count if amount == 0 else -1
|
||||
# USD [25,10,5,1] → canonical, greedy works
|
||||
# [1,3,4] → NOT canonical, greedy fails for 6
|
||||
```
|
||||
|
||||
### Set cover (approximation, ln(n) factor)
|
||||
```python
|
||||
def set_cover(universe: set, sets: list[set]) -> list[int]:
|
||||
"""Greedy: pick set covering most uncovered. ln(n)-approx."""
|
||||
covered, picked = set(), []
|
||||
while covered != universe:
|
||||
best = max(range(len(sets)), key=lambda i: len(sets[i] - covered))
|
||||
picked.append(best)
|
||||
covered |= sets[best]
|
||||
return picked
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 매 matroid structure 의 detect | Greedy (provably optimal) |
|
||||
| 매 exchange argument 의 의 | Greedy |
|
||||
| 매 NP-hard, approximation OK | Greedy (set cover, vertex cover) |
|
||||
| 매 overlap subproblem | DP (greedy 의 X) |
|
||||
| 매 backtrack 의 needed | Branch & Bound |
|
||||
| 매 proof X | DP / brute-force 의 first |
|
||||
|
||||
**기본값**: 매 problem 의 simple structure 의 greedy 의 first 시도. 매 counterexample 의 found → DP / B&B.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Optimization]]
|
||||
- 응용: [[Dijkstra's Algorithm]]
|
||||
- Adjacent: [[Dynamic Programming]] · [[Linear Programming]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 simple optimization, 매 sorting + linear scan 의 의 의 의 의 의, 매 NP-hard 의 approximation 의 의, 매 streaming algorithm.
|
||||
**언제 X**: 매 0/1 knapsack, 매 LCS, 매 edit distance — 매 DP 의 의. 매 counterexample 의 unsure 의 first.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **proof X**: 매 greedy 의 silent wrong answer (coin change [1,3,4], 0/1 knapsack).
|
||||
- **canonical 가정**: 매 USD coins 의 greedy works, but 매 arbitrary denominations 의 fails.
|
||||
- **local minima trap**: 매 hill-climbing 의 local optimum 의 stuck — 매 simulated annealing / restart 의 의.
|
||||
- **greedy + DP confusion**: 매 fractional knapsack (greedy works) vs 0/1 knapsack (DP needed).
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (CLRS Ch 16; Kleinberg-Tardos Ch 4).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Greedy with activity selection, Huffman, Kruskal, set cover |
|
||||
@@ -0,0 +1,214 @@
|
||||
---
|
||||
id: wiki-2026-0508-grounded-theory-method
|
||||
title: Grounded Theory Method
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [GTM, Grounded Theory, Constructivist GT, Glaserian GT, Straussian GT]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.85
|
||||
verification_status: applied
|
||||
tags: [research-methodology, qualitative-research, sociology, hci, theory-building]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: NVivo / atlas.ti / qualitative coding
|
||||
---
|
||||
|
||||
# Grounded Theory Method
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 data 에서 'grounded' 한 substantive theory 의 inductive 으로 construction — 매 hypothesis 의 a priori X, data 가 theory 를 결정"**. 1967년 Glaser & Strauss "The Discovery of Grounded Theory" — 매 sociology / nursing / HCI / SE research 의 foundational qualitative methodology. 매 modern (2026) 의 Charmaz 의 constructivist GT, 매 LLM-augmented coding 의 emerging.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Origin & schools
|
||||
- **Classic Glaserian** (1967, 1992): 매 emergence-driven, 매 minimal preconception, 매 substantive→formal theory.
|
||||
- **Straussian** (Strauss & Corbin 1990): 매 axial coding 의 추가 — 매 paradigm model (cause/context/consequence).
|
||||
- **Constructivist GT** (Charmaz 2006): 매 researcher 의 active construction 인정 — 매 reflexivity 강조.
|
||||
|
||||
### 매 핵심 procedures
|
||||
1. **Theoretical sampling**: 매 emerging theory 가 다음 sample 결정 (not random).
|
||||
2. **Constant comparison**: 매 incident → incident, code → code 의 지속 비교.
|
||||
3. **Coding levels**:
|
||||
- **Open coding**: 매 line-by-line / incident-by-incident 의 initial label.
|
||||
- **Axial coding** (Strauss): 매 categories 간 relationship — paradigm model.
|
||||
- **Selective / Theoretical coding**: 매 core category 중심으로 통합.
|
||||
4. **Memo writing**: 매 analytical thoughts 의 ongoing record.
|
||||
5. **Theoretical saturation**: 매 new data 가 새로운 insight 안 줄 때까지.
|
||||
|
||||
### 매 Output
|
||||
- **Substantive theory**: 매 specific area (e.g., "How nurses cope with terminal patients").
|
||||
- **Formal theory**: 매 broader applicability.
|
||||
- **Core category**: 매 central phenomenon.
|
||||
- **Properties + dimensions** of categories.
|
||||
|
||||
### 매 응용
|
||||
1. **HCI / UX research**: 매 user behavior pattern 의 emergent understanding.
|
||||
2. **Software engineering**: 매 developer practice 의 study (Stol et al. 2016).
|
||||
3. **Nursing / healthcare**: 매 patient experience.
|
||||
4. **Education**: 매 learning process.
|
||||
5. **Organizational studies**.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### 매 Coding 의 example (line-by-line)
|
||||
```python
|
||||
# 매 raw interview transcript:
|
||||
transcript = """
|
||||
Researcher: How do you handle a critical bug in production?
|
||||
Developer: First, I panic for 5 minutes. Then I check the logs.
|
||||
I look for recent deployments. Often it's the last commit.
|
||||
I roll back if I can. Otherwise I write a hotfix.
|
||||
"""
|
||||
|
||||
# 매 open coding (manual):
|
||||
codes = {
|
||||
"panic for 5 minutes": ["emotional_response", "stress"],
|
||||
"check the logs": ["diagnostic_action", "data_gathering"],
|
||||
"look for recent deployments": ["temporal_reasoning", "blame_locality"],
|
||||
"roll back if I can": ["containment", "reversibility_first"],
|
||||
"write a hotfix": ["repair", "containment"],
|
||||
}
|
||||
|
||||
# 매 axial: 매 cluster
|
||||
categories = {
|
||||
"Initial reaction": ["emotional_response", "stress"],
|
||||
"Diagnosis": ["diagnostic_action", "data_gathering", "temporal_reasoning"],
|
||||
"Containment strategy": ["reversibility_first", "containment"],
|
||||
"Repair": ["repair"],
|
||||
}
|
||||
|
||||
# 매 selective: 매 core category candidate
|
||||
core = "Containment-First Incident Response"
|
||||
```
|
||||
|
||||
### 매 Constant Comparison (매 incident comparison)
|
||||
```python
|
||||
def constant_compare(incidents, codes_so_far):
|
||||
"""매 each new incident 의 기존 codes 와 비교.
|
||||
매 fits → assign existing. 매 doesn't → new code or category refinement."""
|
||||
for inc in incidents:
|
||||
matched = []
|
||||
for code, examples in codes_so_far.items():
|
||||
if semantic_similarity(inc, examples) > 0.7: # 매 LLM-assisted
|
||||
matched.append(code)
|
||||
if matched:
|
||||
for c in matched:
|
||||
codes_so_far[c].append(inc)
|
||||
else:
|
||||
new_code = invent_label(inc)
|
||||
codes_so_far[new_code] = [inc]
|
||||
return codes_so_far
|
||||
```
|
||||
|
||||
### 매 LLM-augmented coding (2026 modern practice)
|
||||
```python
|
||||
import anthropic
|
||||
|
||||
def llm_open_code(text, prior_codes=None):
|
||||
"""매 Claude 4.7 의 grounded theory open coding assistance.
|
||||
매 IMPORTANT: 매 researcher 의 final judgment 필수 — LLM 의 first-pass only."""
|
||||
client = anthropic.Anthropic()
|
||||
system = (
|
||||
"You are assisting a grounded theory researcher. "
|
||||
"Generate open codes for each incident. Codes must be GROUNDED in the data. "
|
||||
"Use gerunds (action-oriented) per Charmaz. "
|
||||
"Avoid imposing prior theoretical frameworks."
|
||||
)
|
||||
if prior_codes:
|
||||
system += f"\n\nExisting codes (use if fits, propose new if not): {prior_codes}"
|
||||
|
||||
msg = client.messages.create(
|
||||
model="claude-opus-4-7",
|
||||
max_tokens=4096,
|
||||
system=system,
|
||||
messages=[{"role": "user", "content": f"Code this incident:\n\n{text}"}]
|
||||
)
|
||||
return msg.content[0].text
|
||||
|
||||
# 매 caveat: 매 LLM 의 hidden bias — researcher 의 verification 필수
|
||||
```
|
||||
|
||||
### 매 Theoretical Saturation 의 detection
|
||||
```python
|
||||
def saturation_check(new_codes_per_interview):
|
||||
"""매 marginal new codes 가 0 에 가까워지면 saturated.
|
||||
매 typical: 12-25 interviews."""
|
||||
counts = [len(set(codes)) for codes in new_codes_per_interview]
|
||||
# 매 cumulative new codes
|
||||
cum = []
|
||||
seen = set()
|
||||
for codes in new_codes_per_interview:
|
||||
before = len(seen)
|
||||
seen.update(codes)
|
||||
cum.append(len(seen) - before)
|
||||
# 매 saturation: 매 last 3 interviews 의 new codes < threshold
|
||||
if len(cum) >= 3 and sum(cum[-3:]) < 3:
|
||||
return True, len(seen)
|
||||
return False, len(seen)
|
||||
```
|
||||
|
||||
### 매 Memo 의 example
|
||||
```markdown
|
||||
# Memo: Containment-First Pattern (2026-05-10)
|
||||
|
||||
매 Across 8 interviews, 매 developers consistently 의 "containment
|
||||
before diagnosis" pattern. 매 Specifically:
|
||||
|
||||
- P3: "First I undo, then I think."
|
||||
- P5: "Stop the bleeding, ask later."
|
||||
- P7: "Roll back is free, downtime isn't."
|
||||
|
||||
매 This contradicts Glaser-style "diagnose first" conventional wisdom.
|
||||
매 Hypothesis: 매 production-incident contexts 의 reversibility 의 highly
|
||||
asymmetric cost structure 의 produce. 매 Theoretical sampling: 매 next,
|
||||
매 sample developers 의 IRREVERSIBLE deployment 의 (e.g., DB migrations)
|
||||
— 매 to test boundary.
|
||||
|
||||
매 Connects to: literature on "blameless postmortem" but timing 다름.
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | School / Approach |
|
||||
|---|---|
|
||||
| Pure emergence, minimal preconception | Glaserian classic |
|
||||
| Structured paradigm needed | Straussian (axial coding) |
|
||||
| Reflexive / interpretive | Charmaz constructivist |
|
||||
| Software engineering | Stol et al. 2016 guidelines |
|
||||
| Existing theory verification | NOT GT — 매 deductive method |
|
||||
| Quick exploration | Thematic analysis (lighter) |
|
||||
| Massive corpus | LLM-assisted GT (2026+) but careful |
|
||||
|
||||
**기본값**: 매 modern (2026) 의 **Charmaz constructivist** — 매 reflexivity 의 honest, LLM-assistance OK 의 transparent.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Research-Methodology]]
|
||||
- 변형: [[Glaserian-GT]] · [[Straussian-GT]] · [[Constructivist-GT]]
|
||||
- Adjacent: [[Ethnography]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 first-pass open coding 의 acceleration, 매 memo 작성 의 brainstorm, 매 literature 의 sensitizing concepts 의 식별, 매 saturation 의 estimation.
|
||||
**언제 X**: 매 final coding decisions, 매 theoretical insights 의 generation 단독 (researcher 의 reflexive interpretation 필수), 매 sensitive / vulnerable participant data — 매 privacy concern.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **A priori 의 hypothesis verification 시도**: 매 NOT GT — 매 deductive method 와 혼동.
|
||||
- **Theoretical sampling 의 random sampling 으로 대체**: 매 GT 의 핵심 violation.
|
||||
- **Memo 작성 생략**: 매 GT 의 analytical engine — 매 skip 시 thin theory.
|
||||
- **Saturation 의 declaration 의 too early**: 매 5 interviews 의 saturated 주장 — 매 typically 15+ 필요.
|
||||
- **LLM 코딩 만 사용**: 매 researcher 의 reflexivity 부재 — 매 Charmaz violation.
|
||||
- **"Coded by AI" 의 unreflective use**: 매 2026 의 emerging issue — 매 transparent disclosure 필요.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Glaser & Strauss 1967, Charmaz 2014 "Constructing Grounded Theory", Stol et al. 2016 "Grounded Theory in Software Engineering Research").
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — three schools, coding levels, LLM-augmented practice, anti-patterns |
|
||||
@@ -0,0 +1,169 @@
|
||||
---
|
||||
id: wiki-2026-0508-hardware-verification
|
||||
title: Hardware Verification
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Formal Verification, Chip Verification, RTL Verification]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.93
|
||||
verification_status: applied
|
||||
tags: [hardware, verification, formal-methods, eda, rtl]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: SystemVerilog
|
||||
framework: UVM/JasperGold/SymbiYosys
|
||||
---
|
||||
|
||||
# Hardware Verification
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 silicon 의 mistake 의 cost ≫ software bug — 매 60-70% chip dev effort 가 verification"**. Pentium FDIV (1994, $475M recall) 매 watershed; modern flow 매 simulation (UVM) + formal (property checking) + emulation (Palladium/Veloce) + post-silicon validation. 매 RISC-V 의 open verification revolution (2024-26).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 layers
|
||||
- **Simulation** (UVM/SystemVerilog): constrained-random + coverage-driven.
|
||||
- **Formal verification**: mathematical proof of property (CDC, register, security).
|
||||
- **Emulation**: FPGA/dedicated boxes (Palladium, Veloce, ZeBu) — 매 1000× faster than sim, full SoC.
|
||||
- **Static**: linting, CDC (clock domain crossing), RDC (reset domain).
|
||||
- **Post-silicon**: bringup on actual die — bugs that escaped pre-si.
|
||||
|
||||
### 매 metrics
|
||||
- **Code coverage**: line/branch/toggle/FSM (necessary, not sufficient).
|
||||
- **Functional coverage**: covergroups on intent.
|
||||
- **Bug curve**: bugs/week vs time — closure when asymptote.
|
||||
|
||||
### 매 응용
|
||||
1. CPU verification (RISC-V cores, ARM, x86).
|
||||
2. AI accelerator verification (TPU, GPU, NPU).
|
||||
3. Safety-critical (ISO 26262 ASIL-D, DO-254).
|
||||
4. Security (Spectre/Meltdown class — formal info-flow).
|
||||
5. Cryptography hardware (AES, post-quantum).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### UVM testbench skeleton
|
||||
```systemverilog
|
||||
class my_test extends uvm_test;
|
||||
`uvm_component_utils(my_test)
|
||||
my_env env;
|
||||
function void build_phase(uvm_phase phase);
|
||||
env = my_env::type_id::create("env", this);
|
||||
endfunction
|
||||
task run_phase(uvm_phase phase);
|
||||
my_seq seq = my_seq::type_id::create("seq");
|
||||
phase.raise_objection(this);
|
||||
seq.start(env.agt.sqr);
|
||||
phase.drop_objection(this);
|
||||
endtask
|
||||
endclass
|
||||
```
|
||||
|
||||
### SystemVerilog Assertion (SVA)
|
||||
```systemverilog
|
||||
property req_ack;
|
||||
@(posedge clk) disable iff (rst)
|
||||
req |-> ##[1:5] ack;
|
||||
endproperty
|
||||
assert property (req_ack) else $error("ack timeout");
|
||||
cover property (req_ack);
|
||||
```
|
||||
|
||||
### Formal property (Jasper / SymbiYosys)
|
||||
```systemverilog
|
||||
// Prove: FIFO never overflows
|
||||
property no_overflow;
|
||||
@(posedge clk) (count == DEPTH) |-> !push;
|
||||
endproperty
|
||||
assert property (no_overflow);
|
||||
```
|
||||
|
||||
### Constrained random
|
||||
```systemverilog
|
||||
class transaction;
|
||||
rand bit [31:0] addr;
|
||||
rand bit [31:0] data;
|
||||
constraint c_align { addr[1:0] == 0; }
|
||||
constraint c_range { addr inside {[32'h1000:32'h2000]}; }
|
||||
endclass
|
||||
```
|
||||
|
||||
### Coverage closure
|
||||
```systemverilog
|
||||
covergroup cg @(posedge clk);
|
||||
cp_addr: coverpoint addr {
|
||||
bins low = {[0:32'h0FFF]};
|
||||
bins mid = {[32'h1000:32'hEFFF]};
|
||||
bins high = {[32'hF000:$]};
|
||||
}
|
||||
cp_kind: coverpoint kind { bins all[] = {READ, WRITE, ATOMIC}; }
|
||||
cross cp_addr, cp_kind;
|
||||
endgroup
|
||||
```
|
||||
|
||||
### Open-source flow (SymbiYosys + Yosys)
|
||||
```bash
|
||||
# .sby file
|
||||
[options]
|
||||
mode prove
|
||||
depth 20
|
||||
[engines]
|
||||
smtbmc z3
|
||||
[script]
|
||||
read -formal design.sv
|
||||
prep -top top
|
||||
[files]
|
||||
design.sv
|
||||
sby -f design.sby
|
||||
```
|
||||
|
||||
### CDC check (Spyglass-style)
|
||||
```tcl
|
||||
read_verilog design.sv
|
||||
set_top top
|
||||
analyze cdc
|
||||
report cdc -severity error
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Control logic correctness | Formal (full proof) |
|
||||
| Datapath / large bugs | UVM constrained-random |
|
||||
| Full SoC software boot | Emulation |
|
||||
| Post-RTL freeze | Gate-level sim + FV |
|
||||
| Security properties | Formal info-flow (Coq/Sail) |
|
||||
| Performance | Hybrid emulation + RTL profiling |
|
||||
|
||||
**기본값**: UVM for blocks + formal for control + emulation for system.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Formal Methods]]
|
||||
- 변형: [[Formal-Verification]]
|
||||
- Adjacent: [[Model-Checking]] · [[Theorem-Proving]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: SVA generation from spec text, UVM boilerplate scaffold, coverage closure analysis, debugging waveform descriptions.
|
||||
**언제 X**: signing off tapeout (need human + tool sign-off), safety-critical sole reviewer, novel formal proofs (need expert).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Coverage = correctness**: 100% code coverage 매 buggy chips ship 의 still.
|
||||
- **No assertions**: bugs only at testbench checker → late detection.
|
||||
- **Re-running same seed**: random ineffective without seed sweep.
|
||||
- **Skipping CDC**: silicon metastability bugs 매 hardest to debug.
|
||||
- **Late formal**: starting formal at end of project — embed early on critical blocks.
|
||||
- **No regression triage**: failing tests left "to investigate" rot.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Accellera UVM 1.2/2020 LRM, Cadence/Synopsys/Siemens EDA whitepapers, Pentium FDIV postmortem, RISC-V International verification WG 2024-25).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — UVM/SVA/formal/CDC patterns |
|
||||
@@ -0,0 +1,266 @@
|
||||
---
|
||||
id: wiki-2026-0508-hash-functions-and-maps
|
||||
title: Hash Functions and Maps
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Hash Tables, Hash Maps, Dictionaries, HashMap]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [data-structures, algorithms, hashing, hash-tables, performance]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Rust
|
||||
framework: std::collections + ahash + FxHash
|
||||
---
|
||||
|
||||
# Hash Functions and Maps
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 key → bucket index 의 mapping 을 통해 average O(1) lookup/insert 의 data structure"**. 1953년 IBM 의 Hans Peter Luhn 의 origin — 매 modern Rust HashMap (SipHash), Google SwissTable / Abseil flat_hash_map, Python dict (open addressing + perturbation) 의 모두 derivative. 매 cryptographic hash (SHA-256/3, BLAKE3) 와 non-crypto hash (xxHash, ahash, FxHash) 의 distinction.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Hash function properties
|
||||
- **Determinism**: same input → same output.
|
||||
- **Uniformity**: 매 output 의 uniform distribution.
|
||||
- **Avalanche**: 매 single-bit input change 의 ~50% output bits 의 flip.
|
||||
- **Speed** (non-crypto): 매 ahash/xxHash 의 GB/s.
|
||||
- **Collision resistance** (crypto): 매 finding x≠y, h(x)=h(y) 의 infeasible.
|
||||
|
||||
### 매 Hash table strategies
|
||||
- **Separate chaining**: 매 bucket 의 linked list/tree (Java HashMap 의 default since 8 — list→tree at 8).
|
||||
- **Open addressing**: 매 collision 시 alternative slot probe.
|
||||
- Linear probing: 매 +1, +2, ... (cache-friendly but clustering).
|
||||
- Quadratic probing: 매 +1², +2², ...
|
||||
- Double hashing: 매 +h_2(k), +2h_2(k), ...
|
||||
- **Robin Hood hashing**: 매 displacement 의 minimization (Rust hashbrown 의 historical).
|
||||
- **SwissTable** (2017+, Google): 매 SIMD-based metadata + open addressing — 매 modern fastest.
|
||||
|
||||
### 매 Load factor & resizing
|
||||
- 매 load factor α = n/m. Open addressing 의 α < 0.75 권장, chaining 의 α < 1 권장.
|
||||
- 매 resize: 매 doubling (m → 2m) + rehash all keys.
|
||||
- Amortized O(1) insert.
|
||||
|
||||
### 매 응용
|
||||
1. **Symbol table** (compiler).
|
||||
2. **Cache** (LRU, LFU).
|
||||
3. **Set membership** (HashSet).
|
||||
4. **Counting** (frequency).
|
||||
5. **Dedup**.
|
||||
6. **Database index** (hash join, hash partition).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Rust — 매 modern HashMap
|
||||
```rust
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
// Default: SipHash-1-3 (DoS-resistant but slower).
|
||||
let mut map: HashMap<String, i32> = HashMap::new();
|
||||
map.insert("alice".to_string(), 30);
|
||||
map.insert("bob".to_string(), 25);
|
||||
|
||||
// 매 ergonomic API
|
||||
*map.entry("alice".to_string()).or_insert(0) += 1;
|
||||
|
||||
if let Some(age) = map.get("alice") {
|
||||
println!("Alice: {}", age);
|
||||
}
|
||||
|
||||
// 매 iterator
|
||||
for (k, v) in &map {
|
||||
println!("{} = {}", k, v);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Rust — ahash (매 fastest non-crypto, DoS resistant)
|
||||
```rust
|
||||
// Cargo.toml: ahash = "0.8"
|
||||
use ahash::AHashMap;
|
||||
|
||||
fn main() {
|
||||
let mut map: AHashMap<&str, i32> = AHashMap::new();
|
||||
map.insert("hello", 1);
|
||||
// 매 SipHash 보다 ~5x 빠름, AES-NI 사용 시 더 빠름.
|
||||
// 매 production 의 default 권장 (workload 에 따라).
|
||||
}
|
||||
```
|
||||
|
||||
### Rust — FxHash (매 known-key 의 ultra-fast)
|
||||
```rust
|
||||
// Cargo.toml: rustc-hash = "1.1"
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
fn main() {
|
||||
let mut map: FxHashMap<u64, &str> = FxHashMap::default();
|
||||
map.insert(42, "answer");
|
||||
// 매 rustc 내부 사용. 매 NOT DoS-resistant — 매 untrusted input 시 SipHash/aHash 사용.
|
||||
}
|
||||
```
|
||||
|
||||
### Custom Hash (매 Rust trait)
|
||||
```rust
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
struct Point { x: i32, y: i32 }
|
||||
|
||||
impl Hash for Point {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
// 매 combine fields. 매 Default impl 보다 careful 필요 시 직접.
|
||||
self.x.hash(state);
|
||||
self.y.hash(state);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### C++ — 매 std::unordered_map vs absl::flat_hash_map
|
||||
```cpp
|
||||
#include <absl/container/flat_hash_map.h>
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
// std::unordered_map: 매 chaining, slow due to pointer chasing
|
||||
// absl::flat_hash_map: 매 SwissTable, ~2-3x faster
|
||||
absl::flat_hash_map<std::string, int> map;
|
||||
map["alice"] = 30;
|
||||
map["bob"] = 25;
|
||||
|
||||
if (auto it = map.find("alice"); it != map.end()) {
|
||||
std::cout << it->second << "\n";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Open Addressing (매 simple Linear Probing)
|
||||
```python
|
||||
class LinearProbingHashMap:
|
||||
def __init__(self, capacity=16):
|
||||
self.capacity = capacity
|
||||
self.size = 0
|
||||
self.keys = [None] * capacity
|
||||
self.values = [None] * capacity
|
||||
|
||||
def _probe(self, key):
|
||||
idx = hash(key) % self.capacity
|
||||
while self.keys[idx] is not None and self.keys[idx] != key:
|
||||
idx = (idx + 1) % self.capacity
|
||||
return idx
|
||||
|
||||
def put(self, key, value):
|
||||
if self.size >= self.capacity * 0.75:
|
||||
self._resize()
|
||||
idx = self._probe(key)
|
||||
if self.keys[idx] is None:
|
||||
self.size += 1
|
||||
self.keys[idx] = key
|
||||
self.values[idx] = value
|
||||
|
||||
def get(self, key):
|
||||
idx = self._probe(key)
|
||||
return self.values[idx] if self.keys[idx] is not None else None
|
||||
|
||||
def _resize(self):
|
||||
old_keys, old_values = self.keys, self.values
|
||||
self.capacity *= 2
|
||||
self.keys = [None] * self.capacity
|
||||
self.values = [None] * self.capacity
|
||||
self.size = 0
|
||||
for k, v in zip(old_keys, old_values):
|
||||
if k is not None:
|
||||
self.put(k, v)
|
||||
```
|
||||
|
||||
### Cryptographic hash (매 SHA-256, BLAKE3)
|
||||
```rust
|
||||
use sha2::{Sha256, Digest};
|
||||
use blake3;
|
||||
|
||||
fn main() {
|
||||
// 매 SHA-256: 매 widely supported but slow (~600 MB/s).
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(b"hello world");
|
||||
let result = hasher.finalize();
|
||||
println!("{:x}", result);
|
||||
|
||||
// 매 BLAKE3: 매 modern fastest crypto hash (~6 GB/s with SIMD).
|
||||
let hash = blake3::hash(b"hello world");
|
||||
println!("{}", hash);
|
||||
}
|
||||
```
|
||||
|
||||
### Bloom Filter (매 hash-based set, false-positive OK)
|
||||
```python
|
||||
import mmh3 # MurmurHash3
|
||||
from bitarray import bitarray
|
||||
|
||||
class BloomFilter:
|
||||
def __init__(self, size, num_hashes):
|
||||
self.size = size
|
||||
self.num_hashes = num_hashes
|
||||
self.bits = bitarray(size)
|
||||
self.bits.setall(0)
|
||||
|
||||
def add(self, item):
|
||||
for i in range(self.num_hashes):
|
||||
idx = mmh3.hash(item, i) % self.size
|
||||
self.bits[idx] = 1
|
||||
|
||||
def contains(self, item):
|
||||
return all(self.bits[mmh3.hash(item, i) % self.size] for i in range(self.num_hashes))
|
||||
|
||||
bf = BloomFilter(size=10000, num_hashes=7)
|
||||
bf.add("alice")
|
||||
print(bf.contains("alice")) # True (definitely)
|
||||
print(bf.contains("bob")) # False (definitely) or True (false-positive)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Hash function / Map |
|
||||
|---|---|
|
||||
| Rust trusted input, max speed | FxHash |
|
||||
| Rust untrusted input | std HashMap (SipHash) or aHash |
|
||||
| C++ general | absl::flat_hash_map (SwissTable) |
|
||||
| Python | dict (built-in, optimized) |
|
||||
| Distributed cache key | xxHash3 / FNV-1a |
|
||||
| Cryptographic | BLAKE3 (speed) / SHA-3 (NIST) |
|
||||
| Bloom filter | MurmurHash3 |
|
||||
| String interning | weak hash + linear probe |
|
||||
| Ordered iteration | BTreeMap (not hash) |
|
||||
|
||||
**기본값**: Rust 매 `std::collections::HashMap`, C++ 매 `absl::flat_hash_map`, Python 매 `dict`. 매 performance-critical 시 ahash/FxHash 으로 교체.
|
||||
|
||||
## 🔗 Graph
|
||||
- 변형: [[Bloom-Filter]] · [[HyperLogLog]] · [[Consistent-Hashing]]
|
||||
- Adjacent: [[SHA-256]] · [[xxHash]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 hash function 선택 의 advice, 매 hash table 의 implementation 의 review, 매 collision 의 root cause 의 analysis.
|
||||
**언제 X**: 매 cryptographic hash 의 직접 implement — 매 audited library 사용. 매 production hash function 의 직접 작성.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **String hashing 없이 length 만 사용**: 매 catastrophic collision.
|
||||
- **Untrusted input 의 FxHash**: 매 HashDoS attack 가능 — SipHash/aHash 사용.
|
||||
- **MD5/SHA-1 신규 사용**: 매 broken — BLAKE3/SHA-256 사용.
|
||||
- **Hash 의 modular reduction 의 비균등**: 매 power-of-2 size + bitmask 또는 fastrange 사용.
|
||||
- **High load factor 의 open addressing**: 매 α > 0.9 의 catastrophic — resize.
|
||||
- **Complex key 의 default hash**: 매 distribution 안 좋을 수 있음 — custom impl.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Knuth TAOCP Vol 3, "Designing a fast, efficient, cache-friendly hash table", Abseil docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Rust/C++/Python implementations, SwissTable, ahash, BLAKE3 |
|
||||
@@ -0,0 +1,237 @@
|
||||
---
|
||||
id: wiki-2026-0508-hebbian-theory
|
||||
title: Hebbian Theory
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Hebbian Learning, Hebb's Rule, "Cells that fire together wire together"]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.85
|
||||
verification_status: applied
|
||||
tags: [neuroscience, learning-theory, biological-plasticity, neural-networks, STDP]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: NumPy / Brian2
|
||||
---
|
||||
|
||||
# Hebbian Theory
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 'cells that fire together, wire together' — 매 pre-/post-synaptic activity 의 correlated firing 시 synapse strength 증가"**. 1949년 Donald Hebb "The Organization of Behavior" — 매 modern neuroscience 의 plasticity 의 foundation, STDP / BCM rule / Oja's rule 의 origin. 매 deep learning 의 backprop 과 다른 biological-plausible learning candidate.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Original Hebbian Rule
|
||||
- **Δw_ij = η · x_i · y_j** (η: learning rate, x_i: pre, y_j: post).
|
||||
- 매 unstable: weights 매 unbounded growth — 매 normalization 필요.
|
||||
- Anti-Hebbian: Δw = -η x y — 매 decorrelation.
|
||||
|
||||
### 매 Variants
|
||||
- **Oja's rule** (1982): Δw_ij = η y_j (x_i - y_j w_ij) — 매 weight normalization, 매 PCA 첫번째 component 으로 converges.
|
||||
- **BCM rule** (Bienenstock-Cooper-Munro 1982): 매 sliding threshold θ — y > θ 시 LTP, y < θ 시 LTD.
|
||||
- **STDP (Spike-Timing-Dependent Plasticity)**: 매 actual biological — pre-spike 가 post-spike 직전 시 LTP, 직후 시 LTD. 매 millisecond-scale.
|
||||
- **Triplet STDP**: 매 더 정확한 model.
|
||||
|
||||
### 매 Biological evidence
|
||||
- LTP (Long-Term Potentiation): 매 hippocampal CA1 의 Bliss-Lomo 1973 의 발견.
|
||||
- LTD (Long-Term Depression): 매 cerebellum 의 motor learning.
|
||||
- NMDA receptor 의 핵심: 매 coincidence detector.
|
||||
- 매 calcium dynamics 의 underlying mechanism.
|
||||
|
||||
### 매 ML connections
|
||||
- 매 unsupervised learning 의 model.
|
||||
- Hopfield network 매 Hebbian-trained associative memory.
|
||||
- SOM (Self-Organizing Maps) 매 Hebbian-style competitive learning.
|
||||
- 매 modern: Predictive coding / Free energy principle 의 Hebbian-like rules.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Basic Hebbian Update
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
class HebbianNeuron:
|
||||
def __init__(self, n_inputs, lr=0.01):
|
||||
self.w = np.random.randn(n_inputs) * 0.01
|
||||
self.lr = lr
|
||||
|
||||
def forward(self, x):
|
||||
return np.dot(self.w, x)
|
||||
|
||||
def update(self, x, y):
|
||||
# Δw = η x y
|
||||
self.w += self.lr * x * y
|
||||
|
||||
# Demo: weights 의 unbounded growth (매 problem)
|
||||
neuron = HebbianNeuron(n_inputs=10)
|
||||
for _ in range(1000):
|
||||
x = np.random.randn(10)
|
||||
y = neuron.forward(x)
|
||||
neuron.update(x, y)
|
||||
print(f"Weight norm: {np.linalg.norm(neuron.w):.2f}") # 매 explodes
|
||||
```
|
||||
|
||||
### Oja's Rule (매 stable + PCA)
|
||||
```python
|
||||
class OjasNeuron:
|
||||
"""매 Δw = η y (x - y w). PCA 첫번째 component 으로 converges."""
|
||||
def __init__(self, n_inputs, lr=0.01):
|
||||
self.w = np.random.randn(n_inputs)
|
||||
self.w /= np.linalg.norm(self.w)
|
||||
self.lr = lr
|
||||
|
||||
def update(self, x):
|
||||
y = np.dot(self.w, x)
|
||||
self.w += self.lr * y * (x - y * self.w)
|
||||
|
||||
# 매 verify: top eigenvector 으로 converges
|
||||
np.random.seed(0)
|
||||
data = np.random.randn(1000, 10) @ np.diag([5, 3, 2, 1, 1, 0.5, 0.5, 0.3, 0.3, 0.1])
|
||||
neuron = OjasNeuron(10, lr=0.001)
|
||||
for x in data:
|
||||
neuron.update(x)
|
||||
|
||||
# 매 compare with NumPy PCA top component
|
||||
cov = np.cov(data.T)
|
||||
eigvals, eigvecs = np.linalg.eigh(cov)
|
||||
top_pc = eigvecs[:, -1]
|
||||
similarity = abs(np.dot(neuron.w / np.linalg.norm(neuron.w), top_pc))
|
||||
print(f"Similarity to top PC: {similarity:.4f}") # ≈ 1.0
|
||||
```
|
||||
|
||||
### BCM Rule (매 sliding threshold)
|
||||
```python
|
||||
class BCMNeuron:
|
||||
def __init__(self, n_inputs, lr=0.01, tau=100):
|
||||
self.w = np.random.randn(n_inputs) * 0.1
|
||||
self.lr = lr
|
||||
self.theta = 1.0 # sliding threshold
|
||||
self.tau = tau # time constant
|
||||
self.y_history = []
|
||||
|
||||
def forward(self, x):
|
||||
return np.dot(self.w, x)
|
||||
|
||||
def update(self, x):
|
||||
y = self.forward(x)
|
||||
self.w += self.lr * x * y * (y - self.theta)
|
||||
# Sliding threshold: θ = E[y²]
|
||||
self.y_history.append(y ** 2)
|
||||
if len(self.y_history) > self.tau:
|
||||
self.y_history.pop(0)
|
||||
self.theta = np.mean(self.y_history) if self.y_history else 1.0
|
||||
```
|
||||
|
||||
### STDP (Spike-Timing-Dependent) — Brian2
|
||||
```python
|
||||
from brian2 import *
|
||||
|
||||
# 매 100 input neurons → 1 output, STDP synapses
|
||||
N = 100
|
||||
input_group = PoissonGroup(N, rates=20*Hz)
|
||||
neurons = NeuronGroup(1, '''
|
||||
dv/dt = -v / (10*ms) : 1
|
||||
''', threshold='v > 1', reset='v = 0')
|
||||
|
||||
# 매 STDP synapse model
|
||||
syn = Synapses(input_group, neurons,
|
||||
'''
|
||||
w : 1
|
||||
dapre/dt = -apre/(20*ms) : 1 (event-driven)
|
||||
dapost/dt = -apost/(20*ms) : 1 (event-driven)
|
||||
''',
|
||||
on_pre='''
|
||||
v_post += w
|
||||
apre += 0.01
|
||||
w = clip(w + apost, 0, 1)
|
||||
''',
|
||||
on_post='''
|
||||
apost -= 0.012
|
||||
w = clip(w + apre, 0, 1)
|
||||
'''
|
||||
)
|
||||
syn.connect()
|
||||
syn.w = 'rand() * 0.5'
|
||||
|
||||
run(1000*ms)
|
||||
hist(syn.w[:], 50)
|
||||
# 매 bimodal distribution 의 emergence — 매 STDP signature
|
||||
```
|
||||
|
||||
### Hopfield Network (Hebbian-trained associative memory)
|
||||
```python
|
||||
class HopfieldNetwork:
|
||||
def __init__(self, n):
|
||||
self.n = n
|
||||
self.W = np.zeros((n, n))
|
||||
|
||||
def store(self, patterns):
|
||||
"""Hebbian: W = Σ p p^T (diagonal=0)."""
|
||||
for p in patterns:
|
||||
self.W += np.outer(p, p)
|
||||
np.fill_diagonal(self.W, 0)
|
||||
self.W /= len(patterns)
|
||||
|
||||
def recall(self, pattern, max_iter=100):
|
||||
s = pattern.copy()
|
||||
for _ in range(max_iter):
|
||||
s_new = np.sign(self.W @ s)
|
||||
if np.all(s_new == s):
|
||||
break
|
||||
s = s_new
|
||||
return s
|
||||
|
||||
# Demo: store ±1 patterns, recall from noisy
|
||||
net = HopfieldNetwork(50)
|
||||
patterns = [np.random.choice([-1, 1], 50) for _ in range(3)]
|
||||
net.store(patterns)
|
||||
|
||||
noisy = patterns[0].copy()
|
||||
noisy[:10] = -noisy[:10] # flip 10 bits
|
||||
recalled = net.recall(noisy)
|
||||
print(f"Match: {np.mean(recalled == patterns[0]):.2%}")
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
|
||||
| 상황 | Rule |
|
||||
|---|---|
|
||||
| Educational / simple demo | Plain Hebb |
|
||||
| Stable + PCA emergence | Oja's rule |
|
||||
| Bidirectional plasticity (LTP+LTD) | BCM |
|
||||
| Biological realism (spiking) | STDP |
|
||||
| Associative memory | Hopfield (Hebbian) |
|
||||
| Competitive learning / clustering | SOM (Kohonen) |
|
||||
| Modern deep learning | Backprop (NOT Hebbian) |
|
||||
| Biologically-plausible deep learning | Predictive coding / Equilibrium propagation |
|
||||
|
||||
**기본값**: 매 conceptual 매 Hebb's rule, 매 ML practice 매 Oja's rule, 매 spiking simulation 매 STDP.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Computational-Neuroscience-RL|Computational-Neuroscience]] · [[Synaptic-Plasticity]]
|
||||
- 응용: [[Hopfield Network]] · [[Associative-Memory]] · [[Predictive-Coding]]
|
||||
- Adjacent: [[Free-Energy-Principle]] · [[데이터 사이언스 및 ML 엔지니어링|Backpropagation]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 conceptual explanation, 매 history of computational neuroscience, 매 simple rule derivation.
|
||||
**언제 X**: 매 modern deep learning 의 training — backprop 사용. 매 actual neuroscience research 의 STDP parameter — 매 experimental data 참조.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Plain Hebb 의 production 사용**: 매 weights 의 explosion — Oja/BCM/normalization 사용.
|
||||
- **"Hebbian = backprop" 혼동**: 매 different learning paradigm — backprop 매 supervised, Hebb 매 unsupervised correlation.
|
||||
- **STDP 의 timing 의 부정확**: 매 millisecond precision 필요 — discrete-time approximation 의 한계.
|
||||
- **Hopfield 의 capacity overestimate**: 매 ~0.14 N patterns 의 한계 (Hopfield 1982).
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Hebb 1949 "Organization of Behavior", Oja 1982, Bliss-Lomo 1973 LTP, Bi-Poo 1998 STDP).
|
||||
- 신뢰도 A (foundational neuroscience theory).
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Hebb/Oja/BCM/STDP rules, Hopfield, biological mechanisms |
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
---
|
||||
id: wiki-2026-0508-high-frequency-trading-models
|
||||
title: High Frequency Trading Models
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [HFT, Algorithmic Trading, Market Making]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [hft, trading, latency, market-microstructure]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: cpp
|
||||
framework: kdb+/qpython
|
||||
---
|
||||
|
||||
# High Frequency Trading Models
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 microsecond 매 alpha"**. HFT 매 nanosecond-scale latency 매 statistical arbitrage 의 결합 — 매 2026 quantum-resistant signature 매 co-located FPGA 매 standard. Renaissance, Citadel, Jump 매 dominant; 매 average holding period 매 sub-second.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 latency hierarchy
|
||||
- **L1 (sub-µs)**: FPGA tick-to-trade, kernel bypass NICs (Solarflare, Mellanox).
|
||||
- **L2 (1-10µs)**: 매 C++ hot path, lock-free queues, busy-spin threads.
|
||||
- **L3 (10-100µs)**: 매 Python/kdb+ 매 signal generation.
|
||||
- **L4 (ms+)**: 매 ML inference (XGBoost, transformer order-flow).
|
||||
|
||||
### 매 strategy taxonomy
|
||||
- **Market Making**: 매 bid-ask spread capture, inventory risk hedge.
|
||||
- **Statistical Arbitrage**: 매 cointegration, mean reversion (Ornstein-Uhlenbeck).
|
||||
- **Latency Arbitrage**: 매 venue-to-venue price lag exploit.
|
||||
- **Order-Flow Prediction**: 매 LOB imbalance → micro-price drift.
|
||||
- **Index Arbitrage**: 매 ETF NAV vs constituent basket.
|
||||
|
||||
### 매 응용
|
||||
1. 매 NYSE/NASDAQ co-location.
|
||||
2. 매 crypto MEV (Flashbots, Jito).
|
||||
3. 매 forex ECN aggregation.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### 1. Order Book Imbalance (LOB micro-price)
|
||||
```python
|
||||
def micro_price(bid_px, bid_sz, ask_px, ask_sz):
|
||||
# 매 imbalance-weighted mid — predicts 100ms drift
|
||||
imb = bid_sz / (bid_sz + ask_sz)
|
||||
return ask_px * (1 - imb) + bid_px * imb
|
||||
|
||||
# 매 signal: micro_price - mid_price → directional alpha
|
||||
```
|
||||
|
||||
### 2. Cointegration Pair Trade (Engle-Granger)
|
||||
```python
|
||||
import statsmodels.api as sm
|
||||
import numpy as np
|
||||
|
||||
def find_pairs(prices_a, prices_b):
|
||||
beta = sm.OLS(prices_a, sm.add_constant(prices_b)).fit().params[1]
|
||||
spread = prices_a - beta * prices_b
|
||||
adf = sm.tsa.adfuller(spread)
|
||||
return beta, adf[1] # p-value < 0.05 → tradeable
|
||||
|
||||
# 매 entry: spread > 2σ, exit: spread → 0
|
||||
```
|
||||
|
||||
### 3. Lock-Free Order Book (C++)
|
||||
```cpp
|
||||
struct Level { std::atomic<int64_t> qty; int64_t px; };
|
||||
struct Book { Level bids[1024]; Level asks[1024]; };
|
||||
|
||||
void on_tick(Book& b, int side, int idx, int64_t qty) {
|
||||
// 매 single-writer SPMC — no mutex
|
||||
auto& lvl = (side == 0) ? b.bids[idx] : b.asks[idx];
|
||||
lvl.qty.store(qty, std::memory_order_release);
|
||||
}
|
||||
```
|
||||
|
||||
### 4. Kalman Filter Spread Tracking
|
||||
```python
|
||||
# 매 dynamic hedge ratio — beta drifts over time
|
||||
from pykalman import KalmanFilter
|
||||
kf = KalmanFilter(transition_matrices=[1], observation_matrices=[1],
|
||||
initial_state_mean=0, initial_state_covariance=1,
|
||||
observation_covariance=1, transition_covariance=0.01)
|
||||
state_means, _ = kf.filter(spread_series)
|
||||
```
|
||||
|
||||
### 5. FPGA Tick-to-Trade (Verilog sketch)
|
||||
```verilog
|
||||
// 매 200ns tick parse → order send
|
||||
always @(posedge clk) begin
|
||||
if (md_valid && (bid_px > threshold)) begin
|
||||
ord_send <= 1; ord_px <= bid_px; ord_qty <= 100;
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
### 6. Almgren-Chriss Optimal Execution
|
||||
```python
|
||||
def almgren_chriss(X, T, sigma, eta, gamma, lam):
|
||||
# 매 minimize: variance + market impact
|
||||
kappa = np.sqrt(lam * sigma**2 / eta)
|
||||
n_steps = int(T / dt)
|
||||
schedule = [X * np.sinh(kappa*(T-t)) / np.sinh(kappa*T) for t in times]
|
||||
return schedule # 매 hyperbolic decay
|
||||
```
|
||||
|
||||
### 7. ML Order-Flow (LightGBM)
|
||||
```python
|
||||
import lightgbm as lgb
|
||||
features = ['lob_imb_1','lob_imb_5','vwap_dev','trade_intensity']
|
||||
model = lgb.train({'objective':'regression','num_leaves':31},
|
||||
lgb.Dataset(X[features], y_future_return),
|
||||
num_boost_round=500)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Sub-µs critical | FPGA + kernel bypass |
|
||||
| Stat arb medium freq | Python + kdb+ |
|
||||
| Crypto MEV | Rust + Flashbots bundle |
|
||||
| Backtest | vectorbt, Nautilus Trader |
|
||||
|
||||
**기본값**: C++ hot path + Python research, 매 co-location 매 essential.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Operations-Research]] · [[Statistics]]
|
||||
- 변형: [[Algorithmic Trading]] · [[Market Making]]
|
||||
- 응용: [[Kalman-Filter-and-State-Tracking]] · [[Optimal-Control-Theory]]
|
||||
- Adjacent: [[Signal-Processing-Foundations]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: research signal hypothesis 생성, 매 backtest code scaffolding, 매 strategy documentation.
|
||||
**언제 X**: 매 production hot path (latency budget violated), 매 real-time risk decision.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Garbage Collection in Hot Path**: 매 Java/Python GC pause → 100µs jitter. 매 C++/Rust 사용.
|
||||
- **Overfit Backtest**: 매 in-sample Sharpe 5 → live -2. 매 walk-forward + transaction cost.
|
||||
- **No Inventory Limit**: 매 market-maker blow-up (Knight Capital 2012, $440M loss in 45min).
|
||||
- **Survivorship Bias**: 매 delisted ticker 무시 → inflated returns.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Aldridge, *High-Frequency Trading*; Cartea et al., *Algorithmic and HFT*).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full FULL spec, 7 patterns + decision matrix |
|
||||
@@ -0,0 +1,151 @@
|
||||
---
|
||||
id: wiki-2026-0508-incremental-computation
|
||||
title: Incremental Computation
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Incremental Build, Memoization, Salsa, Adapton]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [incremental, memoization, build-systems, reactive]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: rust
|
||||
framework: salsa
|
||||
---
|
||||
|
||||
# Incremental Computation
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 unchanged 매 recompute X"**. Incremental computation 매 prior result 의 reuse — 매 input change 만 propagate. 매 2026 rust-analyzer (Salsa), Bazel, Buck2, Turbopack 매 standard. 매 trade-off: 매 memory vs recompute time.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 mechanism 분류
|
||||
- **Memoization**: 매 (input → output) cache. 매 pure function 필수.
|
||||
- **Demand-Driven**: 매 query-based; pull 시 dependency graph 추적 (Salsa, Adapton).
|
||||
- **Change-Driven**: 매 push; input change → invalidate downstream (React reactivity).
|
||||
- **Self-Adjusting Computation**: 매 Acar — formal foundation, dynamic dependency graph.
|
||||
|
||||
### 매 invalidation strategy
|
||||
- **Hash-based**: 매 input fingerprint compare (Bazel digest).
|
||||
- **Timestamp**: 매 mtime check (make).
|
||||
- **Reference equality**: 매 pointer compare (React).
|
||||
- **Structural diff**: 매 deep equal (immer, Redux).
|
||||
|
||||
### 매 응용
|
||||
1. 매 build systems (Bazel, Buck2).
|
||||
2. 매 IDE backends (rust-analyzer, TypeScript LSP).
|
||||
3. 매 reactive UI (React, SolidJS signals).
|
||||
4. 매 dataflow / spreadsheets.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### 1. Salsa Query (Rust)
|
||||
```rust
|
||||
#[salsa::query_group(CompilerStorage)]
|
||||
pub trait Compiler: salsa::Database {
|
||||
#[salsa::input]
|
||||
fn source_text(&self, file: FileId) -> Arc<String>;
|
||||
|
||||
fn parse(&self, file: FileId) -> Arc<Ast>;
|
||||
fn type_check(&self, file: FileId) -> Arc<TypeMap>;
|
||||
}
|
||||
|
||||
fn parse(db: &dyn Compiler, file: FileId) -> Arc<Ast> {
|
||||
let text = db.source_text(file); // 매 dependency tracked
|
||||
Arc::new(parse_text(&text))
|
||||
}
|
||||
// 매 source_text unchanged → parse skipped automatically
|
||||
```
|
||||
|
||||
### 2. Memoization with LRU
|
||||
```python
|
||||
from functools import lru_cache
|
||||
|
||||
@lru_cache(maxsize=10_000)
|
||||
def expensive(x: int, y: int) -> int:
|
||||
return slow_compute(x, y)
|
||||
|
||||
# 매 hash(args) → cached result; LRU evict oldest
|
||||
```
|
||||
|
||||
### 3. React useMemo (Reference Equality)
|
||||
```jsx
|
||||
const expensive = useMemo(() => {
|
||||
return items.filter(i => i.active).sort();
|
||||
}, [items]); // 매 items reference unchanged → skip
|
||||
```
|
||||
|
||||
### 4. Bazel Action Cache
|
||||
```python
|
||||
# WORKSPACE — 매 each action keyed by:
|
||||
# hash(inputs) + hash(command) + hash(env)
|
||||
# Output stored in CAS (content-addressable storage)
|
||||
# Remote cache — 매 distributed reuse across team
|
||||
```
|
||||
|
||||
### 5. Self-Adjusting Computation (OCaml-style)
|
||||
```ocaml
|
||||
let m = Mod.create ()
|
||||
let a = Var.create m 1
|
||||
let b = Var.create m 2
|
||||
let sum = Mod.bind m (fun () -> Var.read a + Var.read b)
|
||||
Var.write a 10 (* sum auto-recomputes only its branch *)
|
||||
```
|
||||
|
||||
### 6. Incremental Diff (Patch Generation)
|
||||
```typescript
|
||||
function diff<T>(old: T[], new_: T[]): Patch[] {
|
||||
// 매 Myers diff — O(ND) — minimal edit script
|
||||
// 매 used by git, react reconciler, immer
|
||||
}
|
||||
```
|
||||
|
||||
### 7. Signal-Based Reactivity (SolidJS)
|
||||
```javascript
|
||||
const [count, setCount] = createSignal(0);
|
||||
const doubled = createMemo(() => count() * 2);
|
||||
// 매 fine-grained — only doubled recomputes when count changes
|
||||
// 매 NO virtual DOM diff
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Pure function repeat | `lru_cache` / memoize |
|
||||
| Compiler / IDE | Salsa, Adapton |
|
||||
| UI reactivity | Signals (Solid) > Virtual DOM (React) |
|
||||
| Build system | Bazel / Buck2 / Turbo |
|
||||
| Stream pipeline | Materialize, ksqlDB |
|
||||
|
||||
**기본값**: 매 pure function memoize, 매 large pipeline 매 Salsa pattern.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Theoretical-Computer-Science]] · [[Algorithm-Complexity-Big-O]]
|
||||
- 변형: [[Memoization]]
|
||||
- Adjacent: [[Dynamic-Programming]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 build pipeline design, 매 query system architecture, 매 cache invalidation logic.
|
||||
**언제 X**: 매 input always changes (no reuse benefit), 매 memory-constrained embedded.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Cache invalidation bug**: 매 stale result return. 매 dependency graph correctness 매 critical.
|
||||
- **Unbounded memo**: 매 OOM. 매 LRU/TTL bound 필수.
|
||||
- **Impure function memo**: 매 random()/now() 매 cache 시 incorrect.
|
||||
- **Over-fine-grained**: 매 cache overhead > recompute cost.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Acar, *Self-Adjusting Computation*; Salsa docs; Bazel design).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Salsa/Bazel/SolidJS patterns + decision matrix |
|
||||
@@ -0,0 +1,142 @@
|
||||
---
|
||||
id: wiki-2026-0508-inexact-science
|
||||
title: Inexact Science
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Soft Science, Probabilistic Reasoning, Approximate Methods]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.85
|
||||
verification_status: applied
|
||||
tags: [epistemology, statistics, uncertainty, methodology]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: pymc
|
||||
---
|
||||
|
||||
# Inexact Science
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 uncertainty 매 quantify"**. Inexact science 매 deterministic closed-form X — 매 noise, bias, partial observability 매 inherent. 매 2026 ML interpretability, social science replication crisis 매 forefront. 매 tool: 매 Bayesian inference, robust statistics, sensitivity analysis.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 inexactness 의 source
|
||||
- **Aleatory**: 매 inherent randomness (quantum, dice).
|
||||
- **Epistemic**: 매 ignorance — 매 reducible by data.
|
||||
- **Measurement noise**: 매 instrument precision limit.
|
||||
- **Model misspecification**: 매 wrong functional form.
|
||||
- **Selection bias**: 매 non-representative sample.
|
||||
|
||||
### 매 mitigation 전략
|
||||
- **Bayesian credible intervals** (vs frequentist CI).
|
||||
- **Bootstrap resampling** — 매 distribution-free uncertainty.
|
||||
- **Cross-validation** — 매 generalization estimate.
|
||||
- **Sensitivity analysis** — 매 parameter perturbation.
|
||||
- **Pre-registration** — 매 p-hacking 방지.
|
||||
|
||||
### 매 응용
|
||||
1. 매 medical trials (FDA Phase III).
|
||||
2. 매 ML model deployment (Bayesian deep learning).
|
||||
3. 매 climate modeling (ensemble).
|
||||
4. 매 economics (DSGE models).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### 1. Bayesian Linear Regression (PyMC)
|
||||
```python
|
||||
import pymc as pm
|
||||
|
||||
with pm.Model() as model:
|
||||
alpha = pm.Normal('alpha', 0, 10)
|
||||
beta = pm.Normal('beta', 0, 10)
|
||||
sigma = pm.HalfNormal('sigma', 5)
|
||||
mu = alpha + beta * x_obs
|
||||
y = pm.Normal('y', mu=mu, sigma=sigma, observed=y_obs)
|
||||
trace = pm.sample(2000, tune=1000)
|
||||
# 매 posterior distribution — credible intervals 매 natural
|
||||
```
|
||||
|
||||
### 2. Bootstrap Confidence Interval
|
||||
```python
|
||||
import numpy as np
|
||||
def bootstrap_ci(data, stat_fn, n=10_000, alpha=0.05):
|
||||
boots = [stat_fn(np.random.choice(data, len(data), replace=True))
|
||||
for _ in range(n)]
|
||||
return np.percentile(boots, [100*alpha/2, 100*(1-alpha/2)])
|
||||
```
|
||||
|
||||
### 3. Sensitivity Analysis (Sobol)
|
||||
```python
|
||||
from SALib.analyze import sobol
|
||||
from SALib.sample.sobol import sample as sobol_sample
|
||||
|
||||
problem = {'num_vars': 3, 'names': ['x1','x2','x3'],
|
||||
'bounds': [[0,1]]*3}
|
||||
param_values = sobol_sample(problem, 1024)
|
||||
Y = np.array([model(p) for p in param_values])
|
||||
Si = sobol.analyze(problem, Y) # 매 first/total order indices
|
||||
```
|
||||
|
||||
### 4. Cross-Validation
|
||||
```python
|
||||
from sklearn.model_selection import cross_val_score
|
||||
scores = cross_val_score(model, X, y, cv=10, scoring='neg_mean_squared_error')
|
||||
print(f"MSE: {-scores.mean():.3f} ± {scores.std():.3f}")
|
||||
```
|
||||
|
||||
### 5. Robust Statistics (M-estimator)
|
||||
```python
|
||||
from sklearn.linear_model import HuberRegressor
|
||||
# 매 outlier-resistant — Huber loss 매 quadratic+linear
|
||||
huber = HuberRegressor(epsilon=1.35).fit(X, y)
|
||||
```
|
||||
|
||||
### 6. Conformal Prediction (Distribution-Free)
|
||||
```python
|
||||
# 매 2026 standard — coverage guarantee 매 model-agnostic
|
||||
calib_residuals = np.abs(y_calib - model.predict(X_calib))
|
||||
q_hat = np.quantile(calib_residuals, 0.95)
|
||||
# 매 prediction interval: [pred - q_hat, pred + q_hat]
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Small n, prior knowledge | Bayesian (PyMC, Stan) |
|
||||
| Large n, distribution-free | Bootstrap + conformal |
|
||||
| Causal claim | RCT > obs + IV/DiD |
|
||||
| Outliers heavy | Huber / RANSAC |
|
||||
| Multiple comparisons | BH-FDR / Bonferroni |
|
||||
|
||||
**기본값**: 매 report point estimate + 95% interval; 매 effect size > significance.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Statistics]] · [[Probability Theory]]
|
||||
- 변형: [[Bayesian Inference]]
|
||||
- 응용: [[Statistical-Power]] · [[Multivariate-Analysis]]
|
||||
- Adjacent: [[Epistemology]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 study design review, 매 uncertainty communication, 매 robustness check 제안.
|
||||
**언제 X**: 매 deterministic system (compiler, hash). 매 cryptographic exactness 필요.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **p<0.05 cult**: 매 effect size 무시, multiple-testing 무수정.
|
||||
- **HARKing**: 매 hypothesis after results known.
|
||||
- **Overconfident point estimate**: 매 ±uncertainty 미보고.
|
||||
- **Garrison the data**: 매 outlier 임의 제거.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Gelman, *BDA*; Wasserman, *All of Statistics*; ASA p-value statement).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Bayesian/bootstrap/conformal patterns |
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
---
|
||||
id: wiki-2026-0508-information-retrieval-evaluation
|
||||
title: Information Retrieval Evaluation Metrics
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [IR Metrics, Search Evaluation, NDCG, MRR]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [ir, evaluation, metrics, ranking]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: pytrec_eval
|
||||
---
|
||||
|
||||
# Information Retrieval Evaluation Metrics
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 metric 매 system behavior 의 directs"**. IR evaluation 매 ranked list 의 quality measure — 매 binary (precision, recall) vs graded (NDCG). 매 2026 LLM-as-judge, 매 BEIR/MTEB benchmark 매 standard, 매 nDCG@10 매 default.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 binary relevance metrics
|
||||
- **Precision@k**: 매 top-k 중 relevant 비율.
|
||||
- **Recall@k**: 매 전체 relevant 중 retrieved 비율.
|
||||
- **F1**: 매 harmonic mean.
|
||||
- **MAP** (Mean Average Precision): 매 query별 AP 의 평균.
|
||||
- **MRR** (Mean Reciprocal Rank): 매 first relevant 의 1/rank 평균.
|
||||
|
||||
### 매 graded relevance metrics
|
||||
- **DCG@k**: $\sum_{i=1}^{k} \frac{rel_i}{\log_2(i+1)}$
|
||||
- **NDCG@k**: DCG / IDCG — 매 [0,1] normalize.
|
||||
- **ERR** (Expected Reciprocal Rank): 매 cascade user model.
|
||||
|
||||
### 매 응용
|
||||
1. 매 search engine A/B (Google, Bing).
|
||||
2. 매 RAG retrieval quality (Ragas).
|
||||
3. 매 recommender systems.
|
||||
4. 매 LLM benchmark (BEIR, MTEB, MS MARCO).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### 1. Precision/Recall
|
||||
```python
|
||||
def precision_at_k(retrieved, relevant, k):
|
||||
return len(set(retrieved[:k]) & set(relevant)) / k
|
||||
|
||||
def recall_at_k(retrieved, relevant, k):
|
||||
return len(set(retrieved[:k]) & set(relevant)) / len(relevant)
|
||||
```
|
||||
|
||||
### 2. NDCG (graded)
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
def dcg(rels, k=10):
|
||||
rels = np.asarray(rels)[:k]
|
||||
return np.sum(rels / np.log2(np.arange(2, len(rels)+2)))
|
||||
|
||||
def ndcg(rels, ideal_rels, k=10):
|
||||
return dcg(rels, k) / (dcg(ideal_rels, k) or 1)
|
||||
```
|
||||
|
||||
### 3. MRR
|
||||
```python
|
||||
def mrr(retrieved_lists, relevant_sets):
|
||||
total = 0
|
||||
for retrieved, relevant in zip(retrieved_lists, relevant_sets):
|
||||
for i, doc in enumerate(retrieved, 1):
|
||||
if doc in relevant:
|
||||
total += 1 / i
|
||||
break
|
||||
return total / len(retrieved_lists)
|
||||
```
|
||||
|
||||
### 4. MAP
|
||||
```python
|
||||
def average_precision(retrieved, relevant):
|
||||
hits = 0; sum_p = 0
|
||||
for i, doc in enumerate(retrieved, 1):
|
||||
if doc in relevant:
|
||||
hits += 1
|
||||
sum_p += hits / i
|
||||
return sum_p / len(relevant) if relevant else 0
|
||||
```
|
||||
|
||||
### 5. pytrec_eval (Standard Tool)
|
||||
```python
|
||||
import pytrec_eval
|
||||
qrel = {'q1': {'d1': 1, 'd3': 2}}
|
||||
run = {'q1': {'d1': 0.9, 'd2': 0.5, 'd3': 0.3}}
|
||||
ev = pytrec_eval.RelevanceEvaluator(qrel, {'ndcg_cut.10', 'map', 'recip_rank'})
|
||||
print(ev.evaluate(run))
|
||||
```
|
||||
|
||||
### 6. LLM-as-Judge (2026 trend)
|
||||
```python
|
||||
from anthropic import Anthropic
|
||||
client = Anthropic()
|
||||
prompt = f"Query: {q}\nDoc: {doc}\nRate relevance 0-3:"
|
||||
score = client.messages.create(model="claude-opus-4-7",
|
||||
max_tokens=10, messages=[{"role":"user","content":prompt}])
|
||||
# 매 graded relevance — human-aligned, 매 expensive
|
||||
```
|
||||
|
||||
### 7. Statistical Significance (paired t-test)
|
||||
```python
|
||||
from scipy.stats import ttest_rel
|
||||
t, p = ttest_rel(ndcg_system_A, ndcg_system_B)
|
||||
# 매 p < 0.05 → 매 significant difference
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Metric |
|
||||
|---|---|
|
||||
| Web search top result | MRR |
|
||||
| Long-tail recall | Recall@1000 |
|
||||
| Graded relevance | NDCG@10 |
|
||||
| Multi-relevant per query | MAP |
|
||||
| RAG eval | NDCG@5 + LLM-judge |
|
||||
|
||||
**기본값**: NDCG@10, 매 paired-t test 매 statistical significance.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Information Retrieval]] · [[Statistics]]
|
||||
- 변형: [[Ranking-Algorithms]] · [[Relevance-Feedback]]
|
||||
- 응용: [[Keyword Search]] · [[Knowledge Graph]]
|
||||
- Adjacent: [[Statistical-Power]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 search system A/B 설계, 매 RAG eval pipeline, 매 metric trade-off 분석.
|
||||
**언제 X**: 매 single-doc QA (use exact-match), 매 generative output (use BLEU/ROUGE/judge).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Precision@1 only**: 매 long-tail blind spot.
|
||||
- **No statistical test**: 매 noise-driven conclusion.
|
||||
- **Mismatched qrels**: 매 partial relevance judgment.
|
||||
- **Self-reported benchmark**: 매 trec_eval/standard tool 사용 권장.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Manning et al., *IR Book*; TREC standards; BEIR paper 2021).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full metric coverage + LLM-judge pattern |
|
||||
@@ -0,0 +1,147 @@
|
||||
---
|
||||
id: wiki-2026-0508-information-entropy
|
||||
title: Information Entropy
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Shannon Entropy, H(X), Surprise]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [information-theory, entropy, shannon, ml-foundations]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: scipy
|
||||
---
|
||||
|
||||
# Information Entropy
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 surprise 의 average"**. Shannon entropy $H(X) = -\sum p(x) \log p(x)$ — 매 distribution 의 uncertainty 매 bit 단위 measure. 매 1948 Shannon, 매 2026 LLM token sampling, compression, decision-tree split, MI-based feature selection 매 foundation.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 정의
|
||||
- $H(X) = -\sum_{x} p(x) \log_2 p(x)$ — 매 bit (log2), nat (ln), dit (log10).
|
||||
- $0 \le H(X) \le \log_2 |\mathcal{X}|$ — 매 uniform 시 max.
|
||||
- **Joint**: $H(X,Y)$ · **Conditional**: $H(Y|X) = H(X,Y) - H(X)$.
|
||||
- **Mutual Information**: $I(X;Y) = H(Y) - H(Y|X)$.
|
||||
|
||||
### 매 핵심 properties
|
||||
- **Non-negative**: $H(X) \ge 0$.
|
||||
- **Concavity**: 매 distribution mixing 시 entropy 증가.
|
||||
- **Chain rule**: $H(X,Y) = H(X) + H(Y|X)$.
|
||||
- **Data Processing**: $I(X;Y) \ge I(X;f(Y))$.
|
||||
|
||||
### 매 응용
|
||||
1. 매 lossless compression (Huffman, arithmetic) — limit $H(X)$.
|
||||
2. 매 ML loss (cross-entropy, KL).
|
||||
3. 매 decision tree split (ID3, C4.5 information gain).
|
||||
4. 매 LLM sampling (entropy-aware temperature, min-p).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### 1. Shannon Entropy
|
||||
```python
|
||||
import numpy as np
|
||||
def entropy(probs, base=2):
|
||||
p = np.asarray(probs)
|
||||
p = p[p > 0]
|
||||
return -np.sum(p * np.log(p)) / np.log(base)
|
||||
|
||||
# H([0.5,0.5]) = 1.0 bit
|
||||
# H([1.0,0.0]) = 0.0 bit
|
||||
# H([0.25]*4) = 2.0 bit
|
||||
```
|
||||
|
||||
### 2. Cross-Entropy Loss (PyTorch)
|
||||
```python
|
||||
import torch.nn.functional as F
|
||||
# 매 true distribution q vs predicted p
|
||||
# H(q, p) = -Σ q(x) log p(x)
|
||||
loss = F.cross_entropy(logits, targets) # softmax + NLL
|
||||
```
|
||||
|
||||
### 3. KL Divergence
|
||||
```python
|
||||
def kl_div(p, q):
|
||||
p, q = np.asarray(p), np.asarray(q)
|
||||
return np.sum(p * np.log(p / q + 1e-12))
|
||||
# 매 D_KL(p||q) = H(p,q) - H(p)
|
||||
```
|
||||
|
||||
### 4. Mutual Information (sklearn)
|
||||
```python
|
||||
from sklearn.feature_selection import mutual_info_classif
|
||||
mi = mutual_info_classif(X, y, random_state=0)
|
||||
# 매 feature ranking — 매 non-linear dependency capture
|
||||
```
|
||||
|
||||
### 5. Decision Tree Split (information gain)
|
||||
```python
|
||||
def info_gain(parent_y, splits):
|
||||
H_parent = entropy(np.bincount(parent_y) / len(parent_y))
|
||||
H_children = sum((len(s)/len(parent_y)) * entropy(np.bincount(s)/len(s))
|
||||
for s in splits if len(s) > 0)
|
||||
return H_parent - H_children
|
||||
```
|
||||
|
||||
### 6. LLM Min-p Sampling (entropy-aware)
|
||||
```python
|
||||
# 매 2024+ standard — 매 temperature alternative
|
||||
def min_p_sample(logits, p_base=0.05):
|
||||
probs = softmax(logits)
|
||||
threshold = p_base * probs.max()
|
||||
mask = probs >= threshold
|
||||
probs = probs * mask
|
||||
probs /= probs.sum()
|
||||
return np.random.choice(len(probs), p=probs)
|
||||
```
|
||||
|
||||
### 7. Differential Entropy (Continuous)
|
||||
```python
|
||||
from scipy.stats import differential_entropy
|
||||
samples = np.random.normal(0, 1, 10_000)
|
||||
h = differential_entropy(samples) # ≈ 0.5*log(2πe) ≈ 1.42 nat
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Form |
|
||||
|---|---|
|
||||
| Discrete classification | Cross-entropy loss |
|
||||
| Distribution compare | KL divergence |
|
||||
| Feature selection | Mutual information |
|
||||
| Tree split | Information gain |
|
||||
| LLM sample diversity | Min-p / temperature |
|
||||
|
||||
**기본값**: Cross-entropy loss + softmax, 매 ML classification 매 standard.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Entropy in Information Theory]] · [[Probability Theory]]
|
||||
- 변형: [[Mutual-Information]] · [[Kullback-Leibler-Divergence]] · [[Kolmogorov-Complexity]]
|
||||
- 응용: [[Entropy in Information Theory|Information Theory]] · [[Information Retrieval (IR)]]
|
||||
- Adjacent: [[Statistical-Power]] · [[Bayesian Inference]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 loss design, 매 feature ranking, 매 sampling strategy 설명, 매 compression bound 추정.
|
||||
**언제 X**: 매 small-sample MI estimation 매 unreliable. 매 high-dim differential entropy 매 hard.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **MI without binning correction**: 매 small-n bias.
|
||||
- **KL asymmetry 무시**: $D_{KL}(p\|q) \ne D_{KL}(q\|p)$.
|
||||
- **Cross-entropy on wrong base**: 매 nat vs bit confusion.
|
||||
- **Negative differential entropy 의 panic**: 매 continuous 매 자연스럽다.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Cover & Thomas, *Elements of IT*; MacKay, *ITILA*).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full Shannon/KL/MI + min-p pattern |
|
||||
@@ -0,0 +1,149 @@
|
||||
---
|
||||
id: wiki-2026-0508-inner-product-spaces
|
||||
title: Inner Product Spaces
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Hilbert Space, Dot Product, Vector Geometry]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [linear-algebra, geometry, ml-foundations, hilbert]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: numpy
|
||||
---
|
||||
|
||||
# Inner Product Spaces
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 angle 매 length 의 algebraic foundation"**. Inner product $\langle x, y \rangle$ 매 vector space 매 geometry 부여 — 매 norm, distance, orthogonality 의 derived. 매 2026 ML embedding similarity (cosine, dot), kernel methods, Hilbert-space transformer 매 foundation.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 axioms
|
||||
- **Conjugate symmetry**: $\langle x,y \rangle = \overline{\langle y,x \rangle}$.
|
||||
- **Linearity in 1st arg**: $\langle ax+by, z \rangle = a\langle x,z\rangle + b\langle y,z\rangle$.
|
||||
- **Positive definite**: $\langle x,x \rangle \ge 0$, $=0 \iff x=0$.
|
||||
|
||||
### 매 derived 구조
|
||||
- **Norm**: $\|x\| = \sqrt{\langle x,x \rangle}$.
|
||||
- **Cosine**: $\cos \theta = \langle x,y\rangle / (\|x\|\|y\|)$.
|
||||
- **Cauchy-Schwarz**: $|\langle x,y\rangle| \le \|x\|\|y\|$.
|
||||
- **Orthogonality**: $\langle x,y\rangle = 0$.
|
||||
- **Triangle**: $\|x+y\| \le \|x\| + \|y\|$.
|
||||
|
||||
### 매 응용
|
||||
1. 매 ML embedding similarity (BERT, CLIP, GPT).
|
||||
2. 매 vector DB (FAISS, Pinecone, Qdrant) — cosine/dot index.
|
||||
3. 매 PCA, SVD — orthogonal basis.
|
||||
4. 매 kernel methods (RKHS, SVM).
|
||||
5. 매 Fourier analysis — orthogonal basis functions.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### 1. Dot Product / Cosine
|
||||
```python
|
||||
import numpy as np
|
||||
def cosine_sim(a, b):
|
||||
return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
|
||||
|
||||
# 매 batched (faster):
|
||||
def batch_cosine(A, B):
|
||||
A_n = A / np.linalg.norm(A, axis=1, keepdims=True)
|
||||
B_n = B / np.linalg.norm(B, axis=1, keepdims=True)
|
||||
return A_n @ B_n.T
|
||||
```
|
||||
|
||||
### 2. Gram-Schmidt Orthogonalization
|
||||
```python
|
||||
def gram_schmidt(V):
|
||||
U = []
|
||||
for v in V:
|
||||
w = v.copy()
|
||||
for u in U:
|
||||
w -= np.dot(v, u) / np.dot(u, u) * u
|
||||
if np.linalg.norm(w) > 1e-10:
|
||||
U.append(w)
|
||||
return np.array(U)
|
||||
```
|
||||
|
||||
### 3. Projection
|
||||
```python
|
||||
def project(v, onto):
|
||||
# 매 v 의 onto 위 projection
|
||||
return np.dot(v, onto) / np.dot(onto, onto) * onto
|
||||
```
|
||||
|
||||
### 4. FAISS Inner Product Index
|
||||
```python
|
||||
import faiss
|
||||
d = 768 # embedding dim
|
||||
index = faiss.IndexFlatIP(d) # inner product
|
||||
embs_norm = embs / np.linalg.norm(embs, axis=1, keepdims=True)
|
||||
index.add(embs_norm)
|
||||
D, I = index.search(query_norm, k=10) # 매 cosine via normalized IP
|
||||
```
|
||||
|
||||
### 5. Kernel Trick (RBF)
|
||||
```python
|
||||
def rbf_kernel(X, Y, gamma=1.0):
|
||||
# 매 implicit inner product in infinite-dim RKHS
|
||||
sq = np.sum(X**2, 1)[:,None] + np.sum(Y**2, 1)[None,:] - 2*X@Y.T
|
||||
return np.exp(-gamma * sq)
|
||||
```
|
||||
|
||||
### 6. QR Decomposition
|
||||
```python
|
||||
Q, R = np.linalg.qr(A)
|
||||
# Q: orthonormal columns, R: upper triangular
|
||||
# 매 least-squares solve: x = solve(R, Q.T @ b)
|
||||
```
|
||||
|
||||
### 7. Fourier Inner Product (L2)
|
||||
```python
|
||||
# 매 <f,g> = ∫ f(t) conj(g(t)) dt
|
||||
from scipy.integrate import quad
|
||||
inner = quad(lambda t: f(t) * np.conj(g(t)), -np.pi, np.pi)[0]
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Inner Product |
|
||||
|---|---|
|
||||
| Normalized embedding | Cosine (= dot of normalized) |
|
||||
| Raw magnitude matters | Dot product |
|
||||
| Probability distribution | Bhattacharyya / Hellinger |
|
||||
| Function space | L2 integral |
|
||||
| Non-Euclidean / kernel | RBF / polynomial kernel |
|
||||
|
||||
**기본값**: 매 cosine similarity 매 ML embedding standard, 매 normalize-once-then-dot 매 fast path.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Linear-Algebra-Foundations]] · [[Theoretical-Computer-Science]]
|
||||
- 변형: [[Hilbert-Space]]
|
||||
- 응용: [[Similarity-Metrics]] · [[Singular-Value-Decomposition]] · [[PCA-and-Dimension-Reduction]]
|
||||
- Adjacent: [[Eigenvalues-and-Eigenvectors]] · [[Operator-Theory]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 embedding similarity 설계, 매 vector DB index 선택, 매 orthogonality 직관 설명.
|
||||
**언제 X**: 매 non-metric (graph distance, edit distance) 영역.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Cosine on un-normalized**: 매 magnitude bias — 매 pre-normalize.
|
||||
- **Gram-Schmidt 의 numerical instability**: 매 modified GS 또는 QR 사용.
|
||||
- **Kernel 의 wrong gamma**: 매 grid-search / median heuristic.
|
||||
- **L2 norm 가정 in non-Euclidean**: 매 manifold 의 incorrect.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Axler, *Linear Algebra Done Right*; Trefethen, *Numerical LA*).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — geometry foundation + FAISS/kernel patterns |
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
---
|
||||
id: wiki-2026-0508-kalman-filter-and-state-tracking
|
||||
title: Kalman Filter and State Tracking
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [KF, EKF, UKF, Bayesian Tracking]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [filter, state-estimation, bayesian, control]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: filterpy
|
||||
---
|
||||
|
||||
# Kalman Filter and State Tracking
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 noisy observation 매 hidden state 의 optimal Bayesian estimate"**. Kalman filter 매 1960 Rudolf Kálmán — 매 linear-Gaussian system 의 closed-form recursive Bayesian update. 매 2026 SLAM, sensor fusion, AV path-planning, HFT spread tracking, GPS, IMU 매 ubiquitous.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 model
|
||||
- **State**: $x_k = F x_{k-1} + B u_k + w_k$, $w \sim N(0, Q)$.
|
||||
- **Observation**: $z_k = H x_k + v_k$, $v \sim N(0, R)$.
|
||||
- **Predict**: $\hat{x}_k^- = F\hat{x}_{k-1}$, $P_k^- = FP_{k-1}F^T + Q$.
|
||||
- **Update**: $K = P^-H^T(HP^-H^T + R)^{-1}$, $\hat{x} = \hat{x}^- + K(z - H\hat{x}^-)$.
|
||||
|
||||
### 매 variant
|
||||
- **Linear KF**: 매 linear F, H, Gaussian noise.
|
||||
- **EKF (Extended)**: 매 Jacobian linearization — 매 SLAM 매 standard.
|
||||
- **UKF (Unscented)**: 매 sigma-point — 매 high non-linearity.
|
||||
- **Particle Filter**: 매 fully non-linear, non-Gaussian — 매 multi-modal.
|
||||
- **IMM (Interacting Multiple Model)**: 매 mode switching (radar tracking).
|
||||
|
||||
### 매 응용
|
||||
1. 매 GPS + IMU sensor fusion (smartphone, drone).
|
||||
2. 매 SLAM (autonomous vehicle, robot).
|
||||
3. 매 finance — pair-trade hedge ratio drift.
|
||||
4. 매 AR/VR head-pose prediction.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### 1. Vanilla Linear KF (numpy)
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
class KF:
|
||||
def __init__(self, F, H, Q, R, x0, P0):
|
||||
self.F, self.H, self.Q, self.R = F, H, Q, R
|
||||
self.x, self.P = x0, P0
|
||||
|
||||
def predict(self, u=0, B=None):
|
||||
self.x = self.F @ self.x + (B @ u if B is not None else 0)
|
||||
self.P = self.F @ self.P @ self.F.T + self.Q
|
||||
|
||||
def update(self, z):
|
||||
y = z - self.H @ self.x # innovation
|
||||
S = self.H @ self.P @ self.H.T + self.R
|
||||
K = self.P @ self.H.T @ np.linalg.inv(S)
|
||||
self.x = self.x + K @ y
|
||||
self.P = (np.eye(len(self.x)) - K @ self.H) @ self.P
|
||||
```
|
||||
|
||||
### 2. Constant-Velocity Model
|
||||
```python
|
||||
dt = 0.1
|
||||
F = np.array([[1, dt], [0, 1]]) # [pos, vel]
|
||||
H = np.array([[1, 0]]) # observe pos only
|
||||
Q = np.array([[0.001, 0], [0, 0.01]])
|
||||
R = np.array([[0.5]])
|
||||
kf = KF(F, H, Q, R, np.array([0,0]), np.eye(2))
|
||||
for z in measurements:
|
||||
kf.predict()
|
||||
kf.update(np.array([z]))
|
||||
```
|
||||
|
||||
### 3. Extended KF (Non-linear)
|
||||
```python
|
||||
def ekf_update(x, P, z, h, H_jac, R):
|
||||
H = H_jac(x)
|
||||
y = z - h(x)
|
||||
S = H @ P @ H.T + R
|
||||
K = P @ H.T @ np.linalg.inv(S)
|
||||
x = x + K @ y
|
||||
P = (np.eye(len(x)) - K @ H) @ P
|
||||
return x, P
|
||||
```
|
||||
|
||||
### 4. Unscented KF (sigma-points)
|
||||
```python
|
||||
from filterpy.kalman import UnscentedKalmanFilter, MerweScaledSigmaPoints
|
||||
sp = MerweScaledSigmaPoints(n=4, alpha=0.1, beta=2, kappa=-1)
|
||||
ukf = UnscentedKalmanFilter(dim_x=4, dim_z=2, dt=0.1, fx=fx, hx=hx, points=sp)
|
||||
```
|
||||
|
||||
### 5. Particle Filter
|
||||
```python
|
||||
def particle_filter(particles, weights, z, motion, observe, R):
|
||||
particles = motion(particles) # propagate
|
||||
weights *= observe(particles, z, R)
|
||||
weights /= weights.sum()
|
||||
if 1.0 / np.sum(weights**2) < len(particles)/2:
|
||||
idx = np.random.choice(len(particles), size=len(particles), p=weights)
|
||||
particles, weights = particles[idx], np.ones_like(weights)/len(weights)
|
||||
return particles, weights
|
||||
```
|
||||
|
||||
### 6. Sensor Fusion (GPS + IMU)
|
||||
```python
|
||||
# 매 IMU prediction (high freq), GPS update (low freq)
|
||||
while True:
|
||||
imu = read_imu() # 200 Hz
|
||||
kf.predict_with_imu(imu)
|
||||
if gps_available(): # 10 Hz
|
||||
gps = read_gps()
|
||||
kf.update(gps)
|
||||
```
|
||||
|
||||
### 7. Smoothing (RTS)
|
||||
```python
|
||||
# 매 forward filter → backward smooth — 매 offline analysis
|
||||
xs, Ps = filter_forward(zs)
|
||||
xs_sm, Ps_sm = rts_smoother(xs, Ps, F, Q) # 매 future info 활용
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Filter |
|
||||
|---|---|
|
||||
| Linear, Gaussian | Linear KF |
|
||||
| Mild non-linearity | EKF |
|
||||
| Strong non-linearity | UKF |
|
||||
| Multi-modal / non-Gaussian | Particle Filter |
|
||||
| Mode switching | IMM |
|
||||
| Offline analysis | RTS smoother |
|
||||
|
||||
**기본값**: 매 EKF + constant-velocity, 매 sensor fusion 매 standard starting point.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Probability Theory]] · [[Optimal-Control-Theory]] · [[Linear-Algebra-Foundations]]
|
||||
- 변형: [[Particle-Filter-Algorithms]]
|
||||
- 응용: [[Autonomous-Vehicle-Path-Planning]] · [[High-Frequency-Trading-Models]]
|
||||
- Adjacent: [[Bayesian Inference]] · [[Signal-Processing-Foundations]] · [[Gimbals-and-Orientation]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 sensor fusion architecture 설계, 매 noise model tuning 가이드, 매 SLAM debugging.
|
||||
**언제 X**: 매 highly non-Gaussian (use particle), 매 deterministic system.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Q, R untuned**: 매 filter divergence 또는 over-smoothing.
|
||||
- **EKF on heavy non-linearity**: 매 Jacobian 부정확 → divergence. 매 UKF 또는 PF.
|
||||
- **No covariance inflation**: 매 P → 0 → filter overconfident.
|
||||
- **Joseph form 무시**: 매 numerical loss of symmetry.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Welch & Bishop, *KF Intro*; Thrun et al., *Probabilistic Robotics*; filterpy docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full KF/EKF/UKF/PF + sensor fusion patterns |
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
---
|
||||
id: wiki-2026-0508-kernel-density-estimation-kde
|
||||
title: Kernel Density Estimation (KDE)
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [KDE, Parzen Window, Density Estimation]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [statistics, non-parametric, density-estimation, kernel]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: scipy, scikit-learn, KDEpy
|
||||
---
|
||||
|
||||
# Kernel Density Estimation (KDE)
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 histogram 의 smooth 한 generalization"**. KDE 는 non-parametric density estimator 로, 매 sample point 에 kernel function 을 placing 하고 sum 하여 continuous PDF 추정. Parzen (1962) 와 Rosenblatt (1956) 이 정립했으며, 2026 modern stats/ML 에서 anomaly detection, generative sampling, visualization 에 사용.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 수식
|
||||
- $\hat{f}_h(x) = \frac{1}{nh}\sum_{i=1}^n K\left(\frac{x - x_i}{h}\right)$
|
||||
- $K$ = kernel (Gaussian, Epanechnikov, …)
|
||||
- $h$ = bandwidth (smoothing parameter)
|
||||
- multi-D: $\hat{f}_H(x) = \frac{1}{n|H|^{1/2}}\sum K(H^{-1/2}(x-x_i))$
|
||||
|
||||
### 매 Bandwidth selection
|
||||
- Silverman's rule: $h = 1.06 \hat{\sigma} n^{-1/5}$
|
||||
- Scott's rule: $h = n^{-1/(d+4)}$
|
||||
- cross-validation (likelihood)
|
||||
- plug-in estimators (Sheather-Jones)
|
||||
|
||||
### 매 응용
|
||||
1. EDA visualization (seaborn `kdeplot`).
|
||||
2. Anomaly detection (low-density = outlier).
|
||||
3. Mode finding (mean-shift).
|
||||
4. Bayesian non-parametric prior.
|
||||
5. Generative sampling (smoothed bootstrap).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### scipy KDE
|
||||
```python
|
||||
from scipy.stats import gaussian_kde
|
||||
import numpy as np
|
||||
|
||||
x = np.random.normal(0, 1, 1000)
|
||||
kde = gaussian_kde(x, bw_method="silverman")
|
||||
|
||||
xs = np.linspace(-4, 4, 200)
|
||||
density = kde(xs)
|
||||
```
|
||||
|
||||
### sklearn KernelDensity
|
||||
```python
|
||||
from sklearn.neighbors import KernelDensity
|
||||
import numpy as np
|
||||
|
||||
X = np.random.randn(1000, 2)
|
||||
kde = KernelDensity(kernel="gaussian", bandwidth=0.3).fit(X)
|
||||
log_dens = kde.score_samples(X) # log-density at each point
|
||||
|
||||
# anomaly: lowest 1% as outliers
|
||||
threshold = np.quantile(log_dens, 0.01)
|
||||
outliers = X[log_dens < threshold]
|
||||
```
|
||||
|
||||
### Bandwidth via cross-validation
|
||||
```python
|
||||
from sklearn.model_selection import GridSearchCV
|
||||
|
||||
params = {"bandwidth": np.logspace(-1, 1, 20)}
|
||||
grid = GridSearchCV(KernelDensity(), params, cv=5)
|
||||
grid.fit(X)
|
||||
print(grid.best_params_)
|
||||
```
|
||||
|
||||
### KDEpy fast FFT-based KDE
|
||||
```python
|
||||
from KDEpy import FFTKDE
|
||||
x_grid, y = FFTKDE(kernel="gaussian", bw="silverman").fit(x).evaluate()
|
||||
# O(n + m log m) instead of O(n*m)
|
||||
```
|
||||
|
||||
### Adaptive bandwidth
|
||||
```python
|
||||
def adaptive_kde(x, x_eval, k=10):
|
||||
from scipy.spatial import cKDTree
|
||||
tree = cKDTree(x[:, None])
|
||||
dists, _ = tree.query(x[:, None], k=k+1)
|
||||
h_local = dists[:, -1] # k-NN distance per point
|
||||
out = np.zeros_like(x_eval)
|
||||
for xi, hi in zip(x, h_local):
|
||||
out += np.exp(-0.5*((x_eval - xi)/hi)**2) / hi
|
||||
return out / (len(x) * np.sqrt(2*np.pi))
|
||||
```
|
||||
|
||||
### Visualization
|
||||
```python
|
||||
import seaborn as sns
|
||||
sns.kdeplot(data=df, x="feature", hue="class", fill=True, common_norm=False)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Method |
|
||||
|---|---|
|
||||
| 1D, small n | scipy gaussian_kde |
|
||||
| high-D, n>10⁴ | FFTKDE |
|
||||
| streaming | online KDE (Heinz 2008) |
|
||||
| boundaries | reflection / log-transform |
|
||||
| heavy-tail | adaptive bandwidth |
|
||||
|
||||
**기본값**: Silverman + Gaussian kernel, then validate.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Density-Estimation]]
|
||||
- 응용: [[Anomaly-Detection]]
|
||||
- Adjacent: [[Kernel-Methods]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: small/mid n, distribution shape 알 수 없을 때.
|
||||
**언제 X**: very high-D (curse of dimensionality), n < 30.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Default bandwidth blind use**: Silverman 은 Gaussian 가정 — bimodal 에 over-smooth.
|
||||
- **Boundary bias 무시**: support [0, ∞) 인데 Gaussian kernel 사용 → leak 발생.
|
||||
- **High-D KDE**: d > 6 에서는 거의 useless — vine copula 또는 normalizing flow 사용.
|
||||
- **Sample size 무시**: n < 50 KDE 결과는 거의 noise.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Silverman 1986 textbook, Wand & Jones 1995, Chen 2017 review).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — KDE math, bandwidth selection, scipy/sklearn/KDEpy |
|
||||
@@ -0,0 +1,176 @@
|
||||
---
|
||||
id: wiki-2026-0508-keyword-search
|
||||
title: Keyword Search
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Lexical Search, Sparse Retrieval, BM25 Search]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [search, retrieval, ir, bm25, lexical]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: elasticsearch, opensearch, tantivy, rank-bm25
|
||||
---
|
||||
|
||||
# Keyword Search
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 lexical token-match 의 retrieval"**. Keyword Search 는 query 의 token 과 document 의 token overlap 을 ranking signal 로 사용하는 sparse retrieval. TF-IDF (Salton 1975), BM25 (Robertson 1994) 가 backbone 이고, 2026 RAG era 에서도 매 hybrid (BM25 + dense) 의 indispensable component — out-of-domain robustness 와 exact-match precision 으로.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Scoring
|
||||
- **TF-IDF**: $w_{t,d} = tf(t,d) \cdot \log(N/df_t)$
|
||||
- **BM25**: $\sum_t \text{IDF}(t) \cdot \frac{tf(t,d)(k_1+1)}{tf(t,d) + k_1(1-b+b\cdot|d|/\bar{|d|})}$
|
||||
- $k_1 \approx 1.2$, $b \approx 0.75$
|
||||
- **BM25F**: per-field weighting
|
||||
- **Query Likelihood**: $\prod_t P(t | \theta_d)$ with smoothing
|
||||
|
||||
### 매 Pipeline
|
||||
1. **Tokenization** (Unicode segmentation, locale-aware)
|
||||
2. **Normalization** (lowercase, NFKC, accent fold)
|
||||
3. **Stopword removal** (optional)
|
||||
4. **Stemming / lemmatization** (Porter, Snowball, lemmas)
|
||||
5. **Inverted index** (term → posting list)
|
||||
6. **Query parse + scoring**
|
||||
|
||||
### 매 응용
|
||||
1. Document search (Google Search lexical layer).
|
||||
2. Code search (ripgrep, Sourcegraph zoekt).
|
||||
3. RAG hybrid (BM25 + embeddings → RRF).
|
||||
4. E-commerce (exact SKU match dominant signal).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### rank-bm25 quickstart
|
||||
```python
|
||||
from rank_bm25 import BM25Okapi
|
||||
import re
|
||||
|
||||
corpus = [doc.lower().split() for doc in docs]
|
||||
bm25 = BM25Okapi(corpus, k1=1.5, b=0.75)
|
||||
query = "claude opus context window".split()
|
||||
scores = bm25.get_scores(query)
|
||||
top = sorted(range(len(docs)), key=lambda i: -scores[i])[:5]
|
||||
```
|
||||
|
||||
### Elasticsearch / OpenSearch query
|
||||
```python
|
||||
from opensearchpy import OpenSearch
|
||||
client = OpenSearch("http://localhost:9200")
|
||||
|
||||
client.index(index="docs", id="1",
|
||||
body={"title":"Claude 4.7", "body":"1M context window..."})
|
||||
|
||||
resp = client.search(index="docs", body={
|
||||
"query": {
|
||||
"multi_match": {
|
||||
"query": "claude context window",
|
||||
"fields": ["title^3", "body"],
|
||||
"type": "best_fields"
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Tantivy (Rust, embeddable)
|
||||
```python
|
||||
import tantivy
|
||||
schema_builder = tantivy.SchemaBuilder()
|
||||
schema_builder.add_text_field("title", stored=True)
|
||||
schema_builder.add_text_field("body")
|
||||
schema = schema_builder.build()
|
||||
index = tantivy.Index(schema)
|
||||
writer = index.writer()
|
||||
writer.add_document(tantivy.Document(title="t", body="some body"))
|
||||
writer.commit()
|
||||
searcher = index.searcher()
|
||||
parser = tantivy.QueryParser.for_index(index, ["title","body"])
|
||||
hits = searcher.search(parser.parse_query("body"), 10).hits
|
||||
```
|
||||
|
||||
### Hybrid search with RRF
|
||||
```python
|
||||
def rrf(rank_lists, k=60):
|
||||
scores = {}
|
||||
for ranks in rank_lists:
|
||||
for r, doc_id in enumerate(ranks):
|
||||
scores[doc_id] = scores.get(doc_id, 0) + 1 / (k + r + 1)
|
||||
return sorted(scores.items(), key=lambda x: -x[1])
|
||||
|
||||
bm25_top = bm25_search(q)
|
||||
dense_top = vector_search(q)
|
||||
fused = rrf([bm25_top, dense_top])
|
||||
```
|
||||
|
||||
### Inverted index from scratch
|
||||
```python
|
||||
from collections import defaultdict
|
||||
import math
|
||||
|
||||
class InvertedIndex:
|
||||
def __init__(self):
|
||||
self.idx = defaultdict(dict) # term → {doc_id: tf}
|
||||
self.lens = {}
|
||||
self.N = 0
|
||||
def add(self, doc_id, tokens):
|
||||
self.N += 1
|
||||
self.lens[doc_id] = len(tokens)
|
||||
for t in tokens:
|
||||
self.idx[t][doc_id] = self.idx[t].get(doc_id, 0) + 1
|
||||
def bm25(self, query, k1=1.5, b=0.75):
|
||||
avgdl = sum(self.lens.values()) / self.N
|
||||
scores = defaultdict(float)
|
||||
for t in query:
|
||||
if t not in self.idx: continue
|
||||
df = len(self.idx[t])
|
||||
idf = math.log((self.N - df + 0.5) / (df + 0.5) + 1)
|
||||
for doc, tf in self.idx[t].items():
|
||||
norm = 1 - b + b * self.lens[doc] / avgdl
|
||||
scores[doc] += idf * tf * (k1+1) / (tf + k1 * norm)
|
||||
return sorted(scores.items(), key=lambda x: -x[1])
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| Need | Engine |
|
||||
|---|---|
|
||||
| general-purpose | Elasticsearch / OpenSearch |
|
||||
| embeddable, fast | Tantivy / Lucene |
|
||||
| code search | Zoekt / ripgrep |
|
||||
| in-process small | rank-bm25 / Whoosh |
|
||||
| hybrid RAG | BM25 + dense + RRF |
|
||||
|
||||
**기본값**: BM25 + RRF fusion with dense retriever.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Information Retrieval]]
|
||||
- 변형: [[BM25]] · [[TF-IDF]]
|
||||
- 응용: [[Hybrid Search]] · [[Semantic Search|Semantic-Search]]
|
||||
- Adjacent: [[Tokenization]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: exact-name retrieval, low-resource lang, long-tail terms, hybrid system.
|
||||
**언제 X**: pure semantic paraphrase matching — dense embeddings 가 강함.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Tokenizer mismatch**: 매 query/index 의 다른 tokenizer 사용 → silent recall loss.
|
||||
- **Default BM25 params**: domain-specific tuning 없이 default → suboptimal.
|
||||
- **Stopword over-removal**: "to be or not to be" → empty.
|
||||
- **Synonym 무시**: query expansion 없이 lexical-only 면 recall low.
|
||||
- **Dense-only 의 obsession**: BM25 baseline 무시 → out-of-domain 에서 실패.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Robertson 2009 BM25 paper, Manning IR textbook 2008, Thakur 2021 BEIR benchmark).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — BM25, inverted index, hybrid RRF, ES/Tantivy patterns |
|
||||
@@ -0,0 +1,176 @@
|
||||
---
|
||||
id: wiki-2026-0508-knowledge-graph
|
||||
title: Knowledge Graph
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [KG, Semantic Graph, Entity Graph]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [knowledge-graph, graph, semantic, retrieval]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: networkx, neo4j, rdflib
|
||||
---
|
||||
|
||||
# Knowledge Graph
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 entity-relationship triples 의 graph"**. Knowledge Graph 는 (head, relation, tail) triple 의 collection 으로 구조화된 knowledge 를 저장하는 graph database paradigm. 2012 Google 의 도입 이후 search/RAG/agents 의 backbone 으로 자리잡았으며, 2026 LLM era 에서는 GraphRAG 와 entity-linking 으로 hallucination mitigation 에 사용.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Triple 구조
|
||||
- (subject, predicate, object) — RDF 표준
|
||||
- entity ID (e.g. wikidata Q-id) → unique reference
|
||||
- relation typed (employs, locatedIn, instanceOf, …)
|
||||
- property graph: edges 도 attributes 보유
|
||||
|
||||
### 매 Schema vs Schema-less
|
||||
- ontology-driven: OWL, schema.org → strict typing
|
||||
- LPG (labeled property graph): Neo4j flexible
|
||||
- emergent KG: LLM 으로 unstructured text 에서 자동 추출
|
||||
|
||||
### 매 응용
|
||||
1. Search ranking (Google KG panels).
|
||||
2. RAG with GraphRAG (Microsoft 2024).
|
||||
3. Agent tool: entity disambiguation.
|
||||
4. Recommendation (LinkedIn Economic Graph).
|
||||
5. Drug discovery (Hetionet).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### NetworkX 로 KG build
|
||||
```python
|
||||
import networkx as nx
|
||||
|
||||
G = nx.MultiDiGraph()
|
||||
G.add_edge("Anthropic", "Claude", relation="created")
|
||||
G.add_edge("Claude", "LLM", relation="instanceOf")
|
||||
G.add_edge("Anthropic", "San Francisco", relation="locatedIn")
|
||||
|
||||
# query: what did Anthropic create?
|
||||
for _, target, data in G.out_edges("Anthropic", data=True):
|
||||
if data["relation"] == "created":
|
||||
print(target) # Claude
|
||||
```
|
||||
|
||||
### LLM 으로 triple 추출
|
||||
```python
|
||||
from anthropic import Anthropic
|
||||
|
||||
client = Anthropic()
|
||||
text = "Claude Opus 4.7 was released by Anthropic in 2026."
|
||||
|
||||
resp = client.messages.create(
|
||||
model="claude-opus-4-7",
|
||||
max_tokens=512,
|
||||
messages=[{
|
||||
"role": "user",
|
||||
"content": f"Extract (subject, predicate, object) triples as JSON from: {text}"
|
||||
}]
|
||||
)
|
||||
# → [["Claude Opus 4.7","releasedBy","Anthropic"], ...]
|
||||
```
|
||||
|
||||
### Neo4j Cypher query
|
||||
```cypher
|
||||
// find all 2-hop neighbors of Anthropic
|
||||
MATCH (a:Org {name:"Anthropic"})-[r1]->(x)-[r2]->(y)
|
||||
RETURN a, r1, x, r2, y
|
||||
LIMIT 100;
|
||||
```
|
||||
|
||||
### RDF + SPARQL
|
||||
```python
|
||||
from rdflib import Graph, URIRef, Literal
|
||||
g = Graph()
|
||||
g.parse("dbpedia.ttl", format="turtle")
|
||||
q = """
|
||||
SELECT ?company WHERE {
|
||||
?company a <http://dbpedia.org/ontology/Company> ;
|
||||
<http://dbpedia.org/property/foundedYear> "2021"^^xsd:gYear .
|
||||
}
|
||||
"""
|
||||
for row in g.query(q):
|
||||
print(row.company)
|
||||
```
|
||||
|
||||
### GraphRAG retrieval
|
||||
```python
|
||||
def graph_rag_query(q: str, kg, llm):
|
||||
entities = llm.extract_entities(q)
|
||||
subgraph = kg.k_hop_subgraph(entities, k=2)
|
||||
context = subgraph.to_text()
|
||||
return llm.answer(q, context=context)
|
||||
```
|
||||
|
||||
### Embedding-based KG completion (TransE)
|
||||
```python
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
class TransE(nn.Module):
|
||||
def __init__(self, n_ent, n_rel, dim=128):
|
||||
super().__init__()
|
||||
self.ent = nn.Embedding(n_ent, dim)
|
||||
self.rel = nn.Embedding(n_rel, dim)
|
||||
def score(self, h, r, t):
|
||||
return -torch.norm(self.ent(h) + self.rel(r) - self.ent(t), p=2, dim=-1)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 작은 domain, fast prototype | NetworkX in-memory |
|
||||
| production, ACID | Neo4j |
|
||||
| W3C standards | RDF + SPARQL |
|
||||
| billion-scale, distributed | JanusGraph, TigerGraph |
|
||||
| LLM RAG | GraphRAG (Microsoft) |
|
||||
|
||||
**기본값**: Neo4j + LLM extraction pipeline.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Knowledge Graph|Knowledge-Graph-Foundations]] · [[Graph_Theory|Graph-Theory]]
|
||||
- 변형: [[GraphRAG]] · [[Ontology]]
|
||||
- 응용: [[Semantic Search|Semantic-Search]] · [[Recommendation-Systems]]
|
||||
- Adjacent: [[Embeddings]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: factual grounding, multi-hop reasoning, entity disambiguation 필요 시.
|
||||
**언제 X**: pure semantic similarity 만 필요할 때 — vector DB 가 더 simple.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Schema explosion**: 매 entity 마다 new relation 정의 → unmanageable.
|
||||
- **Stale KG**: 자동 update pipeline 없이 manual curation → 6 months 지나면 obsolete.
|
||||
- **No entity resolution**: "Anthropic" vs "anthropic Inc." vs "ANTHROPIC" → duplicate nodes.
|
||||
- **Triple-only thinking**: property graph 의 edge attribute 무시.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Bollacker 2008 Freebase, Hogan 2021 KG survey ACM CSUR).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — KG fundamentals, triples, GraphRAG, Neo4j patterns |
|
||||
|
||||
## 🛠️ 적용 사례 (Applied in summary)
|
||||
|
||||
<!-- CODE-GROUNDING:START -->
|
||||
### 🔎 코드베이스 근거 (자동 추출 — E:\Wiki 레포)
|
||||
**실제 구현/사용 위치:**
|
||||
- `connectai/src/features/projectChronicle/guardPrompt.ts:57` — [Omitted long matching line]
|
||||
|
||||
**관련 커밋:**
|
||||
- `connectai d843364 feat: add premium matrix styling to knowledge graph, glowing nodes, and directional particle flow across synapses`
|
||||
- `connectai 279e671 feat: parse real workspace files for knowledge graph topology and add organic organic movement`
|
||||
|
||||
_자동 생성: code_grounding.mjs · 재실행 시 갱신됨_
|
||||
<!-- CODE-GROUNDING:END -->
|
||||
@@ -0,0 +1,151 @@
|
||||
---
|
||||
id: wiki-2026-0508-knowledge-structure
|
||||
title: Knowledge Structure
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Knowledge Organization, Information Structure]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.85
|
||||
verification_status: applied
|
||||
tags: [knowledge, structure, organization, information-architecture]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: networkx, llamaindex
|
||||
---
|
||||
|
||||
# Knowledge Structure
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 raw text → organized hierarchy"**. Knowledge Structure 는 information 을 hierarchies, taxonomies, networks, frames 로 organizing 하는 paradigm 의 study. 2026 LLM era 에서는 retrieval-augmented systems 의 indexing strategy 와 agent memory architecture 의 backbone.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Structures
|
||||
- **Hierarchy / Taxonomy**: tree (subClass, partOf)
|
||||
- **Network / Graph**: arbitrary relations (KG)
|
||||
- **Faceted classification**: orthogonal dimensions (Ranganathan)
|
||||
- **Frames / Schemata**: slots + fillers (Minsky)
|
||||
- **Folksonomy**: tag-based emergent
|
||||
|
||||
### 매 Properties
|
||||
- **Granularity**: atomic facts vs documents
|
||||
- **Reasoning depth**: lookup → multi-hop → analogical
|
||||
- **Update frequency**: static → real-time
|
||||
- **Source provenance**: trust chain
|
||||
|
||||
### 매 응용
|
||||
1. Wiki 의 backlinks + categories (Roam-style).
|
||||
2. RAG indexing (chunks + metadata).
|
||||
3. Agent long-term memory (MemGPT, LangMem).
|
||||
4. Personal Knowledge Management (Zettelkasten).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Hierarchical taxonomy
|
||||
```python
|
||||
from anytree import Node, RenderTree
|
||||
|
||||
ai = Node("AI")
|
||||
ml = Node("ML", parent=ai)
|
||||
dl = Node("DL", parent=ml)
|
||||
llm = Node("LLM", parent=dl)
|
||||
opus = Node("Claude Opus 4.7", parent=llm)
|
||||
|
||||
for pre, _, node in RenderTree(ai):
|
||||
print(f"{pre}{node.name}")
|
||||
```
|
||||
|
||||
### Faceted indexing
|
||||
```python
|
||||
class FacetedIndex:
|
||||
def __init__(self):
|
||||
self.facets = {} # facet_name → {value → set(doc_ids)}
|
||||
def add(self, doc_id, facets):
|
||||
for k, v in facets.items():
|
||||
self.facets.setdefault(k, {}).setdefault(v, set()).add(doc_id)
|
||||
def query(self, **constraints):
|
||||
sets = [self.facets[k][v] for k, v in constraints.items()]
|
||||
return set.intersection(*sets) if sets else set()
|
||||
|
||||
idx = FacetedIndex()
|
||||
idx.add("doc1", {"topic":"ML", "year":"2026", "lang":"en"})
|
||||
idx.query(topic="ML", year="2026")
|
||||
```
|
||||
|
||||
### Zettelkasten-style atomic notes
|
||||
```python
|
||||
import re, hashlib
|
||||
def make_zettel(title, body, tags, links):
|
||||
zid = hashlib.md5(title.encode()).hexdigest()[:8]
|
||||
return {
|
||||
"id": zid, "title": title, "body": body,
|
||||
"tags": tags, "links": links,
|
||||
"wikilinks": re.findall(r"\[\[([^\]]+)\]\]", body),
|
||||
}
|
||||
```
|
||||
|
||||
### Hierarchical RAG indexing (LlamaIndex)
|
||||
```python
|
||||
from llama_index.core import VectorStoreIndex, Document
|
||||
from llama_index.core.node_parser import HierarchicalNodeParser
|
||||
|
||||
parser = HierarchicalNodeParser.from_defaults(
|
||||
chunk_sizes=[2048, 512, 128]
|
||||
)
|
||||
nodes = parser.get_nodes_from_documents(docs)
|
||||
index = VectorStoreIndex(nodes)
|
||||
```
|
||||
|
||||
### Frame-based knowledge
|
||||
```python
|
||||
restaurant_frame = {
|
||||
"name": None,
|
||||
"cuisine": None,
|
||||
"location": {"city": None, "address": None},
|
||||
"menu": [], # list of dish frames
|
||||
"reviews": [],
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| Use case | Structure |
|
||||
|---|---|
|
||||
| stable domain | Taxonomy |
|
||||
| rich relations | Graph (KG) |
|
||||
| multiple dims | Faceted |
|
||||
| stereotyped events | Frames |
|
||||
| user-generated | Folksonomy |
|
||||
| LLM RAG | Hierarchical chunks + metadata |
|
||||
|
||||
**기본값**: Hierarchy + tags + wikilinks (hybrid).
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Knowledge-Representation]]
|
||||
- 변형: [[Ontology]]
|
||||
- 응용: [[Knowledge Graph]]
|
||||
- Adjacent: [[Personal-Knowledge-Management]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: agent memory design, RAG indexing strategy, large doc collection 정리.
|
||||
**언제 X**: 매 single-doc Q&A — 매 over-engineering.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Premature taxonomy**: domain 도 모르고 hierarchy 먼저 design → constant restructuring.
|
||||
- **Single structure forced fit**: 매 problem 이 graph 인데 tree 로 강제.
|
||||
- **No update mechanism**: 매 evolving knowledge 에 frozen schema.
|
||||
- **Tags 없는 hierarchy**: orthogonal facet 표현 불가.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Ranganathan 1933 colon classification, Minsky 1974 frames, Sowa 2000 KR textbook).
|
||||
- 신뢰도 A-.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — taxonomy/graph/facet/frame structures, RAG indexing |
|
||||
@@ -0,0 +1,144 @@
|
||||
---
|
||||
id: wiki-2026-0508-kolmogorov-complexity
|
||||
title: Kolmogorov Complexity
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Algorithmic Complexity, Descriptive Complexity, K-complexity]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [complexity, information-theory, computability, algorithmic-information]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: zlib, lzma
|
||||
---
|
||||
|
||||
# Kolmogorov Complexity
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 string 의 shortest description length"**. Kolmogorov Complexity $K(x)$ 는 universal Turing machine 위에서 string $x$ 를 출력하는 shortest program 의 length. Solomonoff (1960), Kolmogorov (1965), Chaitin (1969) 이 독립적으로 정의했고, 2026 ML 에서는 generalization bounds, MDL, AIXI agents 의 theoretical foundation.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Definition
|
||||
- $K_U(x) = \min \{ |p| : U(p) = x \}$
|
||||
- $U$ = universal Turing machine
|
||||
- invariance theorem: $|K_U(x) - K_{U'}(x)| \le c$ — choice 무관 up to constant
|
||||
- **uncomputable** — no algorithm computes $K(x)$ for arbitrary $x$
|
||||
|
||||
### 매 Variants
|
||||
- **Plain $C(x)$**: any halting program
|
||||
- **Prefix $K(x)$**: prefix-free programs (Levin)
|
||||
- **Conditional $K(x|y)$**: given $y$ as input
|
||||
- **Time-bounded $K^t(x)$**: program runs in ≤ $t$ steps
|
||||
|
||||
### 매 응용
|
||||
1. **MDL principle**: model selection — pick shortest description.
|
||||
2. **Solomonoff prior**: $P(x) \propto 2^{-K(x)}$.
|
||||
3. **Lossless compression**: practical lower bound.
|
||||
4. **Randomness test**: $K(x) \approx |x|$ ⟺ random.
|
||||
5. **AIXI**: optimal universal agent.
|
||||
|
||||
### 매 Properties
|
||||
- $K(x) \le |x| + O(1)$ — copy verbatim
|
||||
- $K(xy) \le K(x) + K(y) + O(\log)$
|
||||
- most strings are incompressible (Counting argument)
|
||||
- Chaitin's $\Omega$ — halting probability, encodes K
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Compression-based estimate
|
||||
```python
|
||||
import zlib, lzma
|
||||
|
||||
def K_approx(x: bytes, codec="lzma") -> int:
|
||||
if codec == "zlib":
|
||||
return len(zlib.compress(x, 9))
|
||||
return len(lzma.compress(x, preset=9 | lzma.PRESET_EXTREME))
|
||||
|
||||
# normalized
|
||||
def NCD(x: bytes, y: bytes) -> float:
|
||||
"""Normalized Compression Distance — Cilibrasi & Vitanyi 2005"""
|
||||
Kx, Ky = K_approx(x), K_approx(y)
|
||||
Kxy = K_approx(x + y)
|
||||
return (Kxy - min(Kx, Ky)) / max(Kx, Ky)
|
||||
```
|
||||
|
||||
### MDL model selection
|
||||
```python
|
||||
def mdl_score(model, data):
|
||||
# L(model) = bits to describe model
|
||||
# L(data|model) = bits to encode data given model
|
||||
return code_length(model) + code_length(data, given=model)
|
||||
|
||||
best = min(candidates, key=lambda m: mdl_score(m, data))
|
||||
```
|
||||
|
||||
### Solomonoff prior approximation (Levin search)
|
||||
```python
|
||||
def levin_search(input, target, max_t):
|
||||
"""enumerate programs by 2^|p| * t — Levin's universal search"""
|
||||
for budget in range(1, max_t):
|
||||
for p in enumerate_programs(max_len=int(np.log2(budget))):
|
||||
if simulate(p, input, steps=budget // (2**len(p))) == target:
|
||||
return p
|
||||
```
|
||||
|
||||
### Compression-based clustering
|
||||
```python
|
||||
from sklearn.cluster import AgglomerativeClustering
|
||||
import numpy as np
|
||||
|
||||
dist = np.array([[NCD(xi, xj) for xj in docs] for xi in docs])
|
||||
labels = AgglomerativeClustering(
|
||||
metric="precomputed", linkage="average", n_clusters=k
|
||||
).fit_predict(dist)
|
||||
```
|
||||
|
||||
### Random string detector
|
||||
```python
|
||||
def is_likely_random(x: bytes, threshold=0.95) -> bool:
|
||||
return K_approx(x) / len(x) > threshold # near-incompressible
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| Need | Tool |
|
||||
|---|---|
|
||||
| theoretical proof | $K$ definition |
|
||||
| practical estimate | LZMA / zstd compress length |
|
||||
| similarity | NCD |
|
||||
| model selection | MDL / BIC |
|
||||
| online learning | Solomonoff (intractable, approximate) |
|
||||
|
||||
**기본값**: LZMA approximation for compute, MDL for principled selection.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Information_Theory|Information-Theory]]
|
||||
- 변형: [[MDL]]
|
||||
- 응용: [[Compression]]
|
||||
- Adjacent: [[Shannon-Entropy]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: model complexity reasoning, compression-as-intelligence arguments, generalization theory.
|
||||
**언제 X**: 매 production code path — uncomputable, only bounds.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Treating K as computable**: 매 K(x) 의 exact value 사용 시도.
|
||||
- **Compressor-specific bound 절대화**: gzip approximation 은 매 noisy upper bound.
|
||||
- **NCD 의 metric assumption**: NCD 는 매 quasi-metric — triangle inequality 약하게 only.
|
||||
- **Confusing K with Shannon H**: K is per-string, H is distributional.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Li & Vitanyi 2019 4th ed textbook, Hutter 2005 AIXI book, Chaitin 1987 algorithmic info theory).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — K definition, MDL, NCD, Solomonoff, AIXI |
|
||||
@@ -0,0 +1,141 @@
|
||||
---
|
||||
id: wiki-2026-0508-kullback-leibler-divergence
|
||||
title: Kullback-Leibler Divergence
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [KL Divergence, Relative Entropy, KL-D]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [information-theory, divergence, ml, vae, rlhf]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: torch, scipy
|
||||
---
|
||||
|
||||
# Kullback-Leibler Divergence
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 distribution 간의 directed information loss"**. KL Divergence $D_{\text{KL}}(P \| Q) = \mathbb{E}_P[\log P/Q]$ 는 reference distribution $Q$ 로 $P$ 를 encode 시 expected extra bits. Kullback & Leibler (1951) 가 정의했고, 2026 ML 에서는 VAE ELBO, RLHF (PPO/DPO), variational inference, distillation 의 매 core loss term.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Definition
|
||||
- discrete: $D_{\text{KL}}(P\|Q) = \sum_x P(x) \log \frac{P(x)}{Q(x)}$
|
||||
- continuous: $\int p(x) \log \frac{p(x)}{q(x)} dx$
|
||||
- always $\ge 0$ (Gibbs inequality), $=0$ iff $P=Q$
|
||||
- **NOT symmetric**, **NOT a metric** (no triangle inequality)
|
||||
- $D_{\text{KL}}(P\|Q) = H(P, Q) - H(P)$ — cross-entropy minus entropy
|
||||
|
||||
### 매 Mode behavior
|
||||
- **Forward $D_{\text{KL}}(P\|Q)$**: Q must cover all mass of P → "mode-covering"
|
||||
- **Reverse $D_{\text{KL}}(Q\|P)$**: Q goes where P has mass → "mode-seeking"
|
||||
- VAE 는 reverse, EP 는 forward
|
||||
|
||||
### 매 응용
|
||||
1. **VAE ELBO**: $\mathbb{E}[\log p(x|z)] - D_{\text{KL}}(q(z|x) \| p(z))$.
|
||||
2. **RLHF PPO**: $\beta \cdot D_{\text{KL}}(\pi \| \pi_{\text{ref}})$ penalty.
|
||||
3. **Knowledge distillation**: $D_{\text{KL}}(p_T \| p_S)$ with temperature.
|
||||
4. **Variational inference**: $\arg\min_q D_{\text{KL}}(q \| p)$.
|
||||
5. **Mutual information**: $I(X;Y) = D_{\text{KL}}(p(x,y) \| p(x)p(y))$.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Discrete KL
|
||||
```python
|
||||
import numpy as np
|
||||
def kl_div(p, q, eps=1e-12):
|
||||
p, q = np.asarray(p), np.asarray(q)
|
||||
return np.sum(p * (np.log(p + eps) - np.log(q + eps)))
|
||||
|
||||
p = np.array([0.5, 0.3, 0.2])
|
||||
q = np.array([0.4, 0.4, 0.2])
|
||||
print(kl_div(p, q))
|
||||
```
|
||||
|
||||
### PyTorch KL (numerically stable)
|
||||
```python
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
|
||||
# inputs MUST be log-probs for kl_div first arg
|
||||
log_p = F.log_softmax(model_logits, dim=-1)
|
||||
q = F.softmax(target_logits, dim=-1)
|
||||
loss = F.kl_div(log_p, q, reduction="batchmean")
|
||||
```
|
||||
|
||||
### KL between Gaussians (closed form)
|
||||
```python
|
||||
def kl_gaussian(mu1, var1, mu2, var2):
|
||||
return 0.5 * (
|
||||
torch.log(var2 / var1) + (var1 + (mu1-mu2)**2) / var2 - 1
|
||||
).sum()
|
||||
|
||||
# VAE: q ~ N(mu, sigma^2), prior N(0, 1)
|
||||
def kl_to_standard_normal(mu, log_var):
|
||||
return -0.5 * torch.sum(1 + log_var - mu.pow(2) - log_var.exp())
|
||||
```
|
||||
|
||||
### Distillation loss with temperature
|
||||
```python
|
||||
def distill_kl(student_logits, teacher_logits, T=4.0):
|
||||
log_p_s = F.log_softmax(student_logits / T, dim=-1)
|
||||
p_t = F.softmax(teacher_logits / T, dim=-1)
|
||||
return F.kl_div(log_p_s, p_t, reduction="batchmean") * (T*T)
|
||||
```
|
||||
|
||||
### RLHF PPO KL penalty (per-token)
|
||||
```python
|
||||
def ppo_kl_penalty(logp_new, logp_ref, beta=0.05):
|
||||
# token-level KL via log-prob difference
|
||||
return beta * (logp_new - logp_ref) # used as reward shaping
|
||||
```
|
||||
|
||||
### Forward vs reverse comparison
|
||||
```python
|
||||
# Approximate q (Gaussian) to bimodal p
|
||||
# - reverse KL D(q||p): q picks one mode (mode-seeking)
|
||||
# - forward KL D(p||q): q spans both modes (mode-covering, broader)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| Need | Form |
|
||||
|---|---|
|
||||
| variational posterior fit | reverse $D_{\text{KL}}(q\|p)$ |
|
||||
| spread (cover all modes) | forward $D_{\text{KL}}(p\|q)$ |
|
||||
| symmetric | JS divergence |
|
||||
| bounded, metric | Wasserstein, Hellinger |
|
||||
| RLHF stability | per-token reverse KL with $\beta$ schedule |
|
||||
|
||||
**기본값**: 매 problem 따라 — VAE 면 reverse, EP 면 forward.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Information_Theory|Information-Theory]]
|
||||
- 응용: [[VAE]] · [[RLHF]] · [[LLM_Optimization_and_Deployment_Strategies|Knowledge-Distillation]] · [[Variational-Inference]]
|
||||
- Adjacent: [[Cross-Entropy]] · [[Mutual-Information]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 distribution-level loss 정의, RLHF 의 reference model anchoring, distillation.
|
||||
**언제 X**: 매 distance metric 이 필요할 때 — KL 은 metric 이 X — Wasserstein 사용.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Symmetric 가정**: $D_{\text{KL}}(P\|Q) \ne D_{\text{KL}}(Q\|P)$.
|
||||
- **Disjoint support**: $Q(x)=0, P(x)>0$ 이면 $\infty$ — smooth or use JS.
|
||||
- **`F.kl_div` 의 input 순서 혼동**: 첫 arg 는 log-prob.
|
||||
- **Distillation T 무시**: temperature $T$ 없이 sharp distribution 사용 → poor signal.
|
||||
- **RLHF 에서 KL collapse**: $\beta$ 너무 작으면 reward hacking.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Cover & Thomas 2006 textbook ch 2, MacKay 2003 ch 2, Kingma VAE 2013).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — KL definition, mode behavior, VAE/RLHF/distillation patterns |
|
||||
@@ -0,0 +1,152 @@
|
||||
---
|
||||
id: wiki-2026-0508-lagrange-multipliers
|
||||
title: Lagrange Multipliers
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Lagrangian Method, Constrained Optimization, KKT]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [optimization, calculus, constrained, kkt, ml-foundations]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: scipy, cvxpy
|
||||
---
|
||||
|
||||
# Lagrange Multipliers
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 constrained optimization 의 universal trick"**. Lagrange Multiplier 방법은 equality-constrained problem $\min f(x)$ s.t. $g(x)=0$ 을 $\nabla f = \lambda \nabla g$ 의 unconstrained stationary condition 으로 reduce 한다. Joseph-Louis Lagrange (1788) 이 도입했고, 2026 ML 의 SVM, regularization, RLHF reward shaping, physics-informed NN 에 매 fundamental.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Equality 형
|
||||
- problem: $\min f(x)$ s.t. $g_i(x) = 0$
|
||||
- Lagrangian: $\mathcal{L}(x, \lambda) = f(x) + \sum_i \lambda_i g_i(x)$
|
||||
- stationarity: $\nabla_x \mathcal{L} = 0, \nabla_\lambda \mathcal{L} = 0$
|
||||
- $\lambda_i$ = sensitivity of optimal $f^*$ to perturbation of $g_i$ (shadow price)
|
||||
|
||||
### 매 KKT (inequality 확장)
|
||||
- problem: $\min f(x)$ s.t. $g_i(x) \le 0, h_j(x) = 0$
|
||||
- $\mathcal{L} = f + \sum \mu_i g_i + \sum \lambda_j h_j$
|
||||
- KKT conditions:
|
||||
1. **Stationarity**: $\nabla_x \mathcal{L} = 0$
|
||||
2. **Primal feasibility**: $g_i \le 0, h_j = 0$
|
||||
3. **Dual feasibility**: $\mu_i \ge 0$
|
||||
4. **Complementary slackness**: $\mu_i g_i = 0$
|
||||
|
||||
### 매 응용
|
||||
1. **SVM**: max-margin → KKT dual.
|
||||
2. **Regularization**: Lagrangian view of $\min L + \lambda \|w\|^2$.
|
||||
3. **Constrained RL**: CPO, Lagrangian SAC.
|
||||
4. **Physics**: Euler-Lagrange equations of motion.
|
||||
5. **Economics**: utility maximization budget constraint.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Symbolic solve (sympy)
|
||||
```python
|
||||
import sympy as sp
|
||||
|
||||
x, y, lam = sp.symbols("x y lambda")
|
||||
f = x**2 + y**2 # min x^2 + y^2
|
||||
g = x + y - 1 # s.t. x + y = 1
|
||||
L = f + lam * g
|
||||
|
||||
eqs = [sp.diff(L, v) for v in (x, y, lam)]
|
||||
sol = sp.solve(eqs, [x, y, lam])
|
||||
print(sol) # {x: 1/2, y: 1/2, lambda: -1}
|
||||
```
|
||||
|
||||
### scipy constrained
|
||||
```python
|
||||
from scipy.optimize import minimize
|
||||
|
||||
f = lambda x: x[0]**2 + x[1]**2
|
||||
cons = {"type": "eq", "fun": lambda x: x[0] + x[1] - 1}
|
||||
res = minimize(f, x0=[0.0, 0.0], constraints=cons)
|
||||
print(res.x) # ≈ [0.5, 0.5]
|
||||
```
|
||||
|
||||
### CVXPY (convex)
|
||||
```python
|
||||
import cvxpy as cp
|
||||
x = cp.Variable(2)
|
||||
prob = cp.Problem(cp.Minimize(cp.sum_squares(x)),
|
||||
[cp.sum(x) == 1, x >= 0])
|
||||
prob.solve()
|
||||
print(x.value, prob.constraints[0].dual_value) # primal + lambda
|
||||
```
|
||||
|
||||
### SVM dual derivation
|
||||
```python
|
||||
# Primal: min 1/2 ||w||^2 s.t. y_i(w·x_i + b) >= 1
|
||||
# Dual via KKT: max sum a_i - 1/2 sum a_i a_j y_i y_j x_i·x_j
|
||||
# s.t. a_i >= 0, sum a_i y_i = 0
|
||||
import numpy as np
|
||||
from scipy.optimize import minimize
|
||||
|
||||
def svm_dual(X, y):
|
||||
n = len(y)
|
||||
K = (y[:,None]*y) * (X @ X.T)
|
||||
obj = lambda a: 0.5 * a @ K @ a - a.sum()
|
||||
cons = [{"type":"eq", "fun": lambda a: a @ y}]
|
||||
bnds = [(0, None)] * n
|
||||
res = minimize(obj, np.zeros(n), bounds=bnds, constraints=cons)
|
||||
return res.x # dual variables = lambda_i
|
||||
```
|
||||
|
||||
### Penalty / augmented Lagrangian
|
||||
```python
|
||||
def augmented_lagrangian(f, g, x0, mu0=1.0, rho=1.5, iters=20):
|
||||
x, mu = x0, mu0
|
||||
lam = 0.0
|
||||
for _ in range(iters):
|
||||
# solve unconstrained
|
||||
from scipy.optimize import minimize
|
||||
L = lambda x: f(x) + lam*g(x) + (mu/2)*g(x)**2
|
||||
x = minimize(L, x).x
|
||||
lam += mu * g(x) # multiplier update
|
||||
mu *= rho
|
||||
return x, lam
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| Problem | Method |
|
||||
|---|---|
|
||||
| small symbolic | sympy |
|
||||
| smooth nonlinear | scipy SLSQP |
|
||||
| convex | CVXPY |
|
||||
| large-scale | augmented Lagrangian / ADMM |
|
||||
| RL constraints | Lagrangian PPO/SAC |
|
||||
|
||||
**기본값**: CVXPY for convex, scipy SLSQP otherwise.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Optimization]]
|
||||
- 응용: [[SVM]] · [[L1-and-L2-Regularization|Regularization]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: deriving SVM/RLHF math, constrained policy optimization, MLE w/ constraints.
|
||||
**언제 X**: unconstrained smooth — 그냥 gradient descent.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Forgetting CQ**: constraint qualification (LICQ, Slater) 만족 X 면 KKT 무효.
|
||||
- **Sign convention 혼동**: $\le$ 와 $\ge$ 따라 $\mu$ sign flip.
|
||||
- **Non-convex KKT 의 sufficiency 가정**: KKT 는 매 necessary, sufficient 는 convex 에서만.
|
||||
- **Penalty 만 사용**: ill-conditioning — augmented Lagrangian 사용.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Boyd & Vandenberghe 2004 ch 5, Nocedal & Wright 2006 ch 12).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Lagrangian, KKT, SVM dual, augmented Lagrangian |
|
||||
@@ -0,0 +1,122 @@
|
||||
---
|
||||
id: wiki-2026-0508-least-squares-methods
|
||||
title: Least Squares Methods
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Least-Squares, OLS, 최소제곱법]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [optimization, regression, linear-algebra, statistics]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: numpy-scipy
|
||||
---
|
||||
|
||||
# Least Squares Methods
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 residual의 제곱합을 최소화하라"**. Gauss(1795)와 Legendre(1805)가 독립 발견; 매 modern ML의 MSE loss·linear regression·Kalman filter의 직접 조상이다. 2026에도 매 LoRA fine-tuning의 closed-form initializer로 살아있다.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 정식화
|
||||
- **OLS**: minimize ‖y − Xβ‖²; closed-form β̂ = (XᵀX)⁻¹Xᵀy.
|
||||
- **Weighted LS**: residual에 weight W; β̂ = (XᵀWX)⁻¹XᵀWy.
|
||||
- **Total LS**: 매 X에도 noise — SVD 기반.
|
||||
- **Regularized**: Ridge (L2), Lasso (L1), Elastic Net.
|
||||
|
||||
### 매 수치적 안정성
|
||||
- Normal equation 직접 풀이는 매 condition number² 증폭 → QR/SVD 권장.
|
||||
- 매 LAPACK `gels` 는 QR 사용.
|
||||
|
||||
### 매 응용
|
||||
1. Linear regression (econometrics, ML baseline).
|
||||
2. Curve fitting (lmfit, scipy.optimize.curve_fit).
|
||||
3. Bundle adjustment (SLAM, photogrammetry).
|
||||
4. Kalman update step (least-squares projection).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### OLS via NumPy (lstsq)
|
||||
```python
|
||||
import numpy as np
|
||||
beta, residuals, rank, sv = np.linalg.lstsq(X, y, rcond=None)
|
||||
```
|
||||
|
||||
### Ridge regression
|
||||
```python
|
||||
def ridge(X, y, lam):
|
||||
n_features = X.shape[1]
|
||||
return np.linalg.solve(X.T @ X + lam * np.eye(n_features), X.T @ y)
|
||||
```
|
||||
|
||||
### Nonlinear least squares
|
||||
```python
|
||||
from scipy.optimize import least_squares
|
||||
def residual(params, x, y):
|
||||
a, b, c = params
|
||||
return y - (a * np.exp(-b * x) + c)
|
||||
result = least_squares(residual, [1, 1, 0], args=(x, y))
|
||||
```
|
||||
|
||||
### QR-based solve (numerically stable)
|
||||
```python
|
||||
Q, R = np.linalg.qr(X)
|
||||
beta = np.linalg.solve(R, Q.T @ y)
|
||||
```
|
||||
|
||||
### Weighted LS
|
||||
```python
|
||||
W_sqrt = np.sqrt(weights)
|
||||
beta = np.linalg.lstsq(X * W_sqrt[:, None], y * W_sqrt, rcond=None)[0]
|
||||
```
|
||||
|
||||
### Recursive LS (online update)
|
||||
```python
|
||||
def rls_update(P, beta, x, y, lam=0.99):
|
||||
k = P @ x / (lam + x @ P @ x)
|
||||
beta = beta + k * (y - x @ beta)
|
||||
P = (P - np.outer(k, x @ P)) / lam
|
||||
return P, beta
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Well-conditioned, small p | Normal equation |
|
||||
| Ill-conditioned | QR or SVD |
|
||||
| Many features, sparse | Lasso |
|
||||
| Heteroscedastic noise | Weighted LS |
|
||||
| Streaming data | RLS |
|
||||
|
||||
**기본값**: `np.linalg.lstsq` (uses SVD-based GELSD).
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Linear-Algebra-Foundations]] · [[Optimization]]
|
||||
- 변형: [[Ridge-Regression]] · [[Lasso]]
|
||||
- 응용: [[Kalman-Filter-and-State-Tracking]] · [[Linear-Regression]] · [[Bundle-Adjustment]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: Linear/affine model fit, baseline regression, calibration curves.
|
||||
**언제 X**: Outliers 다수 (use Huber/RANSAC), heavy non-linearity (use NN/GP).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Normal equation 남용**: 매 ill-conditioned에서 매 silently 망함.
|
||||
- **Outlier 무시**: L2 loss는 매 outlier 민감 — robust loss 고려.
|
||||
- **Multicollinearity 방치**: VIF 점검 또는 Ridge.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Trefethen & Bau "Numerical Linear Algebra").
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — OLS/Ridge/RLS patterns |
|
||||
@@ -0,0 +1,162 @@
|
||||
---
|
||||
id: wiki-2026-0508-linear-algebra-foundations
|
||||
title: Linear Algebra Foundations
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Matrix Algebra, Vector Spaces, Linear Algebra]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [linear-algebra, math, ml-foundations, matrix]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: numpy, jax, torch
|
||||
---
|
||||
|
||||
# Linear Algebra Foundations
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 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.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 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
|
||||
|
||||
### 매 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
|
||||
|
||||
### 매 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\|$
|
||||
|
||||
### 매 응용
|
||||
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.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### 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))
|
||||
```
|
||||
|
||||
### 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")
|
||||
```
|
||||
|
||||
### 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)
|
||||
```
|
||||
|
||||
### 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)
|
||||
```
|
||||
|
||||
### 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)
|
||||
```
|
||||
|
||||
### 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
|
||||
```
|
||||
|
||||
### 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
|
||||
- 변형: [[SVD]] · [[Eigendecomposition]]
|
||||
- 응용: [[PCA]] · [[Attention Mechanism]] · [[Linear-Regression]]
|
||||
|
||||
## 🤖 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 |
|
||||
@@ -0,0 +1,226 @@
|
||||
---
|
||||
id: wiki-2026-0508-linked-lists-and-trees
|
||||
title: Linked Lists and Trees
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Linked List, Tree, 연결 리스트, 트리]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
verification_status: applied
|
||||
tags: [data-structures, linked-list, tree, fundamentals]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: none
|
||||
---
|
||||
|
||||
# Linked Lists and Trees
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 pointer-based dynamic structure 의 family: 매 1D (list) → 매 hierarchy (tree)"**. 매 1955 Newell-Shaw-Simon 의 IPL 의 origin. 매 modern era 의 in-memory 의 array/hash 의 dominant — 매 list/tree 의 specific use (cache-unfriendly 의 의 X).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Linked List
|
||||
- **node**: data + next pointer.
|
||||
- **singly**: O(1) head insert, O(n) random access, O(n) delete by value.
|
||||
- **doubly**: prev + next — O(1) delete with node pointer.
|
||||
- **circular**: tail.next = head.
|
||||
- **memory**: 매 cache-unfriendly (pointer chasing).
|
||||
|
||||
### 매 Tree
|
||||
- **rooted tree**: parent + children, 매 root 의 single.
|
||||
- **binary tree**: ≤ 2 children.
|
||||
- **BST**: left < root < right — search O(h), 매 worst h = n (degenerate).
|
||||
- **balanced (RB, AVL, Splay)**: h = O(log n).
|
||||
- **traversal**: pre-order (root-left-right), in-order (left-root-right = sorted for BST), post-order, level-order (BFS).
|
||||
|
||||
### 매 modern relevance
|
||||
- **list 의 X**: 매 dynamic array (Vec / list) 의 의 의 amortized O(1) append + O(1) random access + cache-friendly.
|
||||
- **tree 의 use case**: 매 sorted + range query (RB, B+ tree), 매 hierarchy (DOM, AST, filesystem), 매 priority (heap).
|
||||
|
||||
### 매 응용
|
||||
1. AST (compiler).
|
||||
2. DOM (browser).
|
||||
3. Filesystem (directory tree).
|
||||
4. Decision tree (ML).
|
||||
5. Priority queue (heap = array-backed binary tree).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Singly linked list
|
||||
```python
|
||||
class Node:
|
||||
__slots__ = ('val', 'next')
|
||||
def __init__(self, val, next=None):
|
||||
self.val = val; self.next = next
|
||||
|
||||
class LinkedList:
|
||||
def __init__(self):
|
||||
self.head = None
|
||||
def push(self, val): # O(1) head insert
|
||||
self.head = Node(val, self.head)
|
||||
def find(self, val): # O(n)
|
||||
n = self.head
|
||||
while n:
|
||||
if n.val == val: return n
|
||||
n = n.next
|
||||
return None
|
||||
def reverse(self): # O(n) in-place
|
||||
prev, curr = None, self.head
|
||||
while curr:
|
||||
curr.next, prev, curr = prev, curr, curr.next
|
||||
self.head = prev
|
||||
```
|
||||
|
||||
### Detect cycle (Floyd's tortoise & hare)
|
||||
```python
|
||||
def has_cycle(head: Node) -> bool:
|
||||
slow = fast = head
|
||||
while fast and fast.next:
|
||||
slow = slow.next
|
||||
fast = fast.next.next
|
||||
if slow is fast:
|
||||
return True
|
||||
return False
|
||||
```
|
||||
|
||||
### Binary tree traversal
|
||||
```python
|
||||
class TreeNode:
|
||||
def __init__(self, val, left=None, right=None):
|
||||
self.val, self.left, self.right = val, left, right
|
||||
|
||||
def inorder(node): # sorted output for BST
|
||||
if not node: return
|
||||
yield from inorder(node.left)
|
||||
yield node.val
|
||||
yield from inorder(node.right)
|
||||
|
||||
def level_order(root): # BFS
|
||||
from collections import deque
|
||||
if not root: return
|
||||
q = deque([root])
|
||||
while q:
|
||||
node = q.popleft()
|
||||
yield node.val
|
||||
if node.left: q.append(node.left)
|
||||
if node.right: q.append(node.right)
|
||||
```
|
||||
|
||||
### BST insert / search
|
||||
```python
|
||||
class BST:
|
||||
def __init__(self): self.root = None
|
||||
|
||||
def insert(self, val):
|
||||
def _ins(node):
|
||||
if not node: return TreeNode(val)
|
||||
if val < node.val: node.left = _ins(node.left)
|
||||
elif val > node.val: node.right = _ins(node.right)
|
||||
return node
|
||||
self.root = _ins(self.root)
|
||||
|
||||
def search(self, val) -> bool:
|
||||
n = self.root
|
||||
while n:
|
||||
if val == n.val: return True
|
||||
n = n.left if val < n.val else n.right
|
||||
return False
|
||||
```
|
||||
|
||||
### LRU cache (doubly linked list + dict)
|
||||
```python
|
||||
class LRUCache:
|
||||
class Node:
|
||||
__slots__ = ('k', 'v', 'prev', 'nxt')
|
||||
def __init__(self, k, v): self.k, self.v, self.prev, self.nxt = k, v, None, None
|
||||
|
||||
def __init__(self, cap):
|
||||
self.cap = cap; self.map = {}
|
||||
self.head = self.Node(0, 0); self.tail = self.Node(0, 0)
|
||||
self.head.nxt = self.tail; self.tail.prev = self.head
|
||||
|
||||
def _remove(self, n):
|
||||
n.prev.nxt = n.nxt; n.nxt.prev = n.prev
|
||||
|
||||
def _add_front(self, n):
|
||||
n.nxt = self.head.nxt; n.prev = self.head
|
||||
self.head.nxt.prev = n; self.head.nxt = n
|
||||
|
||||
def get(self, k):
|
||||
if k not in self.map: return -1
|
||||
n = self.map[k]
|
||||
self._remove(n); self._add_front(n)
|
||||
return n.v
|
||||
|
||||
def put(self, k, v):
|
||||
if k in self.map:
|
||||
self._remove(self.map[k])
|
||||
elif len(self.map) >= self.cap:
|
||||
lru = self.tail.prev
|
||||
self._remove(lru); del self.map[lru.k]
|
||||
n = self.Node(k, v); self.map[k] = n
|
||||
self._add_front(n)
|
||||
```
|
||||
|
||||
### Tree height + balance check
|
||||
```python
|
||||
def height(node):
|
||||
if not node: return 0
|
||||
return 1 + max(height(node.left), height(node.right))
|
||||
|
||||
def is_balanced(node) -> bool:
|
||||
def check(n):
|
||||
if not n: return 0 # height
|
||||
l = check(n.left)
|
||||
if l == -1: return -1
|
||||
r = check(n.right)
|
||||
if r == -1 or abs(l - r) > 1: return -1
|
||||
return 1 + max(l, r)
|
||||
return check(node) != -1
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 매 random access | array / dynamic array (NOT list) |
|
||||
| 매 head insert frequent | linked list |
|
||||
| 매 LRU eviction | doubly linked list + dict |
|
||||
| 매 sorted + range | balanced BST / B+ tree |
|
||||
| 매 priority | binary heap (array-backed) |
|
||||
| 매 hierarchy (DOM, AST) | n-ary tree |
|
||||
| 매 unique key lookup | hash map |
|
||||
| 매 prefix search | trie |
|
||||
|
||||
**기본값**: list 의 X — dynamic array 의 의. tree 의 specific structure (BST sorted, heap priority, n-ary hierarchy) 의 의.
|
||||
|
||||
## 🔗 Graph
|
||||
- 변형: [[Skip List]]
|
||||
- 응용: [[AST (Abstract Syntax Tree)]] · [[DOM Tree]]
|
||||
- Adjacent: [[Hash Functions and Maps]] · [[B-Tree]] · [[Trie]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 hierarchy 의 model (AST, DOM, filesystem), 매 LRU 의 doubly linked, 매 BST 의 sorted lookup, 매 trie 의 prefix.
|
||||
**언제 X**: 매 1D index access (array), 매 unique lookup (hash), 매 cache-sensitive scan (array), 매 small data (overhead 의 X).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **list 의 random access**: O(n) — 매 array 의 의.
|
||||
- **BST 의 unbalanced**: 매 sorted insert → O(n) height. 매 RB / AVL 의 의.
|
||||
- **memory leak**: 매 unlink X / cycle 의 reference → GC 의 fail (in C, manual free needed).
|
||||
- **shallow copy**: 매 tree clone 의 deep copy 의 의 — `copy.deepcopy` 의 의.
|
||||
- **recursion depth**: 매 deep tree 의 stack overflow — iterative + explicit stack 의 의.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (CLRS Ch 10, 12; Sedgewick Algorithms 4th).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — linked list + tree fundamentals with LRU + Floyd cycle |
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
---
|
||||
id: wiki-2026-0508-locality-sensitive-hashing-lsh
|
||||
title: Locality-Sensitive Hashing (LSH)
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [LSH, Approximate Nearest Neighbor, MinHash, SimHash]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [hashing, ann, retrieval, similarity-search]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: datasketch, faiss
|
||||
---
|
||||
|
||||
# Locality-Sensitive Hashing (LSH)
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 similar item 의 same bucket 으로의 hash"**. LSH 는 hash function family $\mathcal{H}$ 가 매 distance-preserving — close points 는 collide, far points 는 separate. Indyk & Motwani (1998) 이 도입했고, 2026 에서는 ANN 의 매 classical baseline 이며 dedup, plagiarism, blocking, near-duplicate retrieval 의 매 default 로 여전히 사용 (HNSW 가 dominate 하지만 LSH 는 streaming/external memory 에 유리).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Definition
|
||||
$\mathcal{H}$ is $(r_1, r_2, p_1, p_2)$-sensitive iff:
|
||||
- $d(x,y) \le r_1 \Rightarrow \Pr[h(x)=h(y)] \ge p_1$
|
||||
- $d(x,y) \ge r_2 \Rightarrow \Pr[h(x)=h(y)] \le p_2$
|
||||
- $r_1 < r_2$, $p_1 > p_2$
|
||||
|
||||
### 매 Families
|
||||
- **MinHash**: Jaccard distance — set similarity
|
||||
- **SimHash (random hyperplane)**: cosine — sign of $w^\top x$
|
||||
- **p-stable LSH**: $\ell_p$ norms (Datar 2004)
|
||||
- **Cross-polytope**: spherical distance (state-of-art)
|
||||
|
||||
### 매 Amplification
|
||||
- AND: $g(x) = (h_1(x), \dots, h_k(x))$ — reduces $p_2$ to $p_2^k$
|
||||
- OR: $L$ tables, query all → reduces miss rate
|
||||
- tune $(k, L)$ for target precision/recall
|
||||
|
||||
### 매 응용
|
||||
1. **Dedup**: web crawl near-dup pages (MinHash + LSH).
|
||||
2. **Plagiarism**: shingled MinHash.
|
||||
3. **Blocking**: entity resolution candidate generation.
|
||||
4. **ANN**: cosine NN (SimHash baseline).
|
||||
5. **Genomics**: sketch-based read alignment.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### MinHash + LSH for Jaccard
|
||||
```python
|
||||
from datasketch import MinHash, MinHashLSH
|
||||
|
||||
def shingles(text, k=5):
|
||||
return {text[i:i+k] for i in range(len(text)-k+1)}
|
||||
|
||||
def make_mh(s, num_perm=128):
|
||||
m = MinHash(num_perm=num_perm)
|
||||
for sh in s: m.update(sh.encode())
|
||||
return m
|
||||
|
||||
lsh = MinHashLSH(threshold=0.7, num_perm=128)
|
||||
docs = {"d1": "the quick brown fox", "d2": "the quick red fox"}
|
||||
mhs = {k: make_mh(shingles(v)) for k, v in docs.items()}
|
||||
for k, m in mhs.items(): lsh.insert(k, m)
|
||||
|
||||
q = make_mh(shingles("the quick brown fox jumps"))
|
||||
print(lsh.query(q)) # candidate set
|
||||
```
|
||||
|
||||
### SimHash for cosine
|
||||
```python
|
||||
import numpy as np
|
||||
from collections import defaultdict
|
||||
|
||||
def simhash(x, planes):
|
||||
return tuple((x @ planes.T > 0).astype(np.int8))
|
||||
|
||||
# k random hyperplanes
|
||||
d, k, L = 128, 8, 10
|
||||
tables = [np.random.randn(k, d) for _ in range(L)]
|
||||
|
||||
def index(X):
|
||||
out = [defaultdict(list) for _ in range(L)]
|
||||
for i, x in enumerate(X):
|
||||
for li, planes in enumerate(tables):
|
||||
out[li][simhash(x, planes)].append(i)
|
||||
return out
|
||||
|
||||
def query(q, idx):
|
||||
cands = set()
|
||||
for li, planes in enumerate(tables):
|
||||
cands |= set(idx[li].get(simhash(q, planes), []))
|
||||
return cands
|
||||
```
|
||||
|
||||
### p-stable LSH (L2)
|
||||
```python
|
||||
# h(x) = floor((a·x + b) / w), a ~ N(0, I), b ~ U[0, w]
|
||||
def make_l2_lsh(d, w=4.0, k=8):
|
||||
a = np.random.randn(k, d)
|
||||
b = np.random.uniform(0, w, k)
|
||||
return lambda x: tuple(np.floor((a @ x + b) / w).astype(np.int64))
|
||||
```
|
||||
|
||||
### LSH Forest (multi-resolution)
|
||||
```python
|
||||
from datasketch import MinHashLSHForest
|
||||
forest = MinHashLSHForest(num_perm=128)
|
||||
for k, m in mhs.items(): forest.add(k, m)
|
||||
forest.index()
|
||||
print(forest.query(q, 5)) # top-5 approx Jaccard NN
|
||||
```
|
||||
|
||||
### Banding technique (k-AND, L-OR)
|
||||
```python
|
||||
def banded_lsh(signatures, k_per_band, L_bands):
|
||||
# signatures: (n, k_per_band * L_bands)
|
||||
buckets = [defaultdict(list) for _ in range(L_bands)]
|
||||
for i, sig in enumerate(signatures):
|
||||
for b in range(L_bands):
|
||||
band = tuple(sig[b*k_per_band:(b+1)*k_per_band])
|
||||
buckets[b][band].append(i)
|
||||
return buckets
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| Distance | Family |
|
||||
|---|---|
|
||||
| Jaccard (sets) | MinHash |
|
||||
| Cosine | SimHash / Cross-polytope |
|
||||
| $\ell_2$ | p-stable (Gaussian) |
|
||||
| Hamming | bit-sampling |
|
||||
| edit distance | shingle + MinHash approx |
|
||||
|
||||
**기본값**: HNSW for general ANN (faster); LSH for dedup, streaming, external memory, exact-recall guarantee.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Approximate-Nearest-Neighbor]]
|
||||
- 변형: [[MinHash]] · [[SimHash]]
|
||||
- 응용: [[Deduplication]]
|
||||
- Adjacent: [[HNSW]] · [[Faiss]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: massive corpus dedup (e.g. pretraining cleanup), candidate blocking, streaming.
|
||||
**언제 X**: small (n < 10⁵) 또는 high-precision recall — HNSW/IVF 가 더 빠름.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **(k, L) tuning 무시**: default 사용 → too many false positives or misses.
|
||||
- **Wrong family**: cosine 인데 MinHash 사용 → meaningless.
|
||||
- **Re-hash on every query**: index 재build → use persistent lib (datasketch, faiss).
|
||||
- **Treating LSH as exact**: 매 approximate — verify candidates with true distance.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Indyk & Motwani 1998 STOC, Andoni & Indyk 2008 CACM, Leskovec MMDS textbook ch 3).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — LSH families, MinHash/SimHash, banding, dedup patterns |
|
||||
@@ -0,0 +1,162 @@
|
||||
---
|
||||
id: wiki-2026-0508-lubrication
|
||||
title: Lubrication
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Tribology, Friction Reduction, Bearing Lubrication]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.88
|
||||
verification_status: applied
|
||||
tags: [tribology, mechanical-engineering, materials, maintenance]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: scipy, sympy, openturns
|
||||
---
|
||||
|
||||
# Lubrication
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 sliding/rolling surface 사이에 매 friction + wear 의 minimize 의 fluid/film 의 introduction"**. Reynolds (1886) 의 thin-film equation → modern: **EHL (elastohydrodynamic), MoS₂ / DLC solid lubricants, ionic liquids, ML-driven oil-condition monitoring**. 매 mechanical reliability 의 single biggest lever — 매 ~23% global energy 의 friction/wear 에 lost (Holmberg & Erdemir 2017).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Stribeck regimes
|
||||
- **Boundary**: 매 surface contact, additives carry load (boundary additive ZDDP). μ ≈ 0.1.
|
||||
- **Mixed**: 매 partial film + asperity contact.
|
||||
- **Hydrodynamic**: 매 full fluid film, μ ≈ 0.001–0.01.
|
||||
- **EHL (Elastohydrodynamic)**: 매 high-pressure point/line contact (gear teeth, ball bearing) — 매 oil viscosity rises with p, surfaces deform elastically.
|
||||
|
||||
### 매 lubricant types
|
||||
- **Mineral oil** (refined crude).
|
||||
- **Synthetic** (PAO, ester, PAG).
|
||||
- **Grease** (oil + thickener, e.g., lithium-complex).
|
||||
- **Solid** (graphite, MoS₂, PTFE, DLC coating).
|
||||
- **Gas** (air bearing, hard-disk head).
|
||||
- **Bio / water-based** (food, marine).
|
||||
|
||||
### 매 key parameters
|
||||
- **Viscosity** η (Pa·s); kinematic ν = η/ρ (cSt).
|
||||
- **Viscosity index (VI)**: 매 sensitivity to T (higher = better).
|
||||
- **Film thickness** h (μm). 매 minimum h_min / σ (composite roughness) > 3 → 매 full EHL.
|
||||
- **Pressure-viscosity coefficient** α — 매 EHL 의 critical.
|
||||
|
||||
### 매 modern (2026)
|
||||
- **Online oil sensors**: dielectric, IR, viscometer-MEMS, ferrography.
|
||||
- **ML CBM**: LSTM/transformer 의 RUL prediction from oil + vibration.
|
||||
- **Sustainability**: re-refined oils, bio-based esters, dry / minimum-quantity lubrication (MQL) machining.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Reynolds equation (1-D, slider bearing)
|
||||
```python
|
||||
import numpy as np
|
||||
from scipy.integrate import solve_bvp
|
||||
|
||||
eta = 0.05 # Pa·s
|
||||
U = 5.0 # m/s
|
||||
L = 0.05 # m
|
||||
h0, h1 = 50e-6, 25e-6
|
||||
def h(x): return h0 + (h1-h0)*x/L
|
||||
|
||||
def rhs(x, y):
|
||||
p, dpdx = y
|
||||
H = h(x)
|
||||
return np.vstack([dpdx, 6*eta*U/H**3 - 3*dpdx/H * (h1-h0)/L])
|
||||
|
||||
def bc(ya, yb): return np.array([ya[0], yb[0]]) # p=0 at both ends
|
||||
xs = np.linspace(0, L, 50); y0 = np.zeros((2, xs.size))
|
||||
sol = solve_bvp(rhs, bc, xs, y0)
|
||||
W = np.trapz(sol.sol(xs)[0], xs) # load capacity per unit width
|
||||
```
|
||||
|
||||
### Hamrock–Dowson EHL film thickness (point contact)
|
||||
```python
|
||||
def hd_central_film(W, U, G, k=1.0):
|
||||
"""central film thickness ratio H_c (Hamrock–Dowson, point contact)."""
|
||||
return 2.69 * U**0.67 * G**0.53 * W**-0.067 * (1 - 0.61*np.exp(-0.73*k))
|
||||
# W = w/(E'*Rx²), U = η0*us/(E'*Rx), G = α*E' (dimensionless groups)
|
||||
```
|
||||
|
||||
### Stribeck curve simulator
|
||||
```python
|
||||
import numpy as np, matplotlib.pyplot as plt
|
||||
def stribeck(eta_N_over_P):
|
||||
x = np.log10(eta_N_over_P)
|
||||
return 0.001 + 0.15*np.exp(-((x+5)**2)/1.5) # toy μ(η·N/P)
|
||||
xs = np.logspace(-7, -3, 200)
|
||||
plt.semilogx(xs, [stribeck(v) for v in xs])
|
||||
plt.xlabel("η·N/P"); plt.ylabel("μ")
|
||||
```
|
||||
|
||||
### Walther viscosity-temperature
|
||||
```python
|
||||
def walther_nu(T_C, A, B):
|
||||
Z = 10**(A - B*np.log10(T_C + 273.15))
|
||||
return Z - 0.7 # cSt
|
||||
# A, B 의 fit from two data points (e.g., 40 °C and 100 °C).
|
||||
```
|
||||
|
||||
### Oil-condition ML (RUL with LSTM, sketch)
|
||||
```python
|
||||
import torch, torch.nn as nn
|
||||
class RULNet(nn.Module):
|
||||
def __init__(self, in_dim=8, hidden=64):
|
||||
super().__init__()
|
||||
self.lstm = nn.LSTM(in_dim, hidden, 2, batch_first=True)
|
||||
self.head = nn.Linear(hidden, 1)
|
||||
def forward(self, x):
|
||||
h,_ = self.lstm(x); return self.head(h[:, -1, :])
|
||||
# inputs: viscosity, TAN, water%, particle counts, Fe ppm, Cu ppm, T, p
|
||||
```
|
||||
|
||||
### Bearing life (L10, ISO 281)
|
||||
```python
|
||||
def L10_million_revs(C_N, P_N, p_exp=3): # 3 ball, 10/3 roller
|
||||
return (C_N / P_N) ** p_exp
|
||||
def L10h_hours(L10_Mrev, n_rpm):
|
||||
return L10_Mrev * 1e6 / (60 * n_rpm)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Sliding journal bearing | **Hydrodynamic oil + Reynolds** |
|
||||
| Rolling element / gear | **EHL oil with high VI + α** |
|
||||
| High T (engine, turbine) | **Synthetic ester / PAO** |
|
||||
| Vacuum / radiation / dry | **Solid lubricant (MoS₂, DLC)** |
|
||||
| Food, medical | **H1 food-grade / bio-based** |
|
||||
| Sealed-for-life | **Grease (NLGI 2)** |
|
||||
| Precision machining | **MQL (minimum-quantity lubrication)** |
|
||||
| Condition monitoring | **Online sensors + ML RUL** |
|
||||
|
||||
**기본값**: 매 industrial machinery → **mineral/PAO oil + ZDDP additive + ISO VG selected by viscosity-temp/load**, 매 critical → **online oil + vibration CBM**.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Tribology]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 lubricant 의 selection table 의 first cut, 매 viscosity-temp curve 의 fitting, 매 oil-analysis report 의 interpretation, 매 CBM model architecture 의 prototyping.
|
||||
**언제 X**: 매 safety-critical (aerospace, nuclear) 의 final spec — 매 OEM/standards (ISO, DIN, MIL) 직접 검증.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Mixing greases (incompatible thickeners)**: 매 Li + Ca-sulfonate → 매 phase-separates → 매 bearing failure.
|
||||
- **Over-greasing sealed bearing**: 매 churning heat → 매 seal blowout.
|
||||
- **Wrong viscosity grade**: 매 too-low → boundary/wear; too-high → drag/heat.
|
||||
- **Ignoring oil age / oxidation (TAN)**: 매 acid attacks bearing.
|
||||
- **Topping up only**: 매 contaminants accumulate — 매 periodic full change + filter.
|
||||
- **Same oil 매 high-T + low-T 모두**: 매 VI 의 inadequate → 매 multigrade or synthetic 사용.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Reynolds 1886; Hamrock & Dowson 1977; Holmberg & Erdemir 2017; Stachowiak & Batchelor *Engineering Tribology* 4th ed.; ISO 281, ASTM D2270/D341).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 placeholder |
|
||||
| 2026-05-10 | Manual cleanup — Stribeck/EHL theory + 6 patterns + decision matrix |
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
---
|
||||
id: wiki-2026-0508-model-predictive-control-mpc
|
||||
title: Model Predictive Control (MPC)
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [MPC, Receding-Horizon-Control, RHC]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [control, optimization, robotics, autonomous-vehicles, receding-horizon]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: cvxpy-acados
|
||||
---
|
||||
|
||||
# Model Predictive Control (MPC)
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 step마다 future를 optimize, 첫 action만 실행, 매 반복"**. Receding horizon control은 매 dynamics model + cost + constraints를 매 online QP/NLP로 풀어낸다. 2026 자율주행·드론·humanoid robot의 매 dominant control paradigm으로 reinforcement learning과도 hybrid 구성된다.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 정식화
|
||||
```
|
||||
min_{u_0..u_{N-1}} Σ ℓ(x_k, u_k) + V_f(x_N)
|
||||
s.t. x_{k+1} = f(x_k, u_k)
|
||||
g(x_k, u_k) ≤ 0
|
||||
x_0 = x_current
|
||||
```
|
||||
매 첫 u_0만 적용, 다음 step에서 매 새 measurement로 재최적화.
|
||||
|
||||
### 매 종류
|
||||
- **Linear MPC**: f linear, ℓ quadratic → QP.
|
||||
- **Nonlinear MPC (NMPC)**: NLP (IPOPT, acados).
|
||||
- **Robust MPC**: tube/min-max — uncertainty 처리.
|
||||
- **Stochastic MPC**: chance constraints.
|
||||
- **Learning-based MPC**: f를 NN/GP로.
|
||||
|
||||
### 매 응용
|
||||
1. Autonomous driving — trajectory tracking, lane change.
|
||||
2. Quadrotor / drone control.
|
||||
3. Humanoid locomotion (Boston Dynamics, Tesla Optimus 추정).
|
||||
4. Process industry — refinery, chemical plant.
|
||||
5. HVAC, smart grid.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Linear MPC with CVXPY
|
||||
```python
|
||||
import cvxpy as cp, numpy as np
|
||||
def lin_mpc(A, B, x0, N=10, Q=None, R=None):
|
||||
nx, nu = B.shape
|
||||
Q = Q if Q is not None else np.eye(nx)
|
||||
R = R if R is not None else 0.1*np.eye(nu)
|
||||
x = cp.Variable((nx, N+1))
|
||||
u = cp.Variable((nu, N))
|
||||
cost, cons = 0, [x[:, 0] == x0]
|
||||
for k in range(N):
|
||||
cost += cp.quad_form(x[:, k], Q) + cp.quad_form(u[:, k], R)
|
||||
cons += [x[:, k+1] == A @ x[:, k] + B @ u[:, k]]
|
||||
cons += [cp.norm(u[:, k], 'inf') <= 1.0]
|
||||
cp.Problem(cp.Minimize(cost), cons).solve()
|
||||
return u[:, 0].value
|
||||
```
|
||||
|
||||
### NMPC with CasADi/acados (sketch)
|
||||
```python
|
||||
import casadi as ca
|
||||
x = ca.SX.sym('x', nx); u = ca.SX.sym('u', nu)
|
||||
f = ca.Function('f', [x, u], [dynamics(x, u)])
|
||||
# build NLP with multiple shooting...
|
||||
```
|
||||
|
||||
### Receding horizon loop
|
||||
```python
|
||||
for t in range(T):
|
||||
x_meas = sensor.read()
|
||||
u_star = mpc_solve(x_meas)
|
||||
actuator.apply(u_star)
|
||||
```
|
||||
|
||||
### Reference tracking cost
|
||||
```python
|
||||
cost += cp.quad_form(x[:, k] - x_ref, Q)
|
||||
```
|
||||
|
||||
### Soft constraint via slack
|
||||
```python
|
||||
slack = cp.Variable(N, nonneg=True)
|
||||
cons += [g(x[:, k], u[:, k]) <= slack[k]]
|
||||
cost += 1e3 * cp.sum(slack)
|
||||
```
|
||||
|
||||
### Warm-start (next iter uses prev solution)
|
||||
```python
|
||||
solver.set_initial_guess(shift(u_prev))
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | MPC variant |
|
||||
|---|---|
|
||||
| Linear plant, quadratic cost | QP-based linear MPC |
|
||||
| Nonlinear dynamics | NMPC (acados, CasADi) |
|
||||
| Bounded uncertainty | Tube MPC |
|
||||
| Probabilistic constraint | Stochastic MPC |
|
||||
| Hard real-time (kHz) | Explicit MPC (precomputed) |
|
||||
|
||||
**기본값**: Linear MPC + warm-start (cycle time < 10 ms).
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Optimal-Control-Theory]] · [[Optimization]]
|
||||
- 응용: [[Autonomous-Vehicle-Path-Planning]]
|
||||
- Adjacent: [[Reinforcement-Learning]] · [[Kalman-Filter-and-State-Tracking]] · [[Feedback-Control-Systems]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: Constrained dynamic systems, real-time replanning, model + cost are known.
|
||||
**언제 X**: Model 알 수 없거나 long-horizon strategic decision (use RL).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Horizon 너무 짧음**: 매 myopic control.
|
||||
- **Constraint feasibility 무시**: infeasible 시 fallback 없음.
|
||||
- **Cold-start 매 iteration**: 매 latency 폭발 — warm-start 필수.
|
||||
- **Plant-model mismatch 무시**: 매 robust/adaptive 가 필요.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Rawlings, Mayne, Diehl "Model Predictive Control").
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — MPC formulation + CVXPY/acados patterns |
|
||||
@@ -0,0 +1,135 @@
|
||||
---
|
||||
id: wiki-2026-0508-monte-carlo-integration
|
||||
title: Monte Carlo Integration
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Monte-Carlo-Integration, MC-Integration, 몬테카를로-적분]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [numerical, integration, sampling, statistics, simulation]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: numpy-jax
|
||||
---
|
||||
|
||||
# Monte Carlo Integration
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 무작위 샘플의 평균이 적분값으로 수렴"**. ∫f dμ ≈ (1/N)Σf(xᵢ), error O(N⁻¹/²) — 매 dimension에 무관한 게 매 핵심 강점이다. 1949 Metropolis-Ulam에서 Manhattan Project 이후, 2026 LLM 시대에도 매 RLHF reward estimation·diffusion sampling의 backbone.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 estimator
|
||||
- **Standard MC**: x ~ p, Î = (1/N)Σf(xᵢ); Var = σ²/N.
|
||||
- **Importance sampling**: x ~ q, Î = (1/N)Σf(xᵢ)p(xᵢ)/q(xᵢ).
|
||||
- **Control variates**: f → f − c(g − E[g]); 매 variance ↓.
|
||||
- **Stratified**: 매 domain partition.
|
||||
- **Quasi-MC**: Sobol/Halton — error O(N⁻¹ logᵈ N).
|
||||
|
||||
### 매 수렴
|
||||
- Error std ~ σ/√N (CLT).
|
||||
- 매 dim 무관 — high-dim integration의 매 유일한 실용 도구.
|
||||
|
||||
### 매 응용
|
||||
1. Bayesian inference — posterior expectation (MCMC).
|
||||
2. Computer graphics — path tracing, light transport.
|
||||
3. Finance — option pricing (Black-Scholes path).
|
||||
4. RLHF — reward expectation.
|
||||
5. Diffusion model — score-matching expectation.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Basic MC integral
|
||||
```python
|
||||
import numpy as np
|
||||
def mc_integrate(f, low, high, n=10000):
|
||||
x = np.random.uniform(low, high, n)
|
||||
return (high - low) * f(x).mean(), (high - low) * f(x).std() / np.sqrt(n)
|
||||
```
|
||||
|
||||
### Importance sampling
|
||||
```python
|
||||
def importance_mc(f, sampler_q, log_p, log_q, n=10000):
|
||||
x = sampler_q(n)
|
||||
w = np.exp(log_p(x) - log_q(x))
|
||||
return (f(x) * w).mean()
|
||||
```
|
||||
|
||||
### Control variates
|
||||
```python
|
||||
def cv_mc(f, g, Eg, n=10000):
|
||||
x = np.random.uniform(0, 1, n)
|
||||
fx, gx = f(x), g(x)
|
||||
c = -np.cov(fx, gx)[0, 1] / np.var(gx)
|
||||
return (fx + c * (gx - Eg)).mean()
|
||||
```
|
||||
|
||||
### Quasi-MC with Sobol
|
||||
```python
|
||||
from scipy.stats.qmc import Sobol
|
||||
sampler = Sobol(d=5, scramble=True)
|
||||
points = sampler.random_base2(m=14) # 2^14 points
|
||||
estimate = f(points).mean()
|
||||
```
|
||||
|
||||
### MCMC (Metropolis-Hastings)
|
||||
```python
|
||||
def mh(log_pi, x0, n=10000, sigma=0.5):
|
||||
x, samples = x0, [x0]
|
||||
for _ in range(n):
|
||||
x_prop = x + sigma * np.random.randn(*x.shape)
|
||||
if np.log(np.random.rand()) < log_pi(x_prop) - log_pi(x):
|
||||
x = x_prop
|
||||
samples.append(x)
|
||||
return np.array(samples)
|
||||
```
|
||||
|
||||
### JAX vectorized MC
|
||||
```python
|
||||
import jax, jax.numpy as jnp
|
||||
@jax.jit
|
||||
def mc(key, n):
|
||||
x = jax.random.uniform(key, (n,))
|
||||
return jnp.mean(jnp.exp(-x**2))
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Method |
|
||||
|---|---|
|
||||
| Smooth low-dim | Quadrature or QMC |
|
||||
| High-dim | Vanilla MC |
|
||||
| Heavy tail / rare event | Importance sampling |
|
||||
| Posterior | MCMC (NUTS, HMC) |
|
||||
| Light transport | Path tracing + MIS |
|
||||
|
||||
**기본값**: Vanilla MC + control variates (low complexity, low variance).
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Statistics]]
|
||||
- 변형: [[MCMC]]
|
||||
- 응용: [[Bayesian Inference]] · [[RLHF]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: High-dim integration, expectation under intractable distribution, simulation.
|
||||
**언제 X**: 1-3 dim smooth functions (use Gauss quadrature).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Variance 무시**: 매 std error 안 보고 estimate 제출.
|
||||
- **Bad importance proposal**: 매 q tail이 p보다 얇으면 explosion.
|
||||
- **Correlated samples**: MCMC autocorrelation 무시 → 매 ESS 부풀려짐.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Robert & Casella "Monte Carlo Statistical Methods").
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — MC variants + JAX/MCMC patterns |
|
||||
@@ -0,0 +1,148 @@
|
||||
---
|
||||
id: wiki-2026-0508-multivariate-analysis
|
||||
title: Multivariate Analysis
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [MVA, Multivariate Statistics]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [statistics, dimensionality-reduction, multivariate]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: scikit-learn/statsmodels
|
||||
---
|
||||
|
||||
# Multivariate Analysis
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 multiple correlated variables 매 동시에"**. 매 MVA는 covariance·correlation matrix를 base로 PCA/FA/CCA/MANOVA/discriminant analysis 매 통합, 매 2026 ML 시대에도 매 EDA·feature engineering·biostatistics·marketing research에서 매 indispensable foundation.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 covariance matrix Σ
|
||||
- Σᵢⱼ = E[(Xᵢ - μᵢ)(Xⱼ - μⱼ)].
|
||||
- Eigendecomposition Σ = QΛQᵀ가 매 모든 multivariate 기법의 backbone.
|
||||
- Sample S = (1/(n-1)) XᶜᵀXᶜ.
|
||||
|
||||
### 매 family
|
||||
- **PCA**: max variance projection (eigen of Σ).
|
||||
- **FA (Factor Analysis)**: latent factors + idiosyncratic noise (X = ΛF + ε).
|
||||
- **CCA**: max correlation between two variable sets.
|
||||
- **LDA**: discriminant axes (between-class vs within-class scatter).
|
||||
- **MANOVA**: multivariate generalization of ANOVA (Wilks Λ, Pillai trace).
|
||||
- **MDS**: distance-preserving embedding.
|
||||
|
||||
### 매 응용
|
||||
1. EDA on tabular data (correlation heatmap, biplot).
|
||||
2. Feature engineering before tree models or MLP.
|
||||
3. Genomics (gene expression PCA / FA).
|
||||
4. Marketing segmentation (cluster + biplot).
|
||||
5. Psychometrics (factor structure of survey).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### PCA — full pipeline
|
||||
```python
|
||||
from sklearn.decomposition import PCA
|
||||
from sklearn.preprocessing import StandardScaler
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
X_std = StandardScaler().fit_transform(X)
|
||||
pca = PCA(n_components=0.95) # keep 95% variance
|
||||
Z = pca.fit_transform(X_std)
|
||||
print(pca.explained_variance_ratio_.cumsum())
|
||||
|
||||
# Biplot
|
||||
loadings = pca.components_.T * np.sqrt(pca.explained_variance_)
|
||||
plt.scatter(Z[:,0], Z[:,1], alpha=0.3)
|
||||
for i, name in enumerate(feature_names):
|
||||
plt.arrow(0, 0, loadings[i,0]*3, loadings[i,1]*3, color='r')
|
||||
plt.text(loadings[i,0]*3.2, loadings[i,1]*3.2, name)
|
||||
```
|
||||
|
||||
### Factor Analysis with rotation
|
||||
```python
|
||||
from sklearn.decomposition import FactorAnalysis
|
||||
fa = FactorAnalysis(n_components=3, rotation='varimax')
|
||||
fa.fit(X_std)
|
||||
print(fa.components_) # loadings
|
||||
```
|
||||
|
||||
### CCA (cross-modal)
|
||||
```python
|
||||
from sklearn.cross_decomposition import CCA
|
||||
cca = CCA(n_components=2)
|
||||
cca.fit(X_view1, X_view2)
|
||||
U, V = cca.transform(X_view1, X_view2)
|
||||
# diag(corr(U, V)) = canonical correlations
|
||||
```
|
||||
|
||||
### Linear Discriminant Analysis
|
||||
```python
|
||||
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
|
||||
lda = LinearDiscriminantAnalysis(n_components=2)
|
||||
Z = lda.fit_transform(X_std, y) # supervised projection
|
||||
```
|
||||
|
||||
### MANOVA via statsmodels
|
||||
```python
|
||||
from statsmodels.multivariate.manova import MANOVA
|
||||
maov = MANOVA.from_formula('y1 + y2 + y3 ~ group', data=df)
|
||||
print(maov.mv_test()) # Wilks, Pillai, Hotelling, Roy
|
||||
```
|
||||
|
||||
### Mahalanobis distance (multivariate outliers)
|
||||
```python
|
||||
import numpy as np
|
||||
mu = X.mean(axis=0)
|
||||
S_inv = np.linalg.inv(np.cov(X, rowvar=False))
|
||||
def mahal(x):
|
||||
d = x - mu
|
||||
return np.sqrt(d @ S_inv @ d)
|
||||
# threshold: chi2.ppf(0.975, df=p)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Variance compression unsupervised | PCA |
|
||||
| Latent structure interpretation | Factor Analysis (with rotation) |
|
||||
| Two correlated groups of vars | CCA |
|
||||
| Supervised projection | LDA |
|
||||
| Group-mean comparison (multivariate) | MANOVA |
|
||||
| Distance-only data | MDS |
|
||||
| Outlier detection multivariate | Mahalanobis / Min Cov Det |
|
||||
|
||||
**기본값**: 매 EDA에 PCA + correlation heatmap, 매 supervised에 LDA, 매 latent factor에 FA + varimax.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Statistics]] · [[Linear-Algebra-Foundations|Linear-Algebra]]
|
||||
- 변형: [[PCA]] · [[Factor-Analysis]] · [[LDA]]
|
||||
- 응용: [[EDA]] · [[Feature Engineering|Feature-Engineering]]
|
||||
- Adjacent: [[Dimensionality-Reduction]] · [[t-SNE]] · [[UMAP]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 EDA narrative generation (PCA biplot 해석), factor labeling, MANOVA result writeup.
|
||||
**언제 X**: 매 actual decomposition computing (numpy/sklearn use).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **No standardization**: 매 PCA before scaling → 매 large-magnitude vars dominate.
|
||||
- **PCA on nonlinear**: 매 swiss-roll에 매 PCA 매 사용 → 매 t-SNE/UMAP/Isomap 매 사용.
|
||||
- **FA without rotation**: 매 unrotated factors 매 interpret 어려움 — 매 varimax/promax 적용.
|
||||
- **MANOVA assumption**: 매 multivariate normality + equal cov 매 검증 X → wrong p-values.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Johnson & Wichern "Applied Multivariate", Hardle & Simar).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full MVA toolkit (PCA/FA/CCA/LDA/MANOVA) |
|
||||
@@ -0,0 +1,131 @@
|
||||
---
|
||||
id: wiki-2026-0508-mutual-information
|
||||
title: Mutual Information
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Mutual-Information, MI, 상호정보량, I(X;Y)]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [information-theory, statistics, dependence, feature-selection, representation-learning]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: scikit-learn-pytorch
|
||||
---
|
||||
|
||||
# Mutual Information
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 X를 알면 Y에 대해 매 얼마나 덜 놀라는가"**. I(X;Y) = H(X) − H(X|Y) = KL(P_XY ‖ P_X⊗P_Y); 매 어떤 monotonic transform에도 invariant한 dependence measure다. 2026 self-supervised learning(InfoNCE, CLIP)과 disentanglement(β-VAE) 핵심 도구.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 정의
|
||||
- **Discrete**: I(X;Y) = ΣΣ p(x,y) log(p(x,y)/(p(x)p(y))).
|
||||
- **Continuous**: integral 형태.
|
||||
- **KL form**: I(X;Y) = D_KL(P_XY ‖ P_X⊗P_Y) ≥ 0.
|
||||
- 매 0 iff X⊥Y.
|
||||
|
||||
### 매 추정의 어려움
|
||||
- High-dim continuous에서 매 매 어렵다.
|
||||
- KSG(k-NN) — Kraskov-Stögbauer-Grassberger.
|
||||
- MINE — neural net 기반 (Donsker-Varadhan).
|
||||
- InfoNCE bound — contrastive.
|
||||
- KDE 기반 (low dim only).
|
||||
|
||||
### 매 응용
|
||||
1. Feature selection (mRMR).
|
||||
2. Self-supervised learning (SimCLR, CLIP, InfoNCE).
|
||||
3. Representation disentanglement (β-VAE, InfoGAN).
|
||||
4. Causal discovery (CMI tests).
|
||||
5. Information bottleneck.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Discrete MI (sklearn)
|
||||
```python
|
||||
from sklearn.metrics import mutual_info_score
|
||||
mi = mutual_info_score(x_labels, y_labels)
|
||||
```
|
||||
|
||||
### Continuous MI (KSG via sklearn)
|
||||
```python
|
||||
from sklearn.feature_selection import mutual_info_regression
|
||||
mi = mutual_info_regression(X, y, n_neighbors=3)
|
||||
```
|
||||
|
||||
### MINE (PyTorch)
|
||||
```python
|
||||
import torch, torch.nn as nn
|
||||
class MINE(nn.Module):
|
||||
def __init__(self, dim_x, dim_y, hid=256):
|
||||
super().__init__()
|
||||
self.f = nn.Sequential(nn.Linear(dim_x+dim_y, hid),
|
||||
nn.ELU(), nn.Linear(hid, 1))
|
||||
def forward(self, x, y):
|
||||
joint = self.f(torch.cat([x, y], -1))
|
||||
y_perm = y[torch.randperm(y.size(0))]
|
||||
marg = self.f(torch.cat([x, y_perm], -1))
|
||||
return joint.mean() - torch.log(marg.exp().mean())
|
||||
```
|
||||
|
||||
### InfoNCE lower bound
|
||||
```python
|
||||
def infonce(z_x, z_y, tau=0.1):
|
||||
logits = z_x @ z_y.T / tau
|
||||
labels = torch.arange(z_x.size(0), device=z_x.device)
|
||||
return -torch.nn.functional.cross_entropy(logits, labels) + np.log(z_x.size(0))
|
||||
```
|
||||
|
||||
### Conditional MI (KSG-style via partition)
|
||||
```python
|
||||
def cmi_estimate(X, Y, Z, n_neighbors=5):
|
||||
# I(X;Y|Z) = I(X;Y,Z) - I(X;Z)
|
||||
return (mutual_info_regression(X, np.column_stack([Y, Z]), n_neighbors=n_neighbors)
|
||||
- mutual_info_regression(X, Z, n_neighbors=n_neighbors))
|
||||
```
|
||||
|
||||
### Maximal Information Coefficient (MIC)
|
||||
```python
|
||||
from minepy import MINE as MIC
|
||||
mine = MIC(); mine.compute_score(x, y)
|
||||
print(mine.mic())
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Estimator |
|
||||
|---|---|
|
||||
| Discrete labels | sklearn `mutual_info_score` |
|
||||
| Low-dim continuous | KSG (k-NN) |
|
||||
| High-dim, ML training | InfoNCE / MINE |
|
||||
| Equitability needed | MIC |
|
||||
|
||||
**기본값**: KSG for analysis, InfoNCE for SSL training.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Entropy in Information Theory|Information Theory]] · [[Information-Entropy]]
|
||||
- Adjacent: [[Kullback-Leibler-Divergence]] · [[Cross-Entropy]] · [[Causal-Inference]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: Non-linear dependence detection, contrastive representation learning, causal screening.
|
||||
**언제 X**: Sample size 작거나 high-dim continuous (estimator 신뢰도 ↓).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Histogram MI in high-dim**: bias 폭발.
|
||||
- **MI = correlation 가정**: MI는 매 모든 dependence 잡지만 correlation은 linear만.
|
||||
- **Plug-in estimator 그대로**: 매 bias correction 필수.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Cover & Thomas "Elements of Information Theory" ch.2).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — MI estimators + MINE/InfoNCE patterns |
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
---
|
||||
id: wiki-2026-0508-mutually-exclusive-and-collectiv
|
||||
title: Mutually Exclusive and Collectively Exhaustive (MECE)
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [MECE, ME-CE, 상호배타-전체포괄]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [reasoning, problem-solving, consulting, structured-thinking, taxonomy]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: markdown
|
||||
framework: unspecified
|
||||
---
|
||||
|
||||
# Mutually Exclusive and Collectively Exhaustive (MECE)
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 항목 겹치지 않고 매 합쳐 전체"**. Barbara Minto가 McKinsey에서 정형화한 매 categorization 원칙으로, 매 합리적 의사소통과 매 logical decomposition의 매 backbone이다. 2026 LLM agent의 task partitioning에서도 매 동일 원칙이 적용된다.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 두 조건
|
||||
- **Mutually Exclusive (ME)**: 매 두 카테고리의 교집합 = ∅.
|
||||
- **Collectively Exhaustive (CE)**: 매 카테고리들의 합집합 = 전체.
|
||||
|
||||
### 매 typical partition 패턴
|
||||
- Binary split: A vs Not-A.
|
||||
- Process steps: Before / During / After.
|
||||
- Stakeholders: Internal / External.
|
||||
- Time: Past / Present / Future.
|
||||
- Quantitative axes: Price × Volume = Revenue.
|
||||
|
||||
### 매 응용
|
||||
1. Issue tree / logic tree decomposition.
|
||||
2. Market sizing (top-down vs bottom-up).
|
||||
3. SQL GROUP BY 카테고리 설계.
|
||||
4. LLM agent subtask split (no overlap, no gap).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### MECE check (Python)
|
||||
```python
|
||||
def is_mece(categories, universe):
|
||||
union = set().union(*categories)
|
||||
if union != universe:
|
||||
return False, "not exhaustive", universe - union
|
||||
for i, a in enumerate(categories):
|
||||
for b in categories[i+1:]:
|
||||
if a & b:
|
||||
return False, "overlap", a & b
|
||||
return True, "MECE", None
|
||||
```
|
||||
|
||||
### Decision-tree style decomposition
|
||||
```markdown
|
||||
- 매출 감소 원인
|
||||
- 가격 (P)
|
||||
- 수량 (Q) [P와 ME — 가격 효과 통제 후]
|
||||
- 믹스 (M) [구성 변화]
|
||||
→ P + Q + M ≈ ΔRevenue (CE check)
|
||||
```
|
||||
|
||||
### Pandas group MECE validation
|
||||
```python
|
||||
def validate_mece_groups(df, group_col, total_col):
|
||||
grouped = df.groupby(group_col)[total_col].sum()
|
||||
return abs(grouped.sum() - df[total_col].sum()) < 1e-6
|
||||
```
|
||||
|
||||
### Set cover (greedy CE construction)
|
||||
```python
|
||||
def greedy_cover(universe, sets):
|
||||
chosen, remaining = [], set(universe)
|
||||
while remaining:
|
||||
best = max(sets, key=lambda s: len(s & remaining))
|
||||
chosen.append(best)
|
||||
remaining -= best
|
||||
return chosen
|
||||
```
|
||||
|
||||
### LLM prompt for MECE plan
|
||||
```python
|
||||
prompt = """
|
||||
Decompose the task into MECE subtasks:
|
||||
- Subtasks must NOT overlap (ME).
|
||||
- Subtasks must cover the full task (CE).
|
||||
- Output JSON list. Verify by sketching the union set.
|
||||
Task: {task}
|
||||
"""
|
||||
```
|
||||
|
||||
### MECE + Pareto (80/20 prioritization)
|
||||
```python
|
||||
def mece_pareto(buckets, values, top=0.8):
|
||||
sorted_buckets = sorted(zip(buckets, values), key=lambda x: -x[1])
|
||||
cum, picked = 0, []
|
||||
for b, v in sorted_buckets:
|
||||
picked.append(b); cum += v
|
||||
if cum >= top * sum(values): break
|
||||
return picked
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Decomposition axis |
|
||||
|---|---|
|
||||
| Revenue analysis | P × Q × M |
|
||||
| Cost analysis | Fixed vs Variable |
|
||||
| Customer | New vs Existing |
|
||||
| Process | Stage gates |
|
||||
| Bug triage | Severity × Component |
|
||||
|
||||
**기본값**: Quantitative MECE (numerical sum-check 가능).
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Mental_Models|Mental Models]] · [[Pyramid Principle]]
|
||||
- 변형: [[Logic Trees]] · [[Issue Tree]]
|
||||
- 응용: [[Root Cause Analysis]]
|
||||
- Adjacent: [[Decision Theory]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: Task decomposition, structured analysis, taxonomy design, agent planning.
|
||||
**언제 X**: Highly entangled / coupled systems where clean partition is impossible.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Pseudo-MECE**: 매 표면 MECE이나 매 실제 overlap.
|
||||
- **Forced exhaustiveness**: "Other" 버킷으로 매 모든 잔여 처리.
|
||||
- **Wrong axis**: 매 분석 목적과 무관한 축.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Minto "The Pyramid Principle"; Rasiel "The McKinsey Way").
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — MECE conditions + validators |
|
||||
@@ -0,0 +1,127 @@
|
||||
---
|
||||
id: wiki-2026-0508-neural-ignition
|
||||
title: Neural Ignition
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Neural-Ignition, Global-Ignition, Conscious-Access]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.85
|
||||
verification_status: applied
|
||||
tags: [neuroscience, consciousness, global-workspace, attention, cognitive-neuroscience]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: mne-nilearn
|
||||
---
|
||||
|
||||
# Neural Ignition
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 자극이 의식에 진입하는 순간 전체 뇌가 점화된다"**. Dehaene-Changeux Global Neuronal Workspace theory의 매 핵심 phenomenon — 매 sub-threshold 처리가 매 frontoparietal network의 non-linear all-or-none 활성화로 전이된다. 2026 LLM consciousness 논쟁에서 매 reference 모델로 자주 인용.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 특성
|
||||
- **All-or-none**: 매 sub-threshold → ignition 임계 초과 시 매 전역 활성.
|
||||
- **Late, large-amplitude**: P300 / late slow wave (300-500 ms post-stimulus).
|
||||
- **Long-distance synchrony**: gamma/beta cross-frequency coupling.
|
||||
- **Reportable**: 매 ignition된 정보만 self-report 가능 (per GNW).
|
||||
|
||||
### 매 메커니즘 (GNW)
|
||||
- Local processors → workspace neuron(layer 5 pyramidal) 경쟁.
|
||||
- Top-down amplification: prefrontal/parietal feedback.
|
||||
- Inhibitory winner-take-all.
|
||||
|
||||
### 매 응용
|
||||
1. Anesthesia depth monitor (PCI, perturbational complexity).
|
||||
2. Vegetative/MCS patient assessment.
|
||||
3. Subliminal vs supraliminal masking experiments.
|
||||
4. AI consciousness benchmarks (GWT-inspired).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### EEG ERP analysis (MNE)
|
||||
```python
|
||||
import mne
|
||||
epochs = mne.Epochs(raw, events, tmin=-0.2, tmax=0.8,
|
||||
baseline=(None, 0), preload=True)
|
||||
evoked = epochs.average()
|
||||
evoked.plot(picks=['Pz']) # P300 ignition signature
|
||||
```
|
||||
|
||||
### Phase-locking value (long-range sync)
|
||||
```python
|
||||
import numpy as np
|
||||
def plv(sig1, sig2):
|
||||
phase_diff = np.angle(sig1) - np.angle(sig2)
|
||||
return np.abs(np.exp(1j * phase_diff).mean())
|
||||
```
|
||||
|
||||
### PCI (Perturbational Complexity Index)
|
||||
```python
|
||||
from sklearn.cluster import KMeans
|
||||
def pci(tms_eeg_response):
|
||||
binary = (tms_eeg_response > threshold).astype(int)
|
||||
return lempel_ziv_complexity(binary.flatten())
|
||||
```
|
||||
|
||||
### Neural mass model (Wilson-Cowan ignition)
|
||||
```python
|
||||
def wilson_cowan(E, I, P, dt=1e-3, tau_e=10, tau_i=20):
|
||||
dE = (-E + sigmoid(c1*E - c2*I + P)) / tau_e
|
||||
dI = (-I + sigmoid(c3*E - c4*I)) / tau_i
|
||||
return E + dt*dE, I + dt*dI
|
||||
```
|
||||
|
||||
### Detection of ignition events
|
||||
```python
|
||||
def detect_ignition(signal, fs, win_ms=200, k=3):
|
||||
win = int(fs * win_ms / 1000)
|
||||
rolling = np.lib.stride_tricks.sliding_window_view(signal, win)
|
||||
amp = np.abs(rolling).mean(-1)
|
||||
return amp > amp.mean() + k * amp.std()
|
||||
```
|
||||
|
||||
### Cross-frequency coupling
|
||||
```python
|
||||
def pac(low_phase, high_amp):
|
||||
return np.abs((high_amp * np.exp(1j*low_phase)).mean())
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| Question | Method |
|
||||
|---|---|
|
||||
| Conscious access? | P300 / late wave + report |
|
||||
| Anesthesia depth | PCI |
|
||||
| Network ignition | Phase-locking, fMRI distance |
|
||||
| Local vs global | Granger causality, DCM |
|
||||
|
||||
**기본값**: ERP P300 + frontoparietal sync as joint signature.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Global-Workspace-Theory]] · [[Cognitive Neuroscience of Flow]]
|
||||
- 변형: [[Conscious-Access]]
|
||||
- Adjacent: [[Cross-Frequency Coupling (CFC)]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: Consciousness modeling, EEG ignition analysis, GWT-inspired AI architecture.
|
||||
**언제 X**: Pure perceptual processing without report (use V1 models).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Ignition = activity 동치**: 매 baseline 활성과 매 구분 필요.
|
||||
- **Single-area ignition**: 매 GNW는 매 distributed 정의.
|
||||
- **Subjective report 의존**: 매 no-report paradigm 도입 권장.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Dehaene "Consciousness and the Brain"; Mashour et al. 2020).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Ignition signatures + EEG/PCI patterns |
|
||||
@@ -0,0 +1,121 @@
|
||||
---
|
||||
id: wiki-2026-0508-noise
|
||||
title: Noise
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Noise, 노이즈, Random-Noise]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
verification_status: applied
|
||||
tags: [noise, signals, data-quality, information-theory, statistics]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: numpy
|
||||
---
|
||||
|
||||
# Noise
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 signal은 noise와 함께 살아간다"**. Noise는 measurement·channel·process에 섞이는 unwanted variation으로, 매 statistical structure (Gaussian, Poisson, 1/f 등)을 가진다. 2026 ML 시대에서도 매 denoising diffusion model의 핵심 도구로 부활.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 분류 (by spectrum)
|
||||
- **White noise**: flat power spectrum, 매 사실상 i.i.d.
|
||||
- **Pink (1/f) noise**: 매 자연계 보편 — neural firing, music, finance.
|
||||
- **Brownian (1/f²)**: 매 random walk integral.
|
||||
- **Shot noise (Poisson)**: 매 photon counting, low-light imaging.
|
||||
- **Quantization noise**: ADC bit depth 한계.
|
||||
|
||||
### 매 noise model
|
||||
- Additive: y = x + n (대부분 가정).
|
||||
- Multiplicative: y = x · n (speckle, fading).
|
||||
- Convolutive: 매 reverberation.
|
||||
|
||||
### 매 응용
|
||||
1. Denoising diffusion (Stable Diffusion 3, FLUX) — noise를 학습 시그널로 사용.
|
||||
2. Differential privacy — Laplace/Gaussian noise 추가.
|
||||
3. Stochastic optimization — SGD의 noise가 generalization 도움.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Gaussian noise 추가
|
||||
```python
|
||||
import numpy as np
|
||||
def add_gaussian(x, sigma=0.1):
|
||||
return x + np.random.normal(0, sigma, x.shape)
|
||||
```
|
||||
|
||||
### Pink noise 생성 (Voss-McCartney)
|
||||
```python
|
||||
def pink_noise(n, num_sources=16):
|
||||
array = np.zeros((num_sources, n))
|
||||
for i in range(num_sources):
|
||||
step = 2 ** i
|
||||
array[i, ::step] = np.random.randn((n + step - 1) // step)
|
||||
return array.sum(axis=0)
|
||||
```
|
||||
|
||||
### SNR 계산
|
||||
```python
|
||||
def snr_db(signal, noise):
|
||||
return 10 * np.log10(np.var(signal) / np.var(noise))
|
||||
```
|
||||
|
||||
### Wiener filter (optimal linear denoise)
|
||||
```python
|
||||
from scipy.signal import wiener
|
||||
denoised = wiener(noisy, mysize=5)
|
||||
```
|
||||
|
||||
### DP-noise (differential privacy)
|
||||
```python
|
||||
def laplace_dp(value, sensitivity, epsilon):
|
||||
return value + np.random.laplace(0, sensitivity / epsilon)
|
||||
```
|
||||
|
||||
### Diffusion forward process
|
||||
```python
|
||||
def forward_diffuse(x0, t, betas):
|
||||
alpha_bar = np.cumprod(1 - betas)[t]
|
||||
eps = np.random.randn(*x0.shape)
|
||||
return np.sqrt(alpha_bar) * x0 + np.sqrt(1 - alpha_bar) * eps, eps
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Sensor 측정 | Gaussian assumption + Kalman |
|
||||
| Photon-limited | Poisson MLE |
|
||||
| Privacy preserve | Laplace/Gaussian DP |
|
||||
| Generative model | Diffusion (DDPM/EDM) |
|
||||
|
||||
**기본값**: Additive Gaussian (most analyzable).
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Entropy in Information Theory|Information Theory]] · [[Statistics]]
|
||||
- 응용: [[Kalman-Filter-and-State-Tracking]] · [[Differential-Privacy]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: Data augmentation, robustness training, generative modeling, privacy.
|
||||
**언제 X**: Deterministic exact computation 필요 시.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Noise blindness**: noise model 가정 없이 deterministic 처리.
|
||||
- **SNR 무시**: low-SNR 데이터로 high-precision claim.
|
||||
- **Whiteness 가정**: 매 실제는 colored noise인데 white로 모델링.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Papoulis "Probability, Random Variables, and Stochastic Processes").
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Noise taxonomy + DP/diffusion patterns |
|
||||
@@ -0,0 +1,202 @@
|
||||
---
|
||||
id: wiki-2026-0508-ontology
|
||||
title: Ontology
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Formal Ontology, Knowledge Ontology, Domain Model]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [knowledge-representation, semantic-web, philosophy, AI]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python/turtle
|
||||
framework: rdflib/owlready2
|
||||
---
|
||||
|
||||
# Ontology
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 specification of a conceptualization (Gruber 1993) — 매 domain 의 entity, class, relation 의 formal definition"**. Aristotle 의 categories 에서 출발, Tim Berners-Lee 의 Semantic Web (RDF/OWL) 으로 web-scale 구현. 매 2026 의 사용처: knowledge graph (Wikidata, Google KG), biomedical (Gene Ontology, SNOMED CT), enterprise data fabric, LLM 의 retrieval-augmented generation grounding.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 핵심 구성요소
|
||||
- **Class (Concept)**: 매 entity type (e.g., Person, Drug).
|
||||
- **Individual (Instance)**: 매 구체적 entity (e.g., :alice).
|
||||
- **Property**: 매 entity 간 또는 entity-literal 의 binary relation.
|
||||
- **ObjectProperty**: 매 entity → entity (e.g., :hasParent).
|
||||
- **DatatypeProperty**: 매 entity → literal (e.g., :hasAge xsd:int).
|
||||
- **Axiom**: 매 logical statement (subClassOf, equivalentClass, disjointWith).
|
||||
- **Hierarchy**: 매 taxonomy (is-a) + partonomy (part-of).
|
||||
|
||||
### 매 stack
|
||||
- **RDF**: 매 triple (subject, predicate, object) — graph data model.
|
||||
- **RDFS**: 매 lightweight schema (subClassOf, domain, range).
|
||||
- **OWL 2**: 매 description logic 기반 — 매 SROIQ(D), reasoning 가능.
|
||||
- **SPARQL**: 매 query language (SQL for RDF).
|
||||
- **SHACL**: 매 shape-based validation.
|
||||
|
||||
### 매 응용
|
||||
1. Wikidata, DBpedia (general knowledge graph).
|
||||
2. Gene Ontology, SNOMED CT, UMLS (biomedical).
|
||||
3. schema.org (web markup, Google rich results).
|
||||
4. Enterprise: data catalogs (Collibra, Atlan).
|
||||
5. LLM grounding (GraphRAG, knowledge-graph augmented retrieval).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Turtle (RDF/OWL syntax)
|
||||
```turtle
|
||||
@prefix : <http://example.org/> .
|
||||
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
||||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||
|
||||
:Person a owl:Class .
|
||||
:Drug a owl:Class .
|
||||
:Antibiotic rdfs:subClassOf :Drug .
|
||||
|
||||
:hasPrescribed a owl:ObjectProperty ;
|
||||
rdfs:domain :Person ;
|
||||
rdfs:range :Drug .
|
||||
|
||||
:alice a :Person ;
|
||||
:hasPrescribed :amoxicillin .
|
||||
:amoxicillin a :Antibiotic .
|
||||
```
|
||||
|
||||
### rdflib (Python) — load + query
|
||||
```python
|
||||
from rdflib import Graph
|
||||
|
||||
g = Graph()
|
||||
g.parse("ontology.ttl", format="turtle")
|
||||
|
||||
# SPARQL: who was prescribed an antibiotic?
|
||||
q = """
|
||||
PREFIX : <http://example.org/>
|
||||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||
SELECT ?person ?drug WHERE {
|
||||
?person :hasPrescribed ?drug .
|
||||
?drug a/rdfs:subClassOf* :Antibiotic .
|
||||
}
|
||||
"""
|
||||
for row in g.query(q):
|
||||
print(row.person, row.drug)
|
||||
```
|
||||
|
||||
### owlready2 (OWL with reasoning)
|
||||
```python
|
||||
from owlready2 import *
|
||||
|
||||
onto = get_ontology("http://example.org/onto.owl")
|
||||
with onto:
|
||||
class Person(Thing): pass
|
||||
class Drug(Thing): pass
|
||||
class Antibiotic(Drug): pass
|
||||
class hasPrescribed(ObjectProperty):
|
||||
domain = [Person]
|
||||
range = [Drug]
|
||||
|
||||
alice = Person("alice")
|
||||
amox = Antibiotic("amoxicillin")
|
||||
alice.hasPrescribed.append(amox)
|
||||
|
||||
sync_reasoner_pellet() # 매 inference: amox is Drug (subclass)
|
||||
```
|
||||
|
||||
### SHACL validation
|
||||
```turtle
|
||||
:PersonShape a sh:NodeShape ;
|
||||
sh:targetClass :Person ;
|
||||
sh:property [
|
||||
sh:path :hasAge ;
|
||||
sh:datatype xsd:integer ;
|
||||
sh:minInclusive 0 ;
|
||||
sh:maxInclusive 150 ;
|
||||
] .
|
||||
```
|
||||
|
||||
### LLM + ontology RAG (GraphRAG-style)
|
||||
```python
|
||||
def graph_rag(question, llm, kg):
|
||||
# 1. Extract entities from question
|
||||
entities = llm.extract_entities(question)
|
||||
# 2. SPARQL: get neighborhood
|
||||
facts = []
|
||||
for e in entities:
|
||||
facts.extend(kg.query(f"""
|
||||
SELECT ?p ?o WHERE {{ <{e}> ?p ?o }} LIMIT 50
|
||||
"""))
|
||||
# 3. Answer with grounded context
|
||||
return llm.generate(question, context=facts)
|
||||
```
|
||||
|
||||
### Ontology alignment (string + embedding)
|
||||
```python
|
||||
from sentence_transformers import SentenceTransformer, util
|
||||
|
||||
def align_classes(onto_a_labels, onto_b_labels, threshold=0.85):
|
||||
model = SentenceTransformer("all-mpnet-base-v2")
|
||||
emb_a = model.encode(onto_a_labels, convert_to_tensor=True)
|
||||
emb_b = model.encode(onto_b_labels, convert_to_tensor=True)
|
||||
sim = util.cos_sim(emb_a, emb_b)
|
||||
matches = []
|
||||
for i, row in enumerate(sim):
|
||||
j = row.argmax().item()
|
||||
if row[j] > threshold:
|
||||
matches.append((onto_a_labels[i], onto_b_labels[j], row[j].item()))
|
||||
return matches
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| simple tagging / faceting | flat taxonomy |
|
||||
| domain modeling, no reasoning | RDFS |
|
||||
| reasoning required (subsumption, equivalence) | OWL 2 + reasoner |
|
||||
| validation rules | SHACL |
|
||||
| massive scale, low schema | property graph (Neo4j) |
|
||||
| LLM grounding | knowledge graph + GraphRAG |
|
||||
|
||||
**기본값**: 매 enterprise → SKOS + RDFS; 매 reasoning critical → OWL 2 EL/QL profile.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Knowledge Graph]] · [[Semantic-Web]] · [[Knowledge Representation]]
|
||||
- 변형: [[OWL]]
|
||||
- 응용: [[GraphRAG]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 hallucination 감소를 위한 grounding, 매 enterprise data fabric, 매 named-entity resolution against canonical IDs.
|
||||
**언제 X**: 매 small unstructured task — overhead 큼. 매 ontology engineering 비용 > 가치.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **OWL Full 사용**: 매 reasoning undecidable. 매 OWL 2 DL profile (EL/QL/RL) 사용.
|
||||
- **subClassOf 의 오용** as instanceOf: 매 class hierarchy ≠ instance membership.
|
||||
- **No URI versioning**: 매 schema 진화 시 breakage. 매 owl:versionIRI 사용.
|
||||
- **Free-text label only, no canonical URI**: 매 alignment 불가능.
|
||||
- **Reasoning everything** every query: 매 비싸다 — materialize 후 cache.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Gruber 1993; W3C OWL 2 spec; *Foundations of Semantic Web Technologies* Hitzler et al.; GraphRAG Microsoft 2024).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Ontology FULL with RDF/OWL/SHACL/GraphRAG patterns |
|
||||
|
||||
## 🛠️ 적용 사례 (Applied in summary)
|
||||
|
||||
<!-- CODE-GROUNDING:START -->
|
||||
### 🔎 코드베이스 근거 (자동 추출 — E:\Wiki 레포)
|
||||
**실제 구현/사용 위치:**
|
||||
- `connectai/src/features/secondBrainTrace.ts:223` — [Omitted long matching line]
|
||||
|
||||
_자동 생성: code_grounding.mjs · 재실행 시 갱신됨_
|
||||
<!-- CODE-GROUNDING:END -->
|
||||
@@ -0,0 +1,157 @@
|
||||
---
|
||||
id: wiki-2026-0508-operations-research
|
||||
title: Operations Research
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [OR, Management Science, Decision Science]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [optimization, decision-science, mathematical-programming]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: PuLP/Gurobi/OR-Tools
|
||||
---
|
||||
|
||||
# Operations Research
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 decision-making을 mathematical model로"**. 매 WWII 군사 logistics에서 시작된 OR은 매 LP/MIP/network/queueing/simulation으로 확장, 매 2026 현재 supply chain·routing·scheduling·revenue management의 backbone이며 Gurobi 12 / OR-Tools 9.10 / Mosek가 매 industrial workhorse.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 4 sub-disciplines
|
||||
- **Mathematical Programming**: LP, MIP, NLP, SOCP, SDP.
|
||||
- **Network Models**: shortest path, max flow, min-cost flow, assignment.
|
||||
- **Stochastic Models**: queueing (M/M/c), Markov chains, MDP.
|
||||
- **Simulation**: discrete event, Monte Carlo, agent-based.
|
||||
|
||||
### 매 LP duality
|
||||
- Primal min cᵀx s.t. Ax ≥ b, x ≥ 0.
|
||||
- Dual max bᵀy s.t. Aᵀy ≤ c, y ≥ 0.
|
||||
- Strong duality: optimal values equal (Slater's condition).
|
||||
- Dual = shadow prices of constraints.
|
||||
|
||||
### 매 응용
|
||||
1. **Supply chain**: facility location, inventory, transportation.
|
||||
2. **Airline**: crew scheduling, fleet assignment, revenue management.
|
||||
3. **Energy**: unit commitment, economic dispatch.
|
||||
4. **Healthcare**: OR scheduling, ambulance routing.
|
||||
5. **ML 교차**: structured prediction, MIP-based interpretability.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Linear Programming with PuLP
|
||||
```python
|
||||
import pulp
|
||||
prob = pulp.LpProblem("Diet", pulp.LpMinimize)
|
||||
x1 = pulp.LpVariable("bread", lowBound=0)
|
||||
x2 = pulp.LpVariable("milk", lowBound=0)
|
||||
prob += 2*x1 + 3*x2 # cost
|
||||
prob += 4*x1 + 3*x2 >= 100 # protein
|
||||
prob += 2*x1 + 5*x2 >= 80 # vitamin
|
||||
prob.solve(pulp.GUROBI_CMD(msg=0))
|
||||
print(x1.varValue, x2.varValue, pulp.value(prob.objective))
|
||||
```
|
||||
|
||||
### MIP — Facility Location
|
||||
```python
|
||||
from gurobipy import Model, GRB, quicksum
|
||||
m = Model()
|
||||
y = m.addVars(facilities, vtype=GRB.BINARY, name="open")
|
||||
x = m.addVars(facilities, customers, lb=0, name="ship")
|
||||
m.setObjective(
|
||||
quicksum(f[i]*y[i] for i in facilities) +
|
||||
quicksum(c[i,j]*x[i,j] for i in facilities for j in customers),
|
||||
GRB.MINIMIZE)
|
||||
m.addConstrs(quicksum(x[i,j] for i in facilities) == d[j] for j in customers)
|
||||
m.addConstrs(x[i,j] <= d[j]*y[i] for i in facilities for j in customers)
|
||||
m.optimize()
|
||||
```
|
||||
|
||||
### VRP with OR-Tools
|
||||
```python
|
||||
from ortools.constraint_solver import pywrapcp, routing_enums_pb2
|
||||
manager = pywrapcp.RoutingIndexManager(len(dist), num_vehicles, depot)
|
||||
routing = pywrapcp.RoutingModel(manager)
|
||||
def cb(i, j): return dist[manager.IndexToNode(i)][manager.IndexToNode(j)]
|
||||
idx = routing.RegisterTransitCallback(cb)
|
||||
routing.SetArcCostEvaluatorOfAllVehicles(idx)
|
||||
params = pywrapcp.DefaultRoutingSearchParameters()
|
||||
params.first_solution_strategy = routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC
|
||||
solution = routing.SolveWithParameters(params)
|
||||
```
|
||||
|
||||
### Min-Cost Flow (NetworkX)
|
||||
```python
|
||||
import networkx as nx
|
||||
G = nx.DiGraph()
|
||||
G.add_edge('s', 'a', capacity=4, weight=2)
|
||||
G.add_edge('s', 'b', capacity=2, weight=4)
|
||||
G.add_edge('a', 't', capacity=3, weight=1)
|
||||
G.add_edge('b', 't', capacity=5, weight=3)
|
||||
flow_cost, flow_dict = nx.network_simplex(G)
|
||||
```
|
||||
|
||||
### M/M/c queue analysis
|
||||
```python
|
||||
import math
|
||||
def mmc(lam, mu, c):
|
||||
rho = lam/(c*mu)
|
||||
p0_inv = sum((c*rho)**n / math.factorial(n) for n in range(c))
|
||||
p0_inv += (c*rho)**c / (math.factorial(c)*(1-rho))
|
||||
p0 = 1/p0_inv
|
||||
Lq = p0 * (c*rho)**c * rho / (math.factorial(c)*(1-rho)**2)
|
||||
Wq = Lq/lam
|
||||
return {'utilization': rho, 'Lq': Lq, 'Wq': Wq}
|
||||
```
|
||||
|
||||
### Stochastic 2-stage LP
|
||||
```python
|
||||
# x: first-stage, y_s: scenario s recourse
|
||||
# min cᵀx + Σ pₛ qᵀyₛ s.t. Tx + Wyₛ = hₛ
|
||||
# Benders decomposition으로 solve 매 large-scale.
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Continuous, linear | LP (simplex/interior point) |
|
||||
| Discrete decisions | MIP (branch & cut) |
|
||||
| Nonconvex | Global solver (BARON, Gurobi 12) or heuristic |
|
||||
| Stochastic | 2-stage SP / robust optimization |
|
||||
| Sequential decision | MDP / RL |
|
||||
| Combinatorial/routing | OR-Tools CP-SAT |
|
||||
|
||||
**기본값**: Gurobi 12 (commercial) or HiGHS (open-source) for LP/MIP; OR-Tools CP-SAT for combinatorial.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Optimization]] · [[Mathematical-Programming]]
|
||||
- 변형: [[Linear-Programming]] · [[Integer-Programming]]
|
||||
- 응용: [[Supply-Chain]]
|
||||
- Adjacent: [[Reinforcement-Learning]] · [[Combinatorial-Optimization]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 problem formulation translation (NL→model), constraint extraction, MIP warm-start heuristics, post-hoc 해석.
|
||||
**언제 X**: 매 numerical solving 자체 (LLM은 solver 호출 매 wrapping role).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Pure LLM solving**: 매 LLM은 OR solver 아님. 매 Gurobi/OR-Tools 매 사용.
|
||||
- **Ignoring duality**: 매 shadow price 매 sensitivity analysis 의 핵심.
|
||||
- **Over-tight constraints**: 매 infeasibility → IIS (irreducible inconsistent subsystem) 매 분석.
|
||||
- **Symmetry-blind MIP**: 매 symmetry breaking constraint 매 추가, branch tree 매 collapse.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Hillier & Lieberman 11e, Bertsimas & Tsitsiklis, Gurobi docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full OR overview with LP/MIP/VRP/queueing patterns |
|
||||
@@ -0,0 +1,125 @@
|
||||
---
|
||||
id: wiki-2026-0508-operator-theory
|
||||
title: Operator Theory
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Operator-Theory, 작용소-이론, Functional-Analysis-Operators]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [math, functional-analysis, linear-algebra, hilbert-space, spectral-theory]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: scipy-linalg
|
||||
---
|
||||
|
||||
# Operator Theory
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 행렬을 무한차원으로 확장한 게 operator"**. Hilbert/Banach 공간의 linear map을 다루며, 매 spectral theorem·compact operators·C*-algebras를 통해 quantum mechanics·PDE·signal processing을 통합한다. 2026 ML에서는 매 Koopman operator로 dynamical system 학습에 부활.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 분류
|
||||
- **Bounded vs Unbounded**: 매 norm 제한 여부.
|
||||
- **Compact**: 매 unit ball을 relatively compact set으로 보내는 operator.
|
||||
- **Self-adjoint**: T = T*; 매 eigenvalue 실수.
|
||||
- **Unitary**: T*T = I; 매 inner product 보존.
|
||||
- **Normal**: TT* = T*T; 매 spectral theorem 적용 가능.
|
||||
|
||||
### 매 spectral 분해
|
||||
- Finite-dim: eigenvalue decomposition.
|
||||
- Compact self-adjoint: countable eigenvalues + ON eigenvectors (Hilbert-Schmidt).
|
||||
- Bounded self-adjoint: spectral measure dE(λ); T = ∫λ dE(λ).
|
||||
|
||||
### 매 응용
|
||||
1. Quantum mechanics — observable = self-adjoint operator.
|
||||
2. PDE — Laplacian, Schrödinger evolution.
|
||||
3. Koopman/Perron-Frobenius — dynamical system linearization.
|
||||
4. RKHS / kernel methods — integral operator.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Bounded operator (Python class)
|
||||
```python
|
||||
import numpy as np
|
||||
class IntegralOperator:
|
||||
def __init__(self, kernel, grid):
|
||||
self.K = kernel(grid[:, None], grid[None, :]) * (grid[1]-grid[0])
|
||||
def __call__(self, f):
|
||||
return self.K @ f
|
||||
```
|
||||
|
||||
### Self-adjointness check
|
||||
```python
|
||||
def is_self_adjoint(A, tol=1e-10):
|
||||
return np.allclose(A, A.conj().T, atol=tol)
|
||||
```
|
||||
|
||||
### Spectral decomposition
|
||||
```python
|
||||
A = np.array([[2., 1.], [1., 3.]])
|
||||
w, V = np.linalg.eigh(A) # self-adjoint → real eigenvalues
|
||||
# A = V diag(w) V^T
|
||||
```
|
||||
|
||||
### Functional calculus (matrix exp)
|
||||
```python
|
||||
from scipy.linalg import expm
|
||||
U = expm(-1j * H * t) # quantum time evolution
|
||||
```
|
||||
|
||||
### Koopman operator (data-driven)
|
||||
```python
|
||||
def dmd(X, Xp, r=10):
|
||||
U, S, Vt = np.linalg.svd(X, full_matrices=False)
|
||||
Ur, Sr, Vr = U[:, :r], S[:r], Vt[:r].conj().T
|
||||
A_tilde = Ur.conj().T @ Xp @ Vr / Sr
|
||||
eigs, W = np.linalg.eig(A_tilde)
|
||||
modes = Xp @ Vr / Sr @ W
|
||||
return eigs, modes
|
||||
```
|
||||
|
||||
### RKHS kernel as integral operator
|
||||
```python
|
||||
def rkhs_eval(alpha, X, x_new, kernel):
|
||||
return sum(a * kernel(xi, x_new) for a, xi in zip(alpha, X))
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 문제 | Operator class |
|
||||
|---|---|
|
||||
| Quantum observable | Self-adjoint, possibly unbounded |
|
||||
| Markov chain | Stochastic (positivity-preserving) |
|
||||
| Signal filter | Bounded, possibly unitary |
|
||||
| Dynamics learning | Koopman (compact approx) |
|
||||
|
||||
**기본값**: Self-adjoint compact (가장 잘 분석됨).
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Linear-Algebra-Foundations]]
|
||||
- Adjacent: [[Hilbert-Space]] · [[Eigenvalues-and-Eigenvectors]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: Infinite-dim linear systems, PDE/quantum modeling, operator-learning (FNO, DeepONet).
|
||||
**언제 X**: Pure finite-dim — 매 그냥 matrix theory로 충분.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Unbounded operator를 bounded로 가정**: 매 domain 무시.
|
||||
- **Non-normal에 spectral theorem**: 매 잘못 적용.
|
||||
- **Truncation 후 boundary effect 무시**.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Reed & Simon "Methods of Modern Mathematical Physics" Vol. 1).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Operator classes + Koopman pattern |
|
||||
@@ -0,0 +1,176 @@
|
||||
---
|
||||
id: wiki-2026-0508-optimal-control-theory
|
||||
title: Optimal Control Theory
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [OCT, Dynamic Optimization]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [control, optimization, dynamic-programming, mpc]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: CasADi/CVXPY
|
||||
---
|
||||
|
||||
# Optimal Control Theory
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 minimize cost over trajectory subject to dynamics"**. 매 OCT는 매 Pontryagin (PMP), Bellman (DP/HJB), Calculus of Variations 의 세 lens 통합, 매 LQR / MPC / iLQR / DDP 가 매 핵심 algorithm, 매 2026 robotics·autonomous driving·aerospace·battery management·RL 의 매 underlying mathematical foundation.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 formulation
|
||||
- min_u ∫₀ᵀ L(x,u,t)dt + Φ(x(T))
|
||||
- s.t. ẋ = f(x,u,t), x(0)=x₀, c(x,u) ≤ 0.
|
||||
|
||||
### 매 3 approaches
|
||||
- **Variational / PMP**: Hamiltonian H = L + λᵀf, costate λ̇ = -∂H/∂x, optimality ∂H/∂u = 0.
|
||||
- **Dynamic Programming**: V(x,t), Bellman / HJB ∂V/∂t + min_u[L + ∇Vᵀf] = 0.
|
||||
- **Direct methods**: discretize → NLP (transcription).
|
||||
|
||||
### 매 LQR (linear-quadratic, 매 closed form)
|
||||
- ẋ = Ax + Bu, J = ∫(xᵀQx + uᵀRu)dt.
|
||||
- u* = -Kx, K = R⁻¹BᵀP.
|
||||
- P from algebraic Riccati: AᵀP + PA - PBR⁻¹BᵀP + Q = 0.
|
||||
|
||||
### 매 MPC (receding horizon)
|
||||
1. Solve N-step OCP at xₜ.
|
||||
2. Apply only u₀.
|
||||
3. Re-solve at xₜ₊₁.
|
||||
4. Handles constraints + nonlinearity.
|
||||
|
||||
### 매 응용
|
||||
1. Quadrotor / drone trajectory.
|
||||
2. Autonomous driving (lane keep, overtake).
|
||||
3. Battery / HVAC / grid optimization.
|
||||
4. Manipulator motion planning.
|
||||
5. RL connection (Bellman ↔ Q-learning).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Discrete LQR (steady-state)
|
||||
```python
|
||||
import numpy as np
|
||||
from scipy.linalg import solve_discrete_are
|
||||
def dlqr(A, B, Q, R):
|
||||
P = solve_discrete_are(A, B, Q, R)
|
||||
K = np.linalg.solve(R + B.T @ P @ B, B.T @ P @ A)
|
||||
return K, P
|
||||
K, _ = dlqr(A, B, np.eye(n), 0.1*np.eye(m))
|
||||
u = -K @ x
|
||||
```
|
||||
|
||||
### iLQR for nonlinear
|
||||
```python
|
||||
def ilqr(f, l, lf, x0, u_init, n_iter=50):
|
||||
u = u_init.copy(); T = len(u)
|
||||
for it in range(n_iter):
|
||||
# Forward rollout
|
||||
x = [x0]
|
||||
for t in range(T): x.append(f(x[-1], u[t]))
|
||||
# Backward pass: compute K, k
|
||||
Vx = lf_x(x[-1]); Vxx = lf_xx(x[-1])
|
||||
Ks = []; ks = []
|
||||
for t in reversed(range(T)):
|
||||
fx, fu = jacobians(f, x[t], u[t])
|
||||
lx, lu, lxx, luu, lux = quadratics(l, x[t], u[t])
|
||||
Qx = lx + fx.T @ Vx
|
||||
Qu = lu + fu.T @ Vx
|
||||
Qxx = lxx + fx.T @ Vxx @ fx
|
||||
Quu = luu + fu.T @ Vxx @ fu
|
||||
Qux = lux + fu.T @ Vxx @ fx
|
||||
K = -np.linalg.solve(Quu, Qux)
|
||||
k = -np.linalg.solve(Quu, Qu)
|
||||
Vx = Qx + K.T @ Quu @ k + K.T @ Qu + Qux.T @ k
|
||||
Vxx = Qxx + K.T @ Quu @ K + K.T @ Qux + Qux.T @ K
|
||||
Ks.insert(0, K); ks.insert(0, k)
|
||||
# Forward update u with line search...
|
||||
return u
|
||||
```
|
||||
|
||||
### Nonlinear MPC with CasADi
|
||||
```python
|
||||
import casadi as ca
|
||||
N, dt = 20, 0.1
|
||||
opti = ca.Opti()
|
||||
X = opti.variable(nx, N+1); U = opti.variable(nu, N)
|
||||
x0p = opti.parameter(nx)
|
||||
opti.subject_to(X[:,0] == x0p)
|
||||
cost = 0
|
||||
for k in range(N):
|
||||
cost += ca.mtimes([X[:,k].T, Q, X[:,k]]) + ca.mtimes([U[:,k].T, R, U[:,k]])
|
||||
opti.subject_to(X[:,k+1] == X[:,k] + dt*dynamics(X[:,k], U[:,k]))
|
||||
opti.subject_to(opti.bounded(u_min, U[:,k], u_max))
|
||||
opti.minimize(cost)
|
||||
opti.solver('ipopt')
|
||||
# at runtime:
|
||||
opti.set_value(x0p, current_state); sol = opti.solve()
|
||||
u_apply = sol.value(U[:,0])
|
||||
```
|
||||
|
||||
### Direct collocation transcription
|
||||
```python
|
||||
# Trapezoidal: x_{k+1} = x_k + (dt/2)*(f(x_k,u_k) + f(x_{k+1},u_{k+1}))
|
||||
# 매 NLP variables: [x_0..x_N, u_0..u_{N-1}], constraints: dynamics + bounds.
|
||||
```
|
||||
|
||||
### HJB value iteration (small grids)
|
||||
```python
|
||||
def value_iter(grid, f, l, dt, gamma=0.99, n_iter=500):
|
||||
V = np.zeros(len(grid))
|
||||
for _ in range(n_iter):
|
||||
V_new = np.copy(V)
|
||||
for i, x in enumerate(grid):
|
||||
best = np.inf
|
||||
for u in U_set:
|
||||
x_next = x + dt*f(x, u)
|
||||
j = nearest(grid, x_next)
|
||||
best = min(best, dt*l(x,u) + gamma*V[j])
|
||||
V_new[i] = best
|
||||
V = V_new
|
||||
return V
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Linear, quadratic cost | LQR (closed form) |
|
||||
| Mild nonlinear, no constraints | iLQR / DDP |
|
||||
| Constraints + nonlinearity | Nonlinear MPC (collocation/multiple shooting) |
|
||||
| Long horizon / stochastic | DP / RL (Q-learning, SAC) |
|
||||
| Real-time embedded | Explicit MPC / parametric QP |
|
||||
| Trajectory optimization offline | DIRCOL / SQP |
|
||||
|
||||
**기본값**: linear → LQR; nonlinear with constraints → CasADi + IPOPT MPC; 매 long-horizon stochastic → RL.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Control-Theory]] · [[Optimization]]
|
||||
- 응용: [[Robotics]] · [[Autonomous-Driving]]
|
||||
- Adjacent: [[Reinforcement-Learning]] · [[Dynamic-Programming]] · [[데이터 사이언스 및 ML 엔지니어링|Bellman-Equation]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: cost-function design, MPC weight tuning rationale, Pontryagin/HJB derivation 매 explanation.
|
||||
**언제 X**: real-time solving (CasADi/acados/HPIPM 매 사용).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **LQR on nonlinear**: 매 large-deviation regime — 매 iLQR/MPC 매 사용.
|
||||
- **No terminal cost / set in MPC**: 매 stability lost.
|
||||
- **Wrong Q/R scaling**: 매 unit-mismatch — 매 normalize states first.
|
||||
- **Ignoring constraints in CofV**: 매 PMP+constraint 매 KKT-style augmentation 매 필요.
|
||||
- **Pure RL when MPC works**: 매 model-known + smooth → MPC 매 sample-efficient.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Bertsekas "DP & OC", Bryson & Ho, Borrelli "Predictive Control").
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — LQR/iLQR/MPC/HJB unified |
|
||||
@@ -0,0 +1,195 @@
|
||||
---
|
||||
id: wiki-2026-0508-optimization-algorithms
|
||||
title: Optimization Algorithms
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Numerical Optimization, Mathematical Programming]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [optimization, numerics, ml, operations-research]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: scipy/jax/cvxpy
|
||||
---
|
||||
|
||||
# Optimization Algorithms
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 objective f(x) 의 minimum (또는 max) 을 찾는 numerical procedure"**. Newton 1690s gradient 발상에서 시작, 매 1947 Dantzig simplex (LP), 매 1986 backprop (Rumelhart) 으로 ML 에 폭발적 확산. 매 2026 의 landscape: convex (CVXPY/Mosek), nonconvex first-order (AdamW, Lion, Sophia), second-order approximations (Shampoo, K-FAC), black-box (BO, CMA-ES), discrete (MILP via Gurobi/HiGHS).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 problem class
|
||||
- **Convex** (LP, QP, SDP): 매 global optimum 보장. 매 CVXPY/Mosek/SCS.
|
||||
- **Smooth nonconvex**: 매 deep learning loss. 매 first-order (SGD, Adam, Lion).
|
||||
- **Nonsmooth**: 매 L1 (Lasso) — proximal methods.
|
||||
- **Constrained**: KKT conditions, augmented Lagrangian, interior point, projected gradient.
|
||||
- **Discrete**: ILP, combinatorial — branch-and-bound, MCTS.
|
||||
- **Black-box (no gradient)**: BO, CMA-ES, Nelder-Mead.
|
||||
|
||||
### 매 method family
|
||||
- **Zeroth-order**: Nelder-Mead, BO, CMA-ES, evolutionary.
|
||||
- **First-order**: GD, momentum, Nesterov, Adam, AdamW, Lion, RMSProp.
|
||||
- **Quasi-Newton**: BFGS, L-BFGS — Hessian approximation.
|
||||
- **Second-order**: Newton, Gauss-Newton, Levenberg-Marquardt.
|
||||
- **Approx 2nd-order for DL**: K-FAC, Shampoo, Sophia.
|
||||
- **Trust region**: dogleg, Steihaug.
|
||||
- **Interior point**: LP/QP/SDP barrier methods.
|
||||
|
||||
### 매 응용
|
||||
1. Deep learning (AdamW, Lion, Shampoo).
|
||||
2. Reinforcement learning (PPO step, natural gradient).
|
||||
3. LP/MILP (logistics, scheduling — Gurobi).
|
||||
4. Hyperparameter tuning (Optuna with TPE).
|
||||
5. Robotics trajectory (CHOMP, MPC, iLQR).
|
||||
6. RLHF policy optimization.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### scipy.optimize basic
|
||||
```python
|
||||
from scipy.optimize import minimize
|
||||
import numpy as np
|
||||
|
||||
f = lambda x: (x[0]-1)**2 + 100*(x[1]-x[0]**2)**2 # Rosenbrock
|
||||
res = minimize(f, x0=[0, 0], method="L-BFGS-B")
|
||||
print(res.x, res.fun)
|
||||
```
|
||||
|
||||
### Convex via CVXPY
|
||||
```python
|
||||
import cvxpy as cp
|
||||
|
||||
x = cp.Variable(10)
|
||||
A = np.random.randn(20, 10); b = np.random.randn(20)
|
||||
obj = cp.Minimize(cp.sum_squares(A @ x - b) + 0.1 * cp.norm(x, 1))
|
||||
prob = cp.Problem(obj)
|
||||
prob.solve() # Lasso
|
||||
```
|
||||
|
||||
### PyTorch optimizer (AdamW)
|
||||
```python
|
||||
import torch
|
||||
|
||||
opt = torch.optim.AdamW(model.parameters(), lr=3e-4, weight_decay=0.01,
|
||||
betas=(0.9, 0.95))
|
||||
sched = torch.optim.lr_scheduler.CosineAnnealingLR(opt, T_max=10_000)
|
||||
|
||||
for step, (x, y) in enumerate(loader):
|
||||
opt.zero_grad()
|
||||
loss = criterion(model(x), y)
|
||||
loss.backward()
|
||||
torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)
|
||||
opt.step(); sched.step()
|
||||
```
|
||||
|
||||
### Lion optimizer (2023, memory-efficient)
|
||||
```python
|
||||
class Lion(torch.optim.Optimizer):
|
||||
def __init__(self, params, lr=1e-4, betas=(0.9, 0.99), weight_decay=0.0):
|
||||
super().__init__(params, dict(lr=lr, betas=betas, weight_decay=weight_decay))
|
||||
|
||||
@torch.no_grad()
|
||||
def step(self):
|
||||
for group in self.param_groups:
|
||||
for p in group["params"]:
|
||||
if p.grad is None: continue
|
||||
state = self.state[p]
|
||||
if "exp_avg" not in state: state["exp_avg"] = torch.zeros_like(p)
|
||||
m = state["exp_avg"]
|
||||
b1, b2 = group["betas"]
|
||||
update = (b1*m + (1-b1)*p.grad).sign_()
|
||||
p.mul_(1 - group["lr"] * group["weight_decay"]).add_(update, alpha=-group["lr"])
|
||||
m.mul_(b2).add_(p.grad, alpha=1-b2)
|
||||
```
|
||||
|
||||
### Bayesian Optimization (Optuna TPE)
|
||||
```python
|
||||
import optuna
|
||||
|
||||
def objective(trial):
|
||||
lr = trial.suggest_float("lr", 1e-5, 1e-2, log=True)
|
||||
wd = trial.suggest_float("wd", 1e-6, 1e-1, log=True)
|
||||
return train_and_eval(lr, wd)
|
||||
|
||||
study = optuna.create_study(direction="minimize",
|
||||
sampler=optuna.samplers.TPESampler(seed=42))
|
||||
study.optimize(objective, n_trials=50)
|
||||
```
|
||||
|
||||
### CMA-ES (black-box, robust)
|
||||
```python
|
||||
import cma
|
||||
|
||||
es = cma.CMAEvolutionStrategy(x0=[0]*10, sigma0=0.5,
|
||||
inopts={"maxiter": 200, "verbose": -9})
|
||||
es.optimize(lambda x: sum(xi**2 for xi in x))
|
||||
print(es.result.xbest)
|
||||
```
|
||||
|
||||
### MILP via HiGHS
|
||||
```python
|
||||
from scipy.optimize import linprog, milp, LinearConstraint, Bounds
|
||||
|
||||
# minimize cT x s.t. A_ub x <= b_ub, x integer in [0, 1]
|
||||
c = [-1, -2, -3] # minimize → negate to maximize 1+2+3
|
||||
A = [[1, 1, 1]]; b = [2]
|
||||
res = milp(c=c, constraints=LinearConstraint(A, ub=b),
|
||||
integrality=[1, 1, 1], bounds=Bounds(0, 1))
|
||||
```
|
||||
|
||||
### Trust-region Newton (small dense)
|
||||
```python
|
||||
from scipy.optimize import minimize
|
||||
|
||||
res = minimize(f, x0, jac=grad, hess=hess, method="trust-ncg")
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Algorithm |
|
||||
|---|---|
|
||||
| convex small/medium | CVXPY (auto solver) |
|
||||
| LP/MILP industrial | Gurobi / HiGHS |
|
||||
| smooth small (~100 params) | L-BFGS |
|
||||
| deep learning | AdamW / Lion |
|
||||
| HP tuning (cheap eval) | Random / Grid |
|
||||
| HP tuning (expensive) | Optuna TPE / BoTorch |
|
||||
| black-box noisy | CMA-ES |
|
||||
| 2nd-order for transformers | Shampoo / Sophia |
|
||||
| RL policy | PPO / TRPO (natural gradient) |
|
||||
|
||||
**기본값**: 매 ML training → AdamW; 매 cost-expensive HP → BO; 매 industrial LP/MILP → Gurobi.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Operations-Research]]
|
||||
- 변형: [[Combinatorial Optimization]]
|
||||
- 응용: [[Deep Learning]] · [[Reinforcement Learning]]
|
||||
- Adjacent: [[Gradient Descent]] · [[Adam]] · [[Bayesian Optimization]] · [[CMA-ES]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 PEFT (LoRA) AdamW config, 매 RLHF PPO/DPO step, 매 hyperparameter search via Optuna.
|
||||
**언제 X**: 매 closed-form solution 가능한 단순 LS — np.linalg.lstsq.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **No grad clipping in deep learning**: 매 spike → NaN.
|
||||
- **Adam without weight decay**: 매 use AdamW (decoupled).
|
||||
- **Convex problem 인데 SGD**: 매 CVXPY/Mosek 가 정확하고 빠르다.
|
||||
- **MILP 를 LP relaxation 으로 풀고 round**: 매 infeasibility / suboptimal.
|
||||
- **Black-box BO 를 cheap function 에 사용**: 매 random search 가 빠름.
|
||||
- **No restart in nonconvex**: 매 local min 갇힘. 매 multi-start.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Boyd & Vandenberghe *Convex Optimization*; Nocedal & Wright *Numerical Optimization*; Lion Chen et al. 2023; Sophia 2023; Gurobi/HiGHS docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Optimization Algorithms FULL with AdamW/Lion/CVXPY/Optuna/MILP patterns |
|
||||
@@ -0,0 +1,153 @@
|
||||
---
|
||||
id: wiki-2026-0508-optimization
|
||||
title: Optimization
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Mathematical Optimization, Numerical Optimization]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [optimization, convex, gradient-descent, ml-training]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: PyTorch/JAX/CVXPY
|
||||
---
|
||||
|
||||
# Optimization
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 minimize f(x) subject to constraints"**. 매 optimization은 매 ML/OR/control/finance/engineering 의 universal language이며, 매 2026 LLM 학습은 매 AdamW + cosine schedule + grad clip + mixed precision의 매 standard recipe — 매 convexity·smoothness·stochasticity·constraint structure 가 매 algorithm choice를 결정.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 분류축
|
||||
- **Convex vs Nonconvex**: convex → global guarantee; nonconvex (deep nets) → local + heuristics.
|
||||
- **Smooth vs Nonsmooth**: smooth → gradient; nonsmooth → subgradient / proximal.
|
||||
- **Constrained vs Unconstrained**: KKT, Lagrangian, projection.
|
||||
- **Deterministic vs Stochastic**: full grad vs SGD/Adam.
|
||||
- **First-order vs Second-order**: GD/Adam vs Newton/L-BFGS/K-FAC.
|
||||
|
||||
### 매 핵심 이론
|
||||
- Convexity: f(λx+(1-λ)y) ≤ λf(x)+(1-λ)f(y).
|
||||
- Lipschitz smoothness: ‖∇f(x)-∇f(y)‖ ≤ L‖x-y‖.
|
||||
- Strong convexity μ: convergence rate O((1-μ/L)ᵏ).
|
||||
- KKT conditions: stationarity, primal/dual feasibility, complementary slackness.
|
||||
|
||||
### 매 응용
|
||||
1. ML training (SGD/Adam/Lion/Sophia).
|
||||
2. LP/MIP (Gurobi, HiGHS).
|
||||
3. Optimal control (LQR, MPC).
|
||||
4. Portfolio (Markowitz, Black-Litterman).
|
||||
5. Hyperparameter tuning (Bayesian opt, Optuna).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### SGD with momentum (PyTorch)
|
||||
```python
|
||||
import torch
|
||||
from torch.optim import AdamW
|
||||
from torch.optim.lr_scheduler import CosineAnnealingLR
|
||||
|
||||
opt = AdamW(model.parameters(), lr=3e-4, weight_decay=0.1, betas=(0.9, 0.95))
|
||||
sched = CosineAnnealingLR(opt, T_max=total_steps)
|
||||
for x, y in loader:
|
||||
opt.zero_grad()
|
||||
loss = criterion(model(x), y)
|
||||
loss.backward()
|
||||
torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)
|
||||
opt.step()
|
||||
sched.step()
|
||||
```
|
||||
|
||||
### Convex optimization with CVXPY
|
||||
```python
|
||||
import cvxpy as cp
|
||||
x = cp.Variable(n)
|
||||
prob = cp.Problem(
|
||||
cp.Minimize(cp.sum_squares(A@x - b) + lam*cp.norm1(x)),
|
||||
[x >= 0, cp.sum(x) == 1])
|
||||
prob.solve(solver=cp.MOSEK)
|
||||
```
|
||||
|
||||
### L-BFGS for moderate-scale smooth
|
||||
```python
|
||||
from scipy.optimize import minimize
|
||||
res = minimize(f, x0, jac=grad_f, method='L-BFGS-B',
|
||||
bounds=bounds, options={'ftol': 1e-9})
|
||||
```
|
||||
|
||||
### Proximal gradient (FISTA)
|
||||
```python
|
||||
def fista(grad_f, prox_g, x0, L, n_iter=200):
|
||||
x = y = x0.copy(); t = 1.0
|
||||
for k in range(n_iter):
|
||||
x_new = prox_g(y - grad_f(y)/L, 1/L)
|
||||
t_new = 0.5*(1 + np.sqrt(1 + 4*t*t))
|
||||
y = x_new + ((t-1)/t_new)*(x_new - x)
|
||||
x, t = x_new, t_new
|
||||
return x
|
||||
```
|
||||
|
||||
### Bayesian optimization (Optuna)
|
||||
```python
|
||||
import optuna
|
||||
def objective(trial):
|
||||
lr = trial.suggest_float('lr', 1e-5, 1e-2, log=True)
|
||||
wd = trial.suggest_float('wd', 1e-4, 1e-1, log=True)
|
||||
return train_and_eval(lr, wd)
|
||||
study = optuna.create_study(direction='minimize')
|
||||
study.optimize(objective, n_trials=100)
|
||||
```
|
||||
|
||||
### Projected gradient (constraint set)
|
||||
```python
|
||||
def proj_simplex(v):
|
||||
n = len(v); u = np.sort(v)[::-1]
|
||||
cssv = np.cumsum(u) - 1
|
||||
rho = np.where(u - cssv/np.arange(1, n+1) > 0)[0][-1]
|
||||
theta = cssv[rho] / (rho+1)
|
||||
return np.maximum(v - theta, 0)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Smooth convex, small | Newton / L-BFGS |
|
||||
| Smooth convex, large | GD / accelerated GD |
|
||||
| Nonsmooth convex | Subgradient / proximal / ADMM |
|
||||
| Stochastic, deep net | AdamW (default) / Lion / Sophia |
|
||||
| LP / QP | Simplex / interior-point (Gurobi/Mosek) |
|
||||
| Black-box / expensive eval | Bayesian opt (Optuna) |
|
||||
| Combinatorial | MIP / metaheuristic / CP-SAT |
|
||||
|
||||
**기본값**: ML training은 AdamW + cosine; convex은 CVXPY; black-box는 Optuna.
|
||||
|
||||
## 🔗 Graph
|
||||
- 응용: [[Operations-Research]] · [[Optimal-Control-Theory]]
|
||||
- Adjacent: [[Linear-Algebra-Foundations|Linear-Algebra]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: optimizer recipe selection, hyperparam search prior, KKT/Lagrangian derivation 매 explanation.
|
||||
**언제 X**: 실제 numerical solving (PyTorch/CVXPY/Gurobi 매 사용).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Adam everywhere**: 매 small data / convex problem 매 Adam — 매 SGD or L-BFGS 매 더 좋음.
|
||||
- **No grad clipping for transformers**: 매 explosion 매 inevitable.
|
||||
- **Constant LR**: 매 cosine / warmup 매 거의 항상 도움.
|
||||
- **Local minimum panic**: 매 deep net의 saddle point가 매 진짜 problem (not local min).
|
||||
- **Convex assumption violation**: 매 nonconvex에 매 convex solver 매 적용 → 매 wrong answer.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Boyd & Vandenberghe "Convex Optimization", Nocedal & Wright).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full optimization landscape |
|
||||
@@ -0,0 +1,184 @@
|
||||
---
|
||||
id: wiki-2026-0508-pca-and-dimension-reduction
|
||||
title: PCA and Dimension Reduction
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Principal Component Analysis, Dimensionality Reduction]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [statistics, ml, unsupervised, embeddings, visualization]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: scikit-learn/umap
|
||||
---
|
||||
|
||||
# PCA and Dimension Reduction
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 high-dim 데이터를 variance 보존하는 lower-dim 부분공간으로 사영"**. Pearson 1901 / Hotelling 1933 의 PCA 가 시초. 매 2026 의 modern landscape: linear PCA 는 여전히 baseline + interpretation, t-SNE/UMAP 가 visualization 의 default, autoencoder + contrastive 가 representation learning 의 핵심. 매 LLM embedding 의 PCA whitening 도 흔함.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 PCA 수학
|
||||
- **목표**: orthogonal directions 중 variance 최대화.
|
||||
- **계산**: covariance Σ = X^T X / (n-1) → eigendecomposition Σ = V Λ V^T, top-k columns = principal components.
|
||||
- **SVD form**: X = UΣV^T → top-k V_k 가 components, score = X V_k.
|
||||
- **Explained variance ratio**: λ_i / Σ λ_j.
|
||||
- **Whitening**: X V_k Λ_k^{-1/2} → unit variance per dim.
|
||||
|
||||
### 매 family
|
||||
- **Linear**: PCA, Truncated SVD, Factor Analysis, ICA.
|
||||
- **Manifold (preserve local)**: t-SNE, UMAP, LLE, Isomap.
|
||||
- **Neural**: Autoencoder, VAE, contrastive (SimCLR), DINO.
|
||||
- **Random**: Random projection (Johnson-Lindenstrauss).
|
||||
- **Sparse**: Sparse PCA, NMF.
|
||||
|
||||
### 매 응용
|
||||
1. Visualization (t-SNE, UMAP for embeddings/scRNA-seq).
|
||||
2. Compression (PCA whitening before downstream task).
|
||||
3. Denoising (project, then reconstruct).
|
||||
4. Feature engineering pre-classifier.
|
||||
5. LLM embedding analysis (cluster interpretation, anisotropy fix).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### sklearn PCA
|
||||
```python
|
||||
from sklearn.decomposition import PCA
|
||||
import numpy as np
|
||||
|
||||
X = np.random.randn(1000, 100)
|
||||
pca = PCA(n_components=10, whiten=True, random_state=42)
|
||||
X_proj = pca.fit_transform(X)
|
||||
print(pca.explained_variance_ratio_.cumsum()) # 누적 explained
|
||||
print(pca.components_.shape) # (10, 100)
|
||||
```
|
||||
|
||||
### Choose k via cumulative variance
|
||||
```python
|
||||
def choose_k(X, threshold=0.95):
|
||||
pca = PCA().fit(X)
|
||||
cum = pca.explained_variance_ratio_.cumsum()
|
||||
return int(np.searchsorted(cum, threshold) + 1)
|
||||
```
|
||||
|
||||
### Truncated SVD (sparse / very large)
|
||||
```python
|
||||
from sklearn.decomposition import TruncatedSVD
|
||||
from scipy.sparse import csr_matrix
|
||||
|
||||
X_sparse = csr_matrix(X) # 매 PCA centers → dense; TruncatedSVD 매 sparse-friendly
|
||||
svd = TruncatedSVD(n_components=50, n_iter=7, random_state=42)
|
||||
X_proj = svd.fit_transform(X_sparse) # 매 LSA 의 핵심
|
||||
```
|
||||
|
||||
### UMAP (manifold, fast)
|
||||
```python
|
||||
import umap
|
||||
|
||||
reducer = umap.UMAP(
|
||||
n_neighbors=15, # local vs global
|
||||
min_dist=0.1, # cluster separation
|
||||
n_components=2,
|
||||
metric="cosine", # 매 LLM embedding
|
||||
random_state=42,
|
||||
)
|
||||
X_2d = reducer.fit_transform(X)
|
||||
```
|
||||
|
||||
### t-SNE (visualization)
|
||||
```python
|
||||
from sklearn.manifold import TSNE
|
||||
|
||||
# 매 항상 PCA → t-SNE (속도/안정성)
|
||||
X_pca = PCA(n_components=50).fit_transform(X)
|
||||
X_2d = TSNE(n_components=2, perplexity=30, init="pca",
|
||||
learning_rate="auto").fit_transform(X_pca)
|
||||
```
|
||||
|
||||
### Autoencoder (PyTorch)
|
||||
```python
|
||||
import torch.nn as nn
|
||||
|
||||
class AE(nn.Module):
|
||||
def __init__(self, d_in, d_latent):
|
||||
super().__init__()
|
||||
self.enc = nn.Sequential(
|
||||
nn.Linear(d_in, 256), nn.GELU(),
|
||||
nn.Linear(256, d_latent),
|
||||
)
|
||||
self.dec = nn.Sequential(
|
||||
nn.Linear(d_latent, 256), nn.GELU(),
|
||||
nn.Linear(256, d_in),
|
||||
)
|
||||
def forward(self, x):
|
||||
z = self.enc(x); return self.dec(z), z
|
||||
# loss = MSE(x, x_hat). Nonlinear PCA 의 generalization.
|
||||
```
|
||||
|
||||
### LLM embedding whitening (anisotropy 완화)
|
||||
```python
|
||||
def whiten_embeddings(E, k=None):
|
||||
"""Anisotropy fix: subtract mean, decorrelate."""
|
||||
mu = E.mean(axis=0, keepdims=True)
|
||||
Ec = E - mu
|
||||
U, S, Vt = np.linalg.svd(Ec, full_matrices=False)
|
||||
if k is None:
|
||||
k = E.shape[1]
|
||||
W = (Vt[:k].T) / S[:k] # whitening matrix
|
||||
return Ec @ W, mu, W
|
||||
```
|
||||
|
||||
### Random projection (very high-dim, fast)
|
||||
```python
|
||||
from sklearn.random_projection import GaussianRandomProjection
|
||||
|
||||
rp = GaussianRandomProjection(n_components="auto", eps=0.1)
|
||||
X_proj = rp.fit_transform(X) # 매 Johnson-Lindenstrauss 보존
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Method |
|
||||
|---|---|
|
||||
| baseline, interpretable | PCA |
|
||||
| sparse text-term-matrix | TruncatedSVD (LSA) |
|
||||
| visualization 2D/3D | UMAP > t-SNE |
|
||||
| nonlinear, learnable, downstream supervised | Autoencoder / SimCLR |
|
||||
| n >> d, very high-dim | Random projection |
|
||||
| non-negative parts (topics) | NMF |
|
||||
| count data | LDA / NMF |
|
||||
|
||||
**기본값**: 매 baseline PCA → 매 visualization UMAP → 매 representation learning contrastive.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Linear-Algebra-Foundations]] · [[Statistics]]
|
||||
- 변형: [[ICA]]
|
||||
- 응용: [[Feature Engineering]]
|
||||
- Adjacent: [[t-SNE]] · [[UMAP]] · [[Autoencoder]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 embedding analysis, 매 anisotropy whitening, 매 visualizing high-dim attention/activations.
|
||||
**언제 X**: 매 매우 nonlinear task — autoencoder/contrastive 사용. 매 preserving exact distances 필요 — RP 만 보장.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **PCA without scaling**: 매 큰-단위 feature 가 dominate. 매 StandardScaler 필수.
|
||||
- **t-SNE 결과 해석 으로 cluster 크기/거리 신뢰**: 매 t-SNE 매 local-only — 매 global geometry 왜곡.
|
||||
- **PCA 사용 후 inverse_transform 으로 outlier 제거** — 매 그러면 다시 fit X 매 outlier 의 영향 그대로.
|
||||
- **n_components 선택을 임의 값** (e.g., 항상 2): 매 cumulative variance + downstream metric 기반 선택.
|
||||
- **Test set 도 fit_transform**: 매 leakage. 매 fit 은 train 만, test 는 transform.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Bishop *PRML* Ch 12; *ESL* Hastie et al.; UMAP McInnes 2018; sklearn docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — PCA & DR FULL with PCA/UMAP/AE/whitening patterns |
|
||||
@@ -0,0 +1,176 @@
|
||||
---
|
||||
id: wiki-2026-0508-pid-controllers-in-ai
|
||||
title: PID Controllers in AI
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Proportional-Integral-Derivative Control, PID Loop]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [control-theory, robotics, RL, tuning]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: simple_pid/control
|
||||
---
|
||||
|
||||
# PID Controllers in AI
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 error = setpoint - measurement 에 P/I/D 항을 적용해 actuator 를 제어"**. 1922 Minorsky ship steering 에서 시작, 매 산업 control 의 80%+ 사용. 매 2026 의 AI hybrid 사용: drone attitude (PX4), robot joint, LLM token-budget control, RLHF KL-coefficient tuning, training schedules.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 PID 공식
|
||||
- **u(t) = Kp·e(t) + Ki·∫e(τ)dτ + Kd·de/dt**.
|
||||
- **P (Proportional)**: 매 현재 error 에 비례 — 매 fast response, 매 steady-state error 남김.
|
||||
- **I (Integral)**: 매 누적 error — 매 steady-state error 제거, 매 windup 위험.
|
||||
- **D (Derivative)**: 매 변화율 — 매 overshoot 감소, 매 noise 증폭.
|
||||
|
||||
### 매 tuning methods
|
||||
- **Ziegler-Nichols**: 매 Ku, Tu (oscillation) 측정 후 공식 적용.
|
||||
- **Cohen-Coon**: 매 process reaction curve 기반.
|
||||
- **AutoTuning**: 매 relay feedback (Åström-Hägglund).
|
||||
- **Bayesian optimization**: 매 simulation rollout + GP.
|
||||
- **RL-based**: 매 PPO/SAC 으로 Kp, Ki, Kd 학습.
|
||||
|
||||
### 매 응용
|
||||
1. Drone attitude (PX4, ArduPilot).
|
||||
2. Robot joint position control (ROS 2).
|
||||
3. Cruise control, HVAC, 3D printer extruder.
|
||||
4. LLM serving — token-rate controller (vLLM 의 batch sizing).
|
||||
5. RLHF KL-coefficient adaptive tuning.
|
||||
6. Training: gradient norm clipping with adaptive coefficient.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Plain PID (discrete)
|
||||
```python
|
||||
class PID:
|
||||
def __init__(self, kp, ki, kd, dt, output_limits=(-1, 1)):
|
||||
self.kp, self.ki, self.kd, self.dt = kp, ki, kd, dt
|
||||
self.lo, self.hi = output_limits
|
||||
self.integral = 0.0
|
||||
self.prev_error = 0.0
|
||||
|
||||
def __call__(self, setpoint, measurement):
|
||||
error = setpoint - measurement
|
||||
self.integral += error * self.dt
|
||||
derivative = (error - self.prev_error) / self.dt
|
||||
output = self.kp*error + self.ki*self.integral + self.kd*derivative
|
||||
output = max(self.lo, min(self.hi, output))
|
||||
self.prev_error = error
|
||||
return output
|
||||
```
|
||||
|
||||
### Anti-windup (clamp + back-calculation)
|
||||
```python
|
||||
class PIDAntiWindup(PID):
|
||||
def __init__(self, *args, kt=0.5, **kw):
|
||||
super().__init__(*args, **kw)
|
||||
self.kt = kt # back-calc gain
|
||||
|
||||
def __call__(self, setpoint, measurement):
|
||||
error = setpoint - measurement
|
||||
derivative = (error - self.prev_error) / self.dt
|
||||
u_unsat = self.kp*error + self.ki*self.integral + self.kd*derivative
|
||||
u_sat = max(self.lo, min(self.hi, u_unsat))
|
||||
# back-calculation: discount integral when saturated
|
||||
self.integral += self.dt * (error + self.kt * (u_sat - u_unsat))
|
||||
self.prev_error = error
|
||||
return u_sat
|
||||
```
|
||||
|
||||
### Derivative on measurement (D-kick 회피)
|
||||
```python
|
||||
class PIDDerivOnMeas(PID):
|
||||
def __init__(self, *args, **kw):
|
||||
super().__init__(*args, **kw)
|
||||
self.prev_meas = None
|
||||
|
||||
def __call__(self, setpoint, measurement):
|
||||
error = setpoint - measurement
|
||||
if self.prev_meas is None:
|
||||
d = 0
|
||||
else:
|
||||
d = -(measurement - self.prev_meas) / self.dt # 매 setpoint step → spike 없음
|
||||
self.integral += error * self.dt
|
||||
out = self.kp*error + self.ki*self.integral + self.kd*d
|
||||
self.prev_meas = measurement
|
||||
return max(self.lo, min(self.hi, out))
|
||||
```
|
||||
|
||||
### Ziegler-Nichols tuning
|
||||
```python
|
||||
def ziegler_nichols(Ku, Tu, kind="classic"):
|
||||
if kind == "classic":
|
||||
return dict(kp=0.6*Ku, ki=1.2*Ku/Tu, kd=0.075*Ku*Tu)
|
||||
elif kind == "no-overshoot":
|
||||
return dict(kp=0.2*Ku, ki=0.4*Ku/Tu, kd=Ku*Tu/15)
|
||||
elif kind == "PI-only":
|
||||
return dict(kp=0.45*Ku, ki=0.54*Ku/Tu, kd=0)
|
||||
```
|
||||
|
||||
### RLHF adaptive KL (PPO-style β)
|
||||
```python
|
||||
def adaptive_kl_pid(kl_observed, kl_target=0.02, state=None):
|
||||
"""β ↑ when KL too large; β ↓ when too small. PI controller on log(β)."""
|
||||
if state is None:
|
||||
state = {"integral": 0.0, "log_beta": 0.0}
|
||||
error = kl_observed - kl_target
|
||||
state["integral"] += error
|
||||
state["log_beta"] += 0.1 * error + 0.01 * state["integral"]
|
||||
return float(np.exp(state["log_beta"])), state
|
||||
```
|
||||
|
||||
### LLM token-rate controller (server batch)
|
||||
```python
|
||||
def batch_size_pid(target_tps, current_tps, pid_state):
|
||||
"""Maintain target tokens/sec by adjusting batch size."""
|
||||
delta = target_tps - current_tps
|
||||
pid_state["integral"] += delta
|
||||
adj = 0.05*delta + 0.001*pid_state["integral"]
|
||||
return max(1, int(pid_state["batch"] + adj))
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Controller |
|
||||
|---|---|
|
||||
| no steady-state error needed | P only |
|
||||
| eliminate steady-state, slow process | PI |
|
||||
| fast + minimal overshoot | PID with D-on-measurement |
|
||||
| highly nonlinear / complex | MPC or RL (not PID) |
|
||||
| discrete-event / queue | PI on rate |
|
||||
| training schedule (KL, lr) | adaptive PI |
|
||||
|
||||
**기본값**: 매 80% 의 경우 PI 면 충분. 매 D 매 noise 환경에서 신중히.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Control-Theory]] · [[Feedback-Control-Systems]]
|
||||
- 응용: [[Robotics]] · [[RLHF]]
|
||||
- Adjacent: [[Model-Predictive-Control (MPC)]] · [[Kalman-Filter-and-State-Tracking]] · [[Reinforcement-Learning]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 inference server batch sizing, 매 RLHF KL coefficient, 매 lr schedule under loss target.
|
||||
**언제 X**: 매 highly nonlinear delays — MPC. 매 strong constraints — RL/MPC.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **No anti-windup with saturation**: 매 integral 폭주 → overshoot.
|
||||
- **D term on noisy raw signal**: 매 noise 증폭 → 매 LPF (low-pass filter) 필수.
|
||||
- **Derivative on setpoint (D-kick)**: 매 setpoint step → spike. 매 D-on-measurement 사용.
|
||||
- **One-size-fits-all gains across operating regions**: 매 nonlinear 시스템 — gain scheduling 필요.
|
||||
- **Tuning by 임의 가이드**: 매 system 마다 다름 — Ziegler-Nichols 또는 simulation 사용.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Åström & Hägglund, *PID Controllers*; Franklin et al. *Feedback Control of Dynamic Systems*; ArduPilot/PX4 firmware).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — PID FULL with anti-windup, D-on-meas, RLHF/serving applications |
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
---
|
||||
id: wiki-2026-0508-partial-differential-equations
|
||||
title: Partial Differential Equations
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [PDE, Distributed Parameter Systems]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [pde, numerical-methods, scientific-computing, pinn]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: FEniCSx/JAX/PyTorch
|
||||
---
|
||||
|
||||
# Partial Differential Equations
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 multivariable function 의 partial derivative relations"**. 매 PDE는 매 fluid (Navier-Stokes), heat, wave, elasticity, EM (Maxwell), QM (Schrödinger), finance (Black-Scholes) 의 universal language, 매 2026 numerical solving은 매 FDM/FEM/FVM/spectral + PINN/Neural Operator (FNO, DeepONet) 의 hybrid 시대.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 분류 (2nd order linear)
|
||||
- B² - 4AC 로:
|
||||
- **Elliptic** (<0): Laplace ∇²u=0, Poisson — equilibrium.
|
||||
- **Parabolic** (=0): heat uₜ = α∇²u — diffusion.
|
||||
- **Hyperbolic** (>0): wave uₜₜ = c²∇²u — propagation.
|
||||
|
||||
### 매 well-posed (Hadamard)
|
||||
- Existence, uniqueness, continuous dependence on data.
|
||||
- Boundary conditions: Dirichlet, Neumann, Robin.
|
||||
|
||||
### 매 numerical methods
|
||||
- **FDM**: structured grid, easy, low geometry flexibility.
|
||||
- **FEM**: weak form, complex geometry, h/p refinement.
|
||||
- **FVM**: conservation laws (CFD).
|
||||
- **Spectral**: smooth solutions, exponential convergence.
|
||||
- **PINN (2026)**: NN minimizing PDE residual, mesh-free, inverse problems.
|
||||
- **Neural Operator**: FNO/DeepONet learn solution operator.
|
||||
|
||||
### 매 응용
|
||||
1. CFD (aerospace, weather).
|
||||
2. Heat transfer / thermal analysis.
|
||||
3. Structural mechanics.
|
||||
4. EM simulation (CST, COMSOL).
|
||||
5. Option pricing (Black-Scholes PDE).
|
||||
6. Diffusion models (LLM/image gen with score-PDE).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### 1D Heat Equation — explicit FDM
|
||||
```python
|
||||
import numpy as np
|
||||
def heat_explicit(u0, alpha, dx, dt, T):
|
||||
r = alpha*dt/dx**2
|
||||
assert r <= 0.5, "CFL violated"
|
||||
u = u0.copy(); steps = int(T/dt)
|
||||
for _ in range(steps):
|
||||
u[1:-1] = u[1:-1] + r*(u[2:] - 2*u[1:-1] + u[:-2])
|
||||
return u
|
||||
```
|
||||
|
||||
### Crank-Nicolson (implicit, 2nd order)
|
||||
```python
|
||||
from scipy.sparse import diags
|
||||
from scipy.sparse.linalg import spsolve
|
||||
def crank_nicolson(u0, alpha, dx, dt, T):
|
||||
n = len(u0); r = alpha*dt/(2*dx**2)
|
||||
A = diags([-r, 1+2*r, -r], [-1,0,1], shape=(n-2, n-2)).tocsc()
|
||||
B = diags([ r, 1-2*r, r], [-1,0,1], shape=(n-2, n-2))
|
||||
u = u0.copy()
|
||||
for _ in range(int(T/dt)):
|
||||
u[1:-1] = spsolve(A, B @ u[1:-1])
|
||||
return u
|
||||
```
|
||||
|
||||
### 2D Poisson via FEM (FEniCSx)
|
||||
```python
|
||||
from dolfinx import mesh, fem
|
||||
from ufl import TrialFunction, TestFunction, dx, grad, inner
|
||||
import numpy as np
|
||||
domain = mesh.create_unit_square(MPI.COMM_WORLD, 64, 64)
|
||||
V = fem.FunctionSpace(domain, ("Lagrange", 1))
|
||||
u, v = TrialFunction(V), TestFunction(V)
|
||||
f = fem.Constant(domain, 1.0)
|
||||
a = inner(grad(u), grad(v))*dx
|
||||
L = f*v*dx
|
||||
bc = fem.dirichletbc(0.0, ..., V)
|
||||
problem = fem.petsc.LinearProblem(a, L, bcs=[bc])
|
||||
uh = problem.solve()
|
||||
```
|
||||
|
||||
### 1D Wave — leapfrog
|
||||
```python
|
||||
def wave_leapfrog(u0, v0, c, dx, dt, T):
|
||||
r = c*dt/dx
|
||||
assert r <= 1, "CFL"
|
||||
u_prev = u0.copy()
|
||||
u = u0 + dt*v0 # half-step init
|
||||
steps = int(T/dt)
|
||||
for _ in range(steps):
|
||||
u_next = 2*u[1:-1] - u_prev[1:-1] + r**2*(u[2:] - 2*u[1:-1] + u[:-2])
|
||||
u_prev[1:-1] = u[1:-1]; u[1:-1] = u_next
|
||||
return u
|
||||
```
|
||||
|
||||
### PINN for Burgers' equation
|
||||
```python
|
||||
import torch, torch.nn as nn
|
||||
class PINN(nn.Module):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.net = nn.Sequential(
|
||||
nn.Linear(2,64), nn.Tanh(), nn.Linear(64,64), nn.Tanh(),
|
||||
nn.Linear(64,64), nn.Tanh(), nn.Linear(64,1))
|
||||
def forward(self, xt): return self.net(xt)
|
||||
|
||||
def pde_residual(model, xt, nu=0.01/np.pi):
|
||||
xt.requires_grad_(True)
|
||||
u = model(xt)
|
||||
grads = torch.autograd.grad(u, xt, torch.ones_like(u), create_graph=True)[0]
|
||||
u_x, u_t = grads[:,0:1], grads[:,1:2]
|
||||
u_xx = torch.autograd.grad(u_x, xt, torch.ones_like(u_x), create_graph=True)[0][:,0:1]
|
||||
return u_t + u*u_x - nu*u_xx
|
||||
# Loss = MSE(pde_residual) + MSE(IC) + MSE(BC); Adam optimize.
|
||||
```
|
||||
|
||||
### Fourier Neural Operator (FNO, 2026)
|
||||
```python
|
||||
import torch, torch.nn as nn
|
||||
class SpectralConv1d(nn.Module):
|
||||
def __init__(self, in_ch, out_ch, modes):
|
||||
super().__init__()
|
||||
self.modes = modes
|
||||
self.weight = nn.Parameter(torch.randn(in_ch, out_ch, modes, dtype=torch.cfloat)*0.02)
|
||||
def forward(self, x): # x: (B, C, N)
|
||||
N = x.size(-1)
|
||||
x_ft = torch.fft.rfft(x)
|
||||
out_ft = torch.zeros(x.size(0), self.weight.size(1), N//2+1, dtype=torch.cfloat, device=x.device)
|
||||
out_ft[..., :self.modes] = torch.einsum("bcm,com->bom", x_ft[..., :self.modes], self.weight)
|
||||
return torch.fft.irfft(out_ft, n=N)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Simple geometry, structured | FDM |
|
||||
| Complex geometry / multi-physics | FEM |
|
||||
| Conservation laws, shocks | FVM (CFD) |
|
||||
| Smooth, periodic | Spectral / pseudo-spectral |
|
||||
| Inverse / sparse data | PINN |
|
||||
| Many similar PDEs (parametric) | Neural Operator (FNO/DeepONet) |
|
||||
| Stochastic / high-dim | Deep BSDE / Monte Carlo |
|
||||
|
||||
**기본값**: classical solving은 FEM (FEniCSx) or FVM (OpenFOAM); ML-side는 FNO; inverse problem은 PINN.
|
||||
|
||||
## 🔗 Graph
|
||||
- Adjacent: [[PINN]] · [[Diffusion-Models]] · [[Finite-Element-Method]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: PDE classification 설명, BC formulation help, weak form derivation, PINN architecture suggestion.
|
||||
**언제 X**: actual numerical solving (FEniCSx/JAX/OpenFOAM 매 use).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **CFL violation**: explicit scheme에 dt 매 too large → blow up.
|
||||
- **PINN as universal**: PINN 매 hard problems 에 매 종종 fail (high-freq/turbulent) — 매 classical FEM 매 첫 baseline.
|
||||
- **No mesh convergence study**: 매 must show error vs h/p refinement.
|
||||
- **Wrong BC**: Neumann ↔ Dirichlet mistake → 매 entire solution wrong.
|
||||
- **Ignoring stability**: implicit ≠ unconditionally accurate (just stable).
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Strikwerda "Finite Difference Schemes", Brenner & Scott "FEM", Karniadakis et al PINN review).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — classical methods + PINN/FNO (2026) |
|
||||
@@ -0,0 +1,170 @@
|
||||
---
|
||||
id: wiki-2026-0508-particle-filter-algorithms
|
||||
title: Particle Filter Algorithms
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Sequential Monte Carlo, SMC, Bootstrap Filter]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [bayesian, state-estimation, monte-carlo, robotics]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: NumPy/PyTorch
|
||||
---
|
||||
|
||||
# Particle Filter Algorithms
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 nonlinear non-Gaussian state estimation 매 weighted samples로"**. 매 PF는 매 1993 Gordon-Salmond-Smith bootstrap filter에서 출발, 매 Kalman/EKF가 매 fail하는 multimodal posterior을 매 resampling으로 track, 매 2026 SLAM·target tracking·option pricing·epidemiology·neural state-space modeling에서 매 standard SMC tool.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 problem
|
||||
- State-space: xₜ = f(xₜ₋₁) + wₜ, yₜ = h(xₜ) + vₜ.
|
||||
- Goal: posterior p(xₜ | y₁:ₜ).
|
||||
- Bayes filter recursion (predict, update).
|
||||
|
||||
### 매 PF idea
|
||||
- p(xₜ | y₁:ₜ) ≈ Σᵢ wₜ⁽ⁱ⁾ δ(xₜ - xₜ⁽ⁱ⁾).
|
||||
- N particles xₜ⁽ⁱ⁾ with weights wₜ⁽ⁱ⁾.
|
||||
- Predict: sample xₜ⁽ⁱ⁾ ~ q(xₜ | xₜ₋₁⁽ⁱ⁾, yₜ).
|
||||
- Update: wₜ⁽ⁱ⁾ ∝ wₜ₋₁⁽ⁱ⁾ p(yₜ|xₜ⁽ⁱ⁾) p(xₜ⁽ⁱ⁾|xₜ₋₁⁽ⁱ⁾) / q(...).
|
||||
- Resample when ESS < threshold.
|
||||
|
||||
### 매 변형
|
||||
- **Bootstrap filter**: q = transition prior; simplest.
|
||||
- **Auxiliary PF**: 매 informative proposal using yₜ.
|
||||
- **Rao-Blackwellized PF**: marginalize linear-Gaussian sub-state analytically.
|
||||
- **Differentiable PF (2026)**: end-to-end with relaxed resampling.
|
||||
- **PMCMC**: PF inside MCMC for parameter inference.
|
||||
|
||||
### 매 응용
|
||||
1. Robot localization (Monte Carlo Localization, MCL).
|
||||
2. Visual / multi-target tracking.
|
||||
3. Stochastic volatility estimation.
|
||||
4. Epidemic forecasting (SEIR with noise).
|
||||
5. Neural state-space models for time series (2026 Mamba-PF hybrids).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Bootstrap Particle Filter
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
def bootstrap_pf(y, f, h, q_noise, r_noise, N=1000, x0_sampler=None):
|
||||
T = len(y)
|
||||
x = x0_sampler(N)
|
||||
w = np.ones(N) / N
|
||||
means = np.zeros(T)
|
||||
for t in range(T):
|
||||
x = f(x) + q_noise(N) # predict
|
||||
lik = np.exp(-0.5 * ((y[t] - h(x))/r_noise)**2)
|
||||
w = w * lik
|
||||
w /= w.sum()
|
||||
means[t] = np.sum(w * x)
|
||||
ess = 1.0 / np.sum(w*w)
|
||||
if ess < N/2: # systematic resample
|
||||
idx = systematic_resample(w)
|
||||
x = x[idx]; w = np.ones(N) / N
|
||||
return means
|
||||
```
|
||||
|
||||
### Systematic resampling
|
||||
```python
|
||||
def systematic_resample(w):
|
||||
N = len(w)
|
||||
positions = (np.arange(N) + np.random.uniform()) / N
|
||||
cumw = np.cumsum(w)
|
||||
idx = np.zeros(N, dtype=int)
|
||||
i = j = 0
|
||||
while i < N:
|
||||
if positions[i] < cumw[j]:
|
||||
idx[i] = j; i += 1
|
||||
else:
|
||||
j += 1
|
||||
return idx
|
||||
```
|
||||
|
||||
### Auxiliary PF
|
||||
```python
|
||||
def apf_step(x, w, y_next, f_mean, h, r_noise):
|
||||
mu = f_mean(x) # predicted mean
|
||||
pred_lik = np.exp(-0.5*((y_next - h(mu))/r_noise)**2)
|
||||
aux_w = w * pred_lik
|
||||
aux_w /= aux_w.sum()
|
||||
idx = systematic_resample(aux_w)
|
||||
x_new = f(x[idx]) + q_noise(len(x))
|
||||
lik = np.exp(-0.5*((y_next - h(x_new))/r_noise)**2)
|
||||
new_w = lik / pred_lik[idx]
|
||||
new_w /= new_w.sum()
|
||||
return x_new, new_w
|
||||
```
|
||||
|
||||
### Robot MCL (2D)
|
||||
```python
|
||||
# state: [x, y, theta], obs: distance to landmarks
|
||||
def motion_model(particles, u, sigma):
|
||||
dx = u[0]*np.cos(particles[:,2]) + sigma*np.random.randn(len(particles))
|
||||
dy = u[0]*np.sin(particles[:,2]) + sigma*np.random.randn(len(particles))
|
||||
dtheta = u[1] + 0.05*np.random.randn(len(particles))
|
||||
return particles + np.column_stack([dx, dy, dtheta])
|
||||
|
||||
def sensor_model(particles, landmarks, obs, sigma):
|
||||
dists = np.linalg.norm(particles[:,None,:2] - landmarks[None,:,:], axis=2)
|
||||
return np.exp(-0.5*((dists - obs[None,:])/sigma)**2).prod(axis=1)
|
||||
```
|
||||
|
||||
### Differentiable PF (PyTorch, 2026 style)
|
||||
```python
|
||||
import torch
|
||||
def soft_resample(w, alpha=0.5):
|
||||
N = len(w)
|
||||
soft_w = alpha*w + (1-alpha)/N
|
||||
idx = torch.multinomial(soft_w, N, replacement=True)
|
||||
return idx, w[idx] / soft_w[idx] # importance correction, differentiable
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Linear Gaussian | Kalman Filter (exact, no PF needed) |
|
||||
| Mildly nonlinear, unimodal | EKF / UKF |
|
||||
| Nonlinear or multimodal | Particle Filter |
|
||||
| High-dim state (>10) | RBPF or PF + structured proposal |
|
||||
| Need parameter inference too | PMCMC / SMC² |
|
||||
| End-to-end learning | Differentiable PF |
|
||||
|
||||
**기본값**: Bootstrap PF with systematic resampling (ESS<N/2 trigger), N=1000-10000.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Sequential-Monte-Carlo]]
|
||||
- 변형: [[Bootstrap-Filter]]
|
||||
- 응용: [[SLAM]]
|
||||
- Adjacent: [[Kalman-Filter-and-State-Tracking|Kalman-Filter]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: PF tuning rationale (N choice, resample threshold), proposal design discussion, debug degenerate weights.
|
||||
**언제 X**: 실제 sampling/resampling computation.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **No resampling**: 매 weights collapse → 1 particle dominates (degeneracy).
|
||||
- **Resample every step**: 매 sample impoverishment — 매 ESS-based trigger 매 사용.
|
||||
- **Bootstrap in high-dim**: 매 prior proposal 매 explodes — 매 informative proposal 매 필수.
|
||||
- **Too few particles**: 매 N<500 매 high-dim에 매 useless.
|
||||
- **Non-systematic resample**: 매 multinomial 매 high-variance — 매 systematic/stratified 매 사용.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Doucet et al "Sequential Monte Carlo Methods", Thrun "Probabilistic Robotics").
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — bootstrap/APF/RBPF + differentiable PF (2026) |
|
||||
@@ -0,0 +1,156 @@
|
||||
---
|
||||
id: wiki-2026-0508-phase-amplitude-coupling
|
||||
title: Phase Amplitude Coupling
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [PAC, Cross-Frequency Coupling, Theta-Gamma PAC]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.85
|
||||
verification_status: applied
|
||||
tags: [neuroscience, signal-processing, eeg, oscillations]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: mne/numpy
|
||||
---
|
||||
|
||||
# Phase Amplitude Coupling
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 slow rhythm 의 phase 가 매 fast rhythm 의 amplitude 를 모듈레이션."**. 2006 Canolty et al. theta-gamma PAC in human ECoG → 2010s memory/working-memory 의 neural mechanism 으로 자리잡음. 2026 BCI, sleep staging, anesthesia depth monitoring 에 활용.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 What is PAC
|
||||
- Two oscillations: phase φ_low(t) ∈ [−π, π], amplitude A_high(t) ≥ 0.
|
||||
- PAC: A_high 가 φ_low 의 특정 phase에 preferentially elevated.
|
||||
- Canonical pair: theta (4–8 Hz) phase × gamma (30–80 Hz) amplitude.
|
||||
|
||||
### 매 PAC Metrics
|
||||
- **Modulation Index (MI, Tort)**: KL divergence of phase-binned amplitude from uniform.
|
||||
- **Mean Vector Length (MVL, Canolty)**: |⟨A·e^(iφ)⟩|.
|
||||
- **Phase-Locking Value (PLV)**: |⟨e^(i(φ_low − φ_amp_envelope))⟩|.
|
||||
- **GLM-based**: regress A on sin/cos(φ).
|
||||
|
||||
### 매 응용
|
||||
1. Working memory (theta-gamma in hippocampus, PFC).
|
||||
2. Sleep stage classification (slow oscillation × spindle).
|
||||
3. Anesthesia depth (alpha-gamma, alpha-beta PAC).
|
||||
4. Parkinson's DBS biomarker (beta-gamma PAC).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Filter + Hilbert (extract phase & amplitude)
|
||||
```python
|
||||
import numpy as np
|
||||
from scipy.signal import butter, sosfiltfilt, hilbert
|
||||
|
||||
def phase_amp(x, fs, f_low=(4,8), f_high=(30,80)):
|
||||
sos_lo = butter(4, f_low, btype='band', fs=fs, output='sos')
|
||||
sos_hi = butter(4, f_high, btype='band', fs=fs, output='sos')
|
||||
x_lo = sosfiltfilt(sos_lo, x)
|
||||
x_hi = sosfiltfilt(sos_hi, x)
|
||||
phi = np.angle(hilbert(x_lo))
|
||||
amp = np.abs(hilbert(x_hi))
|
||||
return phi, amp
|
||||
```
|
||||
|
||||
### Tort Modulation Index
|
||||
```python
|
||||
def tort_mi(phi, amp, n_bins=18):
|
||||
edges = np.linspace(-np.pi, np.pi, n_bins+1)
|
||||
bin_idx = np.digitize(phi, edges) - 1
|
||||
bin_idx = np.clip(bin_idx, 0, n_bins-1)
|
||||
P = np.array([amp[bin_idx == k].mean() for k in range(n_bins)])
|
||||
P = P / P.sum()
|
||||
H = -np.sum(P * np.log(P + 1e-12))
|
||||
H_max = np.log(n_bins)
|
||||
return (H_max - H) / H_max # MI ∈ [0, 1]
|
||||
```
|
||||
|
||||
### Canolty MVL with surrogate test
|
||||
```python
|
||||
def mvl(phi, amp):
|
||||
return np.abs(np.mean(amp * np.exp(1j * phi)))
|
||||
|
||||
def mvl_significance(phi, amp, n_surr=200):
|
||||
obs = mvl(phi, amp)
|
||||
surr = []
|
||||
for _ in range(n_surr):
|
||||
shift = np.random.randint(len(amp))
|
||||
surr.append(mvl(phi, np.roll(amp, shift)))
|
||||
p = np.mean(np.array(surr) >= obs)
|
||||
z = (obs - np.mean(surr)) / np.std(surr)
|
||||
return obs, z, p
|
||||
```
|
||||
|
||||
### Comodulogram (PAC across freq pairs)
|
||||
```python
|
||||
def comodulogram(x, fs, lo_freqs, hi_freqs):
|
||||
MI = np.zeros((len(lo_freqs)-1, len(hi_freqs)-1))
|
||||
for i in range(len(lo_freqs)-1):
|
||||
for j in range(len(hi_freqs)-1):
|
||||
phi, amp = phase_amp(x, fs,
|
||||
f_low=(lo_freqs[i], lo_freqs[i+1]),
|
||||
f_high=(hi_freqs[j], hi_freqs[j+1]))
|
||||
MI[i, j] = tort_mi(phi, amp)
|
||||
return MI
|
||||
```
|
||||
|
||||
### MNE-Python ready pipeline
|
||||
```python
|
||||
import mne
|
||||
from mne_connectivity import phase_slope_index
|
||||
|
||||
raw = mne.io.read_raw_edf("eeg.edf", preload=True)
|
||||
raw.filter(1, 100).notch_filter(60)
|
||||
epochs = mne.make_fixed_length_epochs(raw, duration=2.0)
|
||||
# pactools for PAC
|
||||
from pactools import Comodulogram
|
||||
estimator = Comodulogram(fs=raw.info['sfreq'],
|
||||
low_fq_range=np.linspace(2, 12, 11),
|
||||
high_fq_range=np.linspace(20, 100, 17),
|
||||
method='tort')
|
||||
estimator.fit(epochs.get_data()[0, 0])
|
||||
estimator.plot()
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Method |
|
||||
|---|---|
|
||||
| Quick screening | Tort MI (robust to amp distribution) |
|
||||
| Phase preference angle | Canolty MVL (gives complex vector) |
|
||||
| Phase-phase coupling | n:m PLV |
|
||||
| Need significance | Surrogate w/ time shifts (≥200) |
|
||||
| Continuous data | sliding-window comodulogram |
|
||||
|
||||
**기본값**: Tort MI + 200 time-shift surrogates + FDR correction across frequency pairs.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Cross-Frequency Coupling (CFC)]] · [[Signal-Processing-Foundations]]
|
||||
- 변형: [[Theta-Gamma Coupling]]
|
||||
- Adjacent: [[Neural Ignition]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: PAC method 선택 explain, comodulogram 결과 interpretation.
|
||||
**언제 X**: 매 raw EEG 매 LLM에 stream (use MNE/pactools locally).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Spurious PAC from sharp transients**: 매 epileptic spikes / artifacts → broadband amp. Always inspect raw + reject artifacts.
|
||||
- **No surrogate test**: MI > 0 always — significance ≠ value.
|
||||
- **Filter bandwidth too narrow**: ringing → spurious phase locking.
|
||||
- **Edge effects**: 매 hilbert 에서 매 처음/끝 cycle 버려야.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Tort et al. 2010 *J Neurophysiol*; Canolty & Knight 2010 *Trends Cogn Sci*).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Tort MI / Canolty MVL / comodulogram 패턴, surrogate test |
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
---
|
||||
id: wiki-2026-0508-posterior-and-prior-probability
|
||||
title: Posterior and Prior Probability
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Bayesian Inference, Prior, Posterior, Bayes Update]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
verification_status: applied
|
||||
tags: [bayesian, statistics, inference, probability]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: pymc/numpyro
|
||||
---
|
||||
|
||||
# Posterior and Prior Probability
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 prior + likelihood = posterior"**. Bayes' theorem 의 사전 belief 의 evidence 의 update 의 posterior 의 derive — 매 modern probabilistic ML / scientific inference 의 backbone (PyMC 5, NumPyro, Stan).
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 정의
|
||||
- **Prior P(θ)**: 매 데이터 이전 의 parameter belief.
|
||||
- **Likelihood P(D|θ)**: 매 parameter 하 의 데이터 의 probability.
|
||||
- **Posterior P(θ|D) ∝ P(D|θ) · P(θ)**: 매 update 후 의 belief.
|
||||
- **Marginal P(D) = ∫ P(D|θ)P(θ) dθ**: 매 normalizing constant.
|
||||
|
||||
### 매 Prior 종류
|
||||
- **Informative**: 매 strong domain knowledge (Beta(20,5)).
|
||||
- **Weakly informative**: 매 mild regularization (Normal(0,10)).
|
||||
- **Non-informative / Jeffreys**: 매 maximum-entropy invariant prior.
|
||||
- **Conjugate**: 매 posterior 의 same family (Beta-Binomial, Normal-Normal, Gamma-Poisson).
|
||||
|
||||
### 매 응용
|
||||
1. A/B testing 의 conversion rate posterior.
|
||||
2. Bayesian neural network weight posterior.
|
||||
3. Kalman filter (sequential prior→posterior).
|
||||
4. Spam classification (Naive Bayes).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Beta-Binomial conjugate update (analytical)
|
||||
```python
|
||||
# Prior: Beta(α, β); Data: k successes in n trials
|
||||
# Posterior: Beta(α+k, β+n-k)
|
||||
import numpy as np
|
||||
from scipy.stats import beta
|
||||
|
||||
alpha_prior, beta_prior = 2, 2 # weakly informative
|
||||
k, n = 7, 10 # observed
|
||||
alpha_post, beta_post = alpha_prior + k, beta_prior + (n - k)
|
||||
|
||||
mean_post = alpha_post / (alpha_post + beta_post)
|
||||
ci_95 = beta.interval(0.95, alpha_post, beta_post)
|
||||
print(f"posterior mean={mean_post:.3f}, 95% CI={ci_95}")
|
||||
```
|
||||
|
||||
### PyMC 5 — MCMC posterior
|
||||
```python
|
||||
import pymc as pm
|
||||
|
||||
with pm.Model() as m:
|
||||
theta = pm.Beta("theta", alpha=2, beta=2)
|
||||
obs = pm.Binomial("obs", n=10, p=theta, observed=7)
|
||||
idata = pm.sample(2000, tune=1000, target_accept=0.95)
|
||||
|
||||
pm.summary(idata, var_names=["theta"]) # mean, hdi_3%, hdi_97%
|
||||
```
|
||||
|
||||
### NumPyro — JAX-accelerated NUTS
|
||||
```python
|
||||
import jax, numpyro, numpyro.distributions as dist
|
||||
from numpyro.infer import MCMC, NUTS
|
||||
|
||||
def model(k=None, n=10):
|
||||
theta = numpyro.sample("theta", dist.Beta(2, 2))
|
||||
numpyro.sample("obs", dist.Binomial(n, theta), obs=k)
|
||||
|
||||
mcmc = MCMC(NUTS(model), num_warmup=1000, num_samples=4000)
|
||||
mcmc.run(jax.random.PRNGKey(0), k=7)
|
||||
mcmc.print_summary()
|
||||
```
|
||||
|
||||
### Sequential Bayesian update
|
||||
```python
|
||||
# Stream of bernoulli observations — posterior becomes next prior
|
||||
a, b = 1.0, 1.0 # uniform start
|
||||
for x in stream:
|
||||
a += x; b += (1 - x)
|
||||
# E[θ] = a / (a+b) at any time
|
||||
```
|
||||
|
||||
### Naive Bayes posterior (text classification)
|
||||
```python
|
||||
from sklearn.feature_extraction.text import TfidfVectorizer
|
||||
from sklearn.naive_bayes import MultinomialNB
|
||||
|
||||
vec = TfidfVectorizer().fit(train_docs)
|
||||
clf = MultinomialNB(alpha=1.0).fit(vec.transform(train_docs), y_train)
|
||||
# alpha = Laplace prior strength; predict_proba returns P(class | doc)
|
||||
proba = clf.predict_proba(vec.transform(test_docs))
|
||||
```
|
||||
|
||||
### Posterior predictive check
|
||||
```python
|
||||
with m:
|
||||
ppc = pm.sample_posterior_predictive(idata, var_names=["obs"])
|
||||
# Compare ppc["obs"] distribution with actual data → model adequacy
|
||||
```
|
||||
|
||||
### Empirical Bayes (data-driven prior)
|
||||
```python
|
||||
# Estimate prior hyperparameters from grouped data, then update per-group
|
||||
# e.g. baseball batting averages — shrinkage toward league mean
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 매 conjugate family fits | Analytical update (closed form) |
|
||||
| 매 small/medium model | PyMC NUTS or NumPyro NUTS |
|
||||
| 매 large neural net | VI (variational), Laplace, or SWAG |
|
||||
| 매 streaming data | Sequential / Kalman-like update |
|
||||
| 매 strong domain knowledge | Informative prior; document it |
|
||||
| 매 weak knowledge + caution | Weakly informative (avoid flat improper) |
|
||||
|
||||
**기본값**: 매 weakly-informative prior + NUTS sampler — 매 PyMC 5 / NumPyro.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Probability Theory]] · [[Statistics]]
|
||||
- 변형: [[MAP Estimation (Maximum A Posteriori)]]
|
||||
- 응용: [[Particle-Filter-Algorithms]] · [[Kalman-Filter-and-State-Tracking]]
|
||||
- Adjacent: [[Entropy in Information Theory|Information Theory]] · [[Decision Theory]] · [[Expectation-Maximization]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 small data + domain prior 의 quantified uncertainty 의 필요. 매 sequential / online update.
|
||||
**언제 X**: 매 huge data + simple point estimate sufficient — 매 frequentist MLE 의 cheaper.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Improper flat prior 무지성 사용**: 매 posterior 의 improper 의 risk.
|
||||
- **Prior cherry-picking ex post**: 매 result 본 후 prior 의 tweak — 매 invalid.
|
||||
- **Likelihood-prior inconsistency**: 매 prior support 가 likelihood 와 mismatch.
|
||||
- **No posterior predictive check**: 매 fit 검증 없이 conclude.
|
||||
- **Overconfident strong prior on tiny data**: 매 prior 가 swamps evidence.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Gelman *Bayesian Data Analysis* 3e; Kruschke *DBDA* 2e; Bishop *PRML* Ch2).
|
||||
- Conjugate updates: 매 analytical, 매 verified math.
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full Bayesian update spec with PyMC 5 / NumPyro patterns |
|
||||
@@ -0,0 +1,147 @@
|
||||
---
|
||||
id: wiki-2026-0508-principle-of-least-action
|
||||
title: Principle of Least Action
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Stationary Action, Hamilton's Principle, Maupertuis Principle]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [physics, variational-calculus, lagrangian, optimization]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: jax/sympy
|
||||
---
|
||||
|
||||
# Principle of Least Action
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 Nature 의 action S 의 stationary 의 path 의 select"**. Maupertuis(1744) → Lagrange → Hamilton 의 발전 의 매 classical/quantum/field theory 의 unified backbone — 매 modern ML 의 neural ODEs / Hamiltonian networks 의 기반.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 정의
|
||||
- **Action**: S[q] = ∫ L(q, q̇, t) dt, 매 L = T − V (Lagrangian).
|
||||
- **Stationary**: δS = 0 (not 항상 minimum — 매 stationary point).
|
||||
- **Euler-Lagrange**: d/dt (∂L/∂q̇) − ∂L/∂q = 0.
|
||||
- **Hamiltonian**: H(q,p) = p·q̇ − L; 매 q̇ = ∂H/∂p, ṗ = −∂H/∂q.
|
||||
|
||||
### 매 형식
|
||||
- **Lagrangian (q, q̇)**: 매 generalized coords 의 자연.
|
||||
- **Hamiltonian (q, p)**: 매 phase-space 의 symplectic structure.
|
||||
- **Path Integral (Feynman)**: 매 amplitude = ∫ Dq exp(iS/ℏ) — 매 quantum extension.
|
||||
|
||||
### 매 응용
|
||||
1. 매 classical mechanics 의 EoM 의 derive.
|
||||
2. Optical path (Fermat) — light follows least-time.
|
||||
3. Geodesics in GR (least proper-time worldline).
|
||||
4. Symplectic ODE integrators (leapfrog).
|
||||
5. Hamiltonian Neural Networks, Lagrangian NN.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### SymPy — symbolic Euler-Lagrange (pendulum)
|
||||
```python
|
||||
import sympy as sp
|
||||
t, m, g, l = sp.symbols("t m g l", positive=True)
|
||||
q = sp.Function("q")(t)
|
||||
T = sp.Rational(1,2) * m * (l*sp.diff(q, t))**2
|
||||
V = -m*g*l*sp.cos(q)
|
||||
L = T - V
|
||||
EL = sp.diff(sp.diff(L, sp.diff(q,t)), t) - sp.diff(L, q)
|
||||
print(sp.simplify(EL)) # m*l^2*q'' + m*g*l*sin(q) = 0
|
||||
```
|
||||
|
||||
### Symplectic leapfrog integrator (preserves H)
|
||||
```python
|
||||
import numpy as np
|
||||
def leapfrog(q, p, dHdq, dHdp, dt, n):
|
||||
for _ in range(n):
|
||||
p = p - 0.5 * dt * dHdq(q)
|
||||
q = q + dt * dHdp(p)
|
||||
p = p - 0.5 * dt * dHdq(q)
|
||||
return q, p
|
||||
```
|
||||
|
||||
### JAX — automatic Lagrangian → EL residual
|
||||
```python
|
||||
import jax, jax.numpy as jnp
|
||||
def lagrangian(q, qdot):
|
||||
return 0.5*jnp.sum(qdot**2) - potential(q)
|
||||
|
||||
def el_residual(q, qdot, qddot):
|
||||
dL_dq = jax.grad(lagrangian, 0)(q, qdot)
|
||||
dL_dqdot = jax.grad(lagrangian, 1)(q, qdot)
|
||||
# d/dt(∂L/∂q̇) along trajectory:
|
||||
H = jax.hessian(lagrangian, argnums=(1,1))(q, qdot)
|
||||
d_dt = H @ qddot # simplified for autonomous L
|
||||
return d_dt - dL_dq
|
||||
```
|
||||
|
||||
### Lagrangian Neural Network (Cranmer 2020)
|
||||
```python
|
||||
# Parameterize L_θ(q,q̇) by an MLP; learn dynamics by enforcing EL eq.
|
||||
class LNN(nn.Module):
|
||||
def __call__(self, q, qdot):
|
||||
return self.mlp(jnp.concatenate([q, qdot]))
|
||||
|
||||
def predicted_qddot(params, q, qdot):
|
||||
L = lambda q,qd: lnn.apply(params, q, qd)
|
||||
H_qd_qd = jax.hessian(L, 1)(q, qdot)
|
||||
grad_q = jax.grad(L, 0)(q, qdot)
|
||||
return jnp.linalg.solve(H_qd_qd, grad_q)
|
||||
```
|
||||
|
||||
### Hamiltonian Neural Network
|
||||
```python
|
||||
# Greydanus 2019: parameterize H_θ(q,p); use symplectic gradients.
|
||||
def hnn_dynamics(params, q, p):
|
||||
H = lambda q,p: hnn.apply(params, q, p)
|
||||
return jax.grad(H, 1)(q,p), -jax.grad(H, 0)(q,p)
|
||||
```
|
||||
|
||||
### Geodesic integration (general metric)
|
||||
```python
|
||||
# Christoffel symbols Γ from g; geodesic eq: q̈^μ + Γ^μ_αβ q̇^α q̇^β = 0
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 매 holonomic constraints | Lagrangian (gen coords) |
|
||||
| 매 phase-space analysis / chaos | Hamiltonian |
|
||||
| 매 long-horizon energy preservation | Symplectic integrator (leapfrog, Verlet) |
|
||||
| 매 learn dynamics from data | LNN / HNN / Neural ODE |
|
||||
| 매 quantum / sum-over-paths | Path integral |
|
||||
| 매 optics / wave fronts | Fermat / eikonal form |
|
||||
|
||||
**기본값**: 매 Lagrangian + EL → leapfrog symplectic integration.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Optimal-Control-Theory]]
|
||||
- Adjacent: [[Optimization]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 conservative system 의 dynamics learn / simulate — 매 long-horizon stability 의 priority. 매 physics-informed ML.
|
||||
**언제 X**: 매 strongly dissipative / non-conservative — 매 Hamiltonian assumption 의 violate. 매 stochastic — 매 Langevin / SDE.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **"Least" action 으로 misinterpret**: 매 stationary, 매 not 항상 min — 매 saddle 도 valid.
|
||||
- **Non-symplectic integrator + long horizon**: 매 energy drift.
|
||||
- **Constraints 의 ad-hoc 처리**: 매 generalized coords 또는 Lagrange multipliers 의 use.
|
||||
- **Time-dependent L 의 Hamiltonian 으로 conserve assume**: 매 ∂L/∂t ≠ 0 → H 의 not conserved.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Goldstein *Classical Mechanics* 3e; Arnold *Mathematical Methods of CM*; Feynman Vol II).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Lagrangian/Hamiltonian/symplectic + LNN/HNN modern ML link |
|
||||
@@ -0,0 +1,152 @@
|
||||
---
|
||||
id: wiki-2026-0508-probability-theory
|
||||
title: Probability Theory
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Probability, Measure-Theoretic Probability, Stochastics]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.93
|
||||
verification_status: applied
|
||||
tags: [probability, statistics, measure-theory, foundations]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: numpy/scipy
|
||||
---
|
||||
|
||||
# Probability Theory
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 uncertainty 의 axiomatic calculus"**. Kolmogorov(1933) 의 (Ω, ℱ, P) triple 의 measure-theoretic foundation 의 매 modern ML / inference / quantum 의 모든 reasoning 의 기반.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 axioms (Kolmogorov)
|
||||
1. P(A) ≥ 0 모든 event A.
|
||||
2. P(Ω) = 1.
|
||||
3. σ-additivity: 매 disjoint {Aᵢ}, P(∪Aᵢ) = Σ P(Aᵢ).
|
||||
|
||||
### 매 핵심 개념
|
||||
- **Sample space Ω**, **σ-algebra ℱ**, **measure P**.
|
||||
- **Random variable**: ℱ-measurable X: Ω→ℝ.
|
||||
- **Distribution / CDF / PDF / PMF**.
|
||||
- **Independence**: P(A∩B) = P(A)P(B).
|
||||
- **Conditional**: P(A|B) = P(A∩B)/P(B); Bayes 의 즉시 derive.
|
||||
- **Expectation E[X] = ∫ X dP**, variance, covariance, MGF.
|
||||
|
||||
### 매 limit theorems
|
||||
- **LLN**: 매 sample mean → E[X].
|
||||
- **CLT**: 매 sum of iid 의 normalized 의 → 𝓝(0,1).
|
||||
- **Borel-Cantelli, SLLN, Kolmogorov 0-1 law**.
|
||||
|
||||
### 매 응용
|
||||
1. ML — likelihood, posterior, generalization bounds.
|
||||
2. Stochastic processes — Brownian motion, Poisson process, MCMC.
|
||||
3. Quantum mechanics (Born rule probabilities).
|
||||
4. Cryptography (random oracles, prob. proofs).
|
||||
5. Information theory (entropy, mutual info).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### NumPy distributions & sampling
|
||||
```python
|
||||
import numpy as np
|
||||
rng = np.random.default_rng(42)
|
||||
x = rng.normal(0, 1, size=10_000)
|
||||
print(x.mean(), x.std()) # 매 ~0, ~1
|
||||
```
|
||||
|
||||
### SciPy CDF / PDF / quantile
|
||||
```python
|
||||
from scipy import stats
|
||||
n = stats.norm(loc=0, scale=1)
|
||||
n.pdf(1.0); n.cdf(1.96); n.ppf(0.975) # ~1.96
|
||||
```
|
||||
|
||||
### Empirical CLT demo
|
||||
```python
|
||||
n, k = 30, 5000
|
||||
sample_means = rng.exponential(1.0, (k, n)).mean(axis=1)
|
||||
# Standardize: (mean - 1) * sqrt(n) → 매 ~ 𝓝(0,1)
|
||||
z = (sample_means - 1.0) * np.sqrt(n)
|
||||
```
|
||||
|
||||
### Conditional expectation via Monte Carlo
|
||||
```python
|
||||
# E[Y | X∈A] estimate
|
||||
mask = (X >= 0.5) & (X <= 0.7)
|
||||
cond_mean = Y[mask].mean()
|
||||
```
|
||||
|
||||
### Bayes update (discrete)
|
||||
```python
|
||||
priors = np.array([0.5, 0.5]) # H1, H2
|
||||
likes = np.array([0.9, 0.1]) # P(D|Hi)
|
||||
post = priors * likes
|
||||
post /= post.sum()
|
||||
```
|
||||
|
||||
### Markov chain stationary distribution
|
||||
```python
|
||||
P = np.array([[0.7,0.3],[0.4,0.6]])
|
||||
vals, vecs = np.linalg.eig(P.T)
|
||||
pi = np.real(vecs[:, np.isclose(vals,1)].ravel())
|
||||
pi /= pi.sum()
|
||||
```
|
||||
|
||||
### Tail bound (Chebyshev / Hoeffding)
|
||||
```python
|
||||
# P(|X̄ - μ| ≥ ε) ≤ 2 exp(-2 n ε² / (b-a)²) (Hoeffding, bounded X)
|
||||
def hoeffding(n, eps, a=0, b=1):
|
||||
return 2*np.exp(-2*n*eps**2 / (b-a)**2)
|
||||
```
|
||||
|
||||
### KL divergence
|
||||
```python
|
||||
from scipy.special import rel_entr
|
||||
kl = rel_entr(p, q).sum() # nats
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 매 finite sample / discrete | PMF, combinatorial |
|
||||
| 매 continuous, smooth | PDF + integration / change of variables |
|
||||
| 매 high-dim posterior | MCMC (NUTS) / VI / SMC |
|
||||
| 매 streaming / online | sufficient statistics, exp-family |
|
||||
| 매 worst-case bounds | Markov / Chebyshev / Hoeffding / Bernstein |
|
||||
| 매 dependence structure | copulas, graphical models |
|
||||
|
||||
**기본값**: 매 explicit (Ω, ℱ, P) framing → 매 distribution 의 identify → 매 numpy/scipy 의 simulate.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Statistics]] · [[Measure Theory]]
|
||||
- 변형: [[Probability Theory|Probability-Theory-Foundations]] (canonical-of-this)
|
||||
- 응용: [[Posterior-and-Prior-Probability]] · [[Entropy in Information Theory|Information Theory]] · [[Statistical-Power]] · [[Sampling-Techniques]]
|
||||
- Adjacent: [[Decision Theory]] · [[Information-Entropy]] · [[Monte-Carlo-Integration]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 uncertainty quantify / propagate / update 의 필요. 매 generative model 의 design.
|
||||
**언제 X**: 매 fully deterministic system — 매 logic / algebra 의 sufficient.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Frequentist↔Bayesian 의 conflate**: 매 different interpretations of P; 매 results 다를 수 있음.
|
||||
- **Independence assume 무근거**: 매 correlated data 의 i.i.d. 처리 → underestimated variance.
|
||||
- **Continuous vs discrete 혼동**: 매 P(X=x)=0 (continuous), 매 density ≠ probability.
|
||||
- **CLT 의 small n 적용**: 매 heavy tails / dependence — 매 fail.
|
||||
- **0/0 conditional**: 매 P(B)=0 의 P(A|B) 의 undefined (regular cond. prob 의 use).
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Billingsley *Probability and Measure* 3e; Durrett *Probability* 5e; Kolmogorov 1933).
|
||||
- 신뢰도 A.
|
||||
- Note: 매 Probability-Theory-Foundations.md 의 매 redirect 의 here.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full Kolmogorov axiomatic spec + numerical patterns; canonical for Probability-Theory-Foundations |
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user