MEMO.org~ 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # add_linkselfie – I/O & Loops memo
  2. ## main.py
  3. **Inputs**
  4. - 実験パラメータ: `budget_list`, `scheduler_names`, `noise_model_names`, `node_path_list`, `importance_list`, `bounces`, `repeat`
  5. **Outputs**
  6. - `evaluation.py` の各関数を並列実行 → `outputs/*.pdf` を生成
  7. **Loops**
  8. - `for noise_model in noise_model_names:`
  9. - `Pool.apply_async(...)` で
  10. - `plot_accuracy_vs_budget(...)`
  11. - `plot_value_vs_used(...)`
  12. - `plot_value_vs_budget_target(...)`
  13. - 最後に `join()` して回収
  14. ---
  15. ## evaluation.py
  16. ### plot_accuracy_vs_budget(...)
  17. **Inputs**: 予算列・スケジューラ名・ノイズモデル・ノード/重要度・`bounces`・`repeat`
  18. **Outputs**: `outputs/plot_accuracy_vs_budget_{noise_model}.pdf`
  19. **Loops**:
  20. - `for C_total in budget_list:`
  21. - `for r in range(repeat):`
  22. - トポロジ生成(ペアごとに fidelity リスト)
  23. - `for name in scheduler_names:` → `run_scheduler(...)`
  24. - 正答率を集計(平均)
  25. ### plot_value_vs_used(...)
  26. **Inputs**: 同上(`return_details=True` で呼ぶ)
  27. **Outputs**: `outputs/plot_value_vs_used_{noise_model}.pdf`(x=実消費コスト平均)
  28. **Loops**:
  29. - `for C_total in budget_list:`
  30. - `for r in range(repeat):`
  31. - トポロジ生成
  32. - `for name in scheduler_names:` → `run_scheduler(..., return_details=True)`
  33. - 受け取った `alloc_by_path` と `est_fid_by_path` で価値を合成
  34. - `total_cost` を保持
  35. ### plot_value_vs_budget_target(...)
  36. **Inputs**: 同上(`return_details=True` で呼ぶ)
  37. **Outputs**: `outputs/plot_value_vs_budget_target_{noise_model}.pdf`(x=目標予算)
  38. **Loops**: `plot_value_vs_used` と同一(プロット時の x だけ `budget_list`)
  39. ---
  40. ## schedulers/__init__.py
  41. **Inputs**: `node_path_list`, `importance_list`, `scheduler_name`, `bounces`, `C_total`, `network_generator`, `return_details`
  42. **Outputs**:
  43. - `"LNaive"` → `lnaive_budget_scheduler(...)` の戻り値をそのまま返す
  44. - `"Greedy"` → `greedy_budget_scheduler(...)` の戻り値をそのまま返す
  45. **Loops**: なし(ディスパッチのみ)
  46. ---
  47. ## schedulers/lnaive_scheduler.py
  48. **Inputs**: `node_path_list`, `importance_list`, `bounces`, `C_total`, `network_generator`, `return_details=False`
  49. **Outputs**:
  50. - `per_pair_results: List[(correct: bool, cost: int, best_fid: float|None)]`
  51. - `total_cost: int`
  52. - `per_pair_details: List[{alloc_by_path, est_fid_by_path}]`(`return_details=True` のとき)
  53. **Loops**:
  54. - `for pair_idx, path_num in enumerate(node_path_list):`
  55. - 各ペアに等分配した予算で `naive_network_benchmarking_with_budget(...)` を1回呼ぶ
  56. ---
  57. ## schedulers/greedy_scheduler.py
  58. **Inputs**: `node_path_list`, `importance_list`, `bounces`, `C_total`, `network_generator`, `C_initial_per_pair=40`, `return_details=False`
  59. **Outputs**: 上記 LNaive と同形(初期+残余の詳細はマージ)
  60. **Loops**:
  61. 1) **初期プローブ**: `for pair_idx, path_num in enumerate(node_path_list):`
  62. - 小予算で `lonline_network_benchmarking(...)` を実行
  63. 2) **優先度計算**: `score = importance * estimated_fidelity` を全ペアで算出し降順ソート
  64. 3) **残余配分**: `for pair_idx in sorted_indices:` 残り予算を順に集中投資(各回 `lonline_network_benchmarking(...)`)
  65. ---
  66. ## schedulers/lonline_nb.py (アルゴ:L-Online)
  67. **Inputs**: `network`, `path_list`, `bounces`, `C_budget`, `return_details=False`
  68. **Outputs**:
  69. - `return_details=False`: `(correct: bool, cost: int, best_fid: float|None)`
  70. - `return_details=True` : 上に加え `alloc_by_path: {path_id:int}`, `est_fid_by_path: {path_id:float}`
  71. **Loops**:
  72. - `while cost < C_budget and len(candidate_set) > 1:`
  73. - ラウンド `s` のサンプル数 `Ns` を決定
  74. - `for path in candidate_set:`(予算が入る分だけ計測)
  75. - 連続削除ルールで候補を間引き
  76. ---
  77. ## schedulers/lnaive_nb.py (アルゴ:L-Naive)
  78. **Inputs**: `network`, `path_list`, `bounces`, `C_budget`, `return_details=False`
  79. **Outputs**: L-Online と同形(3タプル/5タプル)
  80. **Loops**:
  81. - `Ns = floor(C_budget / (len(path_list) * per_sample_cost))` を計算
  82. - `for path in path_list:` 各経路を同じ回数 `Ns` 測定して推定更新