- 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)
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)
- 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.
And that's fascinating to me.
The overall shape of the flock
is a function of the maneuverability
of what would it be the largest bird in the flock?
The least maneuverable bird in the flock?
Maybe.
Okay, here's a walking trail.
I've done this since I was a little boy.
And it goes to a hidden observatory
so that we can see these birds that have migrated here.
(shushing)
Be very quiet.
I really like little bridges here.
(footsteps)
There's a lot of people here today.
It is my understanding that that white one right there
is the endangered whooping crane.
So there's one whooping crane out here.
How do you say, do you say whooping crane?
- [Man] Yup. - [Woman] Whooping crane.
- Whooping crane?
- [Man and Woman] Yup.
- Whooping crane.
- [Woman] It depends on where you're from.
(laughing)
- It depends on where you're from?
One thing I find interesting is
as they start walking in one direction,
they all try to like walk in the same line.
And I wonder if that Boids algorithm
is kind of working on the ground as well.
Like I wonder if they are walking in the same direction
in the same type of pattern that they would fly in.
I don't know.
It's something to think about.
This episode of Smarter Every Day is sponsored by KiwiCo.
There are several different types of kits
that they send to your house.
Everything you need to assemble the kit
is included in the box.
We actually went to headquarters.
Which one did you get?
- (laughing) I got the last one.
- (laughing) This is for you.
This one's yours.
Yeah, that's for five plus.
That's the Kiwi crate.
This is a Tinker crate.
And what, did you get the pinball machine?
- Yes.
- There's a book, shows them what to do.
Everything you need is in the box.
You don't have to go to the store for anything.
If you wanna try this
you can get it by going to KiwiCo.com/smarter,
get this sent to your house and your kids are gonna love it.
KiwiCo is really good at boosting the kids confidence.
And that's part of the reasons
why I reached out to KiwiCo originally
and asked them if they would sponsor Smarter Every Day.
I like it for my kids,
and I think you'll like it for your kids.
- Dad, how do you do this?
- You can do it.
- It's hard.
- I know it's hard, but when you get done with it,
you're gonna be the one that did it.
So flip it right down in there.
- Oh, turn it over.
- There you go, yeah.
How old are you?
- Five.
(Destin laughing)
There's a ton of different grades to choose from
whether you're four or 104
there's something that you will enjoy.
So go check it out at KiwiCo.com/smarter.
Get the first one for free.
And that's like a $20 value or something like that.
It's a subscription box so it comes right to your house
and everything's included.
Go.
That's legit, man.
You're gonna dig it.
We really like it.
- Watch this.
(playful song)
- Oh wow!
- It works on everything.
- I'm gonna go in this store right here
and ask them if the birds always are here.
I have a feeling they are
but they would know since they work here.
How's it going?
- Yes, nice to see you.
We were filming the birds.
Alright so this is Andy and he puts up with the birds.
They're here all the time, right?
- Yeah.
- Every fall and winter.
- Every fall and winter?
What was your name ma'am?
- Wanda.
- Wanda?
- Mostly during winter time
and they stay for a couple months and they leave.
- In the afternoons about 4:30 till,
they're gone in the mornings.
- So do you like the birds?
- They're neat to watch but they're a big nuisance.
(Andy laughs)
- I could smell it a little bit out there.
- I think that's how they sense.
- Really?
- When you start smelling that's when they start coming in.
- What is the smell?
- Their droppings.
- Their urine and poop.
- Yeah.
- That's amazing.
Well, thanks for letting me hang out in your parking lot.
I really appreciate it.
My name is Destin.
- Okay.
- Yeah, Andy and Wanda.
Thank you so much.
Y'all be good.
Good people in Alabama,
that's Andy's RV service.
They're going to the ground now.
I think they're done.
All right, the birds are about to go to sleep, I guess.
Go to their little nest or wherever birds go.
I hope you enjoyed this episode.
Big thanks to Ben Eater for showing me how this stuff works.
It's pretty cool, how powerful a system you can create
with just a few simple rules.
If you feel like this video earned your subscription
please consider doing that maybe hit the bell.
If not, no big deal.
Thanks to the patrons that support Smarter Every Day,
I just want you to look at birds in a new way
and think about what each individual bird is doing,
and what rules dictate the movement of the entire flock.
Anyway, I hope you enjoyed this.
I'm Destin, to getting Smarter Every Day.
Have a good one.
Bye.
(upbeat music))