Method for harmonic media calculation!

Asked

Viewed 997 times

0

Ola I need help to perform a harmonic media calculation of an "infinite" series, so to speak. Ex. I have a data capture system that is always injecting information into a BD. However there are many points added every minute and I need to generate a historical average value of all points of the series since its inception... This generates a lot of BD and PC processing time to update this statistic every minute...

I would like to know whether there is any way of consolidating the media until the last minute and then achieving the new average only with this consolidated value and the new potos purchased after consolidation???

I am programming in C with BD Sqlserver.

Thank you..

  • I don’t understand why exactly use harmonic media; is it mandatory? From what I understand, you want to calculate a certain average according to the sampling done, periodically. Why not use https://pt.wikipedia.org/wikiM%C3%A9dia_m%C3%B3vel?

1 answer

0


The mean (arithmetic) is calculated as follows:,

float media = 0.0;

for (int i = 0; i < qtd; ++i)
{
    media += historico[i];
}

media /= qtd;

For a count novaqtd = qtd + 1 and an earlier average equal to media, the new average novamedia, with the arrival of a new historical value historico[qtd], would be:

float novamedia = (qtd * media + historico[qtd]) / (qtd + 1);

that is to say,

float novamedia = (media + historico[qtd] / qtd) / (1 + (1 / qtd));

Algorithm:

  • Take the new historical value and divide by the previous count
  • Add to previous average
  • With the value obtained, divide by (1 + (1 / previous count))
  • This is the new media

Note a few things:

  • If the count is too high, (1 / count) will be a very low value and (1 + (1 / count)), a value very close to 1, which is to be expected, because very large samples tend to have the closest average of the population
  • Given the required accuracy, it is possible to simplify the formula for: float novamedia = media + historico[qtde] / qtde;
  • 1

    I believe it will work out this way... The amount of points expected is approx. 32,000,000 and then the sampling will be reset again. As the accuracy is only 03 decimal places, I believe that the trend is really to go to 1 in the new samples. More finally we have to do as requested!. hehehe thanks for the help..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.