AForge.Math.ContinuousHistogram.GetRange C# (CSharp) Method

GetRange() public method

Get range around median containing specified percentage of values.

The method calculates range of stochastic variable, which summary probability comprises the specified percentage of histogram's hits.

Sample usage:

// create histogram ContinuousHistogram histogram = new ContinuousHistogram( new int[] { 0, 0, 8, 4, 2, 4, 7, 1, 0 }, new Range( 0.0f, 1.0f ) ); // get 50% range Range range = histogram.GetRange( 0.5f ); // show the range ([0.25, 0.75]) Console.WriteLine( "50% range = [" + range.Min + ", " + range.Max + "]" );
public GetRange ( float percent ) : AForge.Math.Range
percent float Values percentage around median.
return AForge.Math.Range
        public Range GetRange( float percent )
        {
            int min, max, hits;
            int h = (int) ( total * ( percent + ( 1 - percent ) / 2 ) );
            int n = values.Length;
            int nM1 = n - 1;

            // skip left portion
            for ( min = 0, hits = total; min < n; min++ )
            {
                hits -= values[min];
                if ( hits < h )
                    break;
            }
            // skip right portion
            for ( max = nM1, hits = total; max >= 0; max-- )
            {
                hits -= values[max];
                if ( hits < h )
                    break;
            }
            // return range between left and right boundaries
            return new Range(
                ( (float) min / nM1 ) * range.Length + range.Min,
                ( (float) max / nM1 ) * range.Length + range.Min );
        }