GeneticAlgorithmPython icon indicating copy to clipboard operation
GeneticAlgorithmPython copied to clipboard

solution_idx

Open ckattenberg opened this issue 4 years ago • 3 comments

Why does the fitness function need solution_idx as an input parameter if it doesn't do anything with it?

ckattenberg avatar Dec 16 '21 18:12 ckattenberg

The solution_idx holds the solution index in its population.

One usage is updating the neural network corresponding to the solution: https://github.com/ahmedfgad/NeuralGenetic/blob/82e73d92dc1a32ad17f982cfa8230d6eb4d17321/example_XOR_classification.py#L9

It can be used for debugging purposes.

ahmedfgad avatar Jan 01 '22 17:01 ahmedfgad

Just a quick follow up question, I wonder why it always gives me the solution_idx of 0?

xshang93 avatar Dec 02 '22 14:12 xshang93

@xshang93, most of the time the best solution is the first solution in the population. This is why the index 0 is returned almost frequently.

For some cases, it is something different. This only happens if a better solution is found in the last generation.

I advise you to run a code with few generations. You will likely find a different index than 0.

ahmedfgad avatar Feb 14 '23 19:02 ahmedfgad