lnaive_nb.py~ 706 B

1234567891011121314151617181920
  1. def naive_network_benchmarking(network, path_list, bounces, sample_times):
  2. fidelity = {}
  3. cost = 0
  4. # ガード: サンプル0なら何もしない
  5. if sample_times and not any(sample_times.values()):
  6. return 0, 0, None
  7. for path in path_list:
  8. p, bounces_num = network.benchmark_path(path, bounces, sample_times)
  9. fidelity[path] = p + (1 - p) / 2
  10. cost += bounces_num
  11. if not fidelity: # ガード: path_list空など
  12. return 0, cost, None
  13. best_path = max(fidelity, key=fidelity.get)
  14. correctness = (best_path == network.best_path)
  15. best_path_fidelity = fidelity[best_path]
  16. return correctness, cost, best_path_fidelity