-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoring.py
More file actions
30 lines (24 loc) · 877 Bytes
/
Copy pathscoring.py
File metadata and controls
30 lines (24 loc) · 877 Bytes
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
"""
Reward and scoring utilities for Poker44 poker bot detection.
"""
from __future__ import annotations
from typing import Dict, List, Sequence
import numpy as np
import torch
from sklearn.metrics import average_precision_score, confusion_matrix, f1_score
def reward(y_pred: np.ndarray, y_true: np.ndarray) -> tuple[float, dict]:
"""
Compute a reward based on F1, average precision and false-positive control.
"""
preds = np.round(y_pred).astype(int)
cm = confusion_matrix(y_true, preds, labels=[0, 1])
_, fp, _, tp = cm.ravel()
f1 = f1_score(y_true, preds) if (tp + fp) > 0 else 0.0
ap_score = average_precision_score(y_true, y_pred) if y_pred.size else 0.0
res = {
"fp_score": 1 - fp / max(len(y_pred), 1),
"f1_score": f1,
"approve": ap_score
}
rew = sum(res.values()) / len(res)
return rew, res