I wrote the code to draw the evolution of the one-dimensional cellular automaton in Python. Finally, the result of executing with some rules is posted.
Cellular automaton develops the state of a cell according to a local rule, and is a physicist Stephen Wolfram. 82% B9% E3% 83% 86% E3% 82% A3% E3% 83% BC% E3% 83% 96% E3% 83% B3% E3% 83% BB% E3% 82% A6% E3% 83% AB% E3% 83% 95% E3% 83% A9% E3% 83% A0) and mathematician John Horton Conway 83% A7% E3% 83% B3% E3% 83% BB% E3% 83% 9B% E3% 83% BC% E3% 83% 88% E3% 83% B3% E3% 83% BB% E3% 82% Its properties were studied in detail by B3% E3% 83% B3% E3% 82% A6% E3% 82% A7% E3% 82% A4) et al. By changing the rules, various natural phenomena can be imitated, and the two-dimensional one is known as "life game".
The rules for one-dimensional cellular automata are numbered. For example, the rule called rule 214 is as shown in the above figure. If you are not sure, please see this article for details.
Let's implement the above rule.
1d_ca.py
import matplotlib.pyplot as plt
def cellautomaton(l_bit, rule, pattern=False, padding=0):
# pattern:Periodic boundary conditions, padding:Value of cells outside the frame
l_bit_new = []
if not pattern:
l_bit = [padding] + l_bit
l_bit.append(padding)
else:
l_bit = [l_bit[-1]] + l_bit
l_bit.append(l_bit[1])
for i in range(1, len(l_bit)-1):
l_bit_new.append(next_state(l_bit[i-1],l_bit[i],l_bit[i+1], rule))
return l_bit_new
def next_state(l, x, r, rule):
#Determine the state of the next cell
bin_str = format(rule, '08b')
bin_num = int(str(l)+str(x)+str(r), 2)
return int(bin_str[-(bin_num+1)])
def main():
result = []
loop = 200
rule = 110 #Rule number(0~255)
##Specify the initial state in list x
x = [0]*200
x[-1] = 1
result.append(x)
for i in range(loop):
x = cellautomaton(x, rule, pattern=False)
result.append(x)
plt.figure()
plt.title("rule{}".format(rule))
plt.imshow(result, cmap="binary")
plt.show()
main()
By default, the length is 100, and only the rightmost cell is a one-dimensional array with 1 and 0. It is interesting to play around with it and change it. Finally, let's use this code to see an example with some rules.
[Stephen Wolfram](https://ja.wikipedia.org/wiki/%E3%82%B9%E3%83%86%E3%82%A3%E3%83%BC%E3%83%96%E3% 83% B3% E3% 83% BB% E3% 82% A6% E3% 83% AB% E3% 83% 95% E3% 83% A9% E3% 83% A0) has four behaviors of one-dimensional cellular automaton It is classified into classes. Simply put, it looks like this:
--Class 1: Converges to a state like all 0s, all 1s --Class 2: Converge to a state where fixed vibrations are repeated --Class 3: Become chaotic --Class 4: Periodic and chaotic states coexist (edge of chaos)
Rule 30 is a class 3 chaotic rule.
You can see that the pattern is complicated and has no periodicity.
Rule 90 is a class 3 rule that draws a fractal shape called the Sierpinski gasket. A fractal figure is a figure that appears in a similar shape when scaled.
Rule 110 is a class 4 rule that takes an intermediate state between periodic and chaos.
You can see that it has periodicity and breaks after a while. It is known that the dynamics between this order and chaos are often found in natural phenomena, and it is possible to imitate a Turing machine by using the rich dynamics of such areas.
that's all. There are many other rule shapes, such as this article. As a practical example, it seems that it is sometimes used in traffic simulation like this article.
[Illustrated trivia complex system (Norio Konno, Natsumesha)](https://hb.afl.rakuten.co.jp/ichiba/1bc63814.31bba873.1bc63815.5874eb3b/?pc=https%3A%2F%2Fitem.rakuten. co.jp% 2Fcomicset% 2F4816323899% 2F & link_type = hybrid_url & ut = eyJwYWdlIjoiaXRlbSIsInR5cGUiOiJoeWJyaWRfdXJsIiwic2l6ZSI6IjI0MHgyNDAiLCJuYW0iOjEsIm5hbXAiOiJyaWdodCIsImNvbSI6MSwiY29tcCI6ImRvd24iLCJwcmljZSI6MSwiYm9yIjoxLCJjb2wiOjEsImJidG4iOjEsInByb2QiOjB9)
Recommended Posts