cellular automata - department of computer science - …igor/comp308/ppt/lec… · ppt file · web...

59
Cellular Automata COMP308 Unconventional models and paradigms

Upload: buidieu

Post on 21-May-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

Cellular Automata

Cellular Automata

COMP308

Unconventional models and paradigms

1

Failure and Success of Complex Models

New scientific paradigms bring about new insights:

Research shows that complexity is a prerequisite for success of living systems (Jacobs, Langton, Wolfram, Kaufmann, Fotheringhham, Longley & Batty, Frankhauser & Sadler)

Lessons learned:

Complexity complication

3

Mathematical object defined as:

n-dimensional homogeneous and infinite cellular space, consisting of cells of equal size (2-D CA = torus, not a plane);

Cells in one of a discrete number of states;

Cells change state as the result of a transition rule;

Transition rule is defined in terms of the states of cells that are part of a neighbourhood;

Time progresses in discrete steps. All cells change state simultaneously.

What is a Cellular Automata ?

Concept introduced by Von Neumann, Ulam and Burk in late 1940-ies and 1950-ies; (Self-reproducible mechanical automata)

Conways Game of Life (Gardner, 1970)

What is a Cellular Automaton?

A one-dimensional cellular automaton (CA) consists of two things: a row of "cells" and a set of "rules".

Each of the cells can be in one of several "states". The number of possible states depends on the automaton. Think of the states as colors. In a two-state automaton, each of the cells can be either black or white.

Over time, the cells can change from state to state. The cellular automaton's rules determine how the states change.

It works like this: When the time comes for the cells to change state, each cell looks around and gathers information on its neighbors' states. (Exactly which cells are considered "neighbors" is also something that depends on the particular CA.)

Based on its own state, its neighbors' states, and the rules of the CA, the cell decides what its new state should be. All the cells change state at the same time.

3 Black = White

2 Black = Black

1 Black = Black

3 White = White

Now make your own CA

2-Dimensional Automata

2-dimensional cellular automaton consists of an infinite (or finite) grid of cells, each in one of a finite number of states. Time is discrete and the state of a cell at time t is a function of the states of its neighbors at time t-1.

Conways Game of Life

The universe of the Game of Life is an infinite two-dimensional grid of cells, each of which is either alive or dead. Cells interact with their eight neighbors.

8

Example of a Cellular Automata: Conways Life (Gardner, 1970)

Conways Game of Life

At each step in time, the following effects occur:

Any live cell with fewer than two neighbors dies, as if by loneliness.

Any live cell with more than three neighbors dies, as if by overcrowding.

Any live cell with two or three neighbors lives, unchanged, to the next generation.

Any dead cell with exactly three neighbors comes to life.

The initial pattern constitutes the first generation of the system. The second generation is created by applying the above rules simultaneously to every cell in the first generation -- births and deaths happen simultaneously. The rules continue to be applied repeatedly to create further generations.

Applications of Cellular Automata

Simulation of Biological Processes

Simulation of Cancer cells growth

Predator Prey Models

Art

Simulation of Forest Fires

Simulations of Social Movement

many more.. Its a very active area of research.

Cellular Automata: Life with Simple Rules

Sharks and Fish: Predator/Prey Relationships

Based on the work of Bill Madden, Nancy Ricca and Jonathan Rizzo

(Montclair State University)

*Adapted from: Wilkinson,B and M. Allen (1999): Parallel Programming 2nd Edition, NJ, Pearson Prentice Hall, p189

Cellular automata can be used to model complex systems using simple rules.

Key features*

divide problem space into cells

each cell can be in one of several finite states

cells are affected by neighbors according to rules

all cells are affected simultaneously in a generation

rules are reapplied over many generations

12

Main idea

Model predator/prey relationship by CA

Define set of rules

Begins with a randomly distributed population of fish, sharks, and empty cells in a 1000x2000 cell grid (2 million cells)

Initially,

50% of the cells are occupied by fish

25% are occupied by sharks

25% are empty

13

Heres the number 2 million

Fish: red; sharks: yellow; empty: black

14

Rules

A dozen or so rules describe life in each cell:

birth, longevity and death of a fish or shark

breeding of fish and sharks

over- and under-population

fish/shark interaction

Important: what happens in each cell is determined only by rules that apply locally, yet which often yield long-term large-scale patterns.

15

Do a LOT of computation!

Apply a dozen rules to each cell

Do this for 2 million cells in the grid

Do this for 20,000 generations

Well over a trillion calculations per run!

Do this as quickly as you can

Initially cells contain fish, sharks or are empty

Empty cells = 0 (black pixel)

Fish = 1 (red pixel)

Sharks = 1 (yellow pixel)

16

Rules in detail: Breeding Rule

Breeding rule: if the current cell is empty

If there are >= 4 neighbors of one species, and >= 3 of them are of breeding age,

Fish breeding age >= 2,

Shark breeding age >=3,

and there are =5 neighbors are sharks, fish dies (shark food)

If all 8 neighbors are fish, fish dies (overpopulation)

If a fish does not die, increment age

20

Rules in Detail: Shark Rules

If the current cell contains a shark:

Sharks live for 20 generations

If >=6 neighbors are sharks and fish neighbors =0, the shark dies (starvation)

A shark has a 1/32 (.031) chance of dying due to random causes

If a shark does not die, increment age

21

Shark Random Death: Before

I Sure Hope that the

random number

chosen is >.031

22

Shark Random Death: After

YES IT IS!!!

I LIVE

23

Programming logic

Use 2-dimensional array to represent grid

At any one (x, y) position, value is:

Positive integer (fish present)

Negative integer (shark present)

Zero (empty cell)

Absolute value of cell is age

24

Parallelism

A single CPU has to do it all:

Applies rules to first cell in array

Repeats rules for each successive cell in array

After 2 millionth cell is processed, array is updated

One generation has passed

Repeat this process for many generations

Every 100 generations or so, convert array to red, yellow and black pixels and send results to screen

25

Parallelism

How to split the work among 20 CPUs

1 CPU acts as Master (has copy of whole array)

18 CPUs act as Slaves (handle parts of the array)

1 CPU takes care of screen updates

Problem: communication issue concerning cells along array boundaries among slaves

26

Send Right Boundary Values

26

Subdivide grid into 18 vertical slices

Each slice has a left boundary and a right boundary

Set the left boundary of the left-most slice to a preset value (we used 0=empty)

Do same for right boundary of right-most slice (and top and bottom of all slices)

Each slave sends its boundary results to its left and right neighbor slaves

Each slave receives boundary information from its neighbor slaves

At intervals, all slaves update the master CPU

27

Receive Left Boundary Values

28

Send Left Boundary Values

29

Receive Right Boundary Values

30

Send Right Boundary Values

31

Receive Left Boundary Values

32

Send Left Boundary Values

33

Receive Right Boundary Values

34

At intervals, update the master CPU

has copy of entire array

35

Illustration

Next several screens show behavior over a span of 10,000+ generations (about 25 minutes on a cluster of 20 processors )

36

Generation: 0

37

Generation: 100

38

Generation: 500

39

Generation: 1,000

40

Generation: 2,000

41

Generation: 4,000

42

Generation: 8,000

43

Generation: 10,500

44

Variations of Initial Conditions

Still using randomly distributed populations:

Medium-sized population. Fish/sharks occupy:1/16th of total gridFish: 62,703; Sharks: 31,301

Very small population. Fish/sharks occupy:1/800th of total gridInitial population:Fish: 1,298; Sharks: 609

45

Generation 100

2000

1000

4000

8000

Medium-sized population (1/16 of grid)

Random placement of very small populations can favor one species over another

Fish favored: sharks die out

Sharks favored: sharks predominate, but fish survive in stable small numbers

46

Very Small Populations

Random placement of very small populations can favor one species over another

Fish favored: sharks die out

Sharks favored: sharks predominate, but fish survive in stable small numbers

Elementary Cellular Automata

As before think of every cell as having a left and right neighbor and so every cell and its two neighbors will be one of the following types

Replace a black cell with 1 and a white cell with 0

111 110 101 100 011 010 001 000

1 1 1 1 1 0 1 0 1 1 0 0 0 1 1 0 1 0 0 0 1 0 0 0

Every yellow cell above can be filled out with a 0 or a 1 giving a total of 2 8=256 possible update rules.

This allows any string of eight 0s and 1s to represent a distinct update rule

Example: Consider the string 0 1 1 0 1 0 1 0 it can be taken to represent the update rule

1 1 1 1 1 0 1 0 1 1 0 0 0 1 1 0 1 0 0 0 1 0 0 0

0

1

1

0

1

0

1

0

Or equivalently

Now think of 01101010 as the binary expansion of the number

0 27+ 1 26+ 1 25+ 0 24+1 23+ 0 22+ 1 21+ 0 20 = 64+32+8+2=106.

So the update rule is rule # 106

Lets visualize some of these rules using a Mathematica notebook

Rule #45=32+8+4+1

= 0 27+ 0 26+ 1 25+ 0 24+1 23+ 1 22+ 0 21+ 1 20 =0 0 1 0 1 1 0 1

Rule #30=16+8+4+2

= 0 27+ 0 26+ 0 25+ 1 24+1 23+ 1 22+ 1 21+ 0 20 =0 0 0 1 1 1 1 0

This naming convention of the 256 distinct update rules is due to Stephen Wolfram. He is one of the pioneers of Cellular Automata and author of the book a New Kind of Science, which argues that discoveries about cellular automata are not isolated facts but have significance for all disciplines of science.

49

Automata generated using Rule 30

appear in nature, on some shells.

current pattern111110101100011010001000new state for center cell00011110

Rule 184

Rule 184 is a one-dimensional binary cellular automaton rule, notable for solving the majority problem as well as for its ability to simultaneously describe several, seemingly quite different, particle systems:

Rule 184 can be used as a simple model for traffic flow in a single lane of a highway, and forms the basis for many cellular automaton models of traffic flow with greater sophistication. In this model, particles (representing vehicles) move in a single direction, stopping and starting depending on the cars in front of them. The number of particles remains unchanged throughout the simulation. Because of this application, Rule 184 is sometimes called the "traffic rule.

Rule 184 also models a form of deposition of particles onto an irregular surface, in which each local minimum of the surface is filled with a particle in each step. At each step of the simulation, the number of particles increases. Once placed, a particle never moves.

Rule 184

In each step of its evolution, the Rule 184 automaton applies the following rule to determine the new state of each cell, in a one-dimensional array of cells:

current pattern111110101100011010001000new state10111000

The rule set for Rule 184 may also be described intuitively, in several ways:

At each step, whenever there exists in the current state a 1 immediately followed by a 0, these two symbols swap places.

At each step, if a cell with value 1 has a cell with value 0 immediately to its right, the 1 moves rightwards leaving a 0 behind. A 1 with another 1 to its right remains in place, while a 0 that does not have a 1 to its left stays a 0 (traffic flow modeling)

If a cell has state 0, its new state is taken from the cell to its left. Otherwise, its new state is taken from the cell to its right.

Rule 184, run for 128 steps from random configurations with each of three different starting densities: top 25%, middle 50%, bottom 75%.

The view shown is a 300-pixel crop from a wider simulation.

Rule 184 dynamics and majority problem

Two important properties of its dynamics may immediately be seen:

First, in Rule 184, for any finite set of cells with periodic boundary conditions the number of 1s and the number of 0s in a pattern remains invariant throughout the pattern's evolution.

Similarly, if the density of 1s is well-defined for an infinite array of cells, it remains invariant as the automaton carries out its steps.

And second, although Rule 184 is not symmetric under left-right reversal, it does have a different symmetry: reversing left and right and at the same time swapping the roles of the 0 and 1 symbols produces a cellular automaton with the same update rule.

11111010110001101000100010111000

Patterns in Rule 184

Patterns in Rule 184 typically quickly stabilize, either to a pattern in which the cell states move in lockstep one position leftwards at each step, or to a pattern that moves one position rightwards at each step.

Specifically, if the initial density of cells with state 1 is less than 50%, the pattern stabilizes into clusters of cells in state 1, spaced two units apart, with the clusters separated by blocks of cells in state 0. Patterns of this type move rightwards.

If, on the other hand, the initial density is greater than 50%, the pattern stabilizes into clusters of cells in state 0, spaced two units apart, with the clusters separated by blocks of cells in state 1, and patterns of this type move leftwards.

If the density is exactly 50%, the initial pattern stabilizes (more slowly) to a pattern that can equivalently be viewed as moving either leftwards or rightwards at each step: an alternating sequence of 0s and 1s.

Majority Problem

One can view Rule 184 as solving the majority problem, of constructing a cellular automaton that can determine whether an initial configuration has a majority of its cells active:

if Rule 184 is run on a finite set of cells with periodic boundary conditions, and the number of active cells is less than half of all cells, then

each cell will eventually see two consecutive zero states infinitely often, and two consecutive one states only finitely often,

while if the number of active cells forms a majority of the cells then

each cell will eventually see two consecutive ones infinitely often and two consecutive zeros only finitely often.

The majority problem cannot be solved perfectly if it is required that all cells eventually stabilize to the majority state but the Rule 184 solution avoids this impossibility result by relaxing the criterion by which the automaton recognizes a majority.

Traffic flow

Rule 184 interpreted as a simulation of traffic flow. Each 1 cell corresponds to a vehicle, and each vehicle moves forwards only if it has open space in front of it.

Although very primitive, the Rule 184 model of traffic flow already predicts some of the familiar emergent features of real traffic: clusters of freely moving cars separated by stretches of open road when traffic is light, and waves of stop-and-go traffic when it is heavy.

Rule 184 as a model of surface deposition. In a layer of particles forming a diagonally-oriented square lattice, new particles stick in each time step to the local minima of the surface.

We model a segment with slope +1 by an automaton cell with state 0, and a segment with slope -1 by an automaton cell with state 1.

The local minima of the surface are the points where a segment of slope -1 lies to the left of a segment of slope +1; that is, in the automaton, a position where a cell with state 1 lies to the left of a cell with state 0.

Adding a particle to that position corresponds to changing the states of these two adjacent cells from 1,0 to 0,1, which is exactly the behavior of Rule 184.

11111010110001101000100018410111000

Surface deposition

Computer processors

CA processors are a physical, not software only, implementation of CA concepts, which can process information computationally.

Processing elements are arranged in a regular grid of identical cells. The grid is usually a square tiling, or tessellation, of two or three dimensions; other tilings are possible, but not yet used.

Cell states are determined only by interactions with the small number of adjoining cells. Cells interact, communicate, directly only with adjoining, adjacent, neighbor cells. No means exists to communicate directly with cells farther away.

Cell interaction can be via electric charge, magnetism, vibration (phonons at quantum scales), or any other physically useful means. This can be done in several ways so no wires are needed between any elements.