1
$\begingroup$

I'm a beginner with a classic "racing car" sandbox and a homemade simple neural network.

My pattern:

  1. Copy the "top car" (without mutation) to the next generation

  2. If there are some cars still running (because simulation reached the 30s win condition), then copy a mutated version of them for the next generation.

  3. Fill the rest of the pool with mutation of the "top car".

But this is just some dumb intuitive pattern I made on the fly while playing with my code. Perhaps I should copy the cars that are still running as-is instead of mutating them. Or, perhaps, some selection method I don't know about.

A new random track is generated at each new generation. a "top car" may be good on a track and crash immediately on the next track. I just feel that basing everything on the top car is wrong because of the track randomness.

Is there some known pattern for selecting a batch of candidates? (paper, google-fu keyword, interesting blog, etc.)

I don't know what to search for. I don't even know the name of my network or any vocabulary related to AI.

$\endgroup$
3
  • $\begingroup$ What does your neural network represent? It's also not clear to me what you're trying to do. Are you trying to find the best car (that is able to drive in some environment: please, which specify which environment) by having a population of cars that you evolve my mutating? That seems to be just a genetic algorithm. $\endgroup$ – nbro Nov 18 '20 at 12:36
  • $\begingroup$ my post was originall post was bigger and explained what you want but i was told i wasn''t concise enough :D $\endgroup$ – ker2x Nov 18 '20 at 12:54
  • $\begingroup$ I only asked you to ask one question, because you had multiple questions. I didn't say you should remove relevant details. Anyway, you can edit your post again. $\endgroup$ – nbro Nov 18 '20 at 13:31
1
$\begingroup$

The most general descriptive frameworks covering what you are trying to do are:

These put some context around your problem, and might give you some pointers. For instance, reinforcement learning is an alternative approach to the evolutionary system you are trying to build.

The specific AI system you appear to be building is a genetic algorithm, and more specific still you are attempting to find a neural network that is optimal at a task by searching for the best network using a system of population generation, selection and mutation which repeats.

There are lots of ways to set up a system like this, so your approach is not necessarily wrong. However, I think there are two key things that would improve what you have built so far:

  • Use a fitness function for selection. Score each car, perhaps by how far it got before crashing when the episode ends. To reduce luck factor on random courses, you could make this score the mean result from e.g. 3 different courses (it is not necessary, but may address your concern that selection is too random in your case). Select some fraction of top scoring cars, or look into other selection approaches - e.g. weighted selection based on fitness score or ranking.

  • Add "sex", more properly known as genome crossover between selected population members. Mutating individuals is limiting because it silos improvements to a single line of ancestry - if there are two good mutations found at random you rely on that single line finding both of them. Whilst crossover allows sharing of good mutations between lines, making it much more likely that two good mutations will end up in the same individual.

There is a framework called NEAT which covers the issues above plus has other features useful for evolving neural networks. It often does well at control scenarios like the one you are considering. You may want to look into it, if your focus is mainly on solving the control problem. However, it is relatively advanced from where you are, so if your current focus to learn by building from scratch you may get more initially from implementing fitness functions and crossover yourself.

$\endgroup$
2
  • $\begingroup$ thank you very much. I've seen this NEAT in the past but didn't understand it. Now that i played with my simple NN i think i understand it. (and i think that the game called "GridWorld" is doing this). My NN have a fixed topology (defined by me : 7 raycasting input, 1 speed input, 2 hidden layer of 12 and 6 neuron, 2 for speed control and direction) and i'm not encoding phenotype and therefore make crossover more difficult in my code. But i will try this from now on. i could even let the NN try different input sensor by itself (ex : angle of the raycast, tyre friction (drifing in turn), etc) $\endgroup$ – ker2x Nov 18 '20 at 15:02
  • $\begingroup$ It's ambitious but worth it i guess. i won't go anywhere if i keep playing with the same primitive NN forever and it's totally in the direction toward my end goal : a mini-game where you watch a NN learning, playing failing, evolving, ... i specifically don't want a sophisticated fitness function or error computation : it's either "win the right to reproduce/mutate" or "die without offspring". And neat seems to fit the need. $\endgroup$ – ker2x Nov 18 '20 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.