# Figure Generation for Copycat Graph Theory Paper

This folder contains Python scripts to generate all figures for the paper "From Hardcoded Heuristics to Graph-Theoretical Constructs."

## Prerequisites

Install Python 3.7+ and required packages:

```bash
pip install matplotlib numpy networkx scipy
```

## Quick Start

Generate all figures at once:

```bash
python generate_all_figures.py
```

Or run individual scripts:

```bash
python generate_slipnet_graph.py      # Figure 1: Slipnet graph structure
python activation_spreading.py        # Figure 2: Activation spreading dynamics
python resistance_distance.py         # Figure 3: Resistance distance heat map
python workspace_evolution.py         # Figures 4 & 5: Workspace evolution & betweenness
python clustering_analysis.py         # Figure 6: Clustering coefficient analysis
python compare_formulas.py           # Comparison plots of formulas
```

## Generated Files

After running the scripts, you'll get these figures:

### Main Paper Figures
- `figure1_slipnet_graph.pdf/.png` - Slipnet graph with conceptual depth gradient
- `figure2_activation_spreading.pdf/.png` - Activation spreading over time with differential decay
- `figure3_resistance_distance.pdf/.png` - Resistance distance vs shortest path comparison
- `figure4_workspace_evolution.pdf/.png` - Workspace graph at 4 time steps
- `figure5_betweenness_dynamics.pdf/.png` - Betweenness centrality over time
- `figure6_clustering_distribution.pdf/.png` - Clustering coefficient distributions

### Additional Comparison Plots
- `formula_comparison.pdf/.png` - 6-panel comparison of all hardcoded formulas vs proposed alternatives
- `scalability_comparison.pdf/.png` - Performance across string lengths and domain transfer
- `slippability_temperature.pdf/.png` - Temperature-dependent slippability curves
- `external_strength_comparison.pdf/.png` - Current support factor vs clustering coefficient

## Using Figures in LaTeX

Replace the placeholder `\fbox` commands in `paper.tex` with:

```latex
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{figure1_slipnet_graph.pdf}
\caption{Slipnet graph structure...}
\label{fig:slipnet}
\end{figure}
```

## Script Descriptions

### 1. `generate_slipnet_graph.py`
Creates a visualization of the Slipnet semantic network with 30+ key nodes:
- Node colors represent conceptual depth (blue=concrete, red=abstract)
- Edge thickness shows link strength (inverse of link length)
- Hierarchical layout based on depth values

### 2. `compare_formulas.py`
Generates comprehensive comparisons showing:
- Support factor: 0.6^(1/n³) vs clustering coefficient
- Member compatibility: Discrete (0.7/1.0) vs continuous structural equivalence
- Group length factors: Step function vs subgraph density
- Salience weights: Fixed (0.2/0.8) vs betweenness centrality
- Activation jump: Fixed threshold (55.0) vs adaptive percolation threshold
- Mapping factors: Linear increments vs logarithmic path multiplicity

Also creates scalability analysis showing performance across problem sizes and domain transfer.

### 3. `activation_spreading.py`
Simulates Slipnet activation dynamics with:
- 3 time-step snapshots showing spreading from "sameness" node
- Heat map visualization of activation levels
- Time series plots demonstrating differential decay rates
- Annotations showing how shallow nodes (letters) decay faster than deep nodes (abstract concepts)

### 4. `resistance_distance.py`
Computes and visualizes resistance distances:
- Heat map matrix showing resistance distance between all concept pairs
- Comparison with shortest path distances
- Temperature-dependent slippability curves for key concept pairs
- Demonstrates how resistance distance accounts for multiple paths

### 5. `clustering_analysis.py`
Analyzes correlation between clustering and success:
- Histogram comparison: successful vs failed runs
- Box plots with statistical tests (t-test, p-values)
- Scatter plot: clustering coefficient vs solution quality
- Comparison of current support factor formula vs clustering coefficient

### 6. `workspace_evolution.py`
Visualizes dynamic graph rewriting:
- 4 snapshots of workspace evolution for abc→abd problem
- Shows bonds (blue edges), correspondences (green dashed edges)
- Annotates nodes with betweenness centrality values
- Time series showing how betweenness predicts correspondence selection

## Customization

Each script can be modified to:
- Change colors, sizes, layouts
- Add more nodes/edges to graphs
- Adjust simulation parameters
- Generate different problem examples
- Export in different formats (PDF, PNG, SVG)

## Troubleshooting

**"Module not found" errors:**
```bash
pip install --upgrade matplotlib numpy networkx scipy
```

**Font warnings:**
These are harmless warnings about missing fonts. Figures will still generate correctly.

**Layout issues:**
If graph layouts look cluttered, adjust the `k` parameter in `nx.spring_layout()` or use different layout algorithms (`nx.kamada_kawai_layout()`, `nx.spectral_layout()`).

## Contact

For questions about the figures or to report issues, please refer to the paper:
"From Hardcoded Heuristics to Graph-Theoretical Constructs: A Principled Reformulation of the Copycat Architecture"
