Esempio n. 1
0
        public static double[] CheckOutstanding(double[] data, out double[] clearData, float alpha)
        {
            List <double> dataList  = new List <double>(data);
            List <double> trashList = new List <double>();
            bool          changes;

            do
            {
                changes = false;
                data    = dataList.ToArray();
                double mean = StatisticsProcessor.Srednee(data);
                double S    = Math.Sqrt(StatisticsProcessor.Dispersion(data));

                double Xmax  = StatisticsProcessor.FindMax(data);
                double TnMax = (Xmax - mean) / S;
                if (TnMax > TTable(alpha, (uint)(data.Length)))
                {
                    changes = true;
                    dataList.Remove(Xmax);
                    trashList.Add(Xmax);
                }

                double Xmin  = StatisticsProcessor.FindMin(data);
                double TnMin = (mean - Xmin) / S;
                if (TnMin > TTable(alpha, (uint)(data.Length)))
                {
                    changes = true;
                    dataList.Remove(Xmin);
                    trashList.Add(Xmin);
                }
            }while (changes);

            clearData = dataList.ToArray();
            return(trashList.Count > 0 ? trashList.ToArray() : null);
        }
Esempio n. 2
0
        private void DrawPolygon(Graphics g, float zoom_x, float zoom_y)
        {
            DrawAxes(g, ptMargins.Y);

            PointF[] polyPts  = new PointF[Y.Length];
            float    ptDeltaX = sz.Height / 400;
            float    ptDeltaY = sz.Width / 400;

            Pen penCrosses = new Pen(penColor, 5);

            penCrosses.EndCap = penCrosses.StartCap = LineCap.Round;

            double min = StatisticsProcessor.FindMin(Y);

            for (int i = 0; i < Y.Length; i++)
            {
                polyPts[i].X = i * zoom_x + ptMargins.X;
                polyPts[i].Y = (float)(Y[i] - min) * zoom_y + ptMargins.Y;

                g.DrawLine(penCrosses,
                           PointF.Add(polyPts[i], new SizeF(-ptDeltaX, -ptDeltaY)),
                           PointF.Add(polyPts[i], new SizeF(+ptDeltaX, +ptDeltaY)));
                g.DrawLine(penCrosses,
                           PointF.Add(polyPts[i], new SizeF(+ptDeltaX, -ptDeltaY)),
                           PointF.Add(polyPts[i], new SizeF(-ptDeltaX, +ptDeltaY)));
            }

            if (Y.Length > 1)
            {
                g.DrawLines(new Pen(penColor, 2), polyPts);
            }

            DrawValues(g, ptMargins.Y - (float)min * zoom_y, zoom_x, zoom_y);
        }
Esempio n. 3
0
        private void DrawLeftSideArrows(Graphics g, float zoom_x, float zoom_y)
        {
            DrawAxes(g, ptMargins.Y);

            Double min = StatisticsProcessor.FindMin(Y);

            Pen pen      = new Pen(penColor, 2);
            Pen penArrow = new Pen(penColor, 1.2f);

            penArrow.StartCap = penArrow.EndCap = LineCap.Round;

            PointF pt1 = new PointF();
            PointF pt2 = new PointF();

            for (int i = 0; i < Y.Length; i++)
            {
                pt1.X = (i + 1) * zoom_x;
                pt1.Y = (float)(Y[i] - min) * zoom_y;

                pt2.X = i * zoom_x;
                pt2.Y = (float)(Y[i] - min) * zoom_y;

                // line
                g.DrawLine(pen, pt1.X + ptMargins.X, pt1.Y + ptMargins.Y,
                           pt2.X + ptMargins.X, pt2.Y + ptMargins.Y);
                DrawArrowEars(g, penArrow, pt2, zoom_x / 8, 180, 20);
            }

            DrawValues(g, ptMargins.Y - (float)min * zoom_y, zoom_x, zoom_y);
        }
Esempio n. 4
0
        public static bool CheckZn(double[] data, Zakon zn, float alpha)
        {
            double[] ΔLeft, ΔRight;
            int[]    v;
            int      k = StatisticsProcessor.ToIntervals(data, out ΔLeft, out ΔRight, out v);

            double σв   = Math.Sqrt(StatisticsProcessor.Dispersion(data));
            double mean = StatisticsProcessor.Srednee(data);

            double[] p = new double[k];

            for (int i = 0; i < k; i++)
            {
                double x1 = ΔLeft[i];
                double x2 = ΔRight[i];

                switch (zn)
                {
                case Zakon.Ravnom:
                    p[i] = FxRavnom(x2, mean - 1.732 * σв, mean + 1.732 * σв) -
                           FxRavnom(x1, mean - 1.732 * σв, mean + 1.732 * σв);
                    break;

                case Zakon.Exponential:
                    p[i] = FxExponential(x2, 1f / mean) - FxExponential(x1, 1f / mean);
                    break;

                case Zakon.Normal:
                    p[i] = FxNormal((x2 - mean) / σв) - FxNormal((x1 - mean) / σв);
                    break;
                }
            }

            double χSqr = 0;

            for (int i = 0; i < k; i++)
            {
                χSqr += (v[i] - data.Length * p[i]) * (v[i] - data.Length * p[i]) / data.Length / p[i];
            }

            int s = 0;

            switch (zn)
            {
            case Zakon.Ravnom:
                s = 2;
                break;

            case Zakon.Exponential:
                s = 1;
                break;

            case Zakon.Normal:
                s = 2;
                break;
            }

            return(χSqr < χSqrTable(alpha, (uint)(k - s - 1)));
        }
Esempio n. 5
0
        private void DrawMetrolog(Graphics g, float zoom_x, float zoom_y)
        {
            DrawAxes(g, ptMargins.Y);

            PointF[] polyPts  = new PointF[Y.Length];
            float    ptDeltaX = sz.Height / 400;
            float    ptDeltaY = sz.Width / 400;

            Pen penCrosses = new Pen(penColor, 5);

            penCrosses.EndCap = penCrosses.StartCap = LineCap.Round;

            double min = StatisticsProcessor.FindMin(Y);

            for (int i = 0; i < Y.Length; i++)
            {
                polyPts[i].X = i * zoom_x + ptMargins.X;
                polyPts[i].Y = (float)(Y[i] - min) * zoom_y + ptMargins.Y;

                g.DrawLine(penCrosses,
                           PointF.Add(polyPts[i], new SizeF(-ptDeltaX, -ptDeltaY)),
                           PointF.Add(polyPts[i], new SizeF(+ptDeltaX, +ptDeltaY)));
                g.DrawLine(penCrosses,
                           PointF.Add(polyPts[i], new SizeF(+ptDeltaX, -ptDeltaY)),
                           PointF.Add(polyPts[i], new SizeF(-ptDeltaX, +ptDeltaY)));
            }

            if (Y.Length > 1)
            {
                g.DrawLines(new Pen(penColor, 2), polyPts);
            }

            DrawValues(g, ptMargins.Y - (float)min * zoom_y, zoom_x, zoom_y);

            Pen penMids = new Pen(Color.Orange);

            int i0 = 0;

            for (int il = 0; il < indsd.Count; il++)
            {
                int      i  = indsd[il];
                double[] y1 = new double[i - i0];
                Array.Copy(Y, i0, y1, 0, i - i0);

                float mid = (float)StatisticsProcessor.Srednee(y1);

                float gy = (float)(mid - min) * zoom_y + ptMargins.Y;

                g.DrawLine(penMids, ptMargins.X + i0 * zoom_x, gy, ptMargins.X + i * zoom_x, gy);

                i0 = i;
            }
        }
Esempio n. 6
0
        public void Draw(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.HighQuality;

            //Color cl = Color.FromArgb(255, 250, 242);
            Color cl = Color.FromArgb(240, 240, 242);

            g.Clear(cl);

            g.Transform = new Matrix(1, 0, 0, -1, 0, sz.Height - 1);

            #region Zoom calculation

            zoom_x = sz.Width / (Y.Length + 1f);

            ptMargins = new PointF(zoom_x, new Font(FONT_FACE, FONT_HEIGHT).GetHeight() * 2f);
            float MaxMin = (float)(StatisticsProcessor.FindMax(Y) - StatisticsProcessor.FindMin(Y));
            float Ampl   = (MaxMin > float.Epsilon ? MaxMin : 1);

            zoom_y = (sz.Height - 2 * ptMargins.Y - 1) / Ampl;

            #endregion

            #region switch on the kind of the diagram

            switch (kindOfDiagram)
            {
            case KindOfDiagram.LeftArrows:
                DrawLeftSideArrows(g, zoom_x, zoom_y);
                break;

            case KindOfDiagram.Histogram:
                DrawHistogram(g, zoom_x, zoom_y);
                break;

            case KindOfDiagram.Polygon:
                DrawPolygon(g, zoom_x, zoom_y);
                break;

            case KindOfDiagram.Metrolog:
                DrawMetrolog(g, zoom_x, zoom_y);
                break;

            default:
                DrawHistogram(g, zoom_x, zoom_y);
                break;
            }
            #endregion
        }
Esempio n. 7
0
        public static double[] EmpVals(double[] data)
        {
            double[] lX, rX;
            int[]    nX;
            StatisticsProcessor.ToIntervals(data, out lX, out rX, out nX);

            double[] res = new double[nX.Length];

            double sum = 0;

            for (int i = 0; i < nX.Length; i++)
            {
                sum   += nX[i];
                res[i] = sum / data.Length;
            }

            return(res);
        }
Esempio n. 8
0
        private void DrawValues(Graphics g, float oy, float zoom_x, float zoom_y)
        {
            Font       font  = new Font(FONT_FACE, FONT_HEIGHT, FontStyle.Bold);
            SolidBrush brush =
                new SolidBrush(Color.FromKnownColor(KnownColor.ControlText));

            double max  = StatisticsProcessor.FindMax(Y);
            double min  = StatisticsProcessor.FindMin(Y);
            int    stps = 20;

            g.ScaleTransform(1, -1);
            for (int i = 0; i <= stps; i++)
            {
                PointF point = new PointF(
                    0,
                    -((float)((max - min) * i / stps + min) * zoom_y + 0.5f * font.Height + oy)
                    );

                string valStr = string.Format("{0:F2}", (max - min) * i / stps + min);
                g.DrawString(valStr, font, brush, point);
            }
            g.ScaleTransform(1, -1);
        }
Esempio n. 9
0
        private void DrawHistogram(Graphics g, float zoom_x, float zoom_y)
        {
            double min = StatisticsProcessor.FindMin(Y);
            double max = StatisticsProcessor.FindMax(Y);
            float  oy  = 0;
            float  zy  = zoom_y;

            if (max < 0) // signs equals -
            {
                oy = sz.Height - ptMargins.Y;
                zy = (sz.Height - 2 * ptMargins.Y - 1) / (float)Math.Abs(min);
            }
            else if (min > 0) // signs equals +
            {
                oy = ptMargins.Y;
                zy = (sz.Height - 2 * ptMargins.Y - 1) / (float)Math.Abs(max);
            }
            else if (max != min) // signs differs
            {
                oy = (sz.Height - 2 * ptMargins.Y - 1) * (float)(Math.Abs(min) / (max - min)) + ptMargins.Y;
                zy = (sz.Height - 2 * ptMargins.Y - 1) / (float)(Math.Abs(min) + Math.Abs(max));
            }
            else // stable zero
            {
                oy = 0;
                zy = sz.Height - 2 * ptMargins.Y - 1;
            }

            DrawAxes(g, oy);

            for (int i = 0; i < Y.Length; i++)
            {
                RectangleF rect = new RectangleF(
                    i * zoom_x + 0.1f * zoom_x + ptMargins.X / 2f,
                    (float)(Y[i] * zy > 0 ? 0 : Y[i] * zy) + oy,
                    1f * zoom_x - 0.2f * zoom_x,
                    (float)(Math.Abs(Y[i]) * zy));

                if (rect.Height < float.Epsilon)
                {
                    rect.Height += 1.5f;
                }
                //0e+20f * float.Epsilon;

                LinearGradientBrush lgb = new LinearGradientBrush(rect,
                                                                  penColor, Color.FromKnownColor(KnownColor.ControlDark), 75);

                g.FillRectangle(lgb, rect);
            }

            Font       font  = new Font(FONT_FACE, FONT_HEIGHT);
            SolidBrush brush =
                new SolidBrush(Color.FromKnownColor(KnownColor.ControlText));

            g.ScaleTransform(1, -1);
            for (int i = 0; i < Y.Length; i++)
            {
                PointF point = new PointF(
                    (i + .5f) * zoom_x + ptMargins.X / 2f,
                    -(float)(Y[i] * zy + 1.0f * font.Height * Math.Sign(Y[i]) + oy)
                    );

                string       valStr = Y[i].ToString();
                StringFormat sf     = new StringFormat();
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;

                float actual_width = 0;
                int   dig_count    = 1;
                while (actual_width < 0.9f * zoom_x && dig_count <= 15)
                {
                    double trim_val = Math.Round(Y[i], dig_count++);
                    valStr       = trim_val.ToString();
                    actual_width = g.MeasureString(valStr, font, point, sf).Width;
                }
                g.DrawString(valStr, font, brush, point, sf);
            }
            g.ScaleTransform(1, -1);
        }