| import csv |
|
|
|
|
| INPUT_PATH = "data/tester.csv" |
| OUTPUT_PATH = "predictions.csv" |
|
|
|
|
| def to_float(row, key): |
| return float(row[key]) |
|
|
|
|
| def baseline_predict(row): |
| pressure = to_float(row, "system_pressure") |
| buffer_capacity = to_float(row, "buffer_capacity") |
| intervention_lag = to_float(row, "intervention_lag") |
| subsystem_coupling = to_float(row, "subsystem_coupling") |
| drift_gradient = to_float(row, "drift_gradient") |
| boundary_distance = to_float(row, "boundary_distance") |
| intervention_leverage_score = to_float(row, "intervention_leverage_score") |
| intervention_alignment_score = to_float(row, "intervention_alignment_score") |
| side_effect_load = to_float(row, "side_effect_load") |
| recovery_window_width = to_float(row, "recovery_window_width") |
| local_relief_score = to_float(row, "local_relief_score") |
| global_destabilization_risk = to_float(row, "global_destabilization_risk") |
|
|
| rescue_signal = ( |
| 0.30 * buffer_capacity |
| + 0.25 * intervention_alignment_score |
| + 0.15 * recovery_window_width |
| + 0.10 * intervention_leverage_score |
| + 0.10 * boundary_distance |
| + 0.10 * (1.0 - intervention_lag) |
| ) |
|
|
| collapse_signal = ( |
| 0.25 * pressure |
| + 0.20 * subsystem_coupling |
| + 0.20 * drift_gradient |
| + 0.15 * side_effect_load |
| + 0.10 * global_destabilization_risk |
| + 0.10 * (1.0 - boundary_distance) |
| ) |
|
|
| penalty = 0.0 |
|
|
| if ( |
| local_relief_score >= 0.70 |
| and global_destabilization_risk >= 0.65 |
| and subsystem_coupling >= 0.65 |
| ): |
| penalty += 0.15 |
|
|
| if ( |
| intervention_lag >= 0.70 |
| and recovery_window_width <= 0.30 |
| and boundary_distance <= 0.30 |
| ): |
| penalty += 0.15 |
|
|
| score = rescue_signal - collapse_signal - penalty |
|
|
| return 1 if score >= 0.00 else 0 |
|
|
|
|
| def main(): |
| with open(INPUT_PATH, "r", newline="", encoding="utf-8") as f: |
| reader = csv.DictReader(f) |
| rows = list(reader) |
|
|
| predictions = [] |
| for row in rows: |
| predictions.append( |
| { |
| "scenario_id": row["scenario_id"], |
| "prediction": baseline_predict(row), |
| } |
| ) |
|
|
| with open(OUTPUT_PATH, "w", newline="", encoding="utf-8") as f: |
| writer = csv.DictWriter(f, fieldnames=["scenario_id", "prediction"]) |
| writer.writeheader() |
| writer.writerows(predictions) |
|
|
| print(f"Wrote {len(predictions)} predictions to {OUTPUT_PATH}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |