-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathrule122R_entropy_demo.py
44 lines (34 loc) · 1.19 KB
/
rule122R_entropy_demo.py
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
import matplotlib.pyplot as plt
import numpy as np
import cellpylib as cpl
# NKS page 442 - Rule 122R
cellular_automaton = np.array([[0]*40 + [1]*20 + [0]*40])
rule = cpl.ReversibleRule(cellular_automaton[0], 122)
cellular_automaton = cpl.evolve(cellular_automaton, timesteps=1000, apply_rule=rule)
timestep = []
bientropies = []
shannon_entropies = []
average_cell_entropies = []
apentropies = []
for i, c in enumerate(cellular_automaton):
timestep.append(i)
bit_string = ''.join([str(x) for x in c])
bientropies.append(cpl.ktbien(bit_string))
shannon_entropies.append(cpl.shannon_entropy(bit_string))
average_cell_entropies.append(cpl.average_cell_entropy(cellular_automaton[:i+1]))
apentropies.append(cpl.apen(bit_string, m=1, r=0))
print("%s, %s, %s, %s" % (i, bientropies[-1], shannon_entropies[-1], apentropies[-1]))
plt.figure(1)
plt.title("KTBiEn")
plt.plot(timestep, bientropies)
plt.figure(2)
plt.title("Shannon Information")
plt.plot(timestep, shannon_entropies)
plt.figure(3)
plt.title("ApEn")
plt.plot(timestep, apentropies)
plt.figure(4)
plt.title("Avg. Cell (Shannon) Entropy")
plt.plot(timestep, average_cell_entropies)
plt.figure(5)
cpl.plot(cellular_automaton)