Spaces:
Sleeping
Sleeping
KrisKeshav commited on
Improving comments in grading functions for better understanding
Browse files- src/graders.py +4 -7
src/graders.py
CHANGED
|
@@ -11,7 +11,6 @@ from typing import List, Dict, Any, Optional
|
|
| 11 |
def grade_task_easy(history: List[Dict[str, Any]], attack_start_step: int) -> float:
|
| 12 |
"""
|
| 13 |
Task 1 — Sinusoidal FDI Detection (Easy).
|
| 14 |
-
|
| 15 |
Grader logic (relative to attack onset):
|
| 16 |
delay = first_correct_detection_step - attack_start_step
|
| 17 |
if delay <= 20: score = 1.0
|
|
@@ -49,7 +48,6 @@ def grade_task_easy(history: List[Dict[str, Any]], attack_start_step: int) -> fl
|
|
| 49 |
def grade_task_medium(history: List[Dict[str, Any]], attack_start_step: int) -> float:
|
| 50 |
"""
|
| 51 |
Task 2 — Multi-Attack Classification (Medium).
|
| 52 |
-
|
| 53 |
Grader logic:
|
| 54 |
base_score = fraction of steps (after attack_start) where attack_type is correctly classified
|
| 55 |
early_bonus = 0.4 * max(0, 1 - first_correct_classification_step / 100)
|
|
@@ -94,7 +92,6 @@ def grade_task_hard(
|
|
| 94 |
) -> float:
|
| 95 |
"""
|
| 96 |
Task 3 — Stealthy Low-and-Slow Attack (Hard).
|
| 97 |
-
|
| 98 |
Grader logic:
|
| 99 |
if detected before loss_of_lock_step:
|
| 100 |
score = 1.0 * (1 - first_detection_step / loss_of_lock_step)
|
|
@@ -113,14 +110,14 @@ def grade_task_hard(
|
|
| 113 |
attack_active = entry["attack_active"]
|
| 114 |
attack_detected = entry["attack_detected"]
|
| 115 |
|
| 116 |
-
# Only
|
| 117 |
if attack_detected and not attack_active and step < attack_start_step:
|
| 118 |
false_alarm_count += 1
|
| 119 |
|
| 120 |
if attack_detected and attack_active and first_detection_step is None:
|
| 121 |
first_detection_step = step
|
| 122 |
|
| 123 |
-
#
|
| 124 |
if first_detection_step is None:
|
| 125 |
score = 0.0
|
| 126 |
elif loss_of_lock_step is not None and first_detection_step < loss_of_lock_step:
|
|
@@ -131,8 +128,8 @@ def grade_task_hard(
|
|
| 131 |
# No loss of lock occurred but attack was detected
|
| 132 |
score = 0.3
|
| 133 |
|
| 134 |
-
#
|
| 135 |
penalty = 0.2 * false_alarm_count
|
| 136 |
score = max(0.0, score - penalty)
|
| 137 |
|
| 138 |
-
return min(1.0, score)
|
|
|
|
| 11 |
def grade_task_easy(history: List[Dict[str, Any]], attack_start_step: int) -> float:
|
| 12 |
"""
|
| 13 |
Task 1 — Sinusoidal FDI Detection (Easy).
|
|
|
|
| 14 |
Grader logic (relative to attack onset):
|
| 15 |
delay = first_correct_detection_step - attack_start_step
|
| 16 |
if delay <= 20: score = 1.0
|
|
|
|
| 48 |
def grade_task_medium(history: List[Dict[str, Any]], attack_start_step: int) -> float:
|
| 49 |
"""
|
| 50 |
Task 2 — Multi-Attack Classification (Medium).
|
|
|
|
| 51 |
Grader logic:
|
| 52 |
base_score = fraction of steps (after attack_start) where attack_type is correctly classified
|
| 53 |
early_bonus = 0.4 * max(0, 1 - first_correct_classification_step / 100)
|
|
|
|
| 92 |
) -> float:
|
| 93 |
"""
|
| 94 |
Task 3 — Stealthy Low-and-Slow Attack (Hard).
|
|
|
|
| 95 |
Grader logic:
|
| 96 |
if detected before loss_of_lock_step:
|
| 97 |
score = 1.0 * (1 - first_detection_step / loss_of_lock_step)
|
|
|
|
| 110 |
attack_active = entry["attack_active"]
|
| 111 |
attack_detected = entry["attack_detected"]
|
| 112 |
|
| 113 |
+
# Only counting false alarms before the attack starts
|
| 114 |
if attack_detected and not attack_active and step < attack_start_step:
|
| 115 |
false_alarm_count += 1
|
| 116 |
|
| 117 |
if attack_detected and attack_active and first_detection_step is None:
|
| 118 |
first_detection_step = step
|
| 119 |
|
| 120 |
+
# Computing base score
|
| 121 |
if first_detection_step is None:
|
| 122 |
score = 0.0
|
| 123 |
elif loss_of_lock_step is not None and first_detection_step < loss_of_lock_step:
|
|
|
|
| 128 |
# No loss of lock occurred but attack was detected
|
| 129 |
score = 0.3
|
| 130 |
|
| 131 |
+
# Applying false alarm penalty
|
| 132 |
penalty = 0.2 * false_alarm_count
|
| 133 |
score = max(0.0, score - penalty)
|
| 134 |
|
| 135 |
+
return min(1.0, score)
|