[RC5] Stats suggestion
Ben Clifford
benc at hawaga.org.uk
Fri Jan 5 19:43:29 EST 2001
On Fri, 5 Jan 2001 bwilson at fers.com wrote:
> It sounds like there would be a somewhat complex "catch-up" process to get
> all the averages into place.
Not complex - just long winded. You just run through time fast:
Something like:
avg = 0
for day = 0 to today
avg = k1 * history[day] + k2 * avg
end-for
> Do you have a formula handy for calculating k1 and k2 to obtain a given
> half-life?
Yes. It is pretty simple, I just couldn't remember it off the top of my
head so I wrote k1 and k2 which I defined to be the correct values,
rather than posting some other incorrect formulae. I'm sure you can tell I
am a pedant/mathematician :-)
new_avg = K * old_avg + (1-K) * new avg
K can be any value between 0 and 1 - the larger the value, the longer the
half-life.
Scratching away on a bit of paper, I think that:
let i be the number of periods in the half life. ie. if you are performing
an iteration every day, as I believe is happening at the moment, then a
7-day half life would have i=7
Then
K = 0.5 ^ ( 1 / i)
where ^ is "to the power of"
So a half life of 7 days should have K=0.905723 approx.
and 30 days should have K=0.977159 approx.
The arithmetic can be done floating or fixed point - the linux kernel does
it in fixed point. If you want, I can cut the relevant bit of code (in C)
out for you to look at (it is in sched.c and sched.h off the top of my
head).
I would be grateful if some other mathematicians on the list would check
the above and find the stupid mistakes I have probably made.
Ben
--
http://www.hawaga.org.uk/travel/ for my rotating world map applet
http://www.hawaga.org.uk/benc_key.txt PGP / GPG key 0x30F06950 - please use it!
--
To unsubscribe, send 'unsubscribe rc5' to majordomo at lists.distributed.net
rc5-digest subscribers replace rc5 with rc5-digest
More information about the rc5
mailing list