Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

58
Group Behaviors Group Behaviors and Artificial and Artificial Life Life Claire O’Shea Claire O’Shea COMP 259 – Spring 2005 COMP 259 – Spring 2005

Transcript of Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

Page 1: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

Group Behaviors Group Behaviors and Artificial Lifeand Artificial Life

Claire O’SheaClaire O’Shea

COMP 259 – Spring 2005COMP 259 – Spring 2005

Page 2: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

OverviewOverview

Motivation “Flocks, Herds, and Schools” “Artificial Fishes” “Cognitive Modeling” “Constrained Animation of Flocks” Summary

Page 3: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

MotivationMotivation

Many animations require natural-looking behavior from a large number of characters Flock of birds School of fish Crowd of people

Page 4: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

MotivationMotivation

How do we generate this motion? Keyframe every character

This is very labor-intensive, usually ends up looking unrealistic

OR... Let each character generate its own

motion! Much easier, and produces natural,

unscripted motion

Page 5: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

MotivationMotivation

Questions about this method How do we write rules to define natural

behavior? Can self-directed characters do anything

“intelligent”? How can we give the animator some

control over the scene?

We’ll find out in the papers…

Page 6: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Flocks, Herds, and Flocks, Herds, and Schools: A Distributed Schools: A Distributed

Behavioral Model”Behavioral Model”

Craig W. Reynolds, 1987Craig W. Reynolds, 1987

Page 7: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Flocks, Herds, and Flocks, Herds, and Schools”Schools”

“A flock is simply the result of the interaction between the behaviors of individual birds.”

Model a flock of “boids” (bird-oids) as a particle system Each particle has an orientation Behavior of one particle depends on

other particles

Page 8: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Flocks, Herds, and Flocks, Herds, and Schools”Schools”

Modeling boid flight The boid itself can move only in one direction

(“forward” along its local positive z-axis) The boid steers by rotating about its local x

and y axes The boid’s local coordinate system can move

and rotate freely within world coordinates

Page 9: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Flocks, Herds, and Flocks, Herds, and Schools”Schools”

Modeling boid flight Banking turns

The y-axis is always aligned with the direction of acceleration

During straight flight, this is gravity During a turn, radial forces cause the bird to “bank”

(rotate around its z-axis)

Page 10: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Flocks, Herds, and Flocks, Herds, and Schools”Schools”

Modeling boid flight Gravity is used only to help define

banking angle; it is not actually applied as a force

Upper bounds are set on speed and acceleration

Other forces (buoyancy, drag) are not modeled

Page 11: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Flocks, Herds, and Flocks, Herds, and Schools”Schools”

Modeling flocking behavior Three basic rules, each of which generates an

acceleration request

1. Collision Avoidance Avoid running into other boids or static

obstacles2. Velocity Matching

Match velocity with nearby flockmates3. Flock Centering

Stay close to nearby flockmates

Page 12: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Flocks, Herds, and Flocks, Herds, and Schools”Schools”

Combining acceleration requests Weighted average

Fails in certain critical situations (ex. imminent collisions)

Prioritized allocation Acceleration requests are accepted in

priority order, until the maximum acceleration is reached

Works well (at least for this simple system)

Page 13: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Flocks, Herds, and Flocks, Herds, and Schools”Schools”

Simulated Perception All the behavior rules depend only on

nearby objects An individual boid is only aware of other

boids which lie in a spherical region around it

Sensitivity falls off as the inverse square of the distance

Page 14: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

Demo: A flock of Demo: A flock of boidsboids

Page 15: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Artificial Fishes: Physics, Artificial Fishes: Physics, Locomotion, Perception, Locomotion, Perception,

Behavior”Behavior”

Xiaoyuan Tu and Demetri Xiaoyuan Tu and Demetri Terzopoulos, 1994Terzopoulos, 1994

Page 16: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Artificial Fishes”Artificial Fishes”

Simulate a fish using a “holistic model” Physical form Movement Perception Behavior

Page 17: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Artificial Fishes”Artificial Fishes” Fish Physics

Spring-mass model 23 point masses, 91 springs

External springs are “muscles” Fish moves by changing the rest length of these springs!

Page 18: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Artificial Fishes”Artificial Fishes” Fish Movement: Swimming

Fish swings its tail back and forth by alternately contracting and relaxing the muscles on each side

Displacement of water produces a reaction force normal to the fish’s body (Fi

w)

{r1, s2, r2, s2} – amplitude and frequency of muscle contractions

Control amount of force, and thus swimming speed

Optimal values found experimentally

A reaction force (Fiw) is applied

at point ni and acts along theinward normal. It propels thefish both sideways and forward.

Page 19: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Artificial Fishes”Artificial Fishes”

Fish Movement: Turning Fish quickly contracts the muscles on one

side while relaxing them on the other {r0, s0, r1, s1} – contraction amplitude and

frequency of the turning muscles Experimentally determined for turns of 30,

45, 60, and 90 degrees Arbitrary turns are generated by interpolating

these parameters

Page 20: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Artificial Fishes”Artificial Fishes”

More Fish Movement Pitch and yaw are controlled by the pectoral fins Force applied on the fins:

Raising or lowering the leading edge of the fin makes the fish swim up or down

Setting the two fins at different angles causes fish to roll

Setting fins perpendicular to body decreases forward speed

γ)nΑ(||v||v)nΑ(nFf cos

surface areafish’s velocity

angle of finto body

fin’s normalvector

Page 21: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Artificial Fishes”Artificial Fishes”

Fish Perception Simplified simulation of vision Fish can see things that are within its

viewing volume (a 300 degree solid angle around its head) and not occluded

Radius of viewing volume determined by translucency of the water

Page 22: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Artificial Fishes”Artificial Fishes”

Fish Behavior Fish behavior is influenced by several

factors Individual habits (preset by animator) Mental state (functions evaluated at each

timestep) Perceived environment

Intention generator picks an intention based on these factors.

Page 23: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Artificial Fishes”Artificial Fishes”

Fish Behavior Mental state

Hunger:

Libido:

Fear:

]1,/)()(1min[)( He tRtntH

amount eaten

digestion rate time since last meal appetite

]1)),(1)((min[)( tHtstL L

libido function

time since last mating

]1,min[)( i

iFtF ]1),(/min[ 0 tdDF ii

fear of predator idistance topredator i

Page 24: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Artificial Fishes”Artificial Fishes”

Intention Generator Decides on a behavior based on

mental state and priority ordering:

1. Check for imminent collisions2. Check for nearby predators (calculate F(t))3. Evaluate hunger and libido (H(t) and L(t))4. Evaluate happiness with the ambient

conditions

Page 25: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Artificial Fishes”Artificial Fishes”A complete fish model:

Page 26: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Artificial Fishes”Artificial Fishes” Different types of fish can be created just by

changing the intention generator!

Predator: Prey:

Page 27: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

Demo: Foraging FishDemo: Foraging Fish

Page 28: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Cognitive Modeling: Cognitive Modeling: Knowledge, Reasoning and Knowledge, Reasoning and

Planning for Intelligent Planning for Intelligent Characters”Characters”

John Funge, Xiaoyuan Tu, and John Funge, Xiaoyuan Tu, and Demetri Terzopoulos, 1999Demetri Terzopoulos, 1999

Page 29: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Cognitive Modeling”Cognitive Modeling” Builds on the idea of

a holistic character model, but adds another layer: cognitive modeling Character can learn

about its environment Character can plan

ahead to achieve goals

Page 30: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

Some AI background: situation calculus Situation: a description of the state of the world

at a given time Fluent: a property of the world that can change

over time Primitive action: function that translates from

one situation to another situation Precondition axiom: a statement about the state

of the world before the primitive action Effect axiom: a statement about the state of the

world after the primitive action

““Cognitive Modeling”Cognitive Modeling”

Page 31: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Cognitive Modeling”Cognitive Modeling”

Situation calculus examples:(These examples are in CML, a language developed for this paper)

Fluent:Broken(x, s)

Precondition axiom:action drop(x) possible when Holding(x)

Effect axiom:occurrence drop(x) results in Broken(x)

Whether x is brokenin situation s

A primitive action

Page 32: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Cognitive Modeling”Cognitive Modeling”

Domain knowledge specification Character should not have perfect knowledge

of the world; this is unrealistic and uninteresting.

A better model: character makes plans based on limited information, “knows” when it needs more information

Need a way to express uncertainty about aspects of the world!

Page 33: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Cognitive Modeling”Cognitive Modeling” Interval-valued Epistemic Fluents

The usual way to represent uncertainty in AI is with epistemic κ-fluents, but these are difficult to implement.

An alternative is to use interval arithmetic! For each sensory fluent f, introduce an interval-

valued epistemic fluent If. The width of the IVE fluent expresses

uncertainty about the value of f.

Page 34: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Cognitive Modeling”Cognitive Modeling” Interval-valued Epistemic Fluents: Example

speed(x, s): the speed of object x in situation s

Ispeed(s): what the character “thinks” the speed of x is in situation s

Suppose we know the speed at s0:

speed(x, s0) = 20

Ispeed(s0) = <20, 20>

As time goes on, we are less certain about the value! speed(x, s1) = 25

Ispeed(s1) = <10, 30>

Page 35: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Cognitive Modeling”Cognitive Modeling”

Character direction A character can “plan” by finding a sequence

of primitive actions that accomplish a goal Equivalent to searching a tree

Complexity: exponential in the length of the plan! Animator can “prune” the search space by

specifying complex actions (sequences of primitive actions)

Results in nondeterministic behavior; the same goal can be accomplished in many different ways!

Page 36: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Cognitive Modeling”Cognitive Modeling” Creating an animation with “smart”

characters Still need all the lower-level modules (physics,

perception, behavior, etc) Add a reasoning engine to choose a low-level behavior!

Page 37: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Cognitive Modeling”Cognitive Modeling”

Example: Prehistoric world A T-Rex wants to chase raptors out of its

territory It knows that they will run away when it

approaches, so it “herds” them out

Page 38: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Cognitive Modeling”Cognitive Modeling” Example: Undersea world

A merman tries to escape from a shark The merman hides behind obstacles, so that

the shark can’t see him

Page 39: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Matt Anderson, Eric McDaniel, Matt Anderson, Eric McDaniel, and Stephen Chenney, 2003and Stephen Chenney, 2003

Page 40: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

The papers we have looked at so far focus on creating animations with minimal input from the animator

But in real applications, the animator usually wants to specify what happens in the scene!

Page 41: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Two-step model for constrained animation Produce a trajectory that satisfies the

constraints Evaluate plausibility and refine the

trajectory

Page 42: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Constraints Point constraints: a character must be at a point

at a certain time Center-of-mass constraints: the center of mass of

some group must be at a point at a certain time Shape constraints: a group must lie inside a

polygonal shape Except for point constraints, these are not

guaranteed to be satisfied – only approximated.

Page 43: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Behavior model Based on Reynolds’ model Each character gets a randomly sampled wander

impulse at each timestep. The wander contribution added to the character is a

combination of this wander impulse and the normalized wander contribution from the previous timestep.

ŵci-1: previous wander contribution(normalized)

wii: current wander impulse

wci: total wander contribution forthis timestep

Page 44: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Finding initial trajectories Find configurations that satisfy all the

constraints, then interpolate trajectories in the “windows” between them

Possible methods (some or all of these may be used):

Forward simulation Path transformation Backward simulation

Page 45: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Finding initial trajectories Forward simulation

Used when initial conditions are given for a window

Position characters to meet initial conditions, then run an unconstrained simulation using the behavior model

Page 46: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Finding Initial Trajectories Path Transformation

Used when the window is part of a sequence of point or COM constraints

Fit a B-spline curve through the sequence of points

Run a forward simulation, and at each timestep, move the character onto the curve

Page 47: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Finding Initial Trajectories Backward Simulation

Used when end constraints are given for the window

Position characters to meet end constraints, then run the simulation backwards (just reverse the birds’ perception)

Blend the resulting trajectory (xbackward) with the forward simulation (xforward) using a weighting function:

backwardforward uxxux )1( )32( 23 ttu

Page 48: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Evaluating plausibility of an animation Determine whether the wander impulses are

plausibly distributed (gw) Determine how well the animation satisfies

the COM and shape constraints (gc, gs) Bias the animation toward producing a

single flock (gf) The overall plausibility function:

t

fscw tAgtAgtAgtAgAg ),(),(),(),()(

Page 49: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Evaluating the wander impulses From the given trajectories, we can deduce the

wander impulse of each character at each timestep gw evaluates whether the wander impulses look

like they were sampled from the right distribution In this model, the wander impulses had uniformly

random direction and normally distributed length, so we evaluate how well the lengths |wii| fit a normal distribution:

i

tAwi

w

wwietAg

22/)||,(||

2

1),(

Page 50: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Evaluating constraint enforcement Center of mass constraints:

COM(A, t) is the center of mass of the group at time t Cx is the center of mass defined in the constraint

Shape constraints: cs is a user-defined constant dist(S, A, t) calculates the sum-of-squares distance of

each character from the shape

C

CtACOM

com

ccomxetAg

22/||),(||

2

1),(

S

tASdistcs

SetAg ),,(),(

Page 51: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Generating a better animation If the current animation fails the plausibility

test, the system generates a new one using one of the following strategies:

Completely re-generate some or all of the trajectories

Add random “bumps” to a trajectory Change the character’s velocity along a

trajectory Only point constraints are enforced during

this phase

Page 52: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

““Constrained Animation of Constrained Animation of Flocks”Flocks”

Repeat the sampling process for a given number of iterations, or until a plausible animation is found.

This animation was generated in 1000 iterations (about two hours)

Page 53: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

Demo: Constrained FlockingDemo: Constrained Flocking

Page 54: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

SummarySummary

“Flocks, Herds, and Schools” Simulates “boid” physics, perception,

and behavior Fairly unrealistic physics – no attempt to

actually model flight Fast and simple to implement, scales

well to large numbers of characters No real control possible from animator

Page 55: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

SummarySummary

“Artificial Fishes” Simulates fish physics, perception,

behavior, and intentions Realistic physics is used for movement

(though not always for rendering) Intention generator enables fish to

engage in complex behaviors No animator control possible, except in

choosing initial values

Page 56: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

SummarySummary

“Cognitive Modeling” Adds another layer of character

simulation (cognitive model) IVE fluents create a realistic model of

character’s domain knowledge Tree searching lets character “plan

ahead” to accomplish a goal Animator can help control scene by

scripting a series of actions

Page 57: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

SummarySummary

“Constrained Animation of Flocks” Introduces random variation into the

trajectories using a wander impulse Allows animator to specify constraints on

movement Not real-time: requires an iterative

refining process Produces “plausible enough” trajectories,

not always completely realistic ones

Page 58: Group Behaviors and Artificial Life Claire O’Shea COMP 259 – Spring 2005.

SummarySummary

AI methods can generate complex animation of multiple characters without low-level control from the animator

Behavior rules can be combined with a physically-based model to create realistic scenes

Problems: Difficult to implement user-specified constraints Complexity issue: hard to generate scenes with

many characters in real time