DEAP / deap

Distributed Evolutionary Algorithms in Python
http://deap.readthedocs.org/
GNU Lesser General Public License v3.0
5.88k stars 1.13k forks source link

replace random.random with np.random.choice in selRoulette #689

Open Mach-2 opened 1 year ago

Mach-2 commented 1 year ago

I noticed that selRoulette was causing a major bottleneck when I tried to scale up to larger populations. This update uses the np.random.choice function in place of random.random, which removes the need to sort the input list of individuals and the nested for loops.

fmder commented 1 year ago

Could this be done with the new random.choices?

Mach-2 commented 1 year ago

Yes, random.choices looks like it does the same thing. This shaved off a bit of runtime again, too! 👍