Pocket Planet
A 100×100 world carved from Perlin noise, then colonized by simulated plants that mutate, compete, and converge on the terrain they're fittest for.
A 100×100 terrain generated from multi-octave Perlin noise is seeded with organisms, each carrying a 5-dimensional genome encoding their ecological niche. Organisms reproduce, mutate, disperse spatially, and compete, with selection pressure proportional to how well their genome matches the local terrain. After ~100 generations, the simulation self-organizes into stable biomes: mountain specialists in the highlands, coastal generalists at the margins, forest species in between.
Terrain and Fitness
The terrain is five biome types (coast, plains, forest, mountain, desert), each associated with an optimal genome . Fitness is the complement of L2 distance between an organism’s genome and the local optimum:
Soft boundaries, no hard biome walls. An organism with a forest genome can survive on plains but at reduced fitness, so it produces fewer offspring and loses competition. The fitness landscape has a smooth gradient structure that rewards specialization without making cross-biome survival impossible.
Each terrain cell’s optimal DNA is fixed at initialization. The evolutionary challenge: the population as a whole must simultaneously cover all five biome types, with different sub-populations converging on different optima.
The Evolutionary Dynamics
Each generation follows four steps:
- Reproduction: each organism draws offspring (fitter organisms get more children on average)
- Mutation: each offspring’s genome is perturbed by , clipped and renormalized to stay on the unit hypercube
- Dispersal: offspring are placed at , spatially close but not identical
- Competition: when cells exceed carrying capacity, survivors are drawn via Boltzmann tournament:
The Boltzmann temperature is the key hyperparameter. High : selection is harsh, fitter organisms almost always win, population converges fast but can get stuck at local optima. Low : near-random drift, slow convergence, more exploration. The critical insight is that should be low early (when the population needs to explore all five biome types) and high late (once colonization is complete, selection pressure drives specialization). Adaptive that increases with mean population fitness converges ~2× faster than fixed .
Colonization
Colonization proceeds in waves. Coastal organisms land first because the terrain is seeded along the shoreline. They’re generalists: mediocre fitness everywhere, but enough to reproduce. Their offspring disperse inland. The first inland migrants encounter mountain or forest terrain where their coastal genome is suboptimal, but they can survive until better-adapted competitors arrive. Coastal DNA is eventually displaced inland by locally optimized genomes; the coastal margin retains specialized coastal organisms.
The speciation boundary forms ~generation 50–70. Before that point, a mountain organism and a coastal organism would interbreed if they met (no reproductive isolation in the model). But dispersal is spatially constrained; mountain organisms rarely reach the coast and vice versa. Geographic isolation does the work that explicit barriers would do in a more complex model.
Convergence
Three metrics track whether the simulation is working:
Mean fitness (left): rises from ~0.30 (random genomes) to ~0.92, following a logistic curve. The plateau represents the fundamental trade-off at biome edges; organisms at the mountain/forest boundary can’t perfectly match either optimum, so mean fitness never reaches 1.0.
Coverage (center): coastal terrain fills first (~generation 25), forest/plains next (~40), mountain last (~70). The ordering reflects dispersal distance from the coastal seed; mountain terrain is hardest to reach and hardest to survive in before local adaptation arrives.
Genetic divergence (right): within-biome variance (how similar organisms in the same biome are to each other) drops over time as local selection pressure pushes genomes toward the biome optimum. Between-biome distance (how different mountain organisms are from coastal organisms) rises. The crossover, where between-biome distance exceeds within-biome variance, marks the onset of functional speciation.
Related projects
Deep Learning from Scratch
The full arc: backpropagation in raw NumPy, CNNs with BatchNorm and Dropout trained to 78% on CIFAR-10, multi-head self-attention for text summarization, and a Masked Autoencoder that reconstructs images from 25% of their patches, then transfers those features to downstream tasks.
Classical ML from Scratch
Two learning paradigms built from NumPy up: tree-based spam classification (decision tree, Random Forest, AdaBoost) and SVD/ALS matrix factorization for movie recommendations. No frameworks; matched scikit-learn on both.
Auto-Stitching Photo Mosaics
Building a panorama pipeline from scratch: Harris corner detection, Adaptive Non-Maximal Suppression, feature matching, RANSAC for homography estimation, and Laplacian-pyramid blending.