Timeline for Incremental averaging
Current License: CC BY-SA 3.0
13 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 4, 2017 at 9:05 | comment | added | Adam Moisa | @Henry I figured it out. Thank you! | |
Jun 4, 2017 at 8:50 | comment | added | Adam Moisa | @Henry I think I'm asking for a single pass version as that's easier for me to translate into code... | |
Jun 4, 2017 at 8:45 | comment | added | Adam Moisa | @Henry Wn refers to the current sum of weights or the current weight of the item I'm up to? What is Wi? I'm trying to write this in code (js specifically) as I iterate through an array. Any further help would be very much appriciated! Here's what I have so far without weights: newMean = prevMean + ((newPrice - prevMean) / currentCount); My own weighted average function is this: weightCount += newWeight; weightSum += newPrice * newWeight; newWeightMean = weightSum / weightCount; But it seems yours would be more accurate... | |
Jun 2, 2017 at 6:55 | comment | added | Henry | @Adam: something like $ m_n = m_{n-1} + \dfrac{w_n(a_{n}-m_{n-1})}{w_n + \sum_{i=1}^{n-1} w_i}$ and instead of keeping the number of terms so far you need to keep the sum of weights so far | |
Jun 2, 2017 at 6:14 | comment | added | Adam Moisa | What would be the best way to add weight to this? | |
Sep 28, 2016 at 12:47 | comment | added | Ashok Goli | The second and the third formulae are basically the same thing. Multiply and divide as necessary and you'll get the third one. But I see how precision errors are avoided in the third case. | |
Jan 9, 2014 at 16:49 | comment | added | Henry | @castarco Suppose you have $n-k$ terms with mean $m_{n-k}$ and $k$ terms with mean $m_k$ with $0 \ll k \ll n$. Then your new combined mean would be $m_{n-k}+ \dfrac{k}{n}(m_k -m_{n-k})$. | |
Jan 9, 2014 at 16:35 | comment | added | castarco | @Henry yes, but we still have a problem. We reach that $n$, and one sample wont change the mean.. but what if we have $k$ new samples? I think the solution is to calculate the mean using a "tree" of averages of samples subsets. | |
Jan 8, 2014 at 18:57 | comment | added | castarco | What if n is so big that (using finite precision float point numbers) $$\frac{a_n - m_{n-1}}{n}$$ gives us zero? | |
Nov 18, 2013 at 19:58 | comment | added | Henry | If $n$ is large, it is likely that $(n-1)m_{n-1}$ will be much larger than $a_n$, so making the addition less precise | |
Nov 18, 2013 at 16:02 | comment | added | Paul | Can you elaborate on why precision errors are smaller in the second expression? Does the first expression contain a subtraction of nearly equal values? | |
Feb 7, 2012 at 17:26 | vote | accept | Ali | ||
Feb 7, 2012 at 16:54 | history | answered | Henry | CC BY-SA 3.0 |