Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Seriously guys, don't write:

  a = lerp(a, B, 1.0 - exp(-delta * RATE2))
Write:

  a = lerp(a, B, -expm1(-delta * RATE2))
This is precisely the situation where you really want to use expm1: https://www.johndcook.com/blog/cpp_expm1/

And (as pointed in the above) if you're worried about the slowness of it, just Taylor expand it to x+x²/2.

Finally, unless division is too costly, do:

  a = lerp(a, B, -expm1(delta / -T))
Where T is the “time constant” (which you can intuitively express in time units, like seconds): https://en.wikipedia.org/wiki/Exponential_smoothing#Time_con...

It's not the half-life (sorry) but it's still a lot more intuitive as a parameter.



That's some very good recommendations you made here. I'm adding all 3 at the end, thank you.




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

Search: