Self Driving Car
based on Neural Networks
By Nihal Shah
Instructions:
This is a simulation of how AI would learn to drive a car. In this simulation you have to save the best car intelligence by pressing the 'Save' button. Discard the saved best car intelligence by pressing 'Delete' button. You may need to save multiple times as the car would learn better the more time the simulation runs. Or you can click the 'Solution' button to get the best AI intelligence and won't have to run the tests. On your right is the neural network visualization and on the left is the simulation. You can select the number of AI cars to run in a test by choosing No.of cars. You can also choose the amount of mutation you need ranging from 0.1 to 1.0 . In simple words less the value of mutation, less will be the difference between parent and child generation. More the value of mutation, more will be the deviation from parent generation. If you don't want to save a particular test simply click 'Refresh' button.
No.of cars
Mutation Level
Rotate the phone to view the neural network visualization
Explanation:
We're working with relatively small networks here. The network is broken into levels. In network.js, we have class level and a level has a layer of input neurons and the layer of output neurons. Each output neuron has a bias, a value above which it will fire. Every input neuron is connected to every output neuron. These connections have weights (strength of connection). The values of weight and biases range from -1 to +1. Negative values because in some situations these negative values help in choosing different option. The inputs will be the values that we get from the car sensors. And what we do is compute the outputs using these weights and biases that we define. Those are random for now. We compute the output values using a feed forward algorithm. In this algorith we compute the sum of weight and input of all the inputs and check if this sum is greater than the bias of the output neuron. If the sum is greater we set the output neuron to '1' i.e. on position. Else its set to '0'. In the neural network we're essentially putting in the output of the previous level, into the new level as the input. And the final outputs will tell us if the car should go forward, backward, left or right. The car sensors sends low values to the neuron if object is far away and higher values when object is closer. For Mutation of the Network, we iterate through all the biases of the levels and linearly interpolate (lerp = A+(B-A)*t) between current value of bias, a random value between -1 and 1, and the amount of mutation. Same is done for weights. So if the amount of mutation is zero, then our biases, and our weights just stayed the same. But if this value is somewhere in between, then it's going to move away from these biases, depending on this amount. This way the car learns to drive through the traffic using neural networks.