AI learns to drive a car using Neural Evolution
Architecture
- 7 Input Neurons:- of lines/rays projected in 7 different directions/angles of projection.
val angles= arrayOf(180f,135f,90f,45f,0f)
-
4 Hidden Neurons
-
2 Output Neurons
- The output velocity of the car.
- The desired rotation.
velocity=max_velocity- max_velocity*output[1].toFloat()
angle+=if(output[0]>=0.5f) -1f else 1f
Evolution
This simulation uses the genetics algorithm inspired by darwinian Evolution with natural selection to evolve the network. Uses checkPoint markers to calculate the fitness function and a time limit for each lap.
-
The fitness function:- calculated by counting the number of checkPoints passed by a given agent. You can also make this even more interesting by also keeping track of time each agent takes to finish a lap.
-
Selection:- In this simulation 50% of the best cars are randomly chosen to breed and create identical copies of themselves to the next generation.( no cross breeding done for this project)
-
Mutation:- All new children are given a 1% mutation rate. (can be any value but this worked best for me. Let trial and error be your guide)