From: Peter Zijlstra <peterz@infradead.org>
To: Bruno Randolf <br1@einfach.org>
Cc: randy.dunlap@oracle.com, akpm@linux-foundation.org,
kevin.granade@gmail.com, Lars_Ericsson@telia.com,
blp@cs.stanford.edu, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] Add generic exponentially weighted moving average (EWMA) function
Date: Thu, 21 Oct 2010 12:04:35 +0200 [thread overview]
Message-ID: <1287655475.3488.99.camel@twins> (raw)
In-Reply-To: <201010211440.24936.br1@einfach.org>
On Thu, 2010-10-21 at 14:40 +0900, Bruno Randolf wrote:
> On Thu October 21 2010 00:03:43 Peter Zijlstra wrote:
> > On Wed, 2010-10-20 at 17:23 +0900, Bruno Randolf wrote:
> > > +/**
> > > + * ewma_add() - Exponentially weighted moving average (EWMA)
> > > + * @avg: Average structure
> > > + * @val: Current value
> > > + *
> > > + * Add a sample to the average.
> > > + */
> > > +struct ewma*
> > > +ewma_add(struct ewma *avg, const unsigned int val)
> > > +{
> > > + avg->internal = avg->internal ?
> > > + (((avg->internal * (avg->weight - 1)) +
> > > + (val * avg->factor)) / avg->weight) :
> > > + (val * avg->factor);
> > > + return avg;
> > > +}
> > > +EXPORT_SYMBOL(ewma_add);
> >
> > How can it be a weighted avg if each sample has the same weight?
>
> by applying the weight again and again, we get an exponential weighting.
>
> http://en.wikipedia.org/wiki/Exponentially_weighted_moving_average
Ah, thanks. It might be worth adding some of that explanation to the
actual comment.
I think the naming is somewhat unfortunate since a weighted average
makes me think of:
\Sum w_i * v_i
wa = ---------------
\Sum w_i
Instead of the described algorithm.
next prev parent reply other threads:[~2010-10-21 10:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-20 8:23 [PATCH v3] Add generic exponentially weighted moving average (EWMA) function Bruno Randolf
2010-10-20 15:03 ` Peter Zijlstra
2010-10-21 5:40 ` Bruno Randolf
2010-10-21 10:04 ` Peter Zijlstra [this message]
2010-10-21 10:31 ` KOSAKI Motohiro
2010-10-22 0:53 ` Bruno Randolf
2010-10-22 1:11 ` KOSAKI Motohiro
2010-10-22 1:25 ` Bruno Randolf
2010-10-22 1:28 ` KOSAKI Motohiro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1287655475.3488.99.camel@twins \
--to=peterz@infradead.org \
--cc=Lars_Ericsson@telia.com \
--cc=akpm@linux-foundation.org \
--cc=blp@cs.stanford.edu \
--cc=br1@einfach.org \
--cc=kevin.granade@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=randy.dunlap@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox