cazala / synaptic

architecture-free neural network library for node.js and the browser
http://caza.la/synaptic
Other
6.92k stars 666 forks source link

help needed for the first helloworld test #308

Open Kaspisijus opened 6 years ago

Kaspisijus commented 6 years ago

Hi and thanks for a great AI class. Although the class is well made and documented, I don't manage to run my first test.

My code: https://github.com/Kaspisijus/track

I am using "genetic.js" with its selection, crossover and mutation methods from Flappy bird example.

I wrote a test, which should generate random track with segments, consisting of 3 elements [0,1,1], where 1 is an obstacle, and 0 is a free path. I move all population members across the track and hope that in a while they will understand to go through 0 to go as far as possible. Fitness is calculated based on how many segments a population member managed to go through.

The members are not improving at all. Going through many generations makes no scence. In this example #99 generations had an avg fitness of 2.8, while #100 gen was 0 again: ("-" is a free way, "o" is obsticle, "C" is a live car (population member) on a free road, "X" is a car, collided to obstacle)

image

any Ideas of what I could setup wrong?

0upsla commented 6 years ago

Hi. I played a little bit with your code, and even if I can't point the problem, I found some interresting things.

The population tends to quickly becomes uniform : all the cars take the same path. That's not bad, but the algorithm you use to select the top cars and repopulate makes this really bad: You take the 4 better cars, but the first of the list. So if all cars perform the same, you take the 4 first cars. And then you let them at their place, meaning next time you have to repopulate, if they all performed the same, you take the same 4 cars. those 4 Cars did not mutate, so if you get stuck with 10 cars that act the same, your mutations might be too small to matters, and you'll repopulate with the same 4 cars again and again, each time erasing the mutations that would, by adding them, change the behavior of the cars.