Пример #1
0
        static Brk[] GenerateBreaks(double[] estimates)
        {
            double[] tbrks = new double[estimates.Length - 1];
            int      j = 0, i = 0;

            while (j < estimates.Length - 1)
            {
                if (estimates[j] < estimates[j + 1])
                {
                    tbrks[i] = (double)(estimates[j] + estimates[j + 1]) / 2;
                    i++;
                    j++;
                }
                else
                {
                    j++;
                }
            }
            Brk[] brks = new Brk[i + 2];
            int   n    = i;

            for (i = 0; i < n; i++)
            {
                brks[i + 1].value = tbrks[i];
            }

            brks[0].value     = double.MinValue;
            brks[0].idx       = -1;
            brks[n + 1].value = double.MaxValue;
            brks[n + 1].idx   = estimates.Length - 1;

            int ii = 0;

            for (int t = 1; t <= n; t++)
            {
                while (estimates[ii] <= brks[t].value)
                {
                    ii++;
                }

                ii--;
                brks[t].idx = ii;
            }

            return(brks);
        }
Пример #2
0
        static Brk[] GenerateBreaks(double[] estimates, int interval)
        {
            double start = estimates[0];
            double end   = estimates[estimates.Length - 1];
            double s     = Math.Ceiling(start / interval) * interval;
            double e     = Math.Floor(end / interval) * interval;
            int    n     = (int)(e - s) / interval + 1;

            if (e == end)
            {
                n = n - 1;
            }
            Brk[] brks = new Brk[n + 2];
            for (int i = 1; i <= n; i++)
            {
                brks[i].value = s + interval * (i - 1);
            }
            brks[0].value     = double.MinValue;
            brks[0].idx       = -1;
            brks[n + 1].value = double.MaxValue;
            brks[n + 1].idx   = estimates.Length - 1;

            int ii = 0;

            for (int t = 1; t <= n; t++)
            {
                while (estimates[ii] <= brks[t].value)
                {
                    ii++;
                }

                ii--;
                brks[t].idx = ii;
            }

            return(brks);
        }