15
Boids: Modeling and Understanding emergent behavior Sudeep Pillai [email protected]

Boids - Modeling and understanding emergent behavior

Embed Size (px)

DESCRIPTION

Here's a presentation I gave (for my Intro to Adaptive Systems course) of birds flocking together while following some simple but decentralized rules. Apart from following the simple rules of Separation, Cohesion and Alignment, I've also added some goal tending influences so that the organisms tend towards the circular object. All the code and simulation was run on Matlab using some slightly modified code from Conrad's pseudocode for boids (http://www.vergenet.net/~conrad/boids/pseudocode.html).Sudeep Pillai

Citation preview

Page 1: Boids - Modeling and understanding emergent behavior

Boids: Modeling and Understanding

emergent behavior

Sudeep [email protected]

Page 2: Boids - Modeling and understanding emergent behavior

Background

• Natural and often seen, yet so intriguingo Discrete birds, but an overall fluidic motion

o Magnificent synchronized behaviors

• Each bird dependent on each othero Based on local perception, they control themselves

o No awareness of global perspective

o Seems like a distributed control

o Is it intentional??

Page 3: Boids - Modeling and understanding emergent behavior

• Formationso Classic “Flying V” formation

– Reduce overall drag force as compared to flying alone

– Upwash produces free lift allowing lower angle of attack

– Lead bird – Two flanking birds dissipate downwash

Intentional flocking

Page 4: Boids - Modeling and understanding emergent behavior

• Reduced Energy expenditureo Greater number cause further reduction in induced drag

– Birds towards the middle gain considerable advantage

– Flanking birds gain free lift through upwash

– Reduced induced drag for birds being flanked

– Research – 70% more flight time, reduced heart rates

– Lead bird – Two flanking birds dissipate downwash

• Communication & Cooperationo Mutual cooperation – Flock Rotations

Evolved over time

Efficient flying formation thereby increasing flight time

Distribution of responsibility within flock during rotations

The “Flying V” formation

Page 5: Boids - Modeling and understanding emergent behavior

• Protection from predatorso Statistically improved survival of gene pool from attacks

o Each creature has knowledge of its local perception

o Cry signals for predator warning increases reaction time

• Improved foragingo Larger effective search patterns

• Advantages for social and mating activities

More reasons to flocking

Page 6: Boids - Modeling and understanding emergent behavior

• Formation of efficient flying ordero Reduced Energy expenditure

o Effective communication among flock

o Improved knowledge and avoidance of predator

o Improved foraging

o Increased social and mating activities

• Emergence - Complex global behavior (flocking)

arising from simple local interaction

Emergent behavior

Page 7: Boids - Modeling and understanding emergent behavior

• Do we model emergence in behavior or the

result of emergence (i.e. flocking) ?o Relatively trivial (using current technology) to create a model

that simulates flocking (boids)

o Less trivial to model emergence and tracing the path towards

flocking

• Accomplishing • the former leads us to understanding the latter

• the latter is difficult, and very specific

Modeling emergent behavior

Page 8: Boids - Modeling and understanding emergent behavior

• Basicso Separation, Alignment, Cohesion

• Slight modifications (In decreasing order of precedence)

o Collision Avoidance – avoid collision with nearby flockmates

o Velocity Matching – match velocity with nearby flockmates

o Flock Centering – stay close to nearby flockmates

• Additional modificationso Tendency towards goal, Limiting flock speed, Bounding

workspace, Perching, Obstacle avoidance, Boid neighborhood

Modeling boids

Page 9: Boids - Modeling and understanding emergent behavior

The Algorithm

flock_init_positions()

Structure b (boids)FOR EACH BOID b

b.position =25* [2*rand-1; 2*rand-1;2* rand-1];b.velocity = [0;0;0];

END

Main instance

Flock_init_positions ()LOOP

flock_draw_boids()flock_move()

END LOOP

Rule 1 : SeperationPROCEDURE rule1(boid bJ)

Vector c = 0;FOR EACH BOID b

IF b != bJ THENIF |b.position - bJ.position| < 100 THEN

c = c - (b.position - bJ.position)END IF

END IFENDRETURN c v1

END PROCEDURE

Rule 2: Velocity Matching PROCEDURE rule2(boid bJ)

Vector pvJ

FOR EACH BOID bIF b != bJ THEN

pvJ = pvJ + b.velocityEND IF

ENDpvJ = pvJ / N-1RETURN (pvJ - bJ.velocity) / 8 v2

END PROCEDURE

Rule 3: Flock centering PROCEDURE rule3(boid bJ)

Vector pcJ

FOR EACH BOID bIF b != bJ && |b.position - bj.position| < 8

THENpcJ = pcJ + b.position

END IFENDpcJ = pcJ / N-1RETURN (pcJ - bJ.position) / 100 v3

END PROCEDURE

Moving boids – flock_move()PROCEDURE

move_all_boids_to_new_positions()Vector v1, v2, v3Boid bFOR EACH BOID b

v1 = rule1(b)v2 = rule2(b)v3 = rule3(b)…..…..…..b.velocity = b.velocity + v1 + v2 + v3 + ….b.position = b.position + b.velocity

ENDEND PROCEDURE

Page 10: Boids - Modeling and understanding emergent behavior

The Algorithm (2) – Further additions

Predator interaction Same procedure as tendency towards goal, except a negative effect.

Return –v (from tend_to_goal) v6

FLOCK LEARNING Fitness functions being iteratively manipulated based on behavior needs

FOR EACH BOID bv1 = c1*rule1(b)v2 = c2*rule2(b)v3 = c3*rule3(b)…..

b.velocity = b.velocity + v1 + v2 + v3 + ….b.position = b.position + b.velocity

END

Tendency towards goal – flock_tendency()

PROCEDURE tend_to_goal(Boid b)Vector goalRETURN (goal - b.position) / 100 v4

END PROCEDURE

Limiting Speed – flock_limitvel()PROCEDURE limit_velocity(Boid b)

Integer vlimVector vIF norm(b.velocity) > vlim THEN

b.velocity = (b.velocity/|b.velocity|*vlim)END IF

END PROCEDURE

Workspace bound – flock bound()PROCEDURE bound_position(Boid b)

Integer Xmin, Xmax, Ymin……Vector vIF b.position.x < Xmin THEN

v.x = 10ELSE IF b.position.x > Xmax THEN

v.x = -10END IF…......Return v v5

END PROCEDURE

Moving boids – flock_move()PROCEDURE

move_all_boids_to_new_positions()Vector v1, v2, v3Boid bFOR EACH BOID b

v1 = rule1(b)v2 = rule2(b)v3 = rule3(b)…..…..…..b.velocity = b.velocity + v1 + v2 + v3 + ….b.position = b.position + b.velocity

ENDEND PROCEDURE

Page 11: Boids - Modeling and understanding emergent behavior

• Anti-flockingo Dispersion of flock due to predator

o Negating flock centering almost solves the problem

• Other behaviorso Negating separation – Boids run into each other

o Negating velocity matching – Boids have semi-chaotic

oscillations

• Different permutations of different behaviors with different fitness

functions not necessarily modeling flocks realistically

Other possibilities

Page 12: Boids - Modeling and understanding emergent behavior

• Trial and error and manual tweaking of

parameters using GAso Flocks can be tuned to exhibit interesting behavior

o Practical application may be limited

• Particle Swarm Optimization (PSO)o Shares evolutionary computation techniques such as GA

o Unlike GA, it has no evolution operators (crossover, mutation)

o Strategy

Initialized with random group

Closest bird to food leads the flock

Solution to the optimization is a single bird, not a group

Each bird‟s fitness is re-evaluated and optimized

Optimization

Page 13: Boids - Modeling and understanding emergent behavior

Simulation

Page 14: Boids - Modeling and understanding emergent behavior

• Modeling from the perspective of the birdo Model effects of other birds that are in its view (local)

o Model effects of aerodynamics (CFD)

o Does it support the “Flying V formation”?

• Implementing highway traffic based on

distributed behavior controlo Simple to implement

o Highly reliable

o Energy efficient

Future work

Page 15: Boids - Modeling and understanding emergent behavior

• Several models and techniques have been

developedo Some based on the behavior of flocks

o Some based on optimizing a specific task

• Similar to how we think of evolution, have

flocks „emerged‟ completely?o Flocking in groups can be beneficial, as is evident. Are we in a

transitional phase? Or will they „emerge‟ further to optimize

flocking behavior?

o Can we predict of any possible optimizations they may

possibly undertake?

My thoughts