In the AForge.net the mean value of a vector is calculated as follows:
public static double Mean( int[] values )
{
int hits;
double total = 0;
double mean = 0;
// for all values
for ( int i = 0, n = values.Length; i < n; i++ )
{
hits = values[i];
// accumulate mean
mean += (double) i * hits;
// accumalate total
total += hits;
}
return ( total == 0 ) ? 0 : mean / total;
}
I couldn't understand this.
As far as I know mean is the value where sum is divided by the count of numbers.
Can anyone explain this to me?
What does it mean by hits here?
Can we calculate mean of real numbers in the same way?
Run the program by hand with some numbers of
values. For values=$245$so as the code says it is
accumulate mean: $$\sum_{n=1}^{\text{digits}}na_n$$ where $a_n$ is the $n$-th digit of input $:)$. The total is sum of digits, therefore the result is $$\dfrac{1\times a_1+2\times a_2+3\times a_3+\cdots+n\times a_n}{a_1+a_2+\cdots+a_n}$$ for number $a_1a_2\cdots a_n$. For number $245$ the result is $$\dfrac{1\times 2+2\times 4+3\times 5}{2+4+5}=\dfrac{25}{11}$$