 Image credit: holoviews.com

# The Chaos GameR

## Generating Order by Constraining Randomness

This result may seem like a nice mathematical/statistical oddity, but there is some potentially deep knowledge about structure of reality to be uncovered here. Another way of saying constraining randomness by imposing rules is restricting the degrees of freedom each individual system has for generating behaviour, by coupling their dynamics.

Of course the “coupling” here is rather artificial, and it is not strictly the case that each system is constrained in their behaviour (e.g. the die will still generate uniformly distributed 1,2,3,4,5,6 events). One can think of it as giving meaning to the probability of a set of events occurring by introducing an association (a redundancy)1 to the occurrence of phenomena in “another world”. In this case the other world is a 2D plane upon which dots can appear and the Sierpinsky Triangle is an expression of the association that was introduced by the coupling of the “different worlds”. This is often referred to as the emergence of order:

“order is essentially the arrival of redundancy in a system, a reduction of possibilities” - von Foerster (2003)

Like with models of growth, the rules of the Chaos Game can be made dependent on other processes or events to make them less of an abstraction, or, to increase the complexity of the outcome. A great example of the latter are the so-called fractal flames implemented in a screen-saver called electric sheep, which combines genetic algorithms, distributed computing and user input (“likes”) to create intruiging visual patterns on your computer screen.2

## Iterated Function Systems in R

The comment section on the Numberphile video has links to simulations in Geogebra:

Below are examples of so-called Iterated Function Systems implemented in R, just copy the code and run!

Try to understand what is going on in the two examples below:

• What is creating the structure at the level of the whole? (also look at the different colours)
• What’s the difference between the Siepinsky Gasket and the Fern? (if any)

### A Triangle

# Sierpinski Gasket using Iterated Function Systems
#
# Module Dynamical and Nonlinear Data analysis and Modeling
#
# May 2008
# Fred Hasselman & Ralf Cox

require(dplyr)

x = 0                  # Starting points
y = 0

# Emppty plot
plot(x,y, xlim=c(0,2), ylim=c(0,1))

for(i in 1:20000){      # This takes some time: 20.000 iterations

coor=runif(1)       # coor becomes a random number between 0 and 1 drawn from the uniform distribution

# Equal chances (33%) to perform one of these 3 transformations of x and y
if(coor<=0.33){
x=0.5*x
y=0.5*y
points(x,y,pch=".", col="green") #plot these points in green
}

if(between(coor,0.33,0.66)){
x=0.5*x+0.5
y=0.5*y+0.5
points(x,y, pch=".", col="blue") # plot these points in blue
}

if(coor>0.66){
x=0.5*x+1
y=0.5*y
points(x,y, pch=".", col="red") #plot these points in red
}
} # for ... ### A Fern

# Barnsley's Fern using Iterated Function Systems
#
# Module Dynamical and Nonlinear Data analysis and Modeling
#
# May 2008
# Fred Hasselman & Ralf Cox

require(dplyr)

x = 0                  # Starting points
y = 0

# Emppty plot
plot(x,y, pch=".", xlim=c(-3,3), ylim=c(0,12))

for(i in 1:50000){      # This takes some time: 20.000 iterations

coor=runif(1)       # coor becomes a random number between 0 and 1 drawn from the uniform distribution

if(coor<=0.01){                  #This transformation 1% of the time
x = 0
y = 0.16 * y
points(x,y, pch=".", col="brown")
}

if(between(coor,0.01, 0.08)){   #This transformation 7% of the time
x = 0.20 * x - 0.26 * y
y = 0.23 * x + 0.22 * y + 1.6
points(x,y, pch=".", col="olivedrab")
}

if(between(coor,0.08,0.15)){   #This transformation 7% of the time
x = -0.15 * x + 0.28 * y
y =  0.26 * x + 0.24 * y + 0.44
points(x,y, pch=".", col="forestgreen")
}

if(coor>0.15){      #This transformation 85% of the time
x =  0.85 * x + 0.04 * y
y=  -0.04 * x + 0.85 * y + 1.6
points(x,y, pch=".", col="springgreen2")
}

} # for ... These Iterated Function Systems also go by the name of the Fractal Game and are used in computer science, the gaming industry, graphic design, etc.

This Wikipedia page on Barnsley’s fern has some good info on the topic. At the end they display Mutant varieties. Try to implement them!

1. Whether one calls this a rule, a reducndancy, a correlation, an association, a coupling, an interaction, etc. is irrelvant. These words express that distinct aspects of reality are to some extent similar in structure and/or behaviour

2. Use at your own risk! You will find yourself silently staring at the screen for longer periods of time. 