Accord.Statistics.Measures.HistogramMean C# (CSharp) Method

HistogramMean() public static method

Calculate mean value of an histogram.

The input array is treated as histogram, i.e. its indexes are treated as values of stochastic function, but array values are treated as "probabilities" (total amount of hits).

public static HistogramMean ( this values ) : double
values this Histogram array.
return double
        public static double HistogramMean(this int[] values)
        {
            double total = 0;
            double mean = 0;

            for (int i = 0; i < values.Length; i++)
            {
                int hits = values[i];
                mean += (double)i * hits;
                total += hits;
            }

            return (total == 0) ? 0 : mean / total;
        }