Adaptive Ecosystem Lab: five species that learn to survive together
I wanted to see whether five species could learn to live together with no rules handed to them, just reward and a lot of trial and error. So I built a vectorized 2D ecosystem and a multi-agent reinforcement learning trainer from scratch in NumPy and PyTorch. Herbivores, predators, decomposers, pollinators, and engineers each train their own policy network at the same time, in a world that pushes right back. The messy part is what makes it a real ML project: the run kept quietly falling apart. A predator policy would mode-collapse, the food web would crater into NaNs, and about 70% of the compute went to waste. I tracked down all three failure modes and fixed them with a PPO ratio-overflow guard, a global carrying cap, and an adaptive entropy controller, which took the run from always collapsing to actually stable. The live demo replays the real trained ecosystem and charts the training score as it collapses and recovers.