A Python-based artificial life simulation where neural network "individuals" evolve through natural selection to navigate a 2D environment with beneficial heal zones and harmful radiation zones. Models are trained only through random mutation and natural selection.
This project explores evolutionary algorithms applied to neural networks in a spatial survival simulation. Individual agents must learn to:
- Navigate toward healing zones for fitness benefits
- Avoid moving radiation zones that cause damage
- Survive and reproduce based on their accumulated healing score
- Input Layer: 10 features including:
- Previous movement direction (2)
- Nearest heal zone direction and distance (3)
- Nearest radiation zone direction and distance (3)
- Radiation zone movement direction (2)
- Hidden Layers: 12 → 8 neurons with ReLU activation
- Output Layer: 5 movement actions (N/S/E/W/Stay) with softmax
- Grid Size: 300×300 simulation space
- Heal Zones: 7 stationary beneficial areas (radius 30)
- Radiation Zones: 6 moving harmful areas (radius 25)
- Population: 120 individuals per generation
- Simulation Length: 300 steps per generation
Key parameters in config.py:
NUM_INDIVS = 120 # Population size
MUTATION_RATE = 0.001 # 1% of weights mutated per generation
MUTATION_MAGNITUDE = 0.001 # Standard deviation of weight changes
GATE_DISABLE_RATE = 0.003 # Probability of connection gating
SELECTION_RATE = 1/3 # Top 33% selected for breedingThe SELECTION_RATE must satisfy mathematical constraints to ensure proper population replacement:
NUM_INDIVSmust be evenly divisible bySELECTION_RATE- The inverse of
SELECTION_RATE(offspring per parent) must be an integer - Valid examples:
1/2(50%),1/3(33%),1/4(25%),1/5(20%) - Invalid examples:
0.4(40%),1/7(14.3%),0.15(15%)
- Selection: Fitness-proportional selection based on
times_healedscore - Breeding: Each selected parent produces 3 offspring
- Mutation: Gaussian noise applied to inherited weights
- Structural Variation: Random gating patterns applied each generation
- Survival: Pure replacement - no individuals survive between generations
# Clone repository
git clone <repository-url>
cd life-sim-python
# Install dependencies and register the CLI
pip install -e .
# Run
life-simSelecting a project launches both the trainer and the visualizer simultaneously.
├── pyproject.toml
└── src/
├── cli/ # Entry point (life-sim command)
├── trainer/
│ ├── core/ # Application and project management
│ ├── model/ # Neural network model and mutations
│ ├── simulation/ # Population, individuals, zones
│ ├── strategies/ # Evolutionary and reinforcement strategies
│ └── rendering/ # Pyglet renderer
├── visualizer/ # Matplotlib fitness visualizer
└── shared/
├── config.py # Simulation parameters
├── services/ # Persistence (projects, individuals)
└── types/ # Shared data types
- Gate inheritance across generations for structural evolution
- This will require a mechanism for opening gates; they're currently created randomly.