~/projects/neural-network
← all projectsNeural Network from Scratch
A neural network written from scratch in C#, with no ML libraries, and trained with a genetic algorithm to control swarm robots in a Unity simulation.
Overview
Each robot in the swarm is controlled by its own small neural network. The network reads the robot's sensors and outputs motor speeds. Instead of backpropagation, the networks are trained with a genetic algorithm: the best performers each generation are copied and mutated.
Training with a genetic algorithm
Every generation, each robot is scored on how well it does its task. The top robots survive, and their weights and biases are copied and randomly mutated to make the next generation.
Key features
- Custom matrix math and forward propagation, no ML libraries
- Genetic algorithm mutates weights and biases each generation
- Fitness function rewards reaching the goal and penalizes collisions
- Simulated in Unity so a whole generation runs in parallel
Results
Early generations wander randomly. After a few hundred generations, the robots learn to move toward the goal and avoid each other.