MCPcopy
hub / github.com/geekcomputers/Python / search

Method search

ML/src/python/neuralforge/nas/evolution.py:88–125  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

86 self.population = new_population
87
88 def search(self) -> Architecture:
89 print(f"Starting evolutionary search for {self.generations} generations...")
90
91 self.initialize_population()
92 self.evaluate_population()
93
94 for generation in range(self.generations):
95 print(f"\n=== Generation {generation + 1}/{self.generations} ===")
96
97 self.population.sort(key=lambda x: x.fitness, reverse=True)
98 best_arch = self.population[0]
99
100 if self.best_architecture is None or best_arch.fitness > self.best_architecture.fitness:
101 self.best_architecture = best_arch
102
103 avg_fitness = np.mean([arch.fitness for arch in self.population])
104 avg_accuracy = np.mean([arch.accuracy for arch in self.population])
105
106 print(f"Best fitness: {best_arch.fitness:.4f}")
107 print(f"Best accuracy: {best_arch.accuracy:.2f}%")
108 print(f"Avg fitness: {avg_fitness:.4f}")
109 print(f"Avg accuracy: {avg_accuracy:.2f}%")
110 print(f"Best params: {best_arch.params:,}")
111
112 self.history.append({
113 'generation': generation + 1,
114 'best_fitness': best_arch.fitness,
115 'best_accuracy': best_arch.accuracy,
116 'avg_fitness': avg_fitness,
117 'avg_accuracy': avg_accuracy,
118 })
119
120 if generation < self.generations - 1:
121 self.evolve_generation()
122 self.evaluate_population()
123
124 print(f"\nSearch completed! Best architecture: {self.best_architecture}")
125 return self.best_architecture
126
127 def get_top_k_architectures(self, k: int = 5) -> List[Architecture]:
128 self.population.sort(key=lambda x: x.fitness, reverse=True)

Callers 2

mainFunction · 0.95
mainFunction · 0.95

Calls 4

initialize_populationMethod · 0.95
evaluate_populationMethod · 0.95
evolve_generationMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected