-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize.py
More file actions
165 lines (126 loc) · 5.4 KB
/
visualize.py
File metadata and controls
165 lines (126 loc) · 5.4 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
"""
Visualization utilities for XOR3N system.
Generates text-based visualizations of phase schedules and training signals.
"""
import sys
import os
# Add parent directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from xor3n import create_xor3n
def visualize_schedule(xor3n, num_steps=None):
"""
Create a visual timeline of phase activations.
Args:
xor3n: XOR3N instance
num_steps: Number of steps to visualize (default: one supercycle)
"""
if num_steps is None:
num_steps = xor3n.supercycle
print(f"\nPhase Activation Timeline (Supercycle = {xor3n.supercycle})")
print("=" * 70)
schedule = xor3n.get_schedule(num_steps)
# Print header
print("Time | Phase A | Phase B | Phase C | Active")
print("-----|---------|---------|---------|" + "-" * 20)
for t, active in schedule:
a_mark = " ● " if 'A' in active else " ○ "
b_mark = " ● " if 'B' in active else " ○ "
c_mark = " ● " if 'C' in active else " ○ "
active_str = ", ".join(active) if active else "none"
print(f" {t:3d} | {a_mark} | {b_mark} | {c_mark} | {active_str}")
def visualize_xor_training(xor3n, num_steps=15):
"""
Visualize XOR training over time with actual signals.
Args:
xor3n: XOR3N instance (should have been run with signals)
num_steps: Number of steps to visualize
"""
print(f"\nXOR Training Visualization")
print("=" * 90)
print("Shows how each phase trains on XOR of the other two")
print()
print("Time | A_sig | B_sig | C_sig | A_train(B⊕C) | B_train(A⊕C) | C_train(A⊕B) | Filter Effect")
print("-----|-------|-------|-------|--------------|--------------|--------------|" + "-" * 20)
for t in range(min(num_steps, len(xor3n.phase_a.signal_history))):
a_sig = xor3n.phase_a.get_signal(t)
b_sig = xor3n.phase_b.get_signal(t)
c_sig = xor3n.phase_c.get_signal(t)
if t < len(xor3n.phase_a.training_history):
a_train = xor3n.phase_a.training_history[t]
b_train = xor3n.phase_b.training_history[t]
c_train = xor3n.phase_c.training_history[t]
# Analyze filter effect
if a_sig == b_sig == c_sig:
effect = "Common → Cancelled"
elif a_train or b_train or c_train:
effect = "Novelty detected!"
else:
effect = "Low novelty"
print(f" {t:3d} | {a_sig} | {b_sig} | {c_sig} | {a_train} | {b_train} | {c_train} | {effect}")
def visualize_hypergraph_structure(xor3n, num_steps=None):
"""
Visualize the hypergraph structure of phase synchronizations.
Args:
xor3n: XOR3N instance
num_steps: Number of steps to analyze (default: one supercycle)
"""
if num_steps is None:
num_steps = xor3n.supercycle
print(f"\nHypergraph Structure (Supercycle = {xor3n.supercycle})")
print("=" * 70)
print("Hyperedges connect phases that are active simultaneously")
print()
schedule = xor3n.get_schedule(num_steps)
# Group by hyperedge pattern
hyperedges = {}
for t, active in schedule:
if active: # Skip empty sets
edge = tuple(sorted(active))
if edge not in hyperedges:
hyperedges[edge] = []
hyperedges[edge].append(t)
print(f"Found {len(hyperedges)} distinct hyperedge patterns:\n")
for edge, times in sorted(hyperedges.items(), key=lambda x: len(x[0]), reverse=True):
edge_str = "{" + ", ".join(edge) + "}"
count = len(times)
freq = count / num_steps * 100
# Show first few occurrences
times_str = ", ".join(str(t) for t in times[:5])
if count > 5:
times_str += f", ... ({count} total)"
print(f" Hyperedge {edge_str:12s}: occurs {count:3d} times ({freq:5.1f}%)")
print(f" Times: t = {times_str}")
print()
def create_demo_visualization():
"""Create a comprehensive demonstration visualization."""
print("\n" + "=" * 70)
print("XOR3N SYSTEM VISUALIZATION DEMO")
print("=" * 70)
# Create system with interesting cadences
xor3n = create_xor3n(cadence_a=2, cadence_b=3, cadence_c=5)
print(f"\nSystem Configuration:")
print(f" Phase A cadence: {xor3n.phase_a.cadence}")
print(f" Phase B cadence: {xor3n.phase_b.cadence}")
print(f" Phase C cadence: {xor3n.phase_c.cadence}")
print(f" Supercycle: T = LCM({xor3n.phase_a.cadence}, {xor3n.phase_b.cadence}, {xor3n.phase_c.cadence}) = {xor3n.supercycle}")
# Visualize schedule
visualize_schedule(xor3n, num_steps=20)
# Run with signals and visualize training
print("\n")
def signal_gen(t, phase):
# Create interesting pattern
if phase == 'A':
return t % 2
elif phase == 'B':
return (t + 1) % 2
else:
return t % 2
xor3n.run_cycle(15, signal_gen)
visualize_xor_training(xor3n, num_steps=15)
# Visualize hypergraph
visualize_hypergraph_structure(xor3n, num_steps=30)
print("\n" + "=" * 70)
print("VISUALIZATION COMPLETE")
print("=" * 70)
if __name__ == '__main__':
create_demo_visualization()