Skip to content

做什么(One-liner)

N 个 agent 初始 lognormal 财富,每 tick 随机两两交换 5% × min 财富(有 -0.025 mean drift),追踪 Gini 演化。纯教学 / demo,NOT 真实市场模拟。

怎么用

Canvas 拖 b0_abm_v1,填 n_agents (default 50)、ticks (default 100)、seed (default 42)。完全确定性:同 seed 字节一致。

canvas node b0_abm_v1 (n_agents=50, ticks=100, seed=42)
  → final_gini ≈ 0.21, gini_sample_path[last 10]

核心公式

python
wealth = rng.lognormal(0, 0.5, n_agents)

for tick in range(ticks):
    i, j = rng.integers(0, n_agents, 2)
    if i == j: continue
    min_w = min(wealth[i], wealth[j])
    transfer = 0.05 * min_w * (rng.random() - 0.45)    # mean drift -0.025
    wealth[i] = max(1e-9, wealth[i] + transfer)
    wealth[j] = max(1e-9, total - wealth[i])
    if tick % max(1, ticks // 20) == 0:
        gini_sampled = gini(wealth)

final_gini = gini(wealth)

假设与适用场景

假设:fully-connected pair selection + lognormal initial + wealth floor 1e-9 + 无外部冲击 + deterministic seed。

适用:Canvas 教学、complexity skill 演示、ABM 入门。

不适用:真实市场、政策分析、破产建模、网络结构研究。

已知局限

  1. Pedagogical only_model 字段显式声明 "toy ABM"
  2. Not calibrated — transfer=0.05 / drift=0.45 是 stylized 常量
  3. Fully-connected — 无网络拓扑
  4. No bankruptcy — 1e-9 floor 使 agent 永存
  5. No external shocks / income / policy
  6. gini_sample_path 只返回最后 10 个
  7. Lognormal ≠ Pareto — 不同于 Dragulescu-Yakovenko uniform 或 Bouchaud-Mézard Pareto

参考文献

  • Dragulescu-Yakovenko (2000) EPJB — pairwise exchange statistical mechanics
  • Bouchaud-Mézard (2000) Physica A — wealth condensation
  • Gini (1912) — Gini coefficient 原始定义

Golden Test

tests/golden/fixtures/tier4/b0_abm/numpy_manual(self-referential:golden IS the source — bit-deterministic pinned numpy rng)。1e-12 tolerance。12 tests

6 Scenarios

  • default_50agents_100ticks (Canvas defaults, seed=42)
  • small_10agents_20ticks
  • large_200agents_500ticks
  • different_seed_123 — verifies seed IS honored
  • short_ticks_5 — sample path with interval=1
  • one_tick — gini_sample_path empty (boundary)

6 Contract tests

  • determinism: 5 reruns byte-identical
  • result_structure: 7 fixed top-level keys
  • gini_in_range: ∈ [0, 1]
  • gini_rounded_to_4_decimals
  • sample_path_last_10: ≤ 10 elements
  • model_field_locked: "toy ABM" substring present

Changelog

  • 1.0.0 (2026-04-21) — 首次 Active(Tier 4 batch 1.1)

Verifiable intelligence for the decisions that demand scrutiny.