red42 / HTML5_Genetic_Cars

A genetic algorithm car evolver in HTML5 canvas.
zlib License
1.19k stars 290 forks source link

Incorrect formula for mutation size #53

Open boothby opened 2 months ago

boothby commented 2 months ago

In mutateNormal, the mutation_range is handled strangely; the resulting formula is originalValue-0.5 + random() * mutation_range (clamping omitted for clarity). The result of this is that when mutation_range is small, every mutated value is reduced to the range [0, mutation_range] within a couple of generations. A more appropriate formula would be originalValue + (random() - 0.5) * mutation_range so that the resulting distribution stays centered at originalValue when unclamped.

opyate commented 1 month ago

Not sure if this is related, but something seems off with the simulation. After a while, a whole bunch of the cars seem to share the exact genes, so much so, that you can't make out individual profiles further down the track (they're all interacting the exact same way with the environment with regards to their wheel size, wheel mass, body shape, etc) - in other words, half the cars look like one car.

Screenshot from 2024-05-16 14-06-13

Another run: 18 our of 20 cars are exactly the same.

Screenshot from 2024-05-17 13-31-08