Hacker News new | past | comments | ask | show | jobs | submit login

Hm, I really need to study this more. The early claim that it requires "complicated float arithmetic" took me by surprise. I'm used to fixed-time-period sampling, so you can just do:

   // Textbook version:
   //average = alpha * new_value + (1-alpha)*average
   // Which is equivalent to:
   //average += (new_value - average)*alpha
   // To get rid of the float, define w=1/alpha  and make it an integer.
   // If w is a power of 2 (try 8), this is just a shift.
   average += (new_value - average) / w



Absolutely. You just need integer implementation of fixed point for evenly spaced data.

For irregularly spaced data, you need exp(-t), but that isn't hard to do with fixed point.


Yeah, it’s easy when alpha is fixed. The complications — the exp() and ln() — come from updating the smoothed rate at varying intervals, whenever a request happens to arrive, so alpha has to be adjusted according to the interval to make sure the exponential decay happens at a fixed speed regardless of the interval.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: