He starts by telling us that "adding is awesome" and explains why. But more interestingly, things that we don't normally think of as adding can actually be expressed in ways that are a lot like adding, so they can be awesome too. His focus is on data aggregation: generating statistics from massive amounts of data when you can't actually store all that data.
| Heart attack on a Paper Towel, flickr user yogma, CC BY 2.0 |
There are four specific properties of addition that make it awesome.
- Binary operation: a + b = c
- Associative: (a + b) + c = a + (b + c)
- Commutative: a + b = b + a
- Has an identity: 0 + a = a
It turns out that some other non-obvious operations can be expressed as commutative monoids: top N items in a set, average value, and histograms. That means you can do all sorts of awesome things when calculating those on large data sets too.
You can also get approximations for some aggregate calculations using commutative monoids: number of unique values in a set (using the HyperLogLog algorithm), set similarity (Min-Hash algorithm), set membership (Bloom filters), and frequency in a set (Count-min sketch). These algorithms don't give you the exact answer, but they may give you a good enough answer for your large data set.
Are there places where you need aggregate statistics, but an approximate value would be sufficient? I now ask myself that question, knowing that there are some algorithms out there that could give me a more efficient way to get the job done.
No comments:
Post a Comment