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

HistogramMode() public static method

Calculate mode 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).

Returns the minimum mode value if the specified histogram is multimodal.

public static HistogramMode ( this values ) : int
values this Histogram array.
return int
        public static int HistogramMode(this int[] values)
        {
            int mode = 0, curMax = 0;

            for (int i = 0; i < values.Length; i++)
            {
                if (values[i] > curMax)
                {
                    curMax = values[i];
                    mode = i;
                }
            }

            return mode;
        }
    }