What is this simulation?
This is a Neural Network Evolution Simulator that demonstrates how artificial intelligence can learn to drive through a simple genetic algorithm. Cars equipped with neural networks learn to navigate around moving obstacles through generations of trial and error.
Watch my demonstration video about this simulation here.
How it works
- Neural Networks: Each car has a brain (neural network) with 5 input neurons (sensors), 2 hidden layers (3â2 neurons), and 1 output neuron (steering)
- Ray Sensors: Cars cast 5 rays in front of them to detect obstacles at different angles
- Fitness: Cars are scored based on how far they travel before hitting obstacles
- Evolution: The best-performing cars pass their "genes" (neural network weights) to the next generation
- Mutation: Random changes to neural network weights create diversity and allow for improvement
Key Parameters Explained
Number of Obstacles: More obstacles = harder challenge. Start with 5-8 for learning, increase to 10+ for advanced testing.
Number of Cars: Larger populations (50-100) explore more strategies but run slower. Smaller populations (20-30) are faster but may get stuck in local optima.
Parent Count: How many best cars survive each generation. 10-20% of population works well. Too few = loss of diversity, too many = slow evolution.
Mutation Rate: Probability of each neural network weight changing. 0.1-0.3 is optimal. Higher = more exploration but less stable learning.
Mutation Magnitude: Maximum change to weights during mutation. 0.1-0.2 works well. Higher = bigger jumps but may overshoot optimal solutions.
Experimentation Tips
- Start Simple: Begin with 5 obstacles, 30 cars, 5 parents, 0.2 mutation rate, 0.15 magnitude
- Explore vs Exploit: Higher mutation rates explore new strategies, lower rates refine existing ones
- Population Size: Larger populations find better solutions but take longer to converge
What to look for
- Learning Curve: Cars should improve over generations, traveling further before crashing
- Emergent Behavior: Watch how cars develop different strategies - some may be aggressive, others cautious
- Convergence: Eventually, most cars will adopt similar successful strategies
- Adaptation: Cars should learn to navigate around obstacles efficiently
Technical Details
- Neural Network: Feed-forward network with tanh activation function
- Input Processing: Ray distances are normalized using exponential scaling for better sensitivity
- Output: Single value between -1 and 1 controlling horizontal movement
- Evolution: Elitism + mutation strategy with random individuals for diversity
- Fitness: Based on distance traveled, with cars eliminated on collision
Educational Value
This simulation demonstrates key concepts in artificial intelligence and evolutionary computation:
- Neural Networks: How simple networks can learn complex behaviors
- Genetic Algorithms: Evolution as an optimization strategy
- Emergent Intelligence: Complex behavior arising from simple rules
- Parameter Tuning: The importance of hyperparameter selection in AI
- Fitness Landscapes: How different strategies compete and evolve