ClarusC64 commited on
Commit
b1c1cb4
·
verified ·
1 Parent(s): c31fcac

Create scorer.py

Browse files
Files changed (1) hide show
  1. scorer.py +46 -0
scorer.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+ from typing import Dict, Any, List
3
+
4
+ @dataclass
5
+ class ScoreResult:
6
+ score: float
7
+ details: Dict[str, Any]
8
+
9
+ def _clamp01(x: float) -> float:
10
+ return max(0.0, min(1.0, x))
11
+
12
+ def score(sample: Dict[str, Any], prediction: Dict[str, Any]) -> ScoreResult:
13
+ # Ground truth
14
+ true_tbr = float(sample.get("baseline_tbr", 0))
15
+ true_coh = float(sample.get("baseline_coherence_score", 0))
16
+ true_flag = int(sample.get("decoupling_flag", 0))
17
+
18
+ # Predictions
19
+ pred_tbr = float(prediction.get("baseline_tbr", 0))
20
+ pred_coh = float(prediction.get("baseline_coherence_score", 0))
21
+ pred_flag = int(prediction.get("decoupling_flag", 0))
22
+
23
+ # Accuracy components
24
+ tbr_err = abs(true_tbr - pred_tbr) / max(true_tbr, 1e-6)
25
+ coh_err = abs(true_coh - pred_coh)
26
+
27
+ tbr_acc = _clamp01(1.0 - tbr_err)
28
+ coh_acc = _clamp01(1.0 - coh_err)
29
+ flag_acc = 1.0 if true_flag == pred_flag else 0.0
30
+
31
+ total = 0.45 * tbr_acc + 0.35 * coh_acc + 0.20 * flag_acc
32
+
33
+ return ScoreResult(
34
+ score=total,
35
+ details={
36
+ "id": sample.get("id"),
37
+ "tbr_err": tbr_err,
38
+ "coh_err": coh_err,
39
+ "flag_acc": flag_acc
40
+ }
41
+ )
42
+
43
+ def aggregate(results: List[ScoreResult]) -> Dict[str, Any]:
44
+ if not results:
45
+ return {"mean": 0.0, "n": 0}
46
+ return {"mean": sum(r.score for r in results) / len(results), "n": len(results)}