Skip to content

Commit 725aa79

Browse files
authored
Update README to improve formatting and clarity
1 parent ce48bf0 commit 725aa79

1 file changed

Lines changed: 19 additions & 107 deletions

File tree

README.md

Lines changed: 19 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Predator-Prey Cellular Automaton: Model Documentation
1+
## Predator-Prey Cellular Automaton: Model Documentation
22

3-
## Overview
3+
### Overview
44

55
This project impelments a spatial predator-prey cellular automaton (CA) to investigate the Hydra effect, a counterintuitive ecological phenomenon where increased prey mortality paradoxically leads to higher prey population densities. The model explores the rise of emergent population dynamics through spatial structure and local interactions that differe fundemntally from well-mixed (mean-field) predictions.
66

77
The codebase uses Numba JIT compilation for computationally intensive kernels and is tuned for high performance computing environments. It supporrs parameter sweeps, finite size scaling analysis, and self-organized criticality exploration.
88

99
---
1010

11-
## Background
11+
### Background
1212

13-
### The Hydra Effect
13+
#### The Hydra Effect
1414

1515
In classical Lotka-Volterra dynamics, increasing prey mortality always reduces the prey population. However, theoretical work has identified conditions where the opposite effect can be observed. The Hydra effect emerges in spatially structured systems where
1616

@@ -20,7 +20,7 @@ In classical Lotka-Volterra dynamics, increasing prey mortality always reduces t
2020

2121
This study uses a cellular automaton framework toi study how spatial strcuture generates the Hydra effecr and whether the system exhibits signatures of self-organized criticality at the transition point.
2222

23-
### Self-Organized Criticality (SOC)
23+
#### Self-Organized Criticality (SOC)
2424

2525
SOC refers to systems that naturally evolve toward a critical state without external tuning. At criticality, such systems exhibit:
2626

@@ -33,9 +33,7 @@ In the predator-prey context, SOC would manifest as the system self-tuning towar
3333

3434
---
3535

36-
## Model Description
37-
38-
### State Space
36+
### Model Description
3937

4038
The model uses a 2D lattice with periodic boundary conditions. Each cell occupies one of three states:
4139

@@ -45,26 +43,18 @@ The model uses a 2D lattice with periodic boundary conditions. Each cell occupie
4543
| Prey | 1 | Prey organism |
4644
| Predator | 2 | Predator organism |
4745

48-
### Transition Rules
49-
5046
The model uses asynchronous updates: cells are processed in random order each timestep, with state changes taking effect immediately. This prevents artificial synchronization artifacts common in parallel update schemes.
5147

52-
#### Prey Dynamics
53-
5448
For each prey cell, in order:
5549

5650
- Death: With probability `prey_death`, the prey dies and the cell becomes empty
5751
- Reproduction: If alive and a randomly selected neighbor is empty, with probability `prey_birth`, a new prey is placed in that neighbor cell
5852

59-
#### Predator Dynamics
60-
6153
For each predator cell, in order:
6254

6355
- Death: With probability `predator_death`, the predator dies (starvation)
6456
- Hunting/Reproduction: If alive and a randomly selected neighbor contains prey, with probability `predator_birth`, the predator consumes the prey and reproduces into that cell
6557

66-
### Neighborhood
67-
6858
The model supports both neighborhood types:
6959

7060
- Moore neighborhood: (default): 8 adjacent cells (including diagonals)
@@ -74,11 +64,11 @@ Moore neighborhoods are used throughout the experiments as they provide more rea
7464

7565
---
7666

77-
## Hunting Modes
67+
### Hunting Modes
7868

7969
The model implements two distinct neighbor selection strategies that qualitatively affect dynamics.
8070

81-
### Random Neighbor Selection (Default)
71+
#### Random Neighbor Selection (Default)
8272

8373
In the standard mode, each organism selects a single random neighbor for interaction:
8474

@@ -94,7 +84,7 @@ if grid[neighbor] == PREY and random() < predator_birth:
9484
```
9585
This creates a blind interaction model where organisms are not aware of their surroundings.
9686

97-
### Directed Hunting Mode
87+
#### Directed Hunting Mode
9888

9989
The directed mode implements "intelligent" neighbor selection:
10090

@@ -119,9 +109,9 @@ This increases the effective reproduction and predation rates without changing t
119109

120110
---
121111

122-
## Implementation Architecture
112+
### Implementation Architecture
123113

124-
### Class Hierarchy
114+
#### Class Hierarchy
125115

126116
```
127117
CA (base class)
@@ -140,7 +130,7 @@ The `PP` class adds:
140130
- Synchronous/asynchronous update dispatch
141131
- Integration with Numba-optimized kernels
142132

143-
### Basic Usage
133+
#### Basic Usage
144134

145135
```python
146136
from models.CA import PP
@@ -170,7 +160,7 @@ prey_count = np.sum(model.grid == 1)
170160
pred_count = np.sum(model.grid == 2)
171161
```
172162

173-
### Evolution Mode
163+
#### Evolution Mode
174164

175165
The model supports per-cell parameter evolution, where offspring inherit (with mutation) their parent's parameter values:
176166

@@ -188,9 +178,7 @@ When evolution is enabled, each prey cell maintains its own `prey_death` value.
188178

189179
---
190180

191-
## Numba Optimization
192-
193-
### Performance Strategy
181+
### Numba Optimization
194182

195183
The computational bottleneck is the update kernel, which must process every occupied cell each timestep. For a 1000×1000 grid with 50% occupancy, this means ~500,000 cell updates per step.
196184

@@ -201,7 +189,7 @@ Key optimizations:
201189
3. **Efficient Shuffling**: Fisher-Yates shuffle implemented in Numba for random cell ordering
202190
4. **Cell Lists for PCF**: Pair correlation functions use spatial hashing for O(N) instead of O(N²) complexity
203191

204-
### PPKernel Class
192+
#### PPKernel Class
205193

206194
```python
207195
class PPKernel:
@@ -223,8 +211,6 @@ class PPKernel:
223211
```
224212
---
225213

226-
## Analysis Methods
227-
228214
### Cluster Detection
229215

230216
Clusters are contiguous groups of same-species cells (using Moore connectivity). The implementation uses stack-based flood fill with periodic boundary conditions.
@@ -241,65 +227,9 @@ print(f"Largest fraction: {stats['largest_fraction']:.3f}")
241227
Metrics collected:
242228
- Cluster size distribution: Power-law indicates criticality
243229
- Largest cluster fraction: Order parameter for percolation transition
244-
245-
---
246-
247-
## Experimental Phases
248-
249-
The project is organized into five experimental phases, each investigating a specific aspect of the Hydra effect and SOC.
250-
251-
### Phase 1: Critical Point Identification
252-
253-
**Goal**: Locate the critical prey mortality rate where the Hydra effect transitions occur.
254-
255-
**Method**: Sweep `prey_death` while holding other parameters fixed. Measure:
256-
- Mean prey/predator populations
257-
- Population variance
258-
- Cluster size distributions
259-
260-
**Output**: Critical value of `prey_death` for subsequent phases.
261-
262-
### Phase 2: Self-Organization Analysis
263-
264-
**Goal**: Test whether evolution drives the system toward criticality.
265-
266-
**Method**: Enable per-cell evolution of `prey_death` with small mutation rates. Track:
267-
- Mean evolved `prey_death` over time
268-
- Convergence toward critical value
269-
- Population stability under evolution
270-
271-
**Expected**: If SOC holds, evolved parameters should cluster near a critical point.
272-
273-
### Phase 3: Finite-Size Scaling
274-
275-
**Goal**: Confirm criticality through scaling relations.
276-
277-
**Method**: Run simulations at the critical point across multiple grid sizes (50 to 2500). Measure how observables scale with system size $L$:
278-
- Largest cluster: $S_{max} \sim L^{d_f}$ (fractal dimension)
279-
280-
**Output**: Critical exponents characterizing the universality class.
281-
282-
### Phase 4: Sensitivity Analysis
283-
284-
**Goal**: Map the full parameter space to understand robustness.
285-
286-
**Method**: 4D sweep over all four parameters (```prey_birth, prey_death, predator_birth, predator_death```). Identify:
287-
- Coexistence regions
288-
- Extinction boundaries
289-
- Hydra effect strength across parameter space
290-
291-
### Phase 5: Model Extensions
292-
293-
**Goal**: Compare random vs. directed hunting dynamics.
294-
295-
**Method**: Repeat Phase 4 analysis with `directed_hunting=True`. Compare:
296-
- Critical point location
297-
- Hydra effect persistence
298-
- SOC signatures
299-
300230
---
301231

302-
## Configuration System
232+
### Configuration System
303233

304234
The `Config` dataclass centralizes all experimental parameters:
305235

@@ -328,7 +258,7 @@ Each phase has a predefined configuration (`PHASE1_CONFIG` through `PHASE5_CONFI
328258

329259
---
330260

331-
## Output Format
261+
### Output Format
332262

333263
Results are saved in JSONL format (one JSON object per line) for efficient streaming and parallel processing:
334264

@@ -348,7 +278,7 @@ Metadata files (`phase{N}_metadata.json`) accompany each results file with confi
348278

349279
---
350280

351-
## Dependencies
281+
### Dependencies
352282

353283
**Required:**
354284
- Python 3.8+
@@ -363,22 +293,4 @@ Metadata files (`phase{N}_metadata.json`) accompany each results file with confi
363293

364294
---
365295

366-
## File Structure
367-
368-
```
369-
models/
370-
├── CA.py # Base CA and PP classes
371-
├── numba_optimized.py # Numba kernels and analysis functions
372-
├── config.py # Configuration dataclass and phase configs
373-
└── experiments.py # Experimental phase runners
374-
375-
results/
376-
├── phase1_results.jsonl # Raw simulation results
377-
├── phase1_config.json # Configuration used
378-
├── phase1_metadata.json # Runtime metadata
379-
└── experiments.log # Execution log
380-
```
381-
382-
---
383-
384-
## References
296+
## References

0 commit comments

Comments
 (0)