A research-grade implementation of a self-driving agent that learns optimal driving policies through Neuroevolution. This project explores the intersection of Evolutionary Strategies, Neural Networks, and Proceedural Generation, presented in a high-fidelity Material Design 3 dashboard.
The agent is controlled by a Feedforward Neural Network built from scratch (no libraries).
- Input Layer (5 Neurons): Ray-casting LIDAR sensors that detect road borders and traffic distance/angles (135° Field of View).
- Hidden Layer (12 Neurons): Dense layer enabling complex decision boundaries for overtaking maneuvers.
- Output Layer (4 Neurons): Continuous control signals for [Forward, Left, Right, Reverse].
- Activation Function: Hyperbolic Tangent (
Math.tanh). Unlike simple binary thresholds, this allows the agent to sense gradients ("Slight Turn" vs "Hard Turn"), resulting in smooth, human-like trajectory control.
Instead of Gradient Descent, we use an Evolutionary Strategy (1+λ) to traverse the non-differentiable fitness landscape.
- Population: N=500 agents are spawned per generation.
-
Fitness Function: Defined by distance traveled (
$d$ ) velocity ($v$ ) and survival time ($t$ ). - Selection: The single best "Brain" is saved when the entire population crashes.
-
Crossover & Mutation: The survivor's weights are mutated by a factor of
$\sigma=0.2$ to produce the next generation.
- Hyper-Speed Training (100x): A slider allows you to decouple simulation speed from rendering speed, enabling the training of 50+ generations in seconds.
- Procedural Environment: Traffic is not hardcoded. The system procedurally generates infinite random traffic patterns ahead of the agent, proving generalization capabilities (Zero-Shot Transfer to new scenarios).
- Aesthetic: A strict implementation of Google's Material You guidelines, featuring tonal palettes, glassmorphism, and responsive grids.
- Visualization: Real-time visualization of the Neural Network's weights and biases, alongside a live training performance chart.
This project is Zero-Dependency Vanilla JavaScript. It runs directly in the browser.
- Clone the repository.
- Open
index.html. - Training:
- Set the Speed Slider to 100x.
- Wait for the "Gen" counter to reach ~20.
- Set the slider back to 1x to watch the mastered policy.
- Controls:
Save: Persists the best model to LocalStorage.Reset: Clears the model and restarts training from scratch.
- Simulation Engine: Custom 2D Physics Engine (JavaScript).
- Machine Learning:
NeuralNetworkclass (Perceptron/Layer logic). - Rendering: HTML5 Canvas API (High Performance).
- Styling: Modern CSS3 (Grid, Variables, Glassmorphism).
