Skip to content

Features suggestion. Option to force recalculating fitness for every solution and some questions about entire pop fitness calculation #303

Open
@KorrawitMick

Description

@KorrawitMick

Referring to "Why the Fitness Function is not Called for Solution at Index 0?"

To force calling the fitness function for each solution in every generation, consider setting keep_elitism and keep_parents to 0. Moreover, keep the 2 parameters save_solutions and save_best_solutions to their default value False.

  1. My project is to find best weights of neural net but subject to input change. So the fitness of the best elite is different in some generations. However, I want to have the feature of keep_elitism to maintain good candidate. How can I get with that?

  2. The phrase Moreover, keep save_solutions = False and save_best_solutions = False. is ambiguous. I'm not sure that this is a must or a suggestion.?

  3. I have created my own function to calculate entire population fitness is more efficient than calling fitness_func separately or in batch. Questions are.

  • When should I call my own function? (On_generation callback I guess)
  • Where should I store my returned fitness value? (I can only think of storing them in a global variable and retrieve from it when fitness_func is called
  • Keeping elitism means that latest fitness value of the elite will not be updated. How to solve this issue?

Activity

ahmedfgad

ahmedfgad commented on Jan 7, 2025

@ahmedfgad
Owner

The fitness of a solution/chromosome is forced to be calculated if the solution is not a parent, elitism, and does not exist in the solutions and best_solutions instance attributes. To not keep any parent, set keep_parents=0. Set keep_elitism=0 to avoid keeping any elitism. To not save the solutions or best solutions, you have to set save_solutions=False and save_best_solutions=False.

You can set fitness_batch_size to the number of solutions. Then call your own function from inside fitness_func(). The fitness are expected to be saved into the last_generation_fitness instance attribute. As long as you update the fitness of the elisitm in last_generation_fitness, then their fitness will change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ahmedfgad@KorrawitMick

        Issue actions

          Features suggestion. Option to force recalculating fitness for every solution and some questions about entire pop fitness calculation · Issue #303 · ahmedfgad/GeneticAlgorithmPython