mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-24 21:32:18 +00:00
分析算子的统计函数(app/analysis/stats.py,纯 Python、不加依赖):正态分布函数(math.erfc)与分位数(Acklam 逼近 + Halley 修正)、t 分布(正则化不完全 β 的连分式,自由度很大时按正态)与分位数(二分)、Wilson(从 eval/stats 移过来,评测改为引用、行为不变)、Newcombe 区间、合并比例 z 检验、Fisher 精确检验(lgamma)、Welch t 检验与区间、Holm 校正、Mann–Kendall(n ≤ 10 且无并列用逆序数递推的精确分布,否则正态近似带并列修正和连续性校正)、Theil–Sen(精确的数在公分母上按整数比,只对浮点相等的那几个精确比)、中位数 / MAD / 名次;测试用公认表值钉住(正态 0.975 分位、t(10) 临界值、品茶表、Newcombe 例子、小样本精确分布对照暴力枚举)
This commit is contained in:
@@ -22,25 +22,15 @@ from collections import Counter
|
||||
from collections.abc import Iterable, Mapping, Sequence
|
||||
from typing import Any
|
||||
|
||||
#: 95% 区间的 z
|
||||
Z95 = 1.959963984540054
|
||||
#: Wilson 区间和 95% 区间的 z 在分析的统计里(总方案 D13:分析和评测共用一套纯 Python 的统计),这里引用、行为不变
|
||||
from app.analysis.stats import Z95, wilson
|
||||
|
||||
#: 问数据页等复核最多这么久(毫秒,同 answer.REVIEW_PAGE_WAIT_S)
|
||||
REVIEW_PAGE_WAIT_MS = 25_000
|
||||
TIERS = ("formal", "degraded", "withheld", "explore")
|
||||
TIMING_KEYS = ("build_ms", "run_wall_ms", "run_active_ms", "review_ms", "total_ms")
|
||||
|
||||
|
||||
def wilson(passed: int, n: int, z: float = Z95) -> tuple[float, float] | None:
|
||||
"""Wilson 区间(缺省 95%)。n 为 0 时没有区间。"""
|
||||
if n <= 0:
|
||||
return None
|
||||
p = passed / n
|
||||
denom = 1 + z * z / n
|
||||
centre = (p + z * z / (2 * n)) / denom
|
||||
half = z * math.sqrt(p * (1 - p) / n + z * z / (4 * n * n)) / denom
|
||||
return round(max(0.0, centre - half), 4), round(min(1.0, centre + half), 4)
|
||||
|
||||
|
||||
def mcnemar_exact(only_a: int, only_b: int) -> float:
|
||||
"""精确 McNemar 双侧 p 值:不一致的那几题里,「只 A 对」服从 Binomial(b + c, 0.5)。没有不一致的题时为 1。"""
|
||||
n = only_a + only_b
|
||||
|
||||
Reference in New Issue
Block a user