good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Combining Exponential Moving Avg with Avg Filteringby bliako (Monsignor) |
on Mar 15, 2020 at 17:09 UTC ( [id://11114301]=note: print w/replies, xml ) | Need Help?? |
I have one observation: you do not need to keep calculating the sum every time a reading is added or removed:
In this way you can have subs add_reading() and remove_reading() which also recalculate the mean without worrying about redandant summations. Secondly, since you are dealing with infinite data, perhaps you can benefit from B.P.Welford's method of "running statistics". This is a simple method to keep a mean and lots of other descriptive statistics (e.g. standard deviation) without ever storing any readings at all! Ingenious yet simple. And you are lucky because last time I looked CPAN had 3 such modules Statistics::Welford, Statistics::Running and Statistics::Running::Tiny (disclaimer last 2 modules by myself). If you want that in C (via C++) have a look at John Cook's blog You may find this approach useful especially if you will need higher-order statistics like standard deviation etc. because you will find that the moving average is not good enough for detecting outliers and you need to add more flexibility to your model. 1 minute EDIT: however, if your running mean varies during the day or the seasons, then keeping a "running" mean since the beginning of time is not right! In which case a model with more input parameters (like time of day) can assess whether a reading is an outlier (over this very recent time). If that's the case, at least you have the first observation, you don't need to re-do the sums for a moving average.
In Section
Seekers of Perl Wisdom
|
|