#pyGAD issue with adaptive mutation type

2 messages · Page 1 of 1 (latest)

hollow bobcat
#

The whole stacktrace looks like this:

TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_22208\1574861451.py in <module>
     16                        on_generation=callback_generation)
     17 
---> 18 ga_instance.run()
     19 
     20 ga_instance.plot_fitness()

D:\Anaconda\lib\site-packages\pygad\pygad.py in run(self)
   1833                         raise TypeError("The output of the mutation step is expected to be of type (numpy.ndarray) but {last_generation_offspring_mutation_type} found.".format(last_generation_offspring_mutation_type=type(self.last_generation_offspring_mutation)))
   1834                 else:
-> 1835                     self.last_generation_offspring_mutation = self.mutation(self.last_generation_offspring_crossover)
   1836 
   1837                 if self.last_generation_offspring_mutation.shape != (self.num_offspring, self.num_genes):

D:\Anaconda\lib\site-packages\pygad\utils\mutation.py in adaptive_mutation(self, offspring)
    466             else:
    467                 # When the attribute 'gene_space' does not exist (i.e. None), the mutation values are selected randomly based on the continuous range specified by the 2 attributes 'random_mutation_min_val' and 'random_mutation_max_val'.
--> 468                 offspring = self.adaptive_mutation_probs_randomly(offspring)
    469 
    470         return offspring
#
D:\Anaconda\lib\site-packages\pygad\utils\mutation.py in adaptive_mutation_probs_randomly(self, offspring)
    770         """
    771 
--> 772         average_fitness, offspring_fitness = self.adaptive_mutation_population_fitness(offspring)
    773 
    774         # Adaptive random mutation changes one or more genes in each offspring randomly.

D:\Anaconda\lib\site-packages\pygad\utils\mutation.py in adaptive_mutation_population_fitness(self, offspring)
    433 
    434         for idx in range(len(parents_to_keep), fitness.shape[0]):
--> 435             fitness[idx] = self.fitness_func(self, temp_population[idx], None)
    436         average_fitness = numpy.mean(fitness)
    437 

~\AppData\Local\Temp\ipykernel_22208\1384526959.py in fitness_func(ga_instance, solution, sol_idx)
      2 def fitness_func(ga_instance, solution, sol_idx):
      3     global GANN_instance, data_inputs, data_outputs
----> 4     predictions = pygad.nn.predict(last_layer=GANN_instance.population_networks[sol_idx],data_inputs=data_inputs)
      5     correct_predictions = numpy.where(predictions == data_outputs)[0].size
      6     solution_fitness = (correct_predictions/data_outputs.size)*100

TypeError: list indices must be integers or slices, not NoneType