Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Combining Exponential Moving Avg with Avg Filtering

by bliako (Monsignor)
on Mar 15, 2020 at 17:09 UTC ( [id://11114301]=note: print w/replies, xml ) Need Help??


in reply to Combining Exponential Moving Avg with Avg Filtering

I have one observation: you do not need to keep calculating the sum every time a reading is added or removed:

$mean = (1+2+3+4) / 4; $newreading = 5; $remove = 1; $newmean = $mean + ($newreading - $remove) / 4;

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11114301]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-19 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found