chore: 初始化 MCM/ICM Toolkit 仓库骨架

审查并精简 ChatGPT 的建库建议后落地的第一版骨架,只定接口不写实现。

- 建议审查:14 个包 → 7 个;约 250 个函数 → 约 40 个;5 个 Result 类 → 1 个
  (docs/01-suggestion-review.md)
- docs/:架构、路线图(含永久不做清单)、环境、Git 工作流、函数卡片模板
- src/mcm_toolkit/:core / data / stats / models / solve / decision / viz
  共 23 个模块,均为签名 + docstring + NotImplementedError
- tests/:9 个文件,其中 test_api_surface.py 已通过(20 passed)
- examples/ problems/ notebooks/ figures/ tables/ 骨架
- pyproject.toml(核心依赖 4 个 + 6 组 extras)、environment.yml
- scripts/:setup-venv.ps1(ASCII + LF)、setup-conda.ps1、doctor.ps1
- 环境:.venv(system-site-packages)与 conda 环境 mcm-toolkit 均已建好,
  数值栈版本与 base 完全对齐(numpy 2.4.6 / scipy 1.18.1 / pandas 3.0.6,MKL 后端)
This commit is contained in:
guzhujushi committed 2026-10-01 17:43:48 +08:00
commit 5319589dfd
76 files changed
+6812

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
"""端到端最小流程:读数据 → 清洗 → 描述 → bootstrap → 出图。
体量刻意压到最小,只用来确认"环境 + 包 + 出图"这条链路是通的。
"""
from __future__ import annotations
import numpy as np
import mcm_toolkit as mcm
def main() -> None:
mcm.set_seed(20260101)
# 1) 造一份带缺失和离群点的数据(真实赛题里这步是 load_table)
rng = np.random.default_rng(20260101)
heights = rng.normal(170, 8, size=300)
heights[[3, 77]] = [260.0, -10.0] # 两个录入错误
# 2) 找出离群点(约定:只标不删,删不删是人来决定)
mask = np.asarray(mcm.data.detect_outliers(heights, method="iqr"))
print(f"检出离群点 {mask.sum()} 个")
clean = heights[~mask]
# 3) 描述统计
print(mcm.stats.describe(clean))
# 4) 中位数的 bootstrap 置信区间(统计量没有解析分布时的通用答案)
ci = mcm.bootstrap_ci(clean, statistic=np.median, n_resamples=10000, random_state=20260101)
print(f"中位数 = {np.median(clean):.2f}, 95% CI = [{ci.params['low']:.2f}, {ci.params['high']:.2f}]")
# 5) 出图(默认同时写 png + pdf,300 dpi)
mcm.viz.mcm_style()
fig, ax = mcm.viz.plot(clean, kind="hist", title="身高分布", xlabel="cm")
paths = mcm.viz.save_figure(fig, "figures/quickstart_hist")
print("已写出:", [str(p) for p in paths])
if __name__ == "__main__":
main()