Spaces:
Configuration error
Configuration error
File size: 1,740 Bytes
5fa2912 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 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
|