Rolling average and standard deviation.....



  • I have a number of variables on a node that I would like to calculate a running average for and one or two that I would like to calculate standard deviation for.

    With limited memory on a pro mini I wonder if anyone has already done this or has any ideas on the best way to approach it?


  • Mod

    @skywatch I usually use an exponential moving average (https://en.wikipedia.org/wiki/Moving_average) as it doesn't require keeping a sliding window of the past x values.
    The idea is simple: new values are averaged over previous values with low weight.

    Eg

    avg = (avg*(weight-1) + new) / weight
    

    weight is just a factor (as would the size of your window be). Large weight causes slow response to changes. If working with integer types pick a power of 2 for the weight, so the compiler optimizes the division to a simple bitshift operation instead of a real division.



  • @Yveaux Thanks for the pointer, I will take a good look at that. What I need is something light that won't have a growing variable. I thought of using an array as the best option, but I will vertainly look at what you have found. Thank you!


Log in to reply
 

Suggested Topics

  • 4
  • 9
  • 3
  • 17
  • 9
  • 20

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts