How yashmittalgroot/ai-car works
Project Type and Purpose
• This is a simulation/training project for an autonomous car, which uses sensors, a feedforward Neural Network, and a Genetic Algorithm. Essentially, the project combines AI and game simulation (via Pygame) to evolve a set of neural weights that enable a car to navigate a track without hitting walls.
Key Components Based on the File Structure and README
a. Car Component:
• Files: car.py, track.png, car1.png, movement1.png (documentation images)
• Role: Represents the car entity including its graphics, movement, and interactions on the track.
b. Sensor Component:
• File: sensor.py
• Role: Simulate sensors on the car that detect the track’s walls by capturing pixel data.
c. Neural Network Component:
• File: nn.py and reference to Keras (a deep learning framework)
• Role: Models the decision-making process. It takes sensor inputs and outputs direction commands for the car.
d. Genetic Algorithm Component:
• Files: geneticAlgoModified.py and genotype.py
• Role: Evolves and tunes the neural network’s weights (genotype) by simulating evolution and selection mechanisms. It also includes modification aspects as mentioned in the README.
e. Game Loop / Simulation Component:
• Files: main.py and game.py
f. Data Storage / Evaluation Component:
• Files: data.npy and check_solution.py
• Role: data.npy stores the neural network weights that have successfully navigated the track. check_solution.py is used to validate a set of weights.
Relationships and Interactions Between Components
• The car (car.py) is the entity being controlled. It receives direction commands generated by the neural network (nn.py), which processes sensor input collected from sensor.py.
• The genetic algorithm (geneticAlgoModified.py) uses a genotype (genotype.py) representation of the neural network’s weights to evolve parameters over successive iterations.
• The training loop in main.py integrates the above components together: it simulates the car moving along the track, processes sensor data, runs the neural network, applies genetic algorithm logic for evolution, and, if a successful navigation is achieved, records the weights in data.npy.
• Additionally, game.py offers a fallback to manually control the car, enabling comparison or testing against the autonomous approach.
• The data stored in data.npy can later be tested using check_solution.py, ensuring that the improved weights indeed produce successful outcomes.
Architectural Patterns and Design Principles
• Modular Design: Each component is encapsulated in its own file (and conceptually separate), making the system modular.
• Simulation Loop: The central game/train loop (in main.py/game.py) handles recurring simulation cycles.
• Evolutionary Computation: The use of a Genetic Algorithm is a key pattern where fitness evaluations determine the evolution of solution weights.
• Separation of Concerns: AI decision-making (neural network), optimization (genetic algorithm), sensing (sensor module), and control (car game logic) are all separate.
Final Recommendations
• Clear labels for every component.
• Modularity by visually separating the AI components from the simulation and control components.