gkhayes / mlrose

Python package for implementing a number of Machine Learning, Randomized Optimization and SEarch algorithms.
https://mlrose.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
235 stars 243 forks source link

GA for NN incorrect #40

Closed tmsuidan closed 4 years ago

tmsuidan commented 4 years ago

"This problem is because the probability of selecting a parent was determined by:

mate_probs = pop_fitness / np.sum(pop_fitness)

This will result in low numbers if pop_fitness is close to 0 and high numbers if pop_fitness is far from zero regardless of sign. Lets say there are 2 people in population with fitness -0.1 (good) and -10 (bad). the mate_probs would be -0.1 / -10.1 = ~0.01 for the good person and -10 / -10.1 or ~0.99 for the bad person. This means we are more likely to mate people with poor fitness...bad! "(taken from a piazza post in a class by the person who found it)

It's corrected in this fork which has basically redesigned/refactored most of the library with additional functionality https://github.com/hiive/mlrose specifically in this file https://github.com/hiive/mlrose/blob/master/mlrose/opt_probs/_opt_prob.py

parkds commented 4 years ago

Just to add on, this only occurs due to the negative sign when we are minimizing using GA. Maximizing with GA seems to work fine.

gkhayes commented 4 years ago

Hi @tmsuidan, Thanks for pointing this out. I am happy to accept a PR that addresses this issue. Regards, Genevieve.