# Stage 4: Analysis & Visualization

Analyzes PPO policies and SR formulas. Generates FFT spectra, action timeseries, and degradation curves.

## Usage

```bash
# PPO action visualization (timeseries + FFT)
PYTHONPATH=src conda run -n pycuda_3_10 python -m SR_analysis.archive.stage4.stage_4_analyze --scene illusion_1L --mode ppo-viz

# Cross-diameter degradation analysis
PYTHONPATH=src conda run -n pycuda_3_10 python -m SR_analysis.archive.stage4.stage_4_analyze \
    --scenes illusion_0.75L,illusion_1L,illusion_1.5L --mode degradation

# Formula comparison (coming soon)
PYTHONPATH=src conda run -n pycuda_3_10 python -m SR_analysis.archive.stage4.stage_4_analyze --scene illusion_1L --mode formula-compare
```

## Modes

- **ppo-viz**: Action timeseries plot + FFT spectrum for each cylinder
- **degradation**: Cross-scene comparison (alpha std, Cd_tot, action range) — finds transition points where control regime changes
- **formula-compare**: (placeholder) Compare PySR formula predictions vs PPO actions

## Output

Figures written to `data/figures/`:
- `ppo_viz_{scene}.png` — timeseries + FFT
- `degradation_metrics.png` — cross-diameter comparison panels

## Regime Detection

The degradation mode detects control regime transitions by:
1. Action amplitude jump (alpha std > 4x)
2. Frequency shift (FFT dominant frequency > 5x)
3. Autocorrelation pattern change (lag-2 ≈ -0.9 = high-frequency switching)

Known transition: Illusion 1.5L shifts from phase-lead compensation to high-frequency periodic modulation.
