Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For our application, I'm trying to find a memory-efficient, incremental algorithm to maintain variance of geometric mean.

This "online algorithm" on Wikipedia seems excellent,

however, I'm not sure if / how I can apply the same idea to geometric mean / variance.

Numerical stability is preferred, but probably not strictly necessary as our samples have limited precision - the range is between 1ms and 30,000ms (timeout - trim value) as integer, in lognormal distribution. Sample data are actually web site response time observed periodically BTW.

share|cite|improve this question
I'm not I understand the question correctly. You've already linked to an algorithm that allows memory-efficient computation of the variance. This is a general algorithm for the variance of any data, so in particular you can apply it to the geometric mean. Are you looking for a memory-efficient algorithm to calculate the geometric mean itself? If so, just update the sum $S$ of the logarithms of the values in each step by adding the $k$-th logarithm, and obtain the geometric mean as $\exp(S/k)$. – joriki Oct 4 '12 at 22:10
Ah, so I should store logarithm of everything (not exp()ing back), and I can use the same calculation? IOW, (log of n-th mean) = log of (n-1)-th mean + (log of n-th value + log of (n-1)-th mean) / n to keep track of geometric mean and so on? – kenn Oct 4 '12 at 22:43
I'm not sure about M(2,n) though. sum of squares of differences will be log(x / geometric mean)^2 rather than (x - mean)^2 correct? No idea what the new recurrence equation for M(2,n) will be... – kenn Oct 4 '12 at 22:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.