-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathrule122R_reverse_demo.py
More file actions
43 lines (34 loc) · 1.92 KB
/
rule122R_reverse_demo.py
File metadata and controls
43 lines (34 loc) · 1.92 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
import matplotlib.pyplot as plt
import netomaton as ntm
import numpy as np
if __name__ == '__main__':
# NKS page 443 - Rule 122R
network = ntm.topology.cellular_automaton(n=100)
# carefully chosen initial conditions
previous_state = [1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1,
0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0,
1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1,
0, 0, 1, 1]
initial_conditions = [1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1,
1, 1, 1, 0, 1, 1, 1]
trajectory = ntm.evolve(initial_conditions=initial_conditions, network=network,
activity_rule=ntm.ReversibleRule(ntm.rules.nks_ca_rule(122)),
past_conditions=[previous_state], timesteps=1002)
timestep = []
average_node_entropies = []
activities = ntm.get_activities_over_time_as_list(trajectory)
for i, c in enumerate(activities):
timestep.append(i)
bit_string = ''.join([str(x) for x in c])
average_node_entropies.append(ntm.average_node_entropy(activities[:i+1]))
print("%s, %s" % (i, average_node_entropies[-1]))
plt.subplot(3, 1, (1, 2))
plt.title("Avg. Node (Shannon) Entropy")
plt.gca().set_xlim(0, 1002)
plt.gca().axes.xaxis.set_ticks([])
plt.plot(timestep, average_node_entropies)
plt.subplot(3, 1, 3)
plt.gca().axes.yaxis.set_ticks([])
ntm.plot_grid(np.array(activities).T.tolist())