Evaluate wearer floor changes by event

This commit is contained in:
Xin Wang
2026-08-30 18:26:15 +08:00
parent 714b530fe4
commit 6f5115f299
2 changed files with 430 additions and 8 deletions

View File

@@ -9,6 +9,7 @@ import numpy as np
from evaluate_floor_state_changes import (
NUM_CLASSES,
NUM_HORIZONS,
evaluate_event_horizon,
evaluate_horizon,
load_arrays,
parse_runs,
@@ -21,6 +22,67 @@ def activity(wearer: int, others: int) -> list[int]:
class FloorStateMetricTests(unittest.TestCase):
def test_event_level_counts_each_boundary_once(self) -> None:
target = np.asarray(
[
activity(0, 1), # other offset follows
activity(0, 0),
activity(1, 0), # wearer responds within 0.4s
activity(1, 0), # other entry follows
activity(1, 1),
activity(0, 1), # wearer yields within 0.4s
activity(0, 1),
activity(0, 1),
activity(0, 0), # short pause, no wearer response
activity(0, 1),
activity(1, 0), # another other entry follows
activity(1, 1),
activity(1, 1), # wearer continues
],
dtype=np.float32,
)
prediction = np.full(
(len(target), NUM_CLASSES, NUM_HORIZONS), 0.5, dtype=np.float32
)
# Fixed source row 0: response score max(0.2, 0.9).
prediction[1, 1, 0] = 0.2
prediction[2, 1, 1] = 0.9
# Fixed source row 7: no-response score max(0.1, 0.2).
prediction[8, 1, 0] = 0.1
prediction[9, 1, 1] = 0.2
# Fixed source row 3: yield score max(0.2, 0.9).
prediction[4, 1, 0] = 0.8
prediction[5, 1, 1] = 0.1
# Fixed source row 10: continue score max(0.1, 0.2).
prediction[11, 1, 0] = 0.9
prediction[12, 1, 1] = 0.8
valid = np.ones((len(target), NUM_HORIZONS), dtype=bool)
session_ids = np.zeros(len(target), dtype=np.int32)
session_ids[10:] = 1
result = evaluate_event_horizon(
target,
prediction,
valid,
session_ids,
1,
[0.8],
midturn_pause_max_steps=10,
)
response = result["other_offset_to_wearer_response_event"]
self.assertEqual(response["num_positive"], 1)
self.assertEqual(response["num_negative"], 1)
self.assertEqual(response["num_short_resume_hard_negative"], 1)
self.assertAlmostEqual(response["average_precision"], 1.0)
self.assertAlmostEqual(
response["operating_points"][0]["negative_false_positive_rate"],
0.0,
)
yield_metric = result["other_onset_to_wearer_yield_event"]
self.assertEqual(yield_metric["num_positive"], 1)
self.assertEqual(yield_metric["num_negative"], 1)
self.assertAlmostEqual(yield_metric["average_precision"], 1.0)
def test_horizon_one_proxies_and_session_boundary(self) -> None:
# t0->t1: EOT-response; t3->t4: HOLD; t4->t5: early entry;
# t6->t7: other-entry yield; t8->t9: other-entry continue.