Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GANN doesn't work with mutation_type='adaptive' #222

Open
alpozcan opened this issue Jul 18, 2023 · 1 comment
Open

GANN doesn't work with mutation_type='adaptive' #222

alpozcan opened this issue Jul 18, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@alpozcan
Copy link

alpozcan commented Jul 18, 2023

versions: Python 3.11.4, PyGAD 3.1.0 on Linux x86_64.

pygad.gann module documentation includes an XOR Example.

It works as is. However, as soon as I switch to using 'adaptive' mutation, I get an error:

list indices must be integers or slices, not NoneType
Traceback (most recent call last):
  File "/home/a/.local/lib/python3.11/site-packages/pygad/pygad.py", line 2019, in run
    self.last_generation_offspring_mutation = self.mutation(self.last_generation_offspring_crossover)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/a/.local/lib/python3.11/site-packages/pygad/utils/mutation.py", line 529, in adaptive_mutation
    offspring = self.adaptive_mutation_randomly(offspring)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/a/.local/lib/python3.11/site-packages/pygad/utils/mutation.py", line 676, in adaptive_mutation_randomly
    average_fitness, offspring_fitness = self.adaptive_mutation_population_fitness(offspring)
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/a/.local/lib/python3.11/site-packages/pygad/utils/mutation.py", line 479, in adaptive_mutation_population_fitness
    fitness[idx] = self.fitness_func(self,
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/dev/shm/xor.py", line 9, in fitness_func
    predictions = pygad.nn.predict(last_layer=GANN_instance.population_networks[sol_idx],
                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
TypeError: list indices must be integers or slices, not NoneType

My only modification to the example from the documentation page linked above:

                       mutation_type='adaptive',
                       mutation_percent_genes=(100, 50),

Is enough to trigger the error. Same with:

                       mutation_probability=(.20, .05),

I would appreciate seeing this bug fixed as I would like to use adaptive mutation.

Please let me know if more information is needed.

@ahmedfgad ahmedfgad added the bug Something isn't working label Aug 16, 2023
@ahmedfgad
Copy link
Owner

Thanks. The issue is solved 01cb71c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants