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:
Antigravity Agent
2026-07-05 00:33:48 +09:00
parent 1cfd3bbb56
commit 9148c358d0
6455 changed files with 1 additions and 86875 deletions
@@ -0,0 +1,193 @@
---
id: wiki-2026-0508-spectral-clustering
title: Spectral Clustering
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Graph Spectral Clustering, Laplacian Clustering, Normalized Cuts]
duplicate_of: none
source_trust_level: A
confidence_score: 0.93
verification_status: applied
tags: [clustering, graph, unsupervised, laplacian, eigendecomposition]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: Python
framework: scikit-learn/scipy/networkx
---
# Spectral Clustering
## 매 한 줄
> **"매 graph Laplacian 의 eigenvector 의 lower-dim embed → k-means"**. Spectral clustering 매 affinity-graph 매 cluster 의 detect, 매 non-convex / manifold 의 흐름 의 break (concentric circle, moons). 매 von Luxburg 2007 tutorial 의 canonical reference; 매 modern 매 Nyström approx + GPU eigen 의 large-scale.
## 매 핵심
### 매 3-step recipe
1. **Affinity matrix** $W$: $w_{ij} = \exp(-\|x_i - x_j\|^2 / 2\sigma^2)$ 또는 k-NN graph.
2. **Laplacian**:
- Unnormalized: $L = D - W$
- Symmetric normalized (Ng-Jordan-Weiss): $L_{sym} = I - D^{-1/2} W D^{-1/2}$
- Random-walk: $L_{rw} = I - D^{-1} W$
3. **Eigendecompose** → take k smallest eigenvectors → row-normalize → k-means on rows.
### 매 why eigenvectors?
- 매 graph cut (RatioCut / NCut) 매 NP-hard.
- 매 spectral relaxation 매 continuous: 매 2nd-smallest eigenvector (Fiedler) 의 sign 매 binary cut 의 approximate.
- 매 k cluster 매 k smallest eigenvectors 의 use.
### 매 variant
- **Ng-Jordan-Weiss (2002)**: $L_{sym}$ + row-normalize.
- **Shi-Malik (2000)**: Normalized Cuts, $L_{rw}$, image segmentation.
- **Self-tuning** (Zelnik-Manor 2004): per-point sigma.
- **Power Iteration Clustering** (Lin-Cohen 2010): 매 cheap approx.
### 매 응용
1. Image segmentation (NCut on pixel graph).
2. Community detection (small social nets).
3. Manifold-aware clustering (Swiss-roll, moons).
4. Speaker diarization (utterance affinity).
5. Document clustering (TF-IDF cosine graph).
## 💻 패턴
### scikit-learn
```python
from sklearn.cluster import SpectralClustering
from sklearn.datasets import make_moons
X, _ = make_moons(n_samples=400, noise=0.05)
sc = SpectralClustering(
n_clusters=2,
affinity="nearest_neighbors", # k-NN graph
n_neighbors=10,
assign_labels="kmeans",
random_state=42,
)
labels = sc.fit_predict(X)
```
### From scratch (numpy + scipy)
```python
import numpy as np
from scipy.sparse import csgraph
from scipy.sparse.linalg import eigsh
from sklearn.cluster import KMeans
from sklearn.neighbors import kneighbors_graph
def spectral_cluster(X, k, n_neighbors=10):
# 1. k-NN affinity
W = kneighbors_graph(X, n_neighbors=n_neighbors, mode='connectivity')
W = 0.5 * (W + W.T) # symmetrize
# 2. Symmetric normalized Laplacian
L = csgraph.laplacian(W, normed=True)
# 3. k smallest eigenvectors
vals, vecs = eigsh(L, k=k, which='SM')
# 4. Row-normalize
norm = np.linalg.norm(vecs, axis=1, keepdims=True)
vecs = vecs / np.clip(norm, 1e-10, None)
# 5. k-means
return KMeans(n_clusters=k, n_init=10).fit_predict(vecs)
```
### RBF affinity
```python
from sklearn.metrics.pairwise import rbf_kernel
def rbf_affinity(X, sigma=1.0):
gamma = 1.0 / (2.0 * sigma**2)
return rbf_kernel(X, gamma=gamma)
```
### Sigma auto-tuning (k-th NN distance)
```python
from sklearn.neighbors import NearestNeighbors
def auto_sigma(X, k=7):
nn = NearestNeighbors(n_neighbors=k+1).fit(X)
d, _ = nn.kneighbors(X)
return np.median(d[:, k])
```
### Eigengap heuristic (choose k)
```python
def eigengap_k(L, max_k=15):
vals, _ = eigsh(L, k=max_k, which='SM')
vals = np.sort(vals)
gaps = np.diff(vals)
return int(np.argmax(gaps)) + 1
```
### Large-scale Nyström approximation
```python
from sklearn.kernel_approximation import Nystroem
from sklearn.cluster import KMeans
# For N >> 10k
nys = Nystroem(kernel='rbf', gamma=0.1, n_components=300, random_state=0)
X_low = nys.fit_transform(X)
labels = KMeans(n_clusters=k, n_init=10).fit_predict(X_low)
```
### Image segmentation (NCut)
```python
from skimage import data, segmentation, color
from skimage.future import graph
img = data.coffee()
labels1 = segmentation.slic(img, compactness=30, n_segments=400)
g = graph.rag_mean_color(img, labels1, mode='similarity')
labels2 = graph.cut_normalized(labels1, g)
out = color.label2rgb(labels2, img, kind='avg')
```
### Diarization affinity (cosine)
```python
def speaker_affinity(embeddings):
# (N, D) speaker embeddings, L2-normalized
sim = embeddings @ embeddings.T
sim = (sim + 1) / 2 # [0,1]
return sim
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Convex blob clusters | k-means (faster) |
| Non-convex / manifold | Spectral (k-NN affinity) |
| N < 5k | Full eigendecomp |
| 5k < N < 50k | k-NN sparse + eigsh |
| N > 50k | Nyström / mini-batch |
| Image seg | NCut + SLIC superpixels |
| Speaker diar | Cosine affinity + spectral |
**기본값**: sklearn `SpectralClustering(affinity='nearest_neighbors', n_neighbors=10)`.
## 🔗 Graph
- 부모: [[Clustering]]
- 변형: [[K-Means]]
- 응용: [[Image-Segmentation]]
- Adjacent: [[Normalized-Cuts]]
## 🤖 LLM 활용
**언제**: 매 affinity choice rationale, 매 eigengap interpretation, 매 sklearn pipeline scaffolding.
**언제 X**: 매 numerical eigendecomp (use scipy/PyTorch), 매 cluster validation 매 ground-truth needed.
## ❌ 안티패턴
- **Dense N×N for N>10k**: 매 OOM. 매 k-NN sparse 의 use.
- **Sigma 의 untuned**: 매 RBF kernel 매 useless. 매 median distance heuristic.
- **k 매 hand-pick**: 매 eigengap heuristic 의 first try.
- **No symmetrization**: 매 k-NN graph 의 directed → 매 complex eigenvalues.
- **Wrong Laplacian for unbalanced**: 매 unnormalized 매 cluster size 의 sensitive. 매 $L_{sym}$ default.
## 🧪 검증 / 중복
- Verified (von Luxburg "A Tutorial on Spectral Clustering" 2007; Ng-Jordan-Weiss NIPS 2002; sklearn docs 1.5).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — full content (Laplacian variants + sklearn/scipy + Nyström patterns) |