Sephfox commited on
Commit
a9dfca1
1 Parent(s): d683d92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -35,15 +35,18 @@ class GeneticAlgorithm:
35
  self.population = [Net() for _ in range(population_size)]
36
 
37
  def selection(self):
38
- X_train, X_test, y_train, y_test = generate_dataset(self.task_id)
39
- fitness = []
40
- for net in self.population:
41
- net.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
42
- net.fit(X_train, y_train, epochs=10, verbose=0)
43
- loss, accuracy = net.evaluate(X_test, y_test, verbose=0)
44
- fitness.append(accuracy)
 
45
  self.population = [self.population[i] for i in np.argsort(fitness)[-self.population_size//2:]]
46
-
 
 
47
  def crossover(self):
48
  offspring = []
49
  X = np.random.rand(1, 10) # dummy input to build the layers
 
35
  self.population = [Net() for _ in range(population_size)]
36
 
37
  def selection(self):
38
+ X_train, X_test, y_train, y_test = generate_dataset(self.task_id)
39
+ fitness = []
40
+ for net in self.population:
41
+ net.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
42
+ net.fit(X_train, y_train, epochs=10, verbose=0)
43
+ loss, accuracy = net.evaluate(X_test, y_test, verbose=0)
44
+ fitness.append(accuracy)
45
+ if len(fitness) > 0:
46
  self.population = [self.population[i] for i in np.argsort(fitness)[-self.population_size//2:]]
47
+ else:
48
+ print("Fitness list is empty. Cannot select individuals.")
49
+
50
  def crossover(self):
51
  offspring = []
52
  X = np.random.rand(1, 10) # dummy input to build the layers