Placeholder Image

字幕列表 影片播放

  • - I don't know why but everyday in that tree right there

  • birds congregate together

  • and then at some point they lift off

  • and they start flying together in a flock.

  • You got all these birds,

  • that are just moving almost like they're a microorganism.

  • You've got like one individual bird

  • and it'll be leading the pack

  • and then when it turns the other ones turn.

  • It's just a fascinating thing, this flock behavior of birds.

  • Today, on Smarter Every Day I wanna talk about that.

  • It has to do with a mathematical algorithm

  • called Boids algorithm.

  • And I've got a computer scientist buddy named Ben Eater

  • who's gonna walk us through that

  • by showing us the map.

  • Oh my goodness!

  • (car engine running)

  • You can't see it on film yet 'cause of the pixel resolution

  • but there is a ton over there,

  • and they're all coming to meet right here.

  • (laughing)

  • Boom!

  • And we're off,

  • okay they're waiting about a mile down the road,

  • let's go look at 'em.

  • (car door opening)

  • We're gonna see if we can see 'em.

  • (car engine running)

  • There they are.

  • (car engine running)

  • Try to do this safely here.

  • (car engine running)

  • And we'll go to the service road just off of the interstate.

  • Oh, man!

  • (car engine running)

  • This is what I normally see every day.

  • (soft guitar music)

  • Let's just watch the birds.

  • When you're watching 'em,

  • think about it at the bird level,

  • like one individual bird,

  • and think about it from the perspective of the whole flock.

  • It's beautiful.

  • And you can see like, it's almost like fluid flowing.

  • When you can see like areas of high pressure

  • or high bird density, areas of low bird density.

  • It's beautiful, I'll quit talking now

  • let's just watch birds 'cause they're cool.

  • (upbeat music)

  • (upbeat music)

  • (upbeat music)

  • (upbeat music)

  • (upbeat music)

  • (upbeat music)

  • (upbeat music)

  • Every single bird is making decisions

  • based on a very simple set of criteria.

  • (upbeat music)

  • So I've watched the birds

  • in this specific location for years and I love it.

  • It's magical every time.

  • But I've recently learned

  • that this is an example of what's called emergent behavior.

  • The decisions of a single bird

  • when thrown in the mix

  • with the decisions of a myriad of other birds

  • creates this beautiful aerodynamic dance.

  • I didn't fully understand

  • how this works in flocking birds

  • until recently when I was at my friend

  • Ben Eater's place out in California.

  • Ben designs and builds his own computers

  • from the individual electronic components,

  • demonstrating how these simple components

  • are combined to make complex modern computers.

  • Ben Eater is an amazing programmer

  • with a YouTube channel you should definitely check out.

  • - And there is an algorithm

  • that simulates flocking behavior in birds.

  • - [Destin] Oh really?

  • - Which is called the Boids algorithm,

  • like bird, -oid object.

  • - [Destin] Okay.

  • - Or sounds like a New Yorker saying bird.

  • - [Destin] Okay.

  • - [Destin] So you're about to show---

  • - [Ben] I thought this.

  • - [Destin] What?

  • I didn't see this.

  • - [Ben] No, you don't see this before.

  • - [Destin] No.

  • - [Ben] So this is just an implementation

  • of the Boids algorithm.

  • - [Destin] Oh, okay, okay, so it's very difficult,

  • but like I'm tracking some of 'em,

  • and they are kinda gravitationally

  • pulled towards the other one.

  • Is that what I'm seeing?

  • - Yeah, so there's actually

  • three things going on here.

  • So let me show you what they are.

  • (keyboard typing)

  • - [Destin] Is this how actual birds work?

  • - Quite possibly.

  • - [Destin] Really?

  • - Yeah.

  • So they're doing a couple of things.

  • So one, let me, (keyboard typing)

  • - [Destin] Are you changing parameters on the fly?

  • - I'm gonna change the code

  • so that they don't do all the things that they're doing.

  • So we can just isolate each one.

  • - [Destin] Okay.

  • - So I can just show you what it's doing.

  • So the first thing that they do

  • is they just fly towards the center of mass.

  • - [Destin] Okay.

  • - So it's just a bunch of different things,

  • they all have a velocity

  • and it says every time period,

  • every tick, every frame, whatever.

  • - [Destin] But is drifting.

  • - And that's because they're not turning immediately.

  • And this is why I went with this algorithm,

  • there's a lot of different parameters you can tune.

  • - [Destin] Okay.

  • - So one parameter you can tune is like,

  • how quickly does it drift towards that center of mass?

  • - [Destin] Okay.

  • - And so what you'll see is

  • if we keep this running for a while,

  • that ball will just get more and more dense,

  • and they'll all just kinda collapse into one point.

  • - [Destin] Like a singularity.

  • It's like, okay, got it.

  • - They're just all attracted to each other.

  • But that will eventually collapse onto itself.

  • And so, the other, the second of the sort of three things

  • that you do in a Boids simulation like this,

  • is you tell the objects to avoid each other.

  • So instead of just coming in and eventually collapsing,

  • if they get too close to something they'll turn away from.

  • - [Destin] Because the birds would fall out of the sky.

  • - Yeah, 'cause birds don't hit each other.

  • - [Destin] Oh okay, so they're like,

  • they're attracted, but they're kind of like both electrons

  • and they repel just a little bit.

  • - Yeah, so we've got two rules right,

  • which is fly towards the center of the flock,

  • and then avoid other birds.

  • - [Destin] Okay.

  • - And that gives you this,

  • you get this sort of like jumbly clouds.

  • - [Destin] So that's only two rules.

  • - [Destin] Okay. - Yep, that's two rules

  • And you get that.

  • - [Devin] Okay.

  • - And then the third rule is

  • try to match your velocity with the other birds.

  • And velocity is speed and direction.

  • - [Devin] Okay.

  • - So this will start to get them

  • to align in the same direction.

  • So now they're gonna try to match vectors.

  • And now you sort of see - [Devin] Oh!

  • the flocking behavior.

  • - [Devin] That is so pleasant.

  • Dude!

  • - And that is essentially the Boids algorithm.

  • And then there's a few things you can do.

  • - [Devin] Wait, wait, so we're seeing three things in there.

  • - You're seeing three things going on.

  • - [Devin] So they're attracted to each other.

  • - Attracted to each other.

  • - [Devin] They're trying not to hit each other.

  • - Yep.

  • - [Devin] And they're trying to match vectors.

  • - Right.

  • - [Devin] Wow!

  • - And then you get this flocking behavior

  • that looks like birds,

  • it looks like fish, it looks like insects,

  • it's pretty cool.

  • - [Devin] Dude, it's really cool.

  • - And so you can do other things,

  • you can say instead of flying towards the center

  • of the, sort of the average position of all the birds

  • fly towards the ones that are within some radius of you,

  • which is actually a little bit more realistic

  • 'cause birds don't know where all the other birds are,

  • they just know where the ones near them are.

  • - [Devin] Right.

  • (keyboard typing)

  • - And that makes it a lot more interesting

  • because now you get these little groups that break off.

  • - [Devin] Yeah, which I see that often in nature.

  • But that's a little more broken than I'm used to.

  • So what parameter are you changing there?

  • - So I have this visual range parameter

  • so we can crank it up a little bit.

  • (keyboard typing)

  • And they'll form tighter groups,

  • maybe that was a little too much (laughs).

  • They're just flying in one group.

  • (keyboard typing)

  • There you can see.

  • - [Destin] It's starting to feel more like

  • the assembly of a murmuration.

  • What's interesting is when they pass,

  • okay, yeah, there you go,

  • it took 'em a while,

  • but they all got together. - Yeah.

  • - [Destin] That feels normal.

  • - Yeah.

  • - [Destin] That feels more real.

  • (upbeat music)

  • (upbeat music)

  • - I am in love with this.

  • It's just math.

  • That's all this is.

  • Each bird is making decisions based on math.

  • (upbeat music)

  • Pick a bird and watch it

  • and watch the decisions it makes.

  • (upbeat music)

  • As they present their bodies to you,

  • they get like really dark.

  • You see that pattern right there.

  • It's really dark.

  • But as they point towards you away from you

  • the aspect angle of their bodies is thinner

  • so they look transparent.

  • But then they'll flash in another direction

  • and they get solid looking again as a cloud.

  • There you go, see it?

  • Isn't that awesome?

  • Look at that.

  • Okay, the cool thing about living where I live is,

  • I'm up next to Wheeler National Wildlife Refuge.

  • And every year,

  • thousands of cranes come down here to winter.

  • Today, as I was driving by,

  • I noticed that there were thousands of 'em

  • and they're all flying in a flock.

  • But I noticed that the flock for these cranes

  • is very different than the small birds.

  • And I think it has to do with the fact that the shape of,

  • I'm sorry, they're flying overhead, and I get excited.

  • The reason the big birds point in one direction

  • and stay going in one direction

  • is because they're less maneuverable than the small birds.