I am trying to design a genetic algorithm with neural networks to move a car through a city generated in Unity to a randomised target destination. I have designed it and the code works but the agent only learns to avoid obstacles and not move to the specified target destination.
Currently my fitness function is:
((1 / (1 + totalDistanceTravelled)) + (1 / (1 + distanceToTarget)) + (1 / (1 + numberOfCollisions)) + sensors.Average())
How can I modify this to meet the desired outcome?
If more is required let me know.
Let's take a closer look at your fitness function in a perhaps more readable way (though I figure the parenthesis are there to help with that too):
Looks like you are equally weighing distance traveled, distance to target, and number of collisions. Not sure what the sensors.Average() is (not familiar with unity), but I will figure that it's probably not the issue.
Let's assume the number of collisions is much less than the distance traveled or distance to the target. Say we have 10 collisions, we have traveled 100 units and we have 100 units left to travel.
The first two are 0.0099, the second one is 0.09. If we figure higher is better, then it would definitely give priority to avoiding stuff, at least until you are super close to the target or you have had a lot of collisions.
A better option would be to use the number of collisions as a coefficient. Something like:
In this case, we equally consider the distances, then we multiply that by the factor of the collisions