-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_publication_figures.py
More file actions
361 lines (307 loc) · 13.2 KB
/
create_publication_figures.py
File metadata and controls
361 lines (307 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
"""
Publication-quality figures for PolyGraphs network epistemology results.
Creates 300 DPI figures demonstrating Zollman effect for consciousness-beliefs:
- Complete graph: Fast convergence to truth
- Cycle graph: Slow convergence to FALSE consensus
- Small-world: Persistent disagreement (realistic)
Author: Studio Farzulla Research
Date: November 2025
"""
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from pathlib import Path
# Publication settings
plt.rcParams.update({
'figure.dpi': 300,
'savefig.dpi': 300,
'font.size': 10,
'axes.labelsize': 11,
'axes.titlesize': 12,
'xtick.labelsize': 9,
'ytick.labelsize': 9,
'legend.fontsize': 9,
'figure.titlesize': 13,
'font.family': 'sans-serif',
'font.sans-serif': ['DejaVu Sans'],
})
# Color-blind friendly palette (Tol palette)
COLORS = {
'complete': '#4477AA', # Blue
'cycle': '#EE6677', # Red/Pink
'small_world': '#228833', # Green
}
# Truth value and neutral line
EPSILON = 0.51
NEUTRAL = 0.5
# Load data
DATA_DIR = Path('/home/kawaiikali/Documents/Resurrexi/projects/needs-work/consciousness-narrative-paper/results_v2')
OUTPUT_DIR = DATA_DIR / 'figures_publication'
OUTPUT_DIR.mkdir(exist_ok=True)
df = pd.read_csv(DATA_DIR / 'simulation_results.csv')
# Rename topologies for publication
topology_labels = {
'complete': 'Complete',
'cycle': 'Cycle',
'small_world': 'Small-World'
}
df['topology_label'] = df['topology'].map(topology_labels)
def figure1_belief_convergence():
"""Figure 1: Belief Convergence by Topology (Boxplot)"""
fig, ax = plt.subplots(figsize=(6, 4.5))
# Boxplot
box_parts = ax.boxplot(
[df[df['topology'] == 'complete']['mean'],
df[df['topology'] == 'cycle']['mean'],
df[df['topology'] == 'small_world']['mean']],
labels=['Complete', 'Cycle', 'Small-World'],
patch_artist=True,
widths=0.6,
showmeans=True,
meanprops=dict(marker='D', markerfacecolor='white', markeredgecolor='black', markersize=6)
)
# Color boxes
for patch, topology in zip(box_parts['boxes'], ['complete', 'cycle', 'small_world']):
patch.set_facecolor(COLORS[topology])
patch.set_alpha(0.7)
# Reference lines
ax.axhline(NEUTRAL, color='red', linestyle='--', linewidth=1.5, alpha=0.7, label='Neutral (0.5)')
ax.axhline(EPSILON, color='green', linestyle='--', linewidth=1.5, alpha=0.7, label=f'Truth (ε = {EPSILON})')
# Annotate false consensus
cycle_mean = df[df['topology'] == 'cycle']['mean'].mean()
ax.annotate(
f'False Consensus\n({cycle_mean:.3f})',
xy=(2, cycle_mean),
xytext=(2.5, cycle_mean - 0.02),
fontsize=9,
color=COLORS['cycle'],
weight='bold',
arrowprops=dict(arrowstyle='->', color=COLORS['cycle'], lw=1.5)
)
ax.set_ylabel('Final Mean Belief', fontsize=11)
ax.set_ylim(0.42, 0.53)
ax.set_title('Network Topology Determines Belief Convergence', fontsize=12, pad=15)
ax.legend(loc='upper right', frameon=True, edgecolor='gray')
ax.grid(axis='y', alpha=0.3, linestyle=':')
plt.tight_layout()
plt.savefig(OUTPUT_DIR / 'figure1_belief_convergence.png', dpi=300, bbox_inches='tight')
plt.close()
print(f"✓ Figure 1 saved: {OUTPUT_DIR / 'figure1_belief_convergence.png'}")
def figure2_speed_accuracy_tradeoff():
"""Figure 2: Convergence Speed vs Truth-Tracking (Scatter)"""
fig, ax = plt.subplots(figsize=(6.5, 4.5))
# Calculate distance from truth
df['distance_from_truth'] = np.abs(df['mean'] - EPSILON)
# Scatter plot for each topology
for topology in ['complete', 'cycle', 'small_world']:
data = df[df['topology'] == topology]
ax.scatter(
data['convergence_time'],
data['distance_from_truth'],
c=COLORS[topology],
label=topology_labels[topology],
s=100,
alpha=0.7,
edgecolors='black',
linewidth=0.5
)
# Annotate key findings
cycle_data = df[df['topology'] == 'cycle']
complete_data = df[df['topology'] == 'complete']
# Cycle: slow + wrong
cycle_x = cycle_data['convergence_time'].mean()
cycle_y = cycle_data['distance_from_truth'].mean()
ax.annotate(
'Slow convergence\nto FALSEHOOD',
xy=(cycle_x, cycle_y),
xytext=(cycle_x + 100, cycle_y + 0.01),
fontsize=8,
color=COLORS['cycle'],
weight='bold',
arrowprops=dict(arrowstyle='->', color=COLORS['cycle'], lw=1.2)
)
# Complete: fast + correct
complete_x = complete_data['convergence_time'].mean()
complete_y = complete_data['distance_from_truth'].mean()
ax.annotate(
'Fast convergence\nto truth',
xy=(complete_x, complete_y),
xytext=(complete_x + 150, complete_y - 0.005),
fontsize=8,
color=COLORS['complete'],
weight='bold',
arrowprops=dict(arrowstyle='->', color=COLORS['complete'], lw=1.2)
)
ax.set_xlabel('Convergence Time (steps)', fontsize=11)
ax.set_ylabel('Distance from Truth |mean - 0.51|', fontsize=11)
ax.set_title('Zollman Effect: Speed-Accuracy Trade-off', fontsize=12, pad=15)
ax.legend(loc='upper right', frameon=True, edgecolor='gray')
ax.grid(alpha=0.3, linestyle=':')
ax.set_xlim(0, 1050)
plt.tight_layout()
plt.savefig(OUTPUT_DIR / 'figure2_speed_accuracy_tradeoff.png', dpi=300, bbox_inches='tight')
plt.close()
print(f"✓ Figure 2 saved: {OUTPUT_DIR / 'figure2_speed_accuracy_tradeoff.png'}")
def figure3_persistent_disagreement():
"""Figure 3: Persistent Disagreement (Standard Deviation)"""
fig, ax = plt.subplots(figsize=(6, 4.5))
# Boxplot of disagreement
box_parts = ax.boxplot(
[df[df['topology'] == 'complete']['std'],
df[df['topology'] == 'cycle']['std'],
df[df['topology'] == 'small_world']['std']],
labels=['Complete', 'Cycle', 'Small-World'],
patch_artist=True,
widths=0.6,
showmeans=True,
meanprops=dict(marker='D', markerfacecolor='white', markeredgecolor='black', markersize=6)
)
# Color boxes
for patch, topology in zip(box_parts['boxes'], ['complete', 'cycle', 'small_world']):
patch.set_facecolor(COLORS[topology])
patch.set_alpha(0.7)
# Annotate small-world persistence
sw_mean = df[df['topology'] == 'small_world']['std'].mean()
ax.annotate(
'Persistent\nDisagreement',
xy=(3, sw_mean),
xytext=(2.4, sw_mean + 0.004),
fontsize=9,
color=COLORS['small_world'],
weight='bold',
arrowprops=dict(arrowstyle='->', color=COLORS['small_world'], lw=1.5)
)
ax.set_ylabel('Belief Disagreement (std)', fontsize=11)
ax.set_title('Realistic Networks Maintain Persistent Disagreement', fontsize=12, pad=15)
ax.grid(axis='y', alpha=0.3, linestyle=':')
plt.tight_layout()
plt.savefig(OUTPUT_DIR / 'figure3_persistent_disagreement.png', dpi=300, bbox_inches='tight')
plt.close()
print(f"✓ Figure 3 saved: {OUTPUT_DIR / 'figure3_persistent_disagreement.png'}")
def figure4_four_panel_summary():
"""Figure 4: Four-Panel Summary (2x2 grid)"""
fig, axes = plt.subplots(2, 2, figsize=(12, 10))
# Top-left: Mean belief
ax = axes[0, 0]
box_parts = ax.boxplot(
[df[df['topology'] == 'complete']['mean'],
df[df['topology'] == 'cycle']['mean'],
df[df['topology'] == 'small_world']['mean']],
labels=['Complete', 'Cycle', 'Small-World'],
patch_artist=True,
widths=0.6
)
for patch, topology in zip(box_parts['boxes'], ['complete', 'cycle', 'small_world']):
patch.set_facecolor(COLORS[topology])
patch.set_alpha(0.7)
ax.axhline(NEUTRAL, color='red', linestyle='--', linewidth=1, alpha=0.5)
ax.axhline(EPSILON, color='green', linestyle='--', linewidth=1, alpha=0.5)
ax.set_ylabel('Final Mean Belief')
ax.set_title('(A) Belief Convergence', fontsize=11, weight='bold')
ax.grid(axis='y', alpha=0.3, linestyle=':')
# Top-right: Convergence time
ax = axes[0, 1]
box_parts = ax.boxplot(
[df[df['topology'] == 'complete']['convergence_time'],
df[df['topology'] == 'cycle']['convergence_time'],
df[df['topology'] == 'small_world']['convergence_time']],
labels=['Complete', 'Cycle', 'Small-World'],
patch_artist=True,
widths=0.6
)
for patch, topology in zip(box_parts['boxes'], ['complete', 'cycle', 'small_world']):
patch.set_facecolor(COLORS[topology])
patch.set_alpha(0.7)
ax.set_ylabel('Convergence Time (steps)')
ax.set_title('(B) Convergence Speed', fontsize=11, weight='bold')
ax.grid(axis='y', alpha=0.3, linestyle=':')
ax.set_yscale('log')
# Bottom-left: Disagreement (std)
ax = axes[1, 0]
box_parts = ax.boxplot(
[df[df['topology'] == 'complete']['std'],
df[df['topology'] == 'cycle']['std'],
df[df['topology'] == 'small_world']['std']],
labels=['Complete', 'Cycle', 'Small-World'],
patch_artist=True,
widths=0.6
)
for patch, topology in zip(box_parts['boxes'], ['complete', 'cycle', 'small_world']):
patch.set_facecolor(COLORS[topology])
patch.set_alpha(0.7)
ax.set_ylabel('Belief Disagreement (std)')
ax.set_title('(C) Persistent Disagreement', fontsize=11, weight='bold')
ax.grid(axis='y', alpha=0.3, linestyle=':')
# Bottom-right: Proportion illusionist
ax = axes[1, 1]
box_parts = ax.boxplot(
[df[df['topology'] == 'complete']['prop_illusionist'],
df[df['topology'] == 'cycle']['prop_illusionist'],
df[df['topology'] == 'small_world']['prop_illusionist']],
labels=['Complete', 'Cycle', 'Small-World'],
patch_artist=True,
widths=0.6
)
for patch, topology in zip(box_parts['boxes'], ['complete', 'cycle', 'small_world']):
patch.set_facecolor(COLORS[topology])
patch.set_alpha(0.7)
ax.axhline(0.5, color='red', linestyle='--', linewidth=1, alpha=0.5, label='50% threshold')
ax.set_ylabel('Proportion Illusionist')
ax.set_title('(D) Final Belief Distribution', fontsize=11, weight='bold')
ax.grid(axis='y', alpha=0.3, linestyle=':')
ax.set_ylim(-0.05, 1.05)
fig.suptitle('Network Epistemology of Consciousness-Beliefs', fontsize=14, weight='bold', y=0.995)
plt.tight_layout()
plt.savefig(OUTPUT_DIR / 'figure4_four_panel_summary.png', dpi=300, bbox_inches='tight')
plt.close()
print(f"✓ Figure 4 saved: {OUTPUT_DIR / 'figure4_four_panel_summary.png'}")
def generate_summary_stats():
"""Generate summary statistics for manuscript"""
stats = {}
for topology in ['complete', 'cycle', 'small_world']:
data = df[df['topology'] == topology]
stats[topology] = {
'mean_belief': f"{data['mean'].mean():.4f} ± {data['mean'].std():.4f}",
'mean_convergence': f"{data['convergence_time'].mean():.1f} ± {data['convergence_time'].std():.1f}",
'mean_disagreement': f"{data['std'].mean():.4f} ± {data['std'].std():.4f}",
'distance_from_truth': f"{np.abs(data['mean'] - EPSILON).mean():.4f}",
}
# Save to text file
with open(OUTPUT_DIR / 'summary_statistics.txt', 'w') as f:
f.write("PolyGraphs Network Epistemology - Summary Statistics\n")
f.write("=" * 60 + "\n\n")
for topology in ['complete', 'cycle', 'small_world']:
f.write(f"{topology.upper()}\n")
f.write("-" * 40 + "\n")
for key, value in stats[topology].items():
f.write(f" {key}: {value}\n")
f.write("\n")
f.write("\nKEY FINDINGS:\n")
f.write("-" * 40 + "\n")
cycle_mean = df[df['topology'] == 'cycle']['mean'].mean()
f.write(f"1. Cycle graph FALSE CONSENSUS: {cycle_mean:.4f} (truth = {EPSILON})\n")
f.write(f" Distance from truth: {abs(cycle_mean - EPSILON):.4f}\n\n")
complete_time = df[df['topology'] == 'complete']['convergence_time'].mean()
cycle_time = df[df['topology'] == 'cycle']['convergence_time'].mean()
f.write(f"2. Convergence speed: Complete ({complete_time:.1f} steps) vs Cycle ({cycle_time:.1f} steps)\n")
f.write(f" Cycle is {cycle_time/complete_time:.1f}x slower\n\n")
sw_std = df[df['topology'] == 'small_world']['std'].mean()
complete_std = df[df['topology'] == 'complete']['std'].mean()
f.write(f"3. Small-world disagreement: {sw_std:.4f} vs Complete: {complete_std:.4f}\n")
f.write(f" Small-world has {sw_std/complete_std:.0f}x more disagreement\n")
print(f"✓ Summary statistics saved: {OUTPUT_DIR / 'summary_statistics.txt'}")
if __name__ == '__main__':
print("Generating publication-quality figures (300 DPI)...\n")
figure1_belief_convergence()
figure2_speed_accuracy_tradeoff()
figure3_persistent_disagreement()
figure4_four_panel_summary()
generate_summary_stats()
print(f"\n✓ All figures saved to: {OUTPUT_DIR}")
print("\nFigures generated:")
print(" - figure1_belief_convergence.png")
print(" - figure2_speed_accuracy_tradeoff.png")
print(" - figure3_persistent_disagreement.png")
print(" - figure4_four_panel_summary.png")
print(" - summary_statistics.txt")