| 122 | plt.close() |
| 123 | |
| 124 | def plot_nas_history( |
| 125 | history: List[Dict], |
| 126 | save_path: Optional[str] = None, |
| 127 | figsize: tuple = (15, 5) |
| 128 | ): |
| 129 | generations = [h['generation'] for h in history] |
| 130 | best_fitness = [h['best_fitness'] for h in history] |
| 131 | avg_fitness = [h['avg_fitness'] for h in history] |
| 132 | best_accuracy = [h['best_accuracy'] for h in history] |
| 133 | avg_accuracy = [h['avg_accuracy'] for h in history] |
| 134 | |
| 135 | fig, axes = plt.subplots(1, 2, figsize=figsize) |
| 136 | |
| 137 | axes[0].plot(generations, best_fitness, label='Best Fitness', linewidth=2, marker='o') |
| 138 | axes[0].plot(generations, avg_fitness, label='Avg Fitness', linewidth=2, marker='s') |
| 139 | axes[0].set_xlabel('Generation') |
| 140 | axes[0].set_ylabel('Fitness') |
| 141 | axes[0].set_title('NAS Fitness Evolution') |
| 142 | axes[0].legend() |
| 143 | axes[0].grid(True, alpha=0.3) |
| 144 | |
| 145 | axes[1].plot(generations, best_accuracy, label='Best Accuracy', linewidth=2, marker='o') |
| 146 | axes[1].plot(generations, avg_accuracy, label='Avg Accuracy', linewidth=2, marker='s') |
| 147 | axes[1].set_xlabel('Generation') |
| 148 | axes[1].set_ylabel('Accuracy (%)') |
| 149 | axes[1].set_title('NAS Accuracy Evolution') |
| 150 | axes[1].legend() |
| 151 | axes[1].grid(True, alpha=0.3) |
| 152 | |
| 153 | plt.tight_layout() |
| 154 | |
| 155 | if save_path: |
| 156 | os.makedirs(os.path.dirname(save_path), exist_ok=True) |
| 157 | plt.savefig(save_path, dpi=300, bbox_inches='tight') |
| 158 | print(f"NAS history plot saved to {save_path}") |
| 159 | |
| 160 | plt.close() |
| 161 | |
| 162 | def plot_gradient_flow(named_parameters, save_path: Optional[str] = None): |
| 163 | ave_grads = [] |