Spaces:
Configuration error
Configuration error
| import sys | |
| import os | |
| import json | |
| import time | |
| import numpy as np | |
| from datetime import datetime | |
| # Adicionar o diretório raiz ao path para importar o core | |
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | |
| from core.logic import SVCA_Core | |
| def run_batch(n_runs=1000): | |
| print(f"Starting batch experiment: {n_runs} runs...") | |
| results = [] | |
| start_time = time.time() | |
| core = SVCA_Core() | |
| for i in range(n_runs): | |
| res = core.compute_algebra(f"run_{i}") | |
| results.append(res) | |
| if (i + 1) % 200 == 0: | |
| print(f"Progress: {i+1}/{n_runs}") | |
| end_time = time.time() | |
| duration = end_time - start_time | |
| # Calcular métricas | |
| psi_values = [r['psi'] for r in results] | |
| omega_values = [r['omega'] for r in results] | |
| metrics = { | |
| "n_runs": n_runs, | |
| "duration_sec": duration, | |
| "avg_psi": np.mean(psi_values), | |
| "std_psi": np.std(psi_values), | |
| "avg_omega": np.mean(omega_values), | |
| "std_omega": np.std(omega_values), | |
| "success_rate": sum(1 for r in results if r['status'] == "VALID") / n_runs, | |
| "timestamp": datetime.now().isoformat() | |
| } | |
| # Salvar resultados | |
| os.makedirs('data', exist_ok=True) | |
| with open('data/experiment_results.json', 'w') as f: | |
| json.dump({"metrics": metrics, "raw": results}, f, indent=2) | |
| print(f"Experiment completed in {duration:.2f}s") | |
| print(f"Average PSI: {metrics['avg_psi']:.4f}") | |
| print(f"Average OMEGA: {metrics['avg_omega']:.4f}") | |
| print(f"Success Rate: {metrics['success_rate']*100:.2f}%") | |
| return metrics | |
| if __name__ == "__main__": | |
| run_batch(1024) # Usando 1024 como sugerido no BULK.txt | |