Files
2nd/10_Wiki/Topics/Architecture/Swarm_Intelligence.md
T
2026-05-10 22:08:15 +09:00

182 lines
6.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: wiki-2026-0508-swarm-intelligence
title: Swarm Intelligence
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Swarm AI, Collective Intelligence, Multi-Agent Optimization]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [optimization, multi-agent, bio-inspired, ai]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: python
framework: numpy-deap
---
# Swarm Intelligence
## 매 한 줄
> **"매 simple agents 의 collective 의 emergent intelligence"**. 매 ant colony, bird flock, bee swarm 의 inspired — 매 local rules + interaction 의 global optimization. 2026 의 application 의 LLM agent swarms (CrewAI, AutoGen) + classic optim.
## 매 핵심
### 매 핵심 algorithms
- **PSO (Particle Swarm Optimization)**: 매 particle 의 personal best + global best 의 update.
- **ACO (Ant Colony Optimization)**: 매 pheromone trail 의 path optim — TSP.
- **ABC (Artificial Bee Colony)**: 매 employed/onlooker/scout 의 분업.
- **Firefly / Cuckoo**: 매 attractiveness / Lévy flight 의 search.
### 매 properties
- **Decentralization**: 매 central control 의 X.
- **Self-organization**: 매 local interaction → global pattern.
- **Robustness**: 매 single agent 의 fail 의 swarm 의 survive.
- **Stigmergy**: 매 environment 의 state 의 indirect communication (pheromone).
### 매 응용
1. Routing (vehicle, network).
2. Scheduling (job shop, cloud workload).
3. Hyperparameter tuning (PSO 의 grid search 의 대체).
4. LLM multi-agent (CrewAI roles, debate, voting).
5. Drone swarms (formation, coverage).
## 💻 패턴
### PSO — minimize objective
```python
import numpy as np
def pso(f, dim, n=30, iters=200, w=0.7, c1=1.5, c2=1.5, lo=-5, hi=5):
x = np.random.uniform(lo, hi, (n, dim))
v = np.zeros_like(x)
pbest = x.copy()
pbest_val = np.array([f(p) for p in x])
g = pbest[pbest_val.argmin()]
for _ in range(iters):
r1, r2 = np.random.rand(n, dim), np.random.rand(n, dim)
v = w*v + c1*r1*(pbest - x) + c2*r2*(g - x)
x = np.clip(x + v, lo, hi)
vals = np.array([f(p) for p in x])
mask = vals < pbest_val
pbest[mask], pbest_val[mask] = x[mask], vals[mask]
g = pbest[pbest_val.argmin()]
return g, pbest_val.min()
best, val = pso(lambda x: np.sum(x**2), dim=10)
```
### ACO — TSP
```python
import numpy as np
def aco_tsp(dist, n_ants=20, iters=100, alpha=1, beta=3, rho=0.1, Q=1):
n = len(dist)
tau = np.ones((n, n))
eta = 1 / (dist + 1e-10)
best_path, best_len = None, float('inf')
for _ in range(iters):
paths = []
for _ in range(n_ants):
path = [np.random.randint(n)]
unvisited = set(range(n)) - {path[0]}
while unvisited:
i = path[-1]
p = np.array([(tau[i,j]**alpha) * (eta[i,j]**beta) for j in unvisited])
p /= p.sum()
j = list(unvisited)[np.random.choice(len(unvisited), p=p)]
path.append(j)
unvisited.remove(j)
paths.append(path)
# update
tau *= (1 - rho)
for path in paths:
length = sum(dist[path[i], path[i+1]] for i in range(n-1))
if length < best_len:
best_len, best_path = length, path
for i in range(n-1):
tau[path[i], path[i+1]] += Q / length
return best_path, best_len
```
### LLM agent swarm — CrewAI
```python
from crewai import Agent, Task, Crew
researcher = Agent(role="Researcher", goal="find facts",
llm="claude-opus-4-7")
critic = Agent(role="Critic", goal="poke holes",
llm="claude-opus-4-7")
synth = Agent(role="Synthesizer", goal="merge views",
llm="claude-opus-4-7")
crew = Crew(
agents=[researcher, critic, synth],
tasks=[
Task(description="research X", agent=researcher),
Task(description="critique research", agent=critic),
Task(description="synthesize", agent=synth),
],
process="sequential",
)
result = crew.kickoff()
```
### Boids — flocking simulation
```python
import numpy as np
def boids_step(pos, vel, sep_r=1, ali_r=3, coh_r=5, max_v=2):
n = len(pos)
new_vel = vel.copy()
for i in range(n):
d = np.linalg.norm(pos - pos[i], axis=1)
sep = -np.sum((pos[d < sep_r] - pos[i]), axis=0)
ali = np.mean(vel[(d < ali_r) & (d > 0)], axis=0) - vel[i] if ((d < ali_r) & (d > 0)).any() else 0
coh = np.mean(pos[(d < coh_r) & (d > 0)], axis=0) - pos[i] if ((d < coh_r) & (d > 0)).any() else 0
new_vel[i] += 0.5*sep + 0.3*ali + 0.2*coh
speed = np.linalg.norm(new_vel[i])
if speed > max_v:
new_vel[i] = new_vel[i] / speed * max_v
return pos + new_vel, new_vel
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Continuous optimization | PSO |
| Combinatorial (TSP, scheduling) | ACO |
| Multi-objective | NSGA-II / MOPSO |
| LLM-based reasoning | Agent swarm (CrewAI) |
| Convex problem | 매 swarm 의 X — gradient descent |
**기본값**: 매 PSO 의 continuous, 매 ACO 의 graph problems.
## 🔗 Graph
- 부모: [[Metaheuristics]] · [[Multi-Agent Systems]]
- 변형: [[Genetic Algorithms]] · [[Simulated Annealing]] · [[CMA-ES]]
- 응용: [[Hyperparameter Tuning]] · [[Drone Swarms]] · [[Agent Frameworks]]
- Adjacent: [[Emergence]] · [[Self-Organization]] · [[Stigmergy]]
## 🤖 LLM 활용
**언제**: black-box optimization, multi-agent reasoning, 매 gradient 의 unavailable.
**언제 X**: convex / differentiable (use gradient methods), small discrete (use exact).
## ❌ 안티패턴
- **No diversification**: 매 premature convergence — 매 inertia / mutation 의 tune.
- **Wrong neighborhood topology**: 매 fully-connected 의 always 의 X — ring/star 의 try.
- **Naive multi-LLM swarm**: 매 cost 의 N× — 매 token budget 의 monitor.
## 🧪 검증 / 중복
- Verified (Kennedy & Eberhart 1995 PSO; Dorigo ACO; CrewAI 2026 docs).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — PSO, ACO, boids, LLM agent swarms |