I Didn't know Birds use Math in Murmurations! - Smarter Every Day 234
I don't know why, but every day in that tree right there, birds congregate together. 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 macro-organism. You've got like one individual bird and it'll be leading the pack, and then when it turns, the other one's turn. It's just a fascinating thing, this flock behavior of birds. They're smarter every day.
I want to talk about that; it has to do with a mathematical algorithm called Boids algorithm. I've got a computer scientist buddy named Ben Eater who's going to walk us through that by showing us the—oh my goodness! You can't see it on film yet because of the pixel resolution, but there is a ton over there, and they're all coming to meet right here. Oh boom! And we're off. Okay, they went about a mile down the road. Let's go look at him.
We're going to see if we can see him. There they are! Try to do this safely here and we'll go to the service road just off of the interstate. Oh man, this is what I normally see every day. Let's just watch the birds. When you're watching them, 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. 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.
Every single bird is making decisions based on a very simple set of criteria. I've watched the birds in this specific location for years, and I love it. It's magical every time, but 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. There's an algorithm that simulates flocking behavior in birds.
Oh really? Which is called the Boids algorithm. Like bird-oid, object?
Okay. Um, so you're about—oh, I didn’t see this.
No, you haven't seen this before?
No, so this is just an implementation of the Boids algorithm.
Oh, okay, okay. So it's very difficult, but like I'm tracking some of them, and they are kind of 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. Is this how actual birds work?
Quite possibly, really?
Yeah. So they're doing a couple things. So one—let me—are you changing parameters on the fly?
I'm going to change the code so that they don't do all the things that they're doing so we can just isolate each one. Just show you what it's doing. So the first thing that they do is they just fly towards the center of mass.
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, but it's drifting. Just—and that's because they're not turning immediately.
Um, so there—and this is why I went with this algorithm. There are a lot of different parameters you can tune.
Okay, so one parameter you can tune is like how quickly does it drift towards that center of mass?
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 kind of collapse into one point like a singularity.
It's like, okay, they're just all attracted to each other.
Um, but that will eventually collapse onto itself. So the other—the second of the sort of three things that you do in a Boid 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 it—because the birds would fall out of the sky.
Yeah, because birds don't want to hit each other.
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 you've got two rules, right? Which is fly towards the center of the flock and then avoid other birds.
Okay, and that gives you this—you get this sort of like jumbly cloud. So that's only two rules?
Yep, that's two rules, and you get that.
Okay, um, and then the third rule is try to match your velocity with the other birds. And velocity is speed and direction.
Okay, so this will start to get them to align in the same direction. So now they're going to try to match vectors, and now you start to see the flocking behavior that is so pleasant.
Dude!
And that is essentially the Boids algorithm. And then there's a few things you can do—wait, wait! So, so we're seeing three things in there. You're seeing three things go on?
So they're attracted to each other, attracted to each other, they're trying not to hit each other, and they're trying to match vectors.
Right! Wow! And then you get this flocking behavior that looks—looks like birds, it looks like fish, it looks like insects.
It's pretty cool, dude. It's really cool.
And, 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 because birds don't know where all the other birds are; they just know where the ones near them are.
Right, um, and that makes it a lot more interesting because now you get these little groups that break off.
Yeah, which I—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 and they'll form tighter groups. Maybe that was a little too much; they just formed one group.
Here you can see 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 them a while, but they all got together.
That feels normal! That feels more real!
I am in love with this! It's just math! That's all this is! Each bird is making decisions based on math! Pick a bird and watch it and watch the decisions it makes.
[Laughter]
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 body 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? 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 them, 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 got 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, um, that's fascinating to me. The overall shape of the flock is a function of the maneuverability of—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, um, and it goes to a hidden observatory so that we can see these birds that have migrated here.
Shh, be very quiet. I really like little bridges here. There are a lot of people here today.
It’s 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 it? You say whooping crane?
Yeah, whooping crane.
Whooping crane? Whooping crane? It depends on where you're from.
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.
I'm going to go in this store right here and ask them if the birds are always here. I have a feeling they are, but they would know since they work here.
How's it going?
Yes, fine! How about you?
We were filming the birds!
All right, so this is Andy, and he puts up with the birds.
They're here all the time, right?
Yeah, every fall and winter.
And what was your name, ma'am?
Wanda.
Wanda! So mostly during the wintertime, and uh, 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.
I could smell it a little bit out there.
I think that’s how they sense!
Really? They start smelling?
And right 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. Oh, 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 nests or wherever birds go.
I hope you enjoyed this episode. Big thanks to Ben Eater for showing me how all 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. You're getting smarter every day. Have a good one!
[Music] Bye!