Probably one of my favorite things I've seen on HN in a long time. The perfect synthesis of tech explanations to biological phenomena. The way the entire page fits together to teach is just beautiful.
Why it's sitting down on the second page with just a few upvotes is beyond me.
On the subject of fireflies and emergent patterns, RadioLab did a wonderful podcast on the subject as well a few years ago: http://www.radiolab.org/story/91500-emergence/
This piece very much reminded me of that.
If you like interactive posts with lots of play, check out Bret Victor's work (if you haven't already). Good start here: http://worrydream.com/ClimateChange/
I think the example works more quickly than it should due to the line "if(ff.clock>1) ff.clock=1;" Every time the clock goes over 1, wouldn't you mod the clock value, not set it to 1 exactly?
I think that's why it works -- if you change that = to a %=, the effect no longer happens.
It does make (intuitive) sense, though, because the only time that makes a significant difference is when a lot of fireflies flash around one firefly simultaneously, in which case the firefly wouldn't decide to flash twice in a row but instead interpret it as a singular flash. And if a firefly sees another one flash when it's about to, it would naturally want to synchronize its flashing with the other.
Right- but the explanation in the 'explorable' is that the effect happens due to the simple pattern of Step 1: When you see a nearby firefly flash, nudge your clock a little bit forward, Step 2: That's it. Problem is, the description of what's happening and what is actually happening doesn't match.
Another poster here showed their own, similar demo of this. There they had each firefly charging like a capacitor. Triggering the light causes the capacitor to deplete. This seems like the better analogy, but more people know what clocks are.
In addition to being a better analogy, I am told it is possible to replicate the effect with a physical capacitor and a gas-discharge lamp: https://news.ycombinator.com/item?id=4600996
No, partly because fireflies take a certain amount of time to "charge" so jumping mid cycle might not be plausible physically.
So what this line does (which is in the section of code where a flash alters the fireflies around it) is that after advancing the other fireflies clocks, if any are over 1 then it puts them in the right state to flash on the next time they're evaluated. If you mod it, then you would have the logic:
"if I'm a firefly and see my neighbour flash while just about to flashing myself, don't flash but reset my clock to part way through the cycle"
rather than
"if I'm a firefly and see my neighbour flash while just about to flashing myself, flash as well"
Edit - setting it to one ensures that each neighbour can't keep adding to the clock, advancing it to a random point in the cycle.
If the fireflies take that time in their clocks to "charge the light", could it be that when they nudge their clock once or more in the cycle, the intensity of the light is a bit lower than it would normally be?
Interesting question. I honestly thought that the process was actually to reset the clocks not move them forwards, that's how I've simulated it in the past.
What an extremely nice interactive read. Works good on mobile. And it applies the biological lesson to human life, which is a nice way to finish a sermon. Article. Well done.
Not so much, there's no competition, so it's easier to track. I used to collect freflies in a jar as a kid. Seems like a similar idea to schools of fish, herds of antelope, etc. Stay together (even if defenseless) and predators have a hard time picking an individual to hunt.
Parable of the polygons is extremely questionable. For one, it attempts to have its cake while eating it too, by pretending it's an abstract demonstration about choices while explicitly calling out to hot topics in diversity, implying a clear causal link. For another, the model involves discrete agents on a discrete grid making decisions based on their immediate 8 square neighborhood, with no persistence or hysteresis, which does not at all match the real life domain it is attempting to model.
If you changed the grid geometry, changed the action radius, or added a more complicated decision mechanism, it is likely to result in a completely different outcome. It is more like a cellular automaton than a sociological model, compounding design choices, not agent choices.
It should probably be called Parable of the Quantization Error instead and held up as an example of an explorable explanation being misused for propaganda purposes, using its medium to present a false image of impartiality.
If you're so passionate about it, you should go implement these changes to show how the model fails. I would read that, if it were done well. It's not obvious to me that simply changing the radius or grid geometry would have the effect you claim.
Your objection is just that the model is too simple, but everyone knows linear regression predicts quite a lot, quadratic polynomials estimate physical motion very well, etc.
On the other hand, I don't think the authors make the claims about faithfully and objectively measuring reality that you say they do. You're building up a straw man there.
Its interesting to see how the simulations looks like they are modeling society, and reminds me strongly on how game of life tries to be a model of artificial life. however, if someone want it to mean more then they really need to test the model and get data on how well it can predict.
I recall a study with LA demographic data that showed the statistical distribution of LA matches the distribution output by the Schelling model. Hazy on the details though :(
FWIW, the majority of the first page of this user's comment history (6/10) are complaining about feminism in some fashion.
(I don't generally like looking at people's comment history, but one, you're absolutely spot-on that it would be easy to change the simulation - it's public domain and it's in JavaScript, this is Hacker News, if you don't know how to edit the JS console yourself there are tons of people who will gladly help if you ask, so the lack of curiosity is interesting. And two, I've seen some sort of shift in more vocal MRA-adjacent / alt-right-adjacent viewpoints on this site in recent weeks and I've been kind of curious where it's coming from.)
Anyway, in the hope of not dragging this too far off-topic: 'tnone, do you have a specific change you'd like to see implemented in the simulation? I'd be happy to implement the change and rehost it and see what happens. I think there are genuine criticisms to be made (for instance, https://github.com/ncase/polygons/issues/9 sounds worth some investigation, despite the phrasing of the comment thread). But given how easy it is to apply actual data to these questions, I think we should do that to avoid FUD.
In particular, how about changing the radius to be the surrounding 24 squares (two steps out, instead of one), or making it less likely that an individual polygon will move again shortly after it has moved?
Since I wrote that comment I feel the itch to do it myself :) He said topology, but I don't think he meant what I'm thinking of: a torus! A Mobius band! The projective plane! My curiosity is getting the better of me.
Apologies for what might be shameless self-promotion, but if you're interested in this idea, you might like my 2012 project , "The Kuramoto Model (1,000 Fireflies)." I built 1,000 microcontroller-based LED devices that synchronized with each other using radio communication, with a similar algorithm to what Nicky used. Link is here:
http://davidrueter.com/projects/2012-the-kuramoto-model.html
Hmm, my city gives away bike lights pretty frequently - they aren't as sophisticated (sadly) but it doesn't seem especially wasteful either way (at least I'd assume that a fair percentage of the riders using them would have bought some kind of light otherwise; and as long as they continue to work, I wouldn't expect them to end up in a landfill). The synchronization is especially fun.
Fascinating! I can see how synchronization across distributed systems would cause problems -- lots of requests against the same type of resource at the same time, for example, resulting in a thundering herd (https://en.wikipedia.org/wiki/Thundering_herd_problem) -- but also how it could be absolutely what you want (like if you want to synchronize clocks across systems, which I guess is exactly what's going on in the OP https://en.wikipedia.org/wiki/Clock_synchronization).
After the point when the whole swarm is synchronised there seems to be no further nudging, does this make sense? Am I missing something? Very interesting, just not sure I understand.
> But whenever you shine, you inspire those close to you to shine too, a little bit sooner than they otherwise would have. And those close to you, in turn, inspire those close to them.
This is adaptation to input disruption on a network of brain impulses. Fascinating that so much correlates with our own perception and technologies.
Really great interactive post both informative and engaging.
In real fireflies, the individual clocks have slightly different frequencies. The inverse of the protocol is no protocol: stop syncing and let the blinks slowly fall back into chaos.
My only hang-up with the explanation/simulation is, why do the fireflies all have clocks that run at the same duration as one another?
I understand advancing your clock to synchronize flashes, but doesn't this presuppose that the clocks run at the same speed?
When I turned on "Show Clocks" in the simulation it indeed looked like the clocks ran at identical durations. Seems like this would be difficult in nature.
This is difficult to explain succinctly, but biochemical processes can set up periodic events with a fair amount of accuracy. For instance, your heart beats roughly once a second when in a resting state.
Some of these processes use physical latency to time the events: if the fireflies were roughly of the same maturity, they would be of similar size and thus have clocks of similar duration.
Same here. I'm glad I scrolled down and resized my screen. I didn't notice it my first viewing actually. I only noticed it when I called my wife down to check it out later.
1. When you see a nearby neighbour flash, nudge your own clock forward.
2. That's it.
My question is -- when the fireflies are firing at the same time, they see each other flash, so they all nudge their clocks forward, correct?
Assuming they don't nudge their clocks forward at the same amount, they would fall out of sync, correct? But they stay in sync, so they must nudge forward at the same amount...is this right?
So my question is -- if everyone keeps nudging their clocks forward, why don't they keep speeding up? They do appear instead to continue flashing at the same steady rate.
Does this mean that there ought to be another detail in the rule, such as,
If you see a neighbour nearby flash, when you are not flashing, nudge your clock forward by a bit.
? Or is the perspective I just said missing something?
I think the rule is not very precise written down (e.g. I do not believe that a firefly nudges its clock multiple times within one cycle, just because it has multiple neighbors).
Exactly. For anyone having trouble, just picture a pure sinusoidal signal, flash = sin(2π·freq·time + phase). Fireflies are changing their phase, not their frequency. Completely independent parameters.
No. The fireflies are able to adjust both their frequencies and phase differences. If their frequencies are matched they are phase-locked. If their phase difference is 0, then they are also synchronized.
> If you see a neighbour nearby flash, when you are not flashing, nudge your clock forward by a bit.
I think this is it. There could be some missing detail (e.g. a firefly is unable to "see" when it flashes) which keeps them from nudging their clocks once already in sync
This reminds me of collision detection algorithms for wireless antennae. You can't 'hear' when you're transmitting, since your own signal drowns out anything you might receive (for simple antenna arrays) - I imagine the same is true for fireflies.
"Speeding up" would only happen when you turn nudging on, it wouldn't continuously keep getting faster.
But the algorithm described by the author has a bigger problem: It wouldn't actually sync the fireflies!
If EVERYONE nudged their clocks forward, then an out-of-sync firefly would be nudged the same as an in-sync firefly, and synchronization wouldn't increase over time!
Your rule avoids this problem:
> If you see a neighbour nearby flash, when you are not flashing, nudge your clock forward by a bit.
If you look in "show clocks" mode, it looks like this is exactly what is implemented.
At least in the Kuramoto model, it's a little more complicated than the OP makes it sound (but not much). Step 1 is more like "if you see a flash, bump your clock closer to midnight."
Specifically, an ODE is given for firefly $i$'s phase angle $
\theta_i$
$$\dot\theta_i = \omega_i + K / N \sum_{j=1}^N \sin(\theta_j - \theta_i)$$
This gets interesting because the flies natural frequencies $\omega_i$ are also assumed to be randomly distributed. So you don't get perfect phase-synchronization--flies with fast natural frequencies lead the pack as it loops around the phase ring, and flies with slow natural frequencies are dragged along at the back. Relative to the mean phase, your excess phase approaches a smooth increasing function of your natural frequency. But, for high enough values of $K$, you do get frequency-synchronization--everyone oscillates at the average frequency.
(For low values of $K$, or too-large natural frequencies, "rogue oscillators" emerge in a SNIPER bifurcation. They zoom around the phase ring at a different frequency, briefly slowing as they pass through the cloud of synchronized oscillators. Also applies for too-slow rogues.)
In the video and the OP's simulation, it looked the natural frequencies were all pretty similar, if not the same. However, there was a second addition that is not in the original Kuramoto model (but is in most subsequent models): rather than observing all other flies, only observe nearest neighbors. This can be added by putting a symmetric boolean adjacency matrix $A_{i,j}$ right before the $\sin$ in the previous equation.
This has the effect of making excess phase a smooth function of not only the natural frequency, but also some structural feature imposed by the network. In random networks like Erdos-Renyi, this feature is the node degree, but in the video it looks like it might be the long axis of the bush (so, like, one of the eigenvectors of the graph Laplacian).
(In general, coupled oscillators, such as circadian gene clocks, show this smooth dependence of excess phase on per-unit heterogeneities, which is the topic for the first half of my PhD dissertation. The second half is figuring out what the heterogeneities are when you only have recordings of the dynamics to go by.)
If anyone is interested in this synchronization process or how it relates to synchronization in general, I highly recommend 'Sync' by Steven Strogatz. It's one of the best popular science/math books I've ever read, and Strogatz is a mathematician at the heart of the research, and a great writer as well, so you really get the story from someone who is a world expert, rather than an interested journalist.
92 comments
[ 3.2 ms ] story [ 81.9 ms ] threadWhy it's sitting down on the second page with just a few upvotes is beyond me.
On the subject of fireflies and emergent patterns, RadioLab did a wonderful podcast on the subject as well a few years ago: http://www.radiolab.org/story/91500-emergence/ This piece very much reminded me of that.
Playable posts are amazing. Interactivity in texts is amazing.
<3
Disclaimer: not sure if memory serves me right though O:)
It does make (intuitive) sense, though, because the only time that makes a significant difference is when a lot of fireflies flash around one firefly simultaneously, in which case the firefly wouldn't decide to flash twice in a row but instead interpret it as a singular flash. And if a firefly sees another one flash when it's about to, it would naturally want to synchronize its flashing with the other.
So what this line does (which is in the section of code where a flash alters the fireflies around it) is that after advancing the other fireflies clocks, if any are over 1 then it puts them in the right state to flash on the next time they're evaluated. If you mod it, then you would have the logic:
"if I'm a firefly and see my neighbour flash while just about to flashing myself, don't flash but reset my clock to part way through the cycle"
rather than
"if I'm a firefly and see my neighbour flash while just about to flashing myself, flash as well"
Edit - setting it to one ensures that each neighbour can't keep adding to the clock, advancing it to a random point in the cycle.
[0] https://ccl.northwestern.edu/netlogo/models/Fireflies [1] http://ccl.northwestern.edu/netlogo/index.shtml
Did they ever figure out why Thailand fireflies do this, instead of just how?
If you changed the grid geometry, changed the action radius, or added a more complicated decision mechanism, it is likely to result in a completely different outcome. It is more like a cellular automaton than a sociological model, compounding design choices, not agent choices.
It should probably be called Parable of the Quantization Error instead and held up as an example of an explorable explanation being misused for propaganda purposes, using its medium to present a false image of impartiality.
Your objection is just that the model is too simple, but everyone knows linear regression predicts quite a lot, quadratic polynomials estimate physical motion very well, etc.
On the other hand, I don't think the authors make the claims about faithfully and objectively measuring reality that you say they do. You're building up a straw man there.
(I don't generally like looking at people's comment history, but one, you're absolutely spot-on that it would be easy to change the simulation - it's public domain and it's in JavaScript, this is Hacker News, if you don't know how to edit the JS console yourself there are tons of people who will gladly help if you ask, so the lack of curiosity is interesting. And two, I've seen some sort of shift in more vocal MRA-adjacent / alt-right-adjacent viewpoints on this site in recent weeks and I've been kind of curious where it's coming from.)
Anyway, in the hope of not dragging this too far off-topic: 'tnone, do you have a specific change you'd like to see implemented in the simulation? I'd be happy to implement the change and rehost it and see what happens. I think there are genuine criticisms to be made (for instance, https://github.com/ncase/polygons/issues/9 sounds worth some investigation, despite the phrasing of the comment thread). But given how easy it is to apply actual data to these questions, I think we should do that to avoid FUD.
In particular, how about changing the radius to be the surrounding 24 squares (two steps out, instead of one), or making it less likely that an individual polygon will move again shortly after it has moved?
http://ee.lbl.gov/papers/sync_94.pdf
This is adaptation to input disruption on a network of brain impulses. Fascinating that so much correlates with our own perception and technologies.
Really great interactive post both informative and engaging.
https://www.michaelfogleman.com/static/fireflies/
I saw your comment: "The cells need not have identical individual frequencies to reach sychronization."
This seems counter-intuitive to me.
https://en.m.wikipedia.org/wiki/Phase-locked_loop
I understand advancing your clock to synchronize flashes, but doesn't this presuppose that the clocks run at the same speed?
When I turned on "Show Clocks" in the simulation it indeed looked like the clocks ran at identical durations. Seems like this would be difficult in nature.
Some of these processes use physical latency to time the events: if the fireflies were roughly of the same maturity, they would be of similar size and thus have clocks of similar duration.
I have a question about a detail.
The rule is:
1. When you see a nearby neighbour flash, nudge your own clock forward.
2. That's it.
My question is -- when the fireflies are firing at the same time, they see each other flash, so they all nudge their clocks forward, correct?
Assuming they don't nudge their clocks forward at the same amount, they would fall out of sync, correct? But they stay in sync, so they must nudge forward at the same amount...is this right?
So my question is -- if everyone keeps nudging their clocks forward, why don't they keep speeding up? They do appear instead to continue flashing at the same steady rate.
Does this mean that there ought to be another detail in the rule, such as,
If you see a neighbour nearby flash, when you are not flashing, nudge your clock forward by a bit.
? Or is the perspective I just said missing something?
From: https://www.math.hmc.edu/~dyong/math164/2006/runyeon/finalre...
I think this is it. There could be some missing detail (e.g. a firefly is unable to "see" when it flashes) which keeps them from nudging their clocks once already in sync
Does it matter if they "nudge their clocks once already in sync" ? If they all do that, they'll stay in sync, with a slightly higher frequency.
But the algorithm described by the author has a bigger problem: It wouldn't actually sync the fireflies!
If EVERYONE nudged their clocks forward, then an out-of-sync firefly would be nudged the same as an in-sync firefly, and synchronization wouldn't increase over time!
Your rule avoids this problem:
> If you see a neighbour nearby flash, when you are not flashing, nudge your clock forward by a bit.
If you look in "show clocks" mode, it looks like this is exactly what is implemented.
Specifically, an ODE is given for firefly $i$'s phase angle $ \theta_i$
$$\dot\theta_i = \omega_i + K / N \sum_{j=1}^N \sin(\theta_j - \theta_i)$$
This gets interesting because the flies natural frequencies $\omega_i$ are also assumed to be randomly distributed. So you don't get perfect phase-synchronization--flies with fast natural frequencies lead the pack as it loops around the phase ring, and flies with slow natural frequencies are dragged along at the back. Relative to the mean phase, your excess phase approaches a smooth increasing function of your natural frequency. But, for high enough values of $K$, you do get frequency-synchronization--everyone oscillates at the average frequency.
(For low values of $K$, or too-large natural frequencies, "rogue oscillators" emerge in a SNIPER bifurcation. They zoom around the phase ring at a different frequency, briefly slowing as they pass through the cloud of synchronized oscillators. Also applies for too-slow rogues.)
In the video and the OP's simulation, it looked the natural frequencies were all pretty similar, if not the same. However, there was a second addition that is not in the original Kuramoto model (but is in most subsequent models): rather than observing all other flies, only observe nearest neighbors. This can be added by putting a symmetric boolean adjacency matrix $A_{i,j}$ right before the $\sin$ in the previous equation.
This has the effect of making excess phase a smooth function of not only the natural frequency, but also some structural feature imposed by the network. In random networks like Erdos-Renyi, this feature is the node degree, but in the video it looks like it might be the long axis of the bush (so, like, one of the eigenvectors of the graph Laplacian).
(In general, coupled oscillators, such as circadian gene clocks, show this smooth dependence of excess phase on per-unit heterogeneities, which is the topic for the first half of my PhD dissertation. The second half is figuring out what the heterogeneities are when you only have recordings of the dynamics to go by.)
What's the quickest way to preview that (without needing a hosted service)?
I just made this small LaTeX document (I'm amazed I knew this by heart, I typed this manually maybe thrice in my life):
but that's still quite a bit of extra work just to view it. Do you know a better way to do it?http://www.HostMath.com/Show.aspx?Code=%5Cdot%5Ctheta_i%20%3...
http://www.sciencedirect.com/science/article/pii/S0378437116...