Files
aituner/runs/intervention-response-v0/test_p1_analysis.py

36 lines
929 B
Python

#!/usr/bin/env python3
from __future__ import annotations
import importlib.util
from pathlib import Path
HERE = Path(__file__).resolve().parent
def load_module():
spec = importlib.util.spec_from_file_location(
"intervention_response_p1", HERE / "analyze_p1.py"
)
module = importlib.util.module_from_spec(spec)
assert spec.loader is not None
spec.loader.exec_module(module)
return module
def main() -> None:
module = load_module()
values = [-2.0, -1.0, 1.0, 2.0]
labels = [0, 0, 1, 1]
threshold, direction, balanced = module._fit_threshold(values, labels)
assert direction == 1
assert -1.0 < threshold < 1.0
assert balanced == 1.0
assert module._balanced_accuracy(labels, labels) == 1.0
assert module._balanced_accuracy(labels, [1, 1, 0, 0]) == 0.0
print("intervention response P1 confirmation analysis: PASS")
if __name__ == "__main__":
main()