If you want to create a uniform moving average with all elements equal weight, I do not see how you cannot keep all the information to compute the average -- it needs to be there by definition.

But if you are willing to relax the uniformity requirement, it is easily to do something real time. Consider the recursive estimate for the time between emails

avg( i ) = (1-k)*(t[i] - t[i-1]) + k*avg( i-1 ) k < 1
where t[i]-t[i-1] is the time interval between the current and previous email and k is a wieghting coefficient. This expression only needs the most recent interval and average to compute the current average.

For k < 1, the previous elements will be exponentially weighted k**n for avg(i-n) and k is adjusted to vary the aproximate number of events averaged in.

From the average interval between emails, you can easily derive the emails per time:

rate[i] = 1/avg[i];
Update: corrected first equation.

-Mark


In reply to Re: Average over time by kvale
in thread Average over time by matija

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.