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

Convergence issue: good solution appears to be forgotten, resulting best solution is not even valid #260

Open
AndreyKolomiets opened this issue Dec 27, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@AndreyKolomiets
Copy link

The following is my code for pygad:

    num_parents_mating = 4
    parent_selection_type = "random"
    keep_parents = -1
    crossover_type = "single_point"
    mutation_type = "random"
    mutation_percent_genes = 10
    num_edge_pairs_per_edges = 5.0
    drop_single_nodes = True
    ga_instance = pygad.GA(num_generations=num_generations,
                           num_parents_mating=num_parents_mating,
                           fitness_func=problem.fitness_func,
                           parent_selection_type=parent_selection_type,
                           keep_parents=keep_parents,
                           crossover_type=crossover_type,
                           mutation_type=mutation_type,
                           mutation_percent_genes=mutation_percent_genes,
                           random_seed=100500,
                           gene_type=int,
                           keep_elitism=0,
                           initial_population=initial_population,
                           stop_criteria=['saturate_15'],
                           logger=logger,
                           save_solutions=False,
                           on_fitness=on_fitness,
                           )

problem is class instance, it is computing fitness as well as logging and saving some data. Best solution and best fitness are stored in best_solution_cls and best_fitness_cls attributes respectively. There is a strange bug in my code, that best_solution_cls doesn't match to best_fitness_cls. While best_fitness_cls is indeed the best fitness across all tries, best_fitness_cls is some other solution, it is usually not even valid (for invalid solutions, fitness=-1000.0 is expected).
The following is conda_env.yml used to create environment:

channels:
  - pytorch
  - anaconda
  - conda-forge
  - defaults
dependencies:
  - python=3.7.15=haa1d7c7_0
  - pip=22.2.2=py37h06a4308_0
  - setuptools=65.5.0=py37h06a4308_0
  - pip:
    - numpy==1.21.6
    - pandas==1.3.5
    - scipy==1.7.3
    - tqdm==4.64.1
    - networkx==2.6.3
    - numba==0.56.4
    - pygad==3.2.0
@ahmedfgad ahmedfgad added the bug Something isn't working label Jan 27, 2024
@ahmedfgad
Copy link
Owner

Hi @AndreyKolomiets,
Since such issues cannot easily reproduced without having a full working code, I appreciate if you would share a sample that reproduces the issue. This will heavily help debug the issue.

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