Exemplo n.º 1
0
        public string ToString(IFormatProvider format)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("{0}: {1}\r\n", nameof(Minimum), Minimum.ToString(format));
            sb.AppendFormat("{0}: {1}\r\n", nameof(Maximum), Maximum.ToString(format));
            sb.AppendFormat("{0}: {1}\r\n", nameof(Range), Range.ToString(format));
            sb.AppendFormat("{0}: {1}\r\n", nameof(Median), Median.ToString(format));
            sb.AppendFormat("{0}: {1}\r\n", nameof(Mode), Mode.ToString(format));
            sb.AppendFormat("{0}: {1}\r\n", nameof(Sum), Sum.ToString(format));
            sb.AppendFormat("{0}: {1}\r\n", nameof(Average), Average.ToString(format));
            sb.AppendFormat("{0}: {1}\r\n", nameof(RootMeanSquare), RootMeanSquare.ToString(format));
            sb.AppendFormat("{0}: {1}\r\n", nameof(Variance), Variance.ToString(format));
            sb.AppendFormat("{0}: {1}\r\n", nameof(StandardDeviation), StandardDeviation.ToString(format));
            return(sb.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Width"></param>
        /// <param name="Height"></param>
        /// <param name="TotalScore">分数</param>
        /// <param name="stdev">标准偏差</param>
        /// <param name="cpk">CPK</param>
        /// <param name="familyName"></param>
        /// <returns></returns>

        public Bitmap GetGaussianDistributionGraph(int Width, int Height, int TotalScore, float stdev, float cpk, string familyName = "宋体")
        {
            //横轴 分数;纵轴 正态分布的值


            Bitmap bitmap = new Bitmap(Width, Height);

            Graphics gdi = Graphics.FromImage(bitmap);

            gdi.Clear(Color.White);
            gdi.SmoothingMode     = SmoothingMode.HighQuality;
            gdi.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            gdi.PixelOffsetMode   = PixelOffsetMode.HighQuality;



            List <Tuple <double, double> > Scores = GetGaussianDistributionYs().OrderBy(x => x.Item1).ToList(); //排序 方便后面点与点之间的连线  保证 分数低的 在左边

            float YHeight = 0.8F * Height;                                                                      // 相对左下角 YHeight*0.9F 将表示 maxY
            float XWidth  = 0.9F * Width;                                                                       //相对左下角 XWidth*0.9F 将表示 maxX

            float marginX = (Width - XWidth) / 2F;                                                              //x轴相对左右图片边缘的像素
            float marginY = (Height - YHeight) / 2F;                                                            //y轴相对上下图片边缘的像素

            PointF leftTop = new PointF(marginX, marginY);

            PointF leftBottom = new PointF(marginX, marginY + YHeight);//坐标轴的左下角


            PointF rightBottom = new PointF(marginX + XWidth, marginY + YHeight);//坐标轴的右下角



            gdi.DrawLine(Pens.Gray, leftBottom, rightBottom); //x轴
            gdi.DrawLine(Pens.Gray, leftBottom, leftTop);     //Y轴

            //两个箭头 四条线 6个坐标 另需4个坐标

            PointF YArrowLeft   = new PointF(leftTop.X - 5, leftTop.Y + 5);
            PointF YArrowRight  = new PointF(leftTop.X + 5, leftTop.Y + 5);
            PointF XArrowTop    = new PointF(rightBottom.X - 5, rightBottom.Y - 5);
            PointF XArrowBottom = new PointF(rightBottom.X - 5, rightBottom.Y + 5);

            gdi.DrawLine(Pens.Gray, leftTop, YArrowLeft);
            gdi.DrawLine(Pens.Gray, leftTop, YArrowRight);
            gdi.DrawLine(Pens.Gray, rightBottom, XArrowTop);
            gdi.DrawLine(Pens.Gray, rightBottom, XArrowBottom);

            float unitX = 0.0F;                                                                                            //X轴转换比率
            float unitY = 0.0F;                                                                                            //Y轴转换比率

            List <PointF> pointFs = ConvertToPointF(Scores, XWidth * 0.9F, YHeight * 0.9F, leftTop, out unitX, out unitY); //将分数和概率 转换成 坐标


            gdi.DrawCurve(Pens.Black, pointFs.ToArray(), 0.0F);//基数样条
            foreach (PointF s in pointFs)
            {
                //   gdi.DrawEllipse(Pens.Red, s.X, s.Y, 5, 5);
                gdi.FillEllipse(Brushes.Red, s.X - 5, s.Y - 5, 10, 10);
            }

            //平均分 与 Y轴平行

            PointF avg_top    = new PointF(leftTop.X + (float)Average * unitX, leftTop.Y);
            PointF avg_bottom = new PointF(leftTop.X + (float)Average * unitX, leftBottom.Y);

            gdi.DrawLine(Pens.Black, avg_top, avg_bottom);
            gdi.DrawString(string.Format("{0}", ((float)Average).ToString("F4")), new Font("宋体", 11), Brushes.Black, avg_bottom.X, avg_bottom.Y - 25);


            //将期望和方差写在横轴下方中间

            PointF variance_pf = new PointF(leftBottom.X + (XWidth / 2) - 180, avg_bottom.Y + 25);

            gdi.DrawString(string.Format("平均值:{0};方差:{1};STDEV:{2};CPK:{3}", ((float)Average).ToString("F4"), Variance.ToString("F4"), stdev.ToString("F4"), cpk.ToString("F4")), new Font("宋体", 11), Brushes.Black, variance_pf.X, variance_pf.Y);



            ////将最小分数 和 最大分数 分成9段 标记在坐标轴横轴上

            //double minX = Scores.Min(x => x.Item1);
            //double maxX = Scores.Max(x => x.Item1);

            //double perSegment = TotalScore / 10;// (maxX - minX) / 9F;//每一段表示的分数

            //List<double> segs = new List<double>();//每一个分段分界线横轴的值

            //segs.Add(leftBottom.X + (float)minX * unitX);

            //for (int i = 1; i < 11; i++)
            //{
            //    segs.Add(leftBottom.X + (float)minX * unitX + perSegment * i * unitX);
            //}
            //for (int i = 0; i < 11; i++)
            //{
            //    gdi.DrawPie(Pens.Black, (float)segs[i] - 1, leftBottom.Y - 1, 2, 2, 0, 360);

            //    gdi.DrawString(string.Format("{0}", ((minX + perSegment * (i))).ToString("F0")), new Font("宋体", 11), Brushes.Black, (float)segs[i] - 15, leftBottom.Y + 5);
            //}



            return(bitmap);
        }
Exemplo n.º 3
0
 public override string ToString()
 {
     return(String.Format("{0} - {1} [{2}, {3}, {4}]", Section, Name, Type.ToString(), Unit.ToString(), Variance.ToString()));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a detailed <see cref="System.String"/> that represents this confusion matrix.
        /// </summary>
        /// <returns>A <see cref="System.String"/> that represents this confusion matrix.</returns>
        /// <remarks></remarks>
        public override string ToString()
        {
            // Write the summary values

            string summary = "";

            summary += "Correct: " + Correct;
            summary += "  Incorrect: " + Incorrect;
            summary += "  Total: " + Observations;
            summary += "  Accuracy: " + Accuracy.ToString("F4");
            summary += "  Error: " + Error.ToString("F4");
            summary += "  Confidence: +/- " + ConfidenceInterval.ToString("F4");
            summary += "  Variance: " + Variance.ToString("F4");
            summary += "\n\n\n";

            // Calculate padding values

            int[] padding = new int[values.Count + 1];
            int   i;
            int   sp = 2;

            foreach (KeyValuePair <string, SortedDictionary <string, int> > pair in values)
            {
                if (pair.Key.Length > padding[0])
                {
                    padding[0] = pair.Key.Length;
                }

                i = 1;
                foreach (KeyValuePair <string, int> pair2 in pair.Value)
                {
                    if (pair2.Value.ToString().Length > padding[i])
                    {
                        padding[i] = pair2.Value.ToString().Length;
                    }
                    i += 1;
                }
            }

            // Write the header
            string output = "";

            output += "".PadRight(padding[0] + 3);

            i = 1;
            foreach (KeyValuePair <string, SortedDictionary <string, int> > pair in values)
            {
                output += pair.Key.PadRight(padding[i] + sp);
                i      += 1;
            }
            output += "\n   ".PadRight(output.Length, '-') + "\n";

            // Write each horizontal line

            foreach (KeyValuePair <string, SortedDictionary <string, int> > pair in values)
            {
                output += pair.Key.PadRight(padding[0]) + " | ";

                i = 1;
                foreach (KeyValuePair <string, int> pair2 in pair.Value)
                {
                    output += pair2.Value.ToString().PadRight(padding[i] + sp);
                    i      += 1;
                }
                output += "\n";
            }

            output += "\n\nConfusions:\n\n" + Confusions(-1);

            return(summary + output + "\n");
        }