File size: 1,508 Bytes
5692d30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from dataclasses import dataclass
from typing import Dict, Any, List
import re

REQ = [
    "loop_coherence_index",
    "resonance_stability_band",
    "control_lag_profile",
    "correction_efficiency_score",
    "baseline_deviation",
]

BANDS = ["stable","fragile","unstable"]

@dataclass
class ScoreResult:
    score: float
    details: Dict[str, Any]

def _f(p: str, key: str):
    m = re.search(rf"{key}\s*[:=]\s*(0\.\d+|1\.0)\b", p)
    return float(m.group(1)) if m else None

def score(sample: Dict[str, Any], prediction: str) -> ScoreResult:
    p = (prediction or "").lower()
    words_ok = len(p.split()) <= 800

    hits = sum(1 for k in REQ if k in p)

    idx = _f(p,"loop_coherence_index")
    eff = _f(p,"correction_efficiency_score")
    dev = _f(p,"baseline_deviation")

    numeric_ok = int(
        idx is not None and 0<=idx<=1 and
        eff is not None and 0<=eff<=1 and
        dev is not None and 0<=dev<=1
    )

    band_ok = int("resonance_stability_band" in p and any(b in p for b in BANDS))
    lag_ok = int("control_lag_profile" in p)

    raw = (
        0.2 * int(words_ok) +
        0.4 * (hits/len(REQ)) +
        0.25 * numeric_ok +
        0.1 * band_ok +
        0.05 * lag_ok
    )

    return ScoreResult(score=min(1.0,raw), details={"id": sample.get("id"),"hits":hits})

def aggregate(results: List[ScoreResult]) -> Dict[str, Any]:
    if not results:
        return {"mean":0.0,"n":0}
    return {"mean":sum(r.score for r in results)/len(results),"n":len(results)}