News for hackers. Stuff that matters.
Re:Computer Scientists Invent an Efficient New Way to Count by rcarmo on Friday May 17, 2024 @09:48AM (#40389818)
That's not streaming if you're already aware of the length of the iterable.
Re:Computer Scientists Invent an Efficient New Way to Count by axitanull on Friday May 17, 2024 @12:39PM (#40391707)
In python, you can simply substitute `A` with an iterable or generator object, which can be a of unknown length.
Re:Computer Scientists Invent an Efficient New Way to Count by rcarmo on Friday May 17, 2024 @04:12PM (#40393759)
Re:Computer Scientists Invent an Efficient New Way to Count by mattkrause on Friday May 17, 2024 @01:33PM (#40392335)
But for this algorithm, you need to know the total length ("m") to set the threshold for the register purges.

Does it still work if you update m as you go?

Re:Computer Scientists Invent an Efficient New Way to Count by cb321 on Friday May 17, 2024 @04:18PM (#40393805)
Besides the ideas from istjohn, empath-nirvana, and rcarmo, you can also just "flip the script": solve for epsilon and report that as 1-delta confidence interval for the worst case data distribution as here: https://news.ycombinator.com/item?id=40388878

Best case error is of course zero, but if you look at my output then you will see as I did that the worst case is a very conservative bound (i.e. 15X bigger than what might "tend to happen". That matters a lot for "space usage" since the error =~ 1/sqrt(space) implying you need a lot more space for lower errors. 15^2 = 225X more space. Space optimization is usually well attended for this kind of problem. And, hey, maybe you know something about the input data distribution?

So, in addition to the worst case bound, average case errors under various distributional scenarios would be very interesting. Or even better "measuring as you go" enough distributional meta data to get a tighter error bound. That latter starts to sound like it's one of Knuth's Hard Questions Which if You Solve He'll Sign your PhD Thesis territory, though. Maybe a starting point would be some kind of online entropy(distribution) estimation, perhaps inspired by https://arxiv.org/abs/2105.07408 . And sure, maybe you need to bound the error ahead of time instead of inspecting it at any point in the stream.

Re:Computer Scientists Invent an Efficient New Way to Count by istjohn on Friday May 17, 2024 @03:23PM (#40393356)
You would want to calculate the threshold by choosing your target epsilon and delta and an 'm' equal to the largest conceivable size of the stream. Fortunately, the threshold increases with log(m), so it's inexpensive to anticipate several orders of magnitude more data than necessary. If you wanted, you could work backwards to calculate the actual 'epsilon' and 'delta' values for the actual 'm' of the stream after the fact.
Re:Computer Scientists Invent an Efficient New Way to Count by empath-nirvana on Friday May 17, 2024 @02:58PM (#40393164)
You actually don't need to do that part in the algorithm. If you don't know the length of the list, you can just choose a threshold that seems reasonable and calculate the margin of error after you're done processing. (or i guess at whatever checkpoints you want if it's continuous)

In this example, they have the length of the list and choose the threshold to give them a desired margin of error.

Re:Computer Scientists Invent an Efficient New Way to Count by rcarmo on Friday May 17, 2024 @04:12PM (#40393758)