Skip to content

harshsinghdev-11/self_learning_car

Repository files navigation

Autonomous Self-Driving Car: Evolutionary Reinforcement Learning

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.

Dashboard Preview

🔬 Research Core: How it Works

1. The "Brain" (Neural Architecture)

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.

2. The "Teacher" (Genetic Algorithm)

Instead of Gradient Descent, we use an Evolutionary Strategy (1+λ) to traverse the non-differentiable fitness landscape.

  1. Population: N=500 agents are spawned per generation.
  2. Fitness Function: Defined by distance traveled ($d$) velocity ($v$) and survival time ($t$).
  3. Selection: The single best "Brain" is saved when the entire population crashes.
  4. Crossover & Mutation: The survivor's weights are mutated by a factor of $\sigma=0.2$ to produce the next generation.

🌟 Key Features

Research Tools

  • 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).

Use Interface (Google Material Design 3)

  • 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.

🚀 How to Run

This project is Zero-Dependency Vanilla JavaScript. It runs directly in the browser.

  1. Clone the repository.
  2. Open index.html.
  3. 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.
  4. Controls:
    • Save: Persists the best model to LocalStorage.
    • Reset: Clears the model and restarts training from scratch.

🛠️ Technology Stack

  • Simulation Engine: Custom 2D Physics Engine (JavaScript).
  • Machine Learning: NeuralNetwork class (Perceptron/Layer logic).
  • Rendering: HTML5 Canvas API (High Performance).
  • Styling: Modern CSS3 (Grid, Variables, Glassmorphism).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors