Cellular Automata

advertisement
Senior Seminar Project
Peter Strader
2012-2013
November 03, 2013
My senior project explores Cellular Automata and its implementation in media. Initially
when choosing a topic, I wanted to study a subject that would keep me interested. I love playing
computer games, so I chose to research computer graphic media. Media like video games and
movies use computer graphics and programming to enhance visual effects and artificial
intelligence. The creative process undertaken by game designers can be time consuming and
result in lost time and money. To expedite the process, game designers turn to Procedural
Generation, media content created algorithmically through computer programs (Peigen, pg. 412419). Procedural generation can create graphics, characters (AI), and in a limited capacity
storyline and speech (Cepero P.G).
In the world of graphic design there are plenty of ways to improve and push the bounds
of natural textures. Some of the first ideas I looked at were Perlin Noise and Fractal Geometry.
In graphic design these two are the most commonly used methods to speed up the process of
texturing objects and creating geometry (Cepero P.G). Fractal geometry, a method of creating
self-similar shapes, is often used in 3D space on two dimensional planes to create naturalistic
mountains and valleys (Cepero P.G). Perlin Noise is used in adding texture to objects. It uses
pseudo-random variables to create cloud and smoke textures to the specifications of the artist.
Also when the algorithm is reiterated into itself it can create finer detail (Cepero P.G). The last
method I researched was cellular automata.
→
*Figures of Perlin Noise increasing in complexity1. *Example of fractal geometry.
Procedural generation can be implemented in many ways both to create content and to
run game content. One way P.G. is used is in Cellular Automata, the discrete modeling of cells
and organisms (Peigen, pg. 412-419). I’ll expand latter on Cellular Automata and how it is used
to create biomes, but more specifically how it is used to determine population in settings of
predation and warring factions for the sake of game play (Cepero P.G). We’ll begin exploring
cellular automata with Conway’s game of life, one of the first mathematical modelings of cell
life and growth that derived how to set rules to. Then we’ll discuss my work on the modeling of
two organisms both as predator-prey and predator-predator relationships. Lastly I’ll discuss
further aspirations for my project.
Cellular automata is a recent field of modeling growth and dynamics of population and
cell growth. Starting in the 1940’s researchers and scientists at Los Alamos Labs first developed
the method to model and predict crystal growth and nano-replication (Peigen, pg. 412-419). The
route of how cellular automata works is by creating or deriving the rules for which organisms
and natural processes work and implementing them in a model. The common modeling form is
with a grid of cells. Each cell can represent the subject you are modeling, bacteria, plants, even
1
You can enter in the original output in order to increase the output in grater density; here we see the
“cloud” output increase in detail as the previous output in fed back into the algorithm. (wiki: Perlin Noise)
communities (Cepero P.G). To demonstrate I created simple one-dimensional two-state model
that means each step is represented by a row of cells (one-dimension) that are either alive or dead
according to their rule set (Two-states). The rules I came up with were as follows, if a cell right
of a living cell is dead then the living cell propagates a living cell in that space; if a living cell
has a living cell to it’s right then it dies. The phases we can deduce from these two rules is
propagation occurs before death, then we proceed to the next step (Peigen, pg. 412-419).
There are many other ways to model simple cell life, the most commonly known was developed
by British mathematician John Conway, The Game of Life. This model runes in two dimensional
space with the same two state concept (Peigen, pg. 412-419). Rules are as follows, first any live
cell with fewer than two live neighbors dies, as if caused by under-population, second any live
cell with two or three live neighbors lives on to the next generation, third any live cell with more
than three live neighbors dies, as if by overcrowding, lastly any dead cell with exactly three live
neighbors becomes a live cell, as if by reproduction.
By now you may be asking yourselves, how does this help with the using of making
games or predicting cell growth. These simple models demonstrate synthetic cellular life with
rules we devised, however the rules of the models can also be derived from nature. With the right
research and data collection one can deduce the key rules to population dynamics for any organic
system. These models can be used to predict the spread of disease, population growth, wildlife
concentrations, disaster outcomes, etc. (Peigen, pg. 412-419). However in games, it’s not just the
outcome of these models that designers took interest in, it was also the model process itself.
Methods like Conway’s can help in the predetermining of procedurally generated settlements,
but the models can have multiple agents, called autonomous units, that can interact.
This interaction in cellular automata becomes the basis for a lot of non-player characters
in games and agents in computer graphics. A well-known example of this modeling was used in
the making of the Lord of the Rings trilogy. With the creation of epic battle scenes, and vast
imposing armies, comes the logistical problem of trying to gather that many people together.
Now one can create billboard cut outs, which is when you repeat the same image of people in a
scene to give an illusion of large groups, but the producers and Peter Jackson wanted to create as
natural and organic a battle as possible. That is when Weta Digital, Jackson’s production
company, developed the M.A.S.S.I.V.E. software engine. The acronym stands for “Multiple
Agent Simulation System In Virtual Environment” and gives a good description of what the
software does. You can create multiple automatons, agents that act with their own “brain” or
code. Each species in the Lord of the Rings battles was given its own basic brain out line. Elves
would stand tall, fight in unison, and march in formation. Orcs would walk with bent backs and
crooked knees, fight haphazardly, and move in a swarm. Then you would get sub groups for
each, those who used spears, swords, or bow. Then you could specialize even further and create
individual traits (Massive Software).
Once all agents have been created, they can set them in a computer generated battlefield,
whether it is the Pelennor fields or the plateau of Gorgoroth, the agents adjust for terrain in
accordance to the code and attack and defend according to their given traits. Now due to the
sheer number of unique agents, battles can often run from the same initial conditions but give
totally different results, as is the magic of cellular automata models, there are always differences
due to randomness. So in order to get a consistent battle run, the programmers and designers can
give orders to the agents and encourage them to lead charges or to run when routed. Once the
battle has been sufficiently recorded, artists go in and add armor and detail to each model.
Though it might sound tedious, the computer can often apply the same outward appearance to
hundreds of agents at a time. Then they render the environment and the armies to make it as
realistic as possible, finally ending with the finished scene.
So began my investigation into cellular automata and its use in digital media, with the
end goal of creating a simulation of my own. So to begin my exploration of creating a battle
simulation I decided to look into the modeling of two organisms. This would both allow me to
model a dynamic system and to draw me closer to the ultimate goal of modeling two agent
groups in conflict. So to start I looked into the predator - prey modeling of wolves and sheep.
Now by this time in my mathematical career here at Loras we have covered such dynamic model
system in linear algebra with the concept of coyotes verses road runners. However dynamical
systems in linear algebra gave the data ahead of time to test if the dynamic system was stable.
With cellular automata we would have to extrapolate such information after several runs of only
one particular set up. We needed a means of seeing if the system could be stable only in the most
general of terms. Luckily we found the Lotka-Volterra equation for predator - prey modeling.
Starting in 1925 as a research project to answer a friend’s observation of the drop of fish
population in the Mediterranean, Vito Volterra, a mathematician who specializes in differential
and integral equations, wrote a paper on the subject of using mathematical methods to predict the
population dynamics of the Mediterranean (Britton, pg.54-62). About this time Alfred Lotka
publish his models of theoretical ecology, and so a system of equations were devised to predict
the population dynamics of two competing organisms (Britton, pg.54-62). The Lotka-Volterra
Prey-Predator Equations. We start by considering what goes into the rise of and fall of two
populations when one is dependent on the other. Since the problem is about the change of
population over time we know we would be modeling the differential equations of population of
prey over time and change of predators’ population over time.
When looking into what programs could handle both code and modeling, we found that
the software Netlogo already had a predator-prey simulation with sheep and wolves. So I began
to experiment by changing the variables given in the simulation. The program had several
adjustable variables characteristic to the ecosystem between two species. Sheep need to eat grass
to build energy towards giving birth. So we have adjustable variables for grass growth, energy
gained from food, birthrate, and the initial number of sheep. Wolves depend on the sheep they
eat to gain energy for reproduction. So they have adjustable variables for energy gained from
food, birthrate, and initial population. Death rate occurred as a result of energy lost over time.
Now energy gained from food represents the influence of resources towards survival. The more
plentiful the food source the more likely the animals will be able to procreate. With these
adjustable variables we can play around with different combinations of variables to see what
makes a stable ecosystem and an unstable one.
Messing around with the different combinations I began to discover that starting from an
initial condition of a stable system, if I adjusted the initial population the ecosystem would
correct the extremes till it found a stable pattern. However, when adjusted the amount of energy
gained from food for sheep from the initial stable condition, by ever so little, the system would
collapse and either let the sheep over populate letting the wolves overindulge of food leading to a
near extinction of the sheep. Finally, with the sheep too few to catch the wolves die off, leading
to a slow recovery of the sheep. This was usually the case when adjusting the energy intake of
sheep, however the wolves would on occasion devour all the sheep, then both would be extinct.
Next from initial conditions, I adjusted the energy from food for the wolves, and instead of
crashing, the system seemed to just increase the oscillations and maintains stability up until the
extreme intake of 100%. This lead to a total extinction of both species.
The next variable we adjusted was the birth rate. Again, starting with initial conditions
known to be stable I adjusted the birthrates of each species separately to compare. Both resulted
with very few crashes, and even then set to the highest settings. So we summarized that we had
critical points when our birthrate for sheep was set just above normal. Now we had to consider in
what way we were to confirm our hypothesis that is where the Lotka-Volterra model comes in
(Britton, pg.54-62).
Lotka-Volterra Predator / Prey Model
The model for predator vs. prey
ΔS= ds/dt = α*S-β*S*W
ΔW= dw/dt = ε*S*W-γ*W
We model our system in the fashion of the Lotka-Volterra. The differential equations
above represent the change of populations over time for sheep and wolves respectively. We can
describe the change of sheep as “sheep added to the population” subtracted by “sheep killed by
wolves and starvation”. Notice that coefficient α represents the combination of factors
contributing to population growth, energy from grass and birthrate. While -β represents the
reduction of population by starvation and being eaten by wolves. Which is why the difference
equation is -β*S*W, since the drop in sheep population is due to a proportional relationship to
wolves. Conversely, the wolves’ population grows proportionally to the population of sheep,
represented in the coefficient ε; leaving death by starvation to be the coefficient –γ (Britton,
pg.54-62).
When comparing two differential equations that are dependent on each other we can test
the stability of the system by finding the stability at the fixed point, where the input is equal to
itself. This involves using the Jacobean matrix of partial derivatives to determine the eigenvalues
of our system (Britton, pg.54-62). The Lotka-Volterra method stipulates that if we take the
nontrivial steady state of the matrix at our first steady state, (0,0) (Britton, pg.54-62). We can
determine by what kind of eigenvalues follow, to whether the system is stable or more likely to
collapse.
First we look for the non-trivial steady state, using Jacobean to describe the population
plain as stable or unstable. The non-trivial as shown below, is the matrix of the partial derivatives
of our differential equations. The first row consists of the sheep differential, with partial
derivative according to population of sheep and then according to wolves. The second row
consists of the partial derivatives of the wolves’ differential according to sheep and then wolves.
Non-trivial steady state:
J(S, W) = [{α-βW, -βS}, {εW, εS-γ} ]
Now we set our populations to zero, to find the location of our first fixed point (Britton, pg.5462). So now our Jacobian matrix is alpha and zero in the first row, and zero and negative gamma.
Leading to our eigenvalues being alpha and negative gamma.
Trivial steady state
J (0, 0) = [{α, 0}, {0, -γ} ]
Eigenvalues are: λ = α,-γ
Eigenvectors are: [1,0] , [0,1]
Now alpha and gamma were our positive coefficients either greater or less than one, our system
dictates that they will have different signs. In differential systems this is a sign that our point at
(0, 0) is a saddle point. This confirms our suspicion that our system does not depend of
population being in a close approximation, but our factors of birthrate and food consumption
being the key factors. The saddle point also indicates that as long as our coefficients are in close
approximation, our populations should have difficulty going extinct. The saddle point tells us
that one direction is growing, specifically the direction of sheep growth. We would have to
physically remove numbers or change coefficient values in order to crash the ecosystem,
resulting in the death of the wolves and the sheep exponentially growing or the sheep die leading
to the wolves dying as well.
The second steady state is the oscillation of population in perpetuity. Which we can think
of as the perfect system, the populations are such that the wolves and sheep have a perfect
ecosystem. This is when we enter the quotient of the constants of our equations into the opposite
species discreet equation. So our Jacobean would be.
Nontrivial steady state
J (γ/ԑ, α/β) = [{0, -γβ/ԑ}, {αԑ/β, 0}]
Eigenvalues are: λ = -i(αγ)^1/2 , i(αγ)^1/2
The complex values only confirm that our system is in perpetual motion, which is what we
would expect of a health ecosystem. The values are imaginary and the fixed point is not
hyperbolic like our saddle point of the previous eigenvalues, so our observations are confirmed
that the system is steady and oscillates. This also confirms our observation that population has a
higher tolerance of change than our constants. Now we can examine the phase plane equation of
our system.
Now that we had our model deciphered we can assume our coefficients were correct to
create the phase plane model of our system. We started with our differential equations and
began the process by separating our system from change of populations over time, to change of
population over change of the other. We combined our differentials as such by dividing our
change of wolves by change of sheep.
Therefore there exists a system we can model:
ΔS = α*S-β*S*W || ΔW=ε*S*W-γ*W
dS/dt = S(α-βW) || dW/dt = W(εS-γ)
dW/dS = W(εS-γ)/ S(α-βW)
Next we had to work our equation to the point where it would integrate into our final phase plane
equation. This was achieved by multiplying the equations into separable integral parts, then
subtracted it all to one side so we had two integral parts equaling zero. Then with integration by
parts we found our phase plane equation to equal some output A.
S (α-βW)dW = W(εS-γ)dS
(α-βW)(1/W)dW = (εS-γ)(1/S)dS
(α-βW)(1/W)dW - (εS-γ)(1/S)dS = 0
The phase plane equation:
ɸ(S,W) = αLog(W)-βW – εS-γLog(S) = A
With this equation we can model the oscillation of our
populations such that any coordinate along the graph is
the population of both species at that point in time.
Shown here is an example of a predator vs. prey phase
plane. Notice the system oscillates, then crashes along
the predator axis. What we are not seeing is the
exponential growth of the prey along the prey axis since
the predator population is zero, we would see a series of coordinate given as (#, 0). Since prey is
the x-axis and predators are the y-axis. If the system would favor a crash of the prey population
over time the population coordinates would just be (0, 0). This would conclude our examination
of the Lotka-Volterra modeling of predator vs. prey. We now turn towards our pursuit of
modeling competitive systems of predator vs. predator.
To continue with our goal of modeling a battle system, we need to investigate the
mathematical model of such a system according to the Lotka-Volterra adjusted for predator
versus predator. We started by reprogramming our NetLogo program so that the sheep had the
same outline program as the wolves. Thus our program became like wolves versus wolves, what
we jokingly called wolves vs. clever sheep. We also removed the critical programming that
dictated birth rate for both species. Now our program went from modeling an ecosystem between
two species, to modeling a battle. Our justification is that in a short fight the end result is a loss
of numbers to both sides with the end result being one victor.
In our experimenting with the new program, we allowed for energy to be gained after
killing an enemy to supplement the energy gained from food for energy gained as a moral boost.
Given we set the program to run till all the animals energy is reduced to zero, this only provided
more time for the fight to continue. Setting both sheep and wolves to the same initial number,
and letting them have their random encounters, we found that both groups had equal chance of
winning the battle. The only time one species had an edge over the other, was when they
outnumbered the other. So we wanted to see if this would be true for an augmented LotkaVolterra model.
This time we concluded that there would be no part of the system that represent growth of
population. Also because the two species method of finding and killing foes was the same, we let
the two species have the same coefficient of loss of population, beta.
The model for predator vs. predator:
ΔS = -β*S*W
ΔW=-β*S*W
This time we look for the non-trivial steady state, using Jacobean to describe the
population plain for our new differential equations. As before the matrix consisted of the partial
derivatives according to sheep and wolves population.
J (W, S) = [{-βW, -βS}, {-βW, -βS} ]
Now it seemed obvious that if we set the matrix to the point (0, 0), we would end up with a zero
matrix. However we can try our matrix at the fix point buy supplementing in, (W, 0) and (0, S)
separately.
J(W,0) = [{-βW, 0} , {-βW , 0} ] or J(0,S) = [{0 , -βS} , {0 , -βS} ]
The eigenvalues of these matrices are [-βW, 0] and [0 , -βS] respectively, which supports our
observation that if one population outnumbers the other, the phase plane will shows has a
negative slope towards the axis of the species with the greater population. So we concluded the
matrix of zero indicates a critical point what the populations are even. So to see if this hypothesis
was true we solved for our phase plane equation. This simply led to the phase plane having a
critical point on the one to one line, or what we called the “tie-line”.
(ΔW /ΔS) = (dW/dt)(dS/dt)=(dW/dS) = (-β*S*W/-β*S*W) = 1.
ɸ(S,W) = x = A
Here is how we would depict our phase graphs. The first graph has the three results of the
eigenvalues. The top blue line being the result of [-βW, 0], the middle line being result of [0, 0],
and the bottom line being result of [0, -βS]. The second graph is just the definition of our tie-line.
At the tie-line we predict that the populations decrease towards the origin, but can either end
with one of the two agents winning the fight or the battle is never resolved leaving it a tie.
We returned to our program to test our findings by running 60 battles between wolves
and sheep. Our first run resulted in three ties, twenty-five victories for wolves and thirty two
victories for sheep. At first glance this graph is not conclusive, however if we consider averages
and round to the nearest tenth. Then the number of victories between the wolves and sheep is
was pretty well split, 30/60 to 30/60.
100 Sheep
100 Wolves
Wolves
25/60
Sheep
32/60
Tie
3/60
So we then considered how we could narrow down our program runs to give us a more definite
result proving that the tie-line is the critical line. So we repeated the 60 battles, but this time with
one to one confrontation. This time the number of ties fifty percent of the number of runs. That
was to be expected proportionally speaking of ties versus victories. However the number of
victories between the two species was not themselves tied. Because if we rounded we get 10/60
for wolves and 20/60 for sheep.
1 Sheep
1 Wolf
Wolves
12/60
Sheep
18/60
Tie
30/60
This became a problem because we saw this same offset during the run between 100 wolves and
100 sheep. Somehow we thought, the sheep had more of a chance of winning than the wolves.
This is a problem because we wrote the code so that the species were the same, no differences as
to develop the “control group” so to speak. We checked our code and found that the sheep had a
special trait. When one sheep came across a wolf, or a wolf came across a sheep the sheep has
the first attempt to kill the wolf. So because of a writing error, the sheep had the upper hand. So
we rewrote the code so the sheep and wolves had an equal chance to kill each other. Our third
run produced the result we were waiting to see. There were more ties, and the sheep and the
wolves had the same number of victories. Thus confirming our prediction that a critical point
exist when the populations are even for species of equal ability in battle.
1 Wolf
1 sheep
Wolves
11/60
Sheep
11/60
Tie
38/60
Finally we can take our control program and develop our combat system. The first thing
decided to add was vision. The original program still had random movement, which was to
represent the average of encounters in the wild. However we want to model the arena and that
means decisive choice of finding and fighting a foe. So we gave each species a program to
recognize the enemy from a specific distance away and within a field of vision. When an enemy
is spotted it also locks that warrior onto the foe. We gave vision distance and field of vision
adjustable toggles. We also changed the species to add some fun, by having the combat to be
between orcs and elves. They both had adjustable initial population, adjustable energy gained
from killing a foe, and adjustable acuteness. Acuteness is a coefficient that helps determine how
well they can track their foe.
The addition of tracking increased the number of victories and lowered the number of
ties. Instead of the time spent wandering randomly around the map, the orcs and elves spend less
energy trying to track down and kill enemies, so the fights end a lot sooner. The tracking also
leads to the clustering of combat on the map, because as the numbers dwindle down the species
with the most people during a fight end up tracking down the last of the enemy together. This
one addition to the code represents a dramatic change towards a more autonomous model. Our
agents, the orcs and elves already have a semblance of simple organic life. Like insects fighting
in a terrarium they have two simple processes in their brain, they see an enemy and they try to
destroy the enemy. That is what took our code from random encounters of the wild to agents that
can “consciously” attack the enemy. This is what we would call a primitive brain in agent
development. While not as advanced as the agents in the Lord of the Rings, MASSIVE engine, it
is a brain nonetheless. This program is but a small step in developing a battle simulator.
For future work I will look to expand the code and develop the brains of the agents, from
a standard brain to more diverse agents. We can designate commanding agents that can lead their
men across the map. The methods of attacking can be varied. Elves could use ranged weapons
like bows and orcs can have stronger defenses like armor. To bring back the dynamics of our
original cellular model, we can introduce reinforcements, and have small boosts of numbers
during long flights. In truth the number of additional code is infinite with the only limitation
being our imagination.
This simple battle simulator is primitive compared to what inspired me to pursue this
research of cellular automata in games and media. However I have expanded my understanding
of what goes into the development of works like Lord of the Rings and the origins ecological
modeling. It is that unique quality of mathematics that just one small field of it can be so
versatile and be implemented in so many varying ways. My research project will hopefully
continue to future development of ecosystem modeling and expand my battle simulator.
Sources:
Nicholas F. Britton, Essential Mathematical Biology, Springer (2003), pg. 54
(Britton, pg.54-62)
Peigen, Jürgens, and Saupe, Chaos and Fractals, New Frontiers of Science, Springer
(1996), pg. 412
(Peigen, pg. 412-419)
NetLogo 5.0.4, (2013)
Miguel Cepero, Procedural World, http://procworld.blogspot.com/ (2013)
(Cepero P.G)
Massive Software (2013)
Download