Files
민헌andClaude Opus 5.5 13ab9dee84 chore: 2차년도 성능평가 측정 구성 초기 업로드
data(train 520·holdout 120), server(발화 생성 서버), eval(grounding_eval), run_eval.py·run_test.sh.
logs/ 는 실행 때마다 생기는 기록이라 README.md 만 올리고 나머지는 .gitignore 로 뺀다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 14:05:48 +09:00

90 lines
2.7 KiB
Python
Raw Permalink 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.
import pytest
from grounding_eval.stats import bootstrap_improvement_ci, improvement_pct, wilcoxon
def test_exact_all_positive():
# n=5, 모두 개선 → W- = 0, 양측 p = 2 × 1/32
result = wilcoxon([0, 0, 0, 0, 0], [1, 2, 3, 4, 5])
assert (result.n, result.w_plus, result.w_minus, result.method) == (5, 15, 0, "exact")
assert result.p_value == pytest.approx(0.0625)
def test_exact_mixed_signs():
# 차이 1, -2, 3, 4, 5 → W+ = 13, W- = 2. 합이 2 이하인 부분집합 {}, {1}, {2} → p = 2 × 3/32
result = wilcoxon([0] * 5, [1, -2, 3, 4, 5])
assert (result.w_plus, result.w_minus) == (13, 2)
assert result.p_value == pytest.approx(0.1875)
def test_zero_differences_are_dropped():
result = wilcoxon([1, 1, 1], [1, 2, 1])
assert result.n == 1
assert result.p_value == pytest.approx(1.0)
def test_no_difference_at_all():
result = wilcoxon([1, 2], [1, 2])
assert (result.n, result.p_value, result.method) == (0, 1.0, "none")
def test_ties_use_average_ranks_and_normal_approximation():
# |d| = 1, 1, 1 → 평균 순위 2
result = wilcoxon([0, 0, 0], [1, 1, -1])
assert (result.w_plus, result.w_minus, result.method) == (4, 2, "normal")
def test_normal_approximation_is_symmetric_and_detects_large_effect():
base = [0.30 + i * 0.001 for i in range(40)]
up = [b + 0.02 + i * 0.0001 for i, b in enumerate(base)]
down = [b - 0.02 - i * 0.0001 for i, b in enumerate(base)]
r_up, r_down = wilcoxon(base, up), wilcoxon(base, down)
assert r_up.method == "normal"
assert r_up.p_value == pytest.approx(r_down.p_value)
assert r_up.p_value < 0.001
def test_length_mismatch_raises():
with pytest.raises(ValueError):
wilcoxon([1], [1, 2])
def test_improvement_pct():
assert improvement_pct(0.30, 0.34) == pytest.approx(13.333, abs=1e-3)
assert improvement_pct(0.0, 0.1) is None
def test_bootstrap_constant_improvement():
lo, hi = bootstrap_improvement_ci([1.0] * 10, [1.1] * 10, iterations=500)
assert lo == pytest.approx(10.0) and hi == pytest.approx(10.0)
def test_bootstrap_is_reproducible_with_seed():
base = [0.2, 0.3, 0.25, 0.4, 0.35]
dev = [0.25, 0.28, 0.3, 0.45, 0.4]
assert bootstrap_improvement_ci(base, dev, iterations=300, seed=7) == \
bootstrap_improvement_ci(base, dev, iterations=300, seed=7)
def test_bootstrap_interval_contains_point_estimate():
base = [0.2, 0.3, 0.25, 0.4, 0.35, 0.28]
dev = [0.25, 0.28, 0.3, 0.45, 0.4, 0.33]
point = improvement_pct(sum(base) / 6, sum(dev) / 6)
lo, hi = bootstrap_improvement_ci(base, dev, iterations=2000)
assert lo <= point <= hi
def test_bootstrap_without_sessions():
assert bootstrap_improvement_ci([], []) is None