Main evaluation function that tests the signal processing algorithm on multiple test signals and calculates the composite performance metric.
(program_path)
| 264 | |
| 265 | |
| 266 | def evaluate(program_path): |
| 267 | """ |
| 268 | Main evaluation function that tests the signal processing algorithm |
| 269 | on multiple test signals and calculates the composite performance metric. |
| 270 | """ |
| 271 | try: |
| 272 | # Load the program |
| 273 | spec = importlib.util.spec_from_file_location("program", program_path) |
| 274 | program = importlib.util.module_from_spec(spec) |
| 275 | spec.loader.exec_module(program) |
| 276 | |
| 277 | # Check if required function exists |
| 278 | if not hasattr(program, "run_signal_processing"): |
| 279 | return {"composite_score": 0.0, "error": "Missing run_signal_processing function"} |
| 280 | |
| 281 | # Generate test signals |
| 282 | test_signals = generate_test_signals(5) |
| 283 | |
| 284 | # Collect metrics across all test signals |
| 285 | all_scores = [] |
| 286 | all_metrics = [] |
| 287 | successful_runs = 0 |
| 288 | |
| 289 | for i, (noisy_signal, clean_signal) in enumerate(test_signals): |
| 290 | try: |
| 291 | # Run the algorithm with timeout |
| 292 | start_time = time.time() |
| 293 | |
| 294 | # Call the program's main function |
| 295 | result = run_with_timeout( |
| 296 | program.run_signal_processing, |
| 297 | kwargs={ |
| 298 | "signal_length": len(noisy_signal), |
| 299 | "noise_level": 0.3, |
| 300 | "window_size": 20, |
| 301 | }, |
| 302 | timeout_seconds=10, |
| 303 | ) |
| 304 | |
| 305 | execution_time = time.time() - start_time |
| 306 | |
| 307 | # Validate result format |
| 308 | if not isinstance(result, dict): |
| 309 | print(f"Signal {i}: Invalid result format") |
| 310 | continue |
| 311 | |
| 312 | if "filtered_signal" not in result: |
| 313 | print(f"Signal {i}: Missing filtered_signal in result") |
| 314 | continue |
| 315 | |
| 316 | filtered_signal = result["filtered_signal"] |
| 317 | |
| 318 | if len(filtered_signal) == 0: |
| 319 | print(f"Signal {i}: Empty filtered signal") |
| 320 | continue |
| 321 | |
| 322 | # Convert to numpy arrays |
| 323 | filtered_signal = np.array(filtered_signal) |
no test coverage detected