Method for calculating harmonic media!

0

I need some 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 DB. But there are many points added every minute and I need to generate a historical media value of all points in the series since its inception ... This generates a lot of processing time for the DB and the PC so every minute is updating this statistic ...

I would like to know if I would have any way to consolidate the media until the last minute and then perform the new average only with this consolidated value and the new potos acquired after consolidation ???

I'm programming in C with BD SQLServer.

Thank you ..

    
asked by anonymous 26.05.2018 / 17:10

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 a previous 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,

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

Algorithm:

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

Note some 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 mean closest to the population mean
  • Given the required accuracy, you can simplify the formula to: float novamedia = media + historico[qtde] / qtde;
27.05.2018 / 18:44