Skip to content

Commit c283ce2

Browse files
committed
SOC analysis
1 parent 2d6d8ce commit c283ce2

4 files changed

Lines changed: 645 additions & 0 deletions

File tree

SOC_ANALYSIS_README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Self-Organized Criticality (SOC) Analysis - Summary
2+
3+
## File Created
4+
**Location:** `scripts/soc_analysis.py`
5+
6+
## Overview
7+
This comprehensive Python analysis script tests whether your prey-predator cellular automaton exhibits **self-organized criticality** (SOC), with focus on perturbations from initial configurations and diverse parameter sampling.
8+
9+
## Key Features
10+
11+
### 1. **Four SOC Properties Analyzed**
12+
- **Slow Drive:** Gradual parameter drift without immediate release
13+
- **Stress Build-up:** Interface-based metric tracking potential energy accumulation
14+
- **Intermittent Release:** Detection of avalanche cascades in population dynamics
15+
- **Self-Organization:** Robustness across diverse parameter combinations
16+
17+
### 2. **Parameter Variations** (Beyond just death/birth rates)
18+
- Grid sizes: 16×16 to 64×64
19+
- Initial densities: prey (0.1–0.4), predator (0.02–0.15)
20+
- Neighborhood types: Neumann & Moore
21+
- Update modes: Synchronous & Asynchronous
22+
- Rate parameters: randomly varied across valid ranges
23+
24+
### 3. **Metrics Computed**
25+
- **Stress Metric:** Normalized count of (predator/prey)↔empty adjacent pairs
26+
- Represents friction and interface gradient (potential energy)
27+
- **Avalanche Detection:** Population change magnitude thresholds
28+
- **Population Variance:** Rolling window variance of prey/predator counts
29+
- **Robustness Metrics:**
30+
- Avalanche count mean/std across configurations
31+
- Magnitude consistency
32+
- Coefficient of variation (measures criticality robustness)
33+
34+
### 4. **Perturbation Experiment Design**
35+
Each experiment runs 230 total steps:
36+
- **Equilibration phase (0–80 steps):** System reaches quasi-steady state
37+
- Stress accumulates during slow drive
38+
- No parameter perturbation
39+
- **Observation phase (80–230 steps):** Gradual parameter drift
40+
- Predator death rate increases by +0.05 (slow drive)
41+
- System responds with cascading events if critical
42+
- Stress release and avalanche events detected
43+
44+
## Visualization Output
45+
46+
The script generates `soc_analysis_results.png` with a **2×2 grid displaying the 4 core SOC properties**:
47+
48+
1. **Panel 1 (Top-Left) - Slow Drive:** Gradual parameter drift over time with equilibration and perturbation phases marked
49+
2. **Panel 2 (Top-Right) - Build-up of Stress:** Stress accumulation with avalanche event thresholds marked as orange stars
50+
3. **Panel 3 (Bottom-Left) - Intermittent Release:** Prey and predator population dynamics showing cascade events during perturbation
51+
4. **Panel 4 (Bottom-Right) - Self-Organization:** Stress-density relation across diverse configurations, colored by avalanche activity
52+
53+
## Usage
54+
55+
```bash
56+
python scripts/soc_analysis.py
57+
```
58+
59+
Output:
60+
- Console report with findings
61+
- PNG visualization saved to workspace root: `soc_analysis_results.png`
62+
63+
## Key Observations from Test Run
64+
65+
- **8 diverse configurations** sampled with varied grid sizes, densities, neighborhoods
66+
- **Avalanche detection:** 1/8 experiments showed clear cascade events
67+
- **Stress persistence:** Mean stress ~0.1529 across all configurations
68+
- **Robustness metric:** Coefficient of Variation = 2.646 (indicates some parameter-dependence; lower values → more robust SOC)
69+
- **Population variance:** Consistent across runs (signature of intermittent release mechanism)
70+
71+
## Code Structure
72+
73+
### Main Functions
74+
- `compute_grid_stress()` – Interface-based stress metric
75+
- `compute_population_variance()` – Rolling window variance calculation
76+
- `detect_avalanche_events()` – Identify cascading population changes
77+
- `sample_parameter_configurations()` – Generate diverse parameter sets
78+
- `run_soc_perturbation_experiment()` – Single experiment with slow drive
79+
- `analyze_soc_robustness()` – Cross-configuration robustness metrics
80+
- `visualize_soc_properties()` – Comprehensive 8-panel figure
81+
- `main()` – Orchestrates full analysis pipeline
82+
83+
### Configuration Space
84+
- **Grid size:** Affects stability and relaxation dynamics
85+
- **Densities:** Controls predator-prey interaction frequency
86+
- **Neighborhood:** Changes spatial coupling strength
87+
- **Rates:** Direct influence on birth/death thresholds
88+
89+
## Scientific Interpretation
90+
91+
The analysis tests the hypothesis:
92+
> *"Does the prey-predator CA exhibit self-organized criticality independent of specific parameter choices?"*
93+
94+
If coefficient of variation is **low** (< 1.0) → SOC is **robust** (self-organized)
95+
If coefficient of variation is **high** (> 1.0) → Behavior is **parameter-dependent** (requires tuning)
96+
97+
---
98+
99+
**Created:** January 2026
100+
**Framework:** NumPy, Matplotlib, custom CA simulation

models/CA.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88

99
import numpy as np
1010
import logging
11+
import sys
12+
from pathlib import Path
13+
14+
# Add parent directory to path for imports
15+
sys.path.insert(0, str(Path(__file__).parent.parent))
16+
1117
from models.numba_optimized import PPKernel, set_numba_seed
18+
from models.cluster_analysis import ClusterAnalyzer
1219

1320
# Module logger
1421
logger = logging.getLogger(__name__)

0 commit comments

Comments
 (0)