I have a collection of n floating point values: x[n]
. When I want to calculate the meanvalue and standard deviation, I need to iterate with two loops over all values:
First loop to sum all values and calculate the meanvalue:
sum = 0
for(i=0; i<n; i++)
sum += x[i]
mean = sum/n
In a second loop I calculate the standard deviation:
sum = 0
for(i=0; i<n; i++)
sum += pow2(x[i] - mean)
sder = sqrt(sum/n)
I am aware that you cannot reduce this complexity if you want to the exact values for meanvalue and standard deviation. But is there a way to calculate them in less time if you just approximate? Favoured in one loop.