11.3: movement of ants (plus more matlab, plus artificial life)

41
11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Upload: olivia-cameron

Post on 03-Jan-2016

223 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

11.3: Movement of Ants

(plus more Matlab, plus

Artificial Life)

Page 2: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Movement of Ants

Ant movement complicates the spread-of-fire model

in a number of ways

1. Each ant has an orientation (N, S, E, W)

2. Each cell contains an ant, a quantity of

pheromone (chemical deposited by ants and

attractive to them), both, or neither

3. Ant cannot move into cell occupied by another

Page 3: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Ordered Pair Representation

• We can represent ant presence/absence/orientation using one number: 0 = no ant; 1 = E, 2 = N, 3 = W, 4 = S

• Another number can represent the concentration of pheromone from zero to some maximum (e.g. 5).

• Book suggests using an ordered pair (like Cartesian coordinate) to combine these; e.g., (1, 3) = east-facing ant in a cell with a 3/5 concentration of pheromone.

Page 4: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Single-Number Representation

Matlab prefers to have a single number in each cell. So we can use a two-digit number to represent an ordered pair: (3,5) becomes 35; (0, 2) becomes 2, etc.

grid = 10*ant + pheromone;

ant = fix(grid/10); % fix keeps integer partpheromone = mod(grid, 10);

Page 5: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Matrices and Indexing• We’ve seen how to perform operations on an entire

matrix at once: grid(rand(n)<probTree) = 1, etc.

• What if we want to operate on individual rows, columns, and elements?

• grid(i, j) accesses row i, column j of grid.

• grid(i, :) accesses all columns of row i

• grid(:, j) accesses all rows of column j

Page 6: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Matrices and Indexing: Examples

grid(2, 3) = 1; % a tree grows at 2,3

grid(1, :) = 2; % whole top row on fire

Page 7: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Ranges and Indexing

• But we’re supposed to start with a gradient strip of pheromone – a range like 0, 1, 2, 3, 4, 5

• In Matlab we can simply say 1:5 grid(3, 4:8) = 1:5;

• For a vertical “strip”, we transpose the range:grid(2:6, 4) = (1:5)’;

• Let’s put an arbitrarily long horizontal strip of gradient in an arbitrary row....

Page 8: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Initializing the Gradient

phergrid = zeros(n); % NxN pheromone grid

row = fix(rand*n)+1; % indices start at 1

len = fix(rand*n)+1; % length of gradient strip

col = fix(rand*(n-len))+1; % starting column

phergrid(row, col:col+len-1) = 1:len; % help me Obi-wan!

Page 9: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Initializing the Ants

• For trees we simply did:

probTree = 0.2;grid = zeros(n);grid(rand(n)<probTree);

• But here we want several possible values for each ant

• So we can set up a grid full of ant values, then zero it out where appropriate....

Page 10: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Initializing the Ants

probAnt = 0.2;antgrid = fix(4*rand(n))+1; % 4 directionsantgrid(rand(n) > probAnt) = 0;

Putting it all together:

grid = 10*antgrid + phergrid;

Page 11: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Updating the Grid

• An ant turns in the direction of the neighboring cell with the greatest amount of pheromone (in a tie, pick one at random), then walks in that direction

• If there’s no ant in a cell, the pheromone decreases by 1 at each time step, with a minimum value of 0.

• If an ant leaves a cell, the amount of pheromone increases by 1 (ant “deposits” pheromone”).

• So long as there is an ant in a cell, the amount of pheromone in the cell stays constant.

Page 12: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Avoiding Collisions

• For an ant facing in a given direction and about to walk in that direction, there are three potential ants in other cells that it could collide with.

• For example, if I am an ant facing North:

me

NW NE

NN

N

Page 13: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Avoiding Collisions

• Because there are four other directions (S, E, W), each cell has a potential collision with 12 others:

me

• As a first approximation, we can ignore collisions: e.g., cell is occupied by last ant to move there, and others go away (maybe replaced by new ones being born).

Page 14: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

The Big Picture: Self-Organization &

Spontaneous Orders• By itself, the rules for movement of ants aren’t

terribly interesting.

• What interests scientists is the spontaneous orders and self-organizing behaviors that emerge from such simple systems of rules.

• This is a profound idea that shows up in biology, economics, and the social sciences.

Page 15: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Spontaneous Orders in Markets

Every individual...generally, indeed, neither intends to promote the public interest, nor knows how much he is promoting it. By preferring the support of domestic to that of foreign industry he intends only his own security; and by directing that industry in such a manner as its produce may be of the greatest value, he intends only his own gain, and he is in this, as in many other cases, led by an invisible hand to promote an end which was no part of his intention.

− Adam Smith, The Wealth of Nations

Adam Smith(1723-1790)

Page 16: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)
Page 17: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)
Page 18: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Termite Nest-Building

Page 19: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Bird Flocks

Page 20: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Boids: Artificial Birds

• Flocks of birds appear to be moving as a coherent whole, following a leader & avoiding obstacles

• Can this global behavior instead be emergent from the local behavior of individuals birds?

• Boids (Reynolds 1986): Each “boid” follows three simple rules

Page 21: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Boids: Artificial Birds

Separation: steer to avoid crowding local flockmates

Alignment: steer towards the average heading of local flockmates

Cohesion: steer to move toward the average position of local flockmates

http://www.red3d.com/cwr/boids/

Page 22: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Evolution of Cooperation

• Consider the Prisoner’s Dilemma game where you and I are arrested for committing a crime.

• If I defect (rat you out) and you cooperate with me (keep quiet), you get 10 years and I go free.

• If I cooperate and you defect, I get 10 years and you go free.

• If we both cooperate, we each get six months

• If we both defect, we both get five years.

• What is the best strategy?

Page 23: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Evolution of Cooperation

• The best strategy is for me is to defect (same for you).

• If I defect, the expected value (average value) of my punishment is 2.5 years (0 if you cooperate, 5 if you defect)

• If I cooperate, the expected value of my punishment is 5.25 years (6 months if you cooperate, 10 years if you defect).

• But what if we repeat this game over and over, allowing each of us to remember what others did in previous iterations (repetitions)?

Page 24: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Iterated Prisoner’s Dilemma• Axelrod (1981/1984) : Held a simulated tournament among

various PD strategies submitted by contestants

• Strategies could be arbitrarily simple (always defect, always cooperate) or complicated (keep track of other guys’ last five moves, then try to predict what he’ll do next time, etc.)

• Amazingly, winning strategy was simple tit for tat (quid pro quo):

• Always cooperate with someone the first time.

• Subsequently, do what he did on your previous encounter with him.

Page 25: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Iterated Prisoner’s Dilemma:

(Artificial) Life Lessons?

In general, most successful strategies followed four rules:

• Be nice: Don’t be the first to defect

• Be provocable (don’t be a sucker)

• Don’t be envious: don’t strive for a payoff greater than the other player’s

• Don’t be too clever (KISS principle)

Page 26: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

The Bad News: People Are

Naturally Envious• Ultimatum game : psychology experiment with

human subjects (Güth et al. 1982)

• Subject A is given $10 and told to share some of it (in whole $$) with subject B, where B knows how much A is given

• Optimal for A is to give B $1 and keep $9

• Typically, A will offer $3, and B will refuse to accept anything less (!)

Page 27: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

The Good News: TFT is an

Evolutionarily Stable Strategy

• Q: What happens when we introduce a “cheater” (always defects) into a population of TFT players?

• A: The cheater initially gains some points by exploiting TFT player’s niceness, but soon is overwhelmed by subsequent TFT retribution.

• So TFT is an evolutionarily stable strategy (Maynard-Smith 1982)

Page 28: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Evolution of Communication

• What is communication?

Communication is the phenomenon of one organism producing a signal that when responded to by another organism confers some advantage (or the statistical probability of it) to the signaler or his group.─ G. Burghardt (1970)

• How does a community come to share a common system of communication (language)?

Page 29: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Evolution of Communication

MacLennan (1990): Simulate communication by a simple matching game: each “simorg” (simulated organism) has a “private” situation that it wants to describe to others.

Page 30: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

• MacLennan (1990): Simulation communication by a simple matching game

• To communicate a situation, the individual looks up its current situation in a table and emits an symbol into the shared environment

• Each individual then uses its own table to convert the shared symbol back into a guess about the private situation of the emitter.

• Whenever an individual matches the emitter’s situation, it and the emitter get a fitness point

• Individuals with highest fitness get to survive

Page 31: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Evolution of Communication:

Results, Fitness

iteration

fitne

ss

Page 32: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Evolution of Communication:

Results, Denotation Matrix

First iteration: random association of symbols with situations

Page 33: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Last iteration: systematic association of symbols with situations

Evolution of Communication:

Results, Denotation Matrix

Page 34: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

synonyms

Page 35: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

homonyms

Page 36: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Quantifying Denotation (Dis)order

Claude Shannon (1916-2001)

• Shannon Information Entropy: quantifies (in # bits) amount of disorder in a distribution

where pk is the probability of event(situation) k

• Examples:

• p = [0.25, .25, .25, .25], H = 2.0

• p =[.95, .025, .0125 ,.0125] , H = 0.36

Page 37: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Choosing the Next Generation

Fitness-Proportionate Selection: use our biased roulette wheel to favor individuals with higher fitness, without ruling out selection of low-fitness individuals

i1

i2i3

i4i160%

i3 i4i28% 10% 22%

.60 .68 .78 1.0normalized fitnesses

individuals

Page 38: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Iterating Over Generations

• A highly expressive language like Matlab may allow us to avoid explicit iteration (looping), via operators like sum, > , etc.

• But when the current generation (population) depends on the previous one, we say that the model is inherently iterative.

• For such models we use an explicit loop, typically a for loop....

Page 39: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Original Population Model in Matlab% growth ratek = 0.1;

% initial populationP0 = 100;P = zeros(1, 20);P(1) = P0;

% iteratefor t = 2:20 P(t) = P(t-1) + k*P(t-1);end

% analytical solutionPa = P0 * exp(k*[1:20]);

% overlay plotsplot(P)hold onplot(Pa, 'r') % red

Page 40: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Modeling & Simulation: Conclusions

• Cellular automata and related simulations can be a powerful and exciting way of exploring phenomena for which an actual experiment is too difficult or costly.

• But one must be careful not to “build-in” the very behavior that one claims is emergent.

• One must also be careful not to over-interpret the results.

Page 41: 11.3: Movement of Ants (plus more Matlab, plus Artificial Life)

Potential Projects

• Implement collision avoidance in ants simulation.

• Implement Conway’s Game of Life in init, update functions.

• Implement MacLennan’s evolution of communication algorithm.