예제 #1
0
        private static void PlotError(string errorName, Dictionary <int, double> epochsErrors)
        {
            double[] epochs = epochsErrors.Keys.Select(e => (double)e).ToArray();
            double[] errors = epochsErrors.Values.ToArray();

            ScatterplotView spv = new ScatterplotView
            {
                Dock         = DockStyle.Fill,
                LinesVisible = true
            };

            spv.Graph.GraphPane.XAxis.Title.Text = "Epoch";
            spv.Graph.GraphPane.YAxis.Title.Text = "Error";
            spv.Graph.GraphPane.Title.Text       = "Error changing through epochs";

            spv.Graph.GraphPane.AddCurve(errorName, epochs, errors, Color.Green, SymbolType.None);

            spv.Graph.GraphPane.AxisChange();

            Form f1 = new Form
            {
                Width  = 600,
                Height = 400
            };

            f1.Controls.Add(spv);
            f1.ShowDialog();
        }
예제 #2
0
        public void ComputeTest1()
        {
            ScatterplotView target = new ScatterplotView();

            double[] data = new double[] { 200.0, 200.0, 200.0 };

            target.DataSource = data;

            target.DataSource = null;

            target.DataSource = data;

            // ScatterplotBox.Show(data);
        }
예제 #3
0
        private static void DrawROCCurve(int[] actual, int[] preds, int numClass, string modelName)
        {
            ScatterplotView spv = new ScatterplotView();

            spv.Dock         = DockStyle.Fill;
            spv.LinesVisible = true;

            Color[] colors = new Color[] {
                Color.Blue, Color.Red, Color.Orange, Color.Yellow, Color.Green,
                Color.Gray, Color.LightSalmon, Color.LightSkyBlue, Color.Black, Color.Pink
            };

            for (int i = 0; i < numClass; i++)
            {
                // Build ROC for Train Set
                bool[] expected  = actual.Select(x => x == i ? true : false).ToArray();
                int[]  predicted = preds.Select(x => x == i ? 1 : 0).ToArray();

                var trainRoc = new ReceiverOperatingCharacteristic(expected, predicted);
                trainRoc.Compute(1000);

                // Get Train AUC
                double   auc   = trainRoc.Area;
                double[] xVals = trainRoc.Points.Select(x => 1 - x.Specificity).ToArray();
                double[] yVals = trainRoc.Points.Select(x => x.Sensitivity).ToArray();

                // Draw ROC Curve
                spv.Graph.GraphPane.AddCurve(
                    String.Format(
                        "Digit: {0} - AUC: {1:0.00}",
                        i, auc
                        ),
                    xVals, yVals, colors[i], SymbolType.None
                    );
                spv.Graph.GraphPane.AxisChange();
            }

            spv.Graph.GraphPane.Title.Text = String.Format(
                "{0} ROC - One vs. Rest",
                modelName
                );

            Form f1 = new Form();

            f1.Width  = 700;
            f1.Height = 500;
            f1.Controls.Add(spv);
            f1.ShowDialog();
        }
예제 #4
0
        public void ComputeTest2()
        {
            ScatterplotView target = new ScatterplotView();

            Scatterplot histogram = new Scatterplot();

            histogram.Compute(new double[] { 200.0, 200.0, 200.0 });

            target.DataSource = null;

            target.DataSource = histogram;

            target.DataSource = null;

            // ScatterplotBox.Show(histogram);
        }
예제 #5
0
        static void DrawVertex(Vertex vertex, ScatterplotView view, int i)
        {
            view.Graph.GraphPane.AddCurve("left_" + i,
                                          new double[] { (double)vertex.LeftEdge.From.X, (double)vertex.LeftEdge.To.X },
                                          new double[] { (double)vertex.LeftEdge.From.Y, (double)vertex.LeftEdge.To.Y },
                                          Color.Blue,
                                          symbols[i]);

            view.Graph.GraphPane.AddCurve("rigth_" + i,
                                          new double[] { (double)vertex.RightEdge.From.X, (double)vertex.RightEdge.To.X },
                                          new double[] { (double)vertex.RightEdge.From.Y, (double)vertex.RightEdge.To.Y },
                                          Color.Green,
                                          symbols[i]);

            view.Graph.GraphPane.AddCurve("bisector_" + i,
                                          new double[] { (double)vertex.AngleBisectorRay.From.X, (double)vertex.AngleBisectorRay.To.X },
                                          new double[] { (double)vertex.AngleBisectorRay.From.Y, (double)vertex.AngleBisectorRay.To.Y },
                                          Color.Red,
                                          symbols[i]);
        }
예제 #6
0
        static void Main()
        {
            Random r = new Random();

            var path = @"D:/Machel/Documents/Test.xlsx";

            Excel.Application excelApp = new Excel.Application();
            //This is set to false, so it will not open the excel file too.
            excelApp.Visible = false;

            excelApp.DisplayAlerts = false;                                                                                                                                                                                                                               //Don't want Excel to display error messageboxes
            Excel.Workbook  workbook = excelApp.Workbooks.Open(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); //This opens the file
            Excel.Worksheet sheet    = workbook.Worksheets[1];                                                                                                                                                                                                            //Get the first sheet in the file
            Excel.Range     bColumn  = sheet.get_Range("B1", "B10");
            Excel.Range     aColumn  = sheet.get_Range("A1", "A10");

            //Instead of creating list of elements, it's also possible to pass directly with index to x, y
            List <double> dataX = new List <double>();
            List <double> dataY = new List <double>();

            foreach (object o in bColumn)
            {
                Excel.Range row = o as Excel.Range;
                double      s   = row.get_Value(null);
                dataX.Add(s);
            }
            foreach (object o in aColumn)
            {
                Excel.Range row = o as Excel.Range;
                double      s   = row.get_Value(null);
                dataY.Add(s);
            }
            int a   = aColumn.Count;
            int max = dataX.Count;

            //Define Arrays
            double[] x  = new double[max];
            double[] x2 = new double[max];
            double[] y1 = new double[max];
            double[] y2 = new double[max];
            double[] y3 = new double[max];

            //Add elements to the arrays
            for (int i = 0; i < max; i++)
            {
                x[i]  = dataX[i];
                y1[i] = dataY[i];
                y2[i] = r.NextDouble() * 5;
            }
            //Test quadratic functions
            for (int i = 0; i < 10; i++)
            {
                x2[i] = -4 + i;
                y3[i] = Math.Pow(x2[i], 2) - 2 * x2[i] + 1;
            }
            ScatterplotView spv = new ScatterplotView();

            spv.Dock = DockStyle.Fill;
            //spv.LinesVisible = false;

            spv.Graph.GraphPane.Title.Text       = "Ploting with C#";
            spv.Graph.GraphPane.XAxis.Title.Text = "Abstand";
            spv.Graph.GraphPane.YAxis.Title.Text = "Leit";
            spv.Graph.GraphPane.XAxis.Cross      = 0;
            spv.Graph.GraphPane.YAxis.Cross      = 0;
            //spv.Graph.GraphPane.AddCurve("ax^2+bx+c", x2, y3, Color.Green,SymbolType.Default);
            spv.Graph.GraphPane.AddCurve("Curve 1", x, y1, Color.Red, SymbolType.Circle);
            spv.Graph.GraphPane.AddCurve("Curve 2", x, y2, Color.Blue, SymbolType.Diamond);

            spv.Graph.GraphPane.AxisChange();


            Form f1 = new Form();

            f1.Text   = "Graph with C#";
            f1.Width  = 600;
            f1.Height = 400;
            f1.Controls.Add(spv);
            f1.ShowDialog();
        }
예제 #7
0
        //Not disguising the testing dataset, so don't need to worry about that calculation.
        static void Main(string[] args)
        {
            double theta = 0;

            DataTable incomeDataset           = LoadIncomeDataset();
            DataTable incomeTrainingDataset   = SplitIncomeDataset(incomeDataset, 0);
            DataTable incomeTestingDataset    = SplitIncomeDataset(incomeDataset, 1);
            double    benchmarkIncomeAccuracy = IncomeDecision(incomeTrainingDataset, incomeTestingDataset);


            double[] accuracyFor0 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);
            theta = 0.1;
            double[] accuracyFor01 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);
            theta = 0.2;
            double[] accuracyFor02 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);
            theta = 0.3;
            double[] accuracyFor03 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);
            theta = 0.4;
            double[] accuracyFor04 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);
            theta = 0.45;
            double[] accuracyFor045 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);
            theta = 0.51;
            double[] accuracyFor051 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);
            theta = 0.55;
            double[] accuracyFor055 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);
            theta = 0.6;
            double[] accuracyFor06 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);
            theta = 0.7;
            double[] accuracyFor07 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);
            theta = 0.8;
            double[] accuracyFor08 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);
            theta = 0.9;
            double[] accuracyFor09 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);
            theta = 1.0;
            double[] accuracyFor10 = testRandomization(incomeTrainingDataset, incomeTestingDataset, theta);

            //Get accuracy means for each theta
            double meanFor0   = Accord.Statistics.Measures.Mean(accuracyFor0);
            double meanFor01  = Accord.Statistics.Measures.Mean(accuracyFor01);
            double meanFor02  = Accord.Statistics.Measures.Mean(accuracyFor02);
            double meanFor03  = Accord.Statistics.Measures.Mean(accuracyFor03);
            double meanFor04  = Accord.Statistics.Measures.Mean(accuracyFor04);
            double meanFor045 = Accord.Statistics.Measures.Mean(accuracyFor045);
            double meanFor051 = Accord.Statistics.Measures.Mean(accuracyFor051);
            double meanFor055 = Accord.Statistics.Measures.Mean(accuracyFor055);
            double meanFor06  = Accord.Statistics.Measures.Mean(accuracyFor06);
            double meanFor07  = Accord.Statistics.Measures.Mean(accuracyFor07);
            double meanFor08  = Accord.Statistics.Measures.Mean(accuracyFor08);
            double meanFor09  = Accord.Statistics.Measures.Mean(accuracyFor09);
            double meanFor10  = Accord.Statistics.Measures.Mean(accuracyFor10);
            Dictionary <double, double> means = new Dictionary <double, double>();

            means.Add(0, meanFor0);
            means.Add(0.1, meanFor01);
            means.Add(0.2, meanFor02);
            means.Add(0.3, meanFor03);
            means.Add(0.4, meanFor04);
            means.Add(0.45, meanFor045);
            means.Add(0.51, meanFor051);
            means.Add(0.55, meanFor055);
            means.Add(0.6, meanFor06);
            means.Add(0.7, meanFor07);
            means.Add(0.8, meanFor08);
            means.Add(0.9, meanFor09);
            means.Add(1, meanFor10);

            //Get accuracy variances for each theta
            double varianceFor0   = Accord.Statistics.Measures.Variance(accuracyFor0);
            double varianceFor01  = Accord.Statistics.Measures.Variance(accuracyFor01);
            double varianceFor02  = Accord.Statistics.Measures.Variance(accuracyFor02);
            double varianceFor03  = Accord.Statistics.Measures.Variance(accuracyFor03);
            double varianceFor04  = Accord.Statistics.Measures.Variance(accuracyFor04);
            double varianceFor045 = Accord.Statistics.Measures.Variance(accuracyFor045);
            double varianceFor051 = Accord.Statistics.Measures.Variance(accuracyFor051);
            double varianceFor055 = Accord.Statistics.Measures.Variance(accuracyFor055);
            double varianceFor06  = Accord.Statistics.Measures.Variance(accuracyFor06);
            double varianceFor07  = Accord.Statistics.Measures.Variance(accuracyFor07);
            double varianceFor08  = Accord.Statistics.Measures.Variance(accuracyFor08);
            double varianceFor09  = Accord.Statistics.Measures.Variance(accuracyFor09);
            double varianceFor10  = Accord.Statistics.Measures.Variance(accuracyFor10);
            Dictionary <double, double> variances = new Dictionary <double, double>();

            variances.Add(0, varianceFor0);
            variances.Add(0.1, varianceFor01);
            variances.Add(0.2, varianceFor02);
            variances.Add(0.3, varianceFor03);
            variances.Add(0.4, varianceFor04);
            variances.Add(0.45, varianceFor045);
            variances.Add(0.51, varianceFor051);
            variances.Add(0.55, varianceFor055);
            variances.Add(0.6, varianceFor06);
            variances.Add(0.7, varianceFor07);
            variances.Add(0.8, varianceFor08);
            variances.Add(0.9, varianceFor09);
            variances.Add(1, varianceFor10);

            double[] thetas         = means.Keys.ToArray <double>();
            double[] meanValues     = means.Values.ToArray <double>();
            double[] varianceValues = variances.Values.ToArray <double>();


            int max = thetas.Length;

            double[] benchmarkAccuracies = new double[max];
            double[] benchmarkVariances  = new double[max];

            //Create graph for means
            for (int i = 0; i < max; i++)
            {
                benchmarkAccuracies[i] = benchmarkIncomeAccuracy;
            }

            ScatterplotView meanPlot = new ScatterplotView();

            meanPlot.Dock         = DockStyle.Fill;
            meanPlot.LinesVisible = true;

            meanPlot.Graph.GraphPane.AddCurve("Curve 1", thetas, meanValues, Color.Red, SymbolType.Circle);
            meanPlot.Graph.GraphPane.AddCurve("Curve 2", thetas, benchmarkAccuracies, Color.Blue, SymbolType.Diamond);

            meanPlot.Graph.GraphPane.AxisChange();

            Form meanForm = new Form();

            meanForm.Width  = 600;
            meanForm.Height = 400;
            meanForm.Controls.Add(meanPlot);
            meanForm.ShowDialog();

            //Create graph for variances
            for (int i = 0; i < max; i++)
            {
                benchmarkVariances[i] = 0;
            }

            ScatterplotView variancePlot = new ScatterplotView();

            variancePlot.Dock         = DockStyle.Fill;
            variancePlot.LinesVisible = true;

            variancePlot.Graph.GraphPane.AddCurve("Curve 1", thetas, varianceValues, Color.Red, SymbolType.Circle);
            variancePlot.Graph.GraphPane.AddCurve("Curve 2", thetas, benchmarkVariances, Color.Blue, SymbolType.Diamond);

            variancePlot.Graph.GraphPane.AxisChange();

            Form varianceForm = new Form();

            varianceForm.Width  = 600;
            varianceForm.Height = 400;
            varianceForm.Controls.Add(variancePlot);
            varianceForm.ShowDialog();
        }
예제 #8
0
        public static void Run(string path)
        {
            ScatterplotView view = new ScatterplotView();

            view.Dock         = System.Windows.Forms.DockStyle.Fill;
            view.LinesVisible = true;

            var outerLimit = new PdfPoint[]
            {
                new PdfPoint(30, 100),
                new PdfPoint(50, 200),
                new PdfPoint(220, 240),
                new PdfPoint(440, 240),
                new PdfPoint(430, 40),
                new PdfPoint(230, 30),
                new PdfPoint(85, 40)
            };

            List <Vertex>   vertices   = new List <Vertex>();
            List <PdfPoint> intersects = new List <PdfPoint>();

            for (int i = 0; i < outerLimit.Count() - 2; i++)
            {
                var vertex = new Vertex(new Line(outerLimit[i], outerLimit[i + 1]), new Line(outerLimit[i + 1], outerLimit[i + 2]));
                DrawVertex(vertex, view, i);
                vertices.Add(vertex);
                if (vertices.Count > 1)
                {
                    var intersection = vertex.AngleBisectorsInterscAt(vertices[i - 1]);
                    if (intersection != null)
                    {
                        intersects.Add((PdfPoint)intersection);
                    }
                }

                if (i == outerLimit.Count() - 3)
                {
                    var vertexFinal = new Vertex(new Line(outerLimit[i + 1], outerLimit[i + 2]), new Line(outerLimit[i + 2], outerLimit.First()));
                    DrawVertex(vertexFinal, view, i + 1);
                    vertices.Add(vertexFinal);
                    var intersection = vertex.AngleBisectorsInterscAt(vertices[i - 1]);
                    if (intersection != null)
                    {
                        intersects.Add((PdfPoint)intersection);
                    }

                    vertexFinal = new Vertex(new Line(outerLimit[i + 2], outerLimit.First()), new Line(outerLimit.First(), outerLimit[1]));
                    DrawVertex(vertexFinal, view, i + 2);
                    vertices.Add(vertexFinal);
                    var intersection2 = vertex.AngleBisectorsInterscAt(vertices[i - 1]);
                    if (intersection2 != null)
                    {
                        intersects.Add((PdfPoint)intersection2);
                    }
                    var intersection3 = vertexFinal.AngleBisectorsInterscAt(vertices.First());
                    if (intersection3 != null)
                    {
                        intersects.Add((PdfPoint)intersection3);
                    }
                }
            }

            List <Tuple <Vertex, PdfPoint, double> > queue = new List <Tuple <Vertex, PdfPoint, double> >();

            for (int v = 1; v < vertices.Count - 1; v++) // one is missing
            {
                var previous = vertices[v - 1];
                var current  = vertices[v];
                var next     = vertices[v + 1];

                var i1 = current.AngleBisectorsInterscAt(previous);
                if (i1.HasValue)
                {
                    var dist1 = Vertex.DistancePointToLine(current.LeftEdge, i1.Value);
                    queue.Add(new Tuple <Vertex, PdfPoint, double>(current, i1.Value, dist1));
                }

                var i2 = current.AngleBisectorsInterscAt(next);
                if (i2.HasValue)
                {
                    var dist2 = Vertex.DistancePointToLine(current.LeftEdge, i2.Value);
                    queue.Add(new Tuple <Vertex, PdfPoint, double>(current, i2.Value, dist2));
                }
            }

            queue = queue.OrderBy(t => t.Item3).ToList();

            foreach (var pop in queue)
            {
            }

            foreach (var point in intersects)
            {
                view.Graph.GraphPane.AddCurve("intersect",
                                              new double[] { (double)point.X },
                                              new double[] { (double)point.Y },
                                              Color.DarkBlue,
                                              ZedGraph.SymbolType.TriangleDown);
            }

            var hole = new PdfPoint[]
            {
                new PdfPoint(175, 85),
                new PdfPoint(245, 140),
                new PdfPoint(315, 90),
                new PdfPoint(385, 160),
                new PdfPoint(330, 200),
                new PdfPoint(165, 180)
            };

            for (int i = 0; i < hole.Count() - 2; i++)
            {
                var vertex = new Vertex(new Line(hole[i], hole[i + 1]), new Line(hole[i + 1], hole[i + 2]));
                DrawVertex(vertex, view, i);

                if (i == hole.Count() - 3)
                {
                    var vertexFinal = new Vertex(new Line(hole[i + 1], hole[i + 2]), new Line(hole[i + 2], hole.First()));
                    DrawVertex(vertexFinal, view, i + 1);

                    var vertexFinal1 = new Vertex(new Line(hole[i + 2], hole.First()), new Line(hole.First(), hole[1]));
                    DrawVertex(vertexFinal1, view, i + 2);

                    var cross = vertexFinal.AngleBisectorsInterscAt(vertexFinal1);
                }
            }

            view.Graph.GraphPane.AxisChange();
            var f1 = new System.Windows.Forms.Form();

            f1.Width  = 600;
            f1.Height = 400;
            f1.Controls.Add(view);
            f1.ShowDialog();
        }
예제 #9
0
        public static void Run(string path)
        {
            // check shape, see http://www.aforgenet.com/articles/shape_checker/
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker()
            {
            };

            float zoom     = 20;
            var   pinkPen  = new Pen(Color.HotPink, zoom * 0.4f);
            var   greenPen = new Pen(Color.GreenYellow, zoom * 0.7f);
            var   aquaPen  = new Pen(Color.Aqua, zoom * 0.7f);
            var   redPen   = new Pen(Color.Red, zoom * 0.4f);
            var   bluePen  = new Pen(Color.Blue, zoom * 0.4f);
            var   blackPen = new Pen(Color.Black, zoom * 0.7f);

            using (var converter = new PdfImageConverter(path))
                using (PdfDocument document = PdfDocument.Open(path))
                {
                    for (var i = 0; i < document.NumberOfPages; i++)
                    {
                        var page       = document.GetPage(i + 1);
                        var paths      = page.ExperimentalAccess.Paths;
                        var geometries = paths.Select(p => new PdfGeometry(p)).ToList();

                        var verticals = geometries.Where(g => g.IsVerticalLine()).ToList();

                        var horizontals = geometries.Where(g => g.IsHorizontalLine()).ToList();


                        using (var bitmap = converter.GetPage(i + 1, zoom))
                            using (var graphics = Graphics.FromImage(bitmap))
                            {
                                var imageHeight = bitmap.Height;

                                foreach (var letter in page.Letters)
                                {
                                    var rect = new Rectangle(
                                        (int)(letter.GlyphRectangle.Left * (decimal)zoom),
                                        imageHeight - (int)(letter.GlyphRectangle.Top * (decimal)zoom),
                                        (int)(letter.GlyphRectangle.Width * (decimal)zoom),
                                        (int)(letter.GlyphRectangle.Height * (decimal)zoom));
                                    graphics.DrawRectangle(pinkPen, rect);
                                }

                                foreach (var p in paths)
                                {
                                    if (p == null)
                                    {
                                        continue;
                                    }
                                    PdfGeometry geometry = new PdfGeometry(p);

                                    var isClosed    = geometry.IsClosed;
                                    var isClockwise = geometry.IsClockwise;

                                    var commands = p.Commands;
                                    var points   = ToOrderedPoints(commands);

                                    if (isClosed) //.SubGeometries.Count > 1)
                                    {
                                        //Scatterplot scatterplot = new Scatterplot();
                                        //scatterplot.Compute(
                                        //    points.Select(po => (double)po.X).Take(31).ToArray(),
                                        //    points.Select(po => (double)po.Y).Take(31).ToArray(),
                                        //    Enumerable.Range(0, points.Count).Take(31).ToArray());
                                        //ScatterplotBox.Show(scatterplot);


                                        ScatterplotView view = new ScatterplotView();
                                        view.Dock         = System.Windows.Forms.DockStyle.Fill;
                                        view.LinesVisible = true;
                                        view.Graph.GraphPane.Title.Text = isClockwise ? "CW" : "CCW";

                                        foreach (var command in commands)
                                        {
                                            if (command is PdfPath.Line line)
                                            {
                                                view.Graph.GraphPane.GraphObjList.Add(new ZedGraph.ArrowObj(
                                                                                          Color.Blue, 10.0f, (double)line.From.X, (double)line.From.Y,
                                                                                          (double)line.To.X, (double)line.To.Y));

                                                view.Graph.GraphPane.AddCurve("",
                                                                              new[] { (double)line.From.X, (double)line.To.X },
                                                                              new[] { (double)line.From.Y, (double)line.To.Y },
                                                                              Color.Red);
                                            }
                                            else if (command is BezierCurve curve)
                                            {
                                                foreach (var lineB in BezierCurveToPaths(curve))
                                                {
                                                    view.Graph.GraphPane.GraphObjList.Add(new ZedGraph.ArrowObj(
                                                                                              Color.Blue, 10.0f, (double)lineB.From.X, (double)lineB.From.Y,
                                                                                              (double)lineB.To.X, (double)lineB.To.Y));

                                                    view.Graph.GraphPane.AddCurve("",
                                                                                  new[] { (double)lineB.From.X, (double)lineB.To.X },
                                                                                  new[] { (double)lineB.From.Y, (double)lineB.To.Y },
                                                                                  Color.Red);
                                                }
                                            }
                                        }


                                        //view.Graph.GraphPane.AddCurve("curve",
                                        //    points.Select(po => (double)po.X).ToArray(),
                                        //    points.Select(po => (double)po.Y).ToArray(),
                                        //    Color.Blue,
                                        //    ZedGraph.SymbolType.Circle);
                                        view.Graph.GraphPane.AxisChange();
                                        var f1 = new System.Windows.Forms.Form();
                                        f1.Width  = 1000;
                                        f1.Height = 1000;
                                        f1.Controls.Add(view);
                                        f1.ShowDialog();
                                    }

                                    var shape   = shapeChecker.CheckShapeType(points);
                                    var subType = shapeChecker.CheckPolygonSubType(points);

                                    var bboxF = GetBoundingRectangle(commands);
                                    if (bboxF.HasValue)
                                    {
                                        var rect = new Rectangle(
                                            (int)(bboxF.Value.Left * (decimal)zoom),
                                            imageHeight - (int)(bboxF.Value.Top * (decimal)zoom),
                                            (int)(bboxF.Value.Width == 0 ? 1 : bboxF.Value.Width * (decimal)zoom),
                                            (int)(bboxF.Value.Height == 0 ? 1 : bboxF.Value.Height * (decimal)zoom));

                                        graphics.DrawRectangle(greenPen, rect);
                                    }

                                    /*foreach (var command in commands)
                                     * {
                                     *  if (command is PdfPath.Line line)
                                     *  {
                                     *      var bbox = line.GetBoundingRectangle();
                                     *      if (bbox.HasValue)
                                     *      {
                                     *          var rect = new Rectangle(
                                     *              (int)(bbox.Value.Left * (decimal)zoom),
                                     *              imageHeight - (int)(bbox.Value.Top * (decimal)zoom),
                                     *              (int)(bbox.Value.Width == 0 ? 1 : bbox.Value.Width * (decimal)zoom),
                                     *              (int)(bbox.Value.Height == 0 ? 1 : bbox.Value.Height * (decimal)zoom));
                                     *          graphics.DrawRectangle(bluePen, rect);
                                     *      }
                                     *  }
                                     *  else if (command is BezierCurve curve)
                                     *  {
                                     *      var bbox = curve.GetBoundingRectangle();
                                     *      if (bbox.HasValue)
                                     *      {
                                     *          var rect = new Rectangle(
                                     *              (int)(bbox.Value.Left * (decimal)zoom),
                                     *              imageHeight - (int)(bbox.Value.Top * (decimal)zoom),
                                     *              (int)(bbox.Value.Width == 0 ? 1 : bbox.Value.Width * (decimal)zoom),
                                     *              (int)(bbox.Value.Height == 0 ? 1 : bbox.Value.Height * (decimal)zoom));
                                     *          graphics.DrawRectangle(redPen, rect);
                                     *      }
                                     *  }
                                     *  else if (command is Close close)
                                     *  {
                                     *      var bbox = close.GetBoundingRectangle();
                                     *      if (bbox.HasValue)
                                     *      {
                                     *          var rect = new Rectangle(
                                     *              (int)(bbox.Value.Left * (decimal)zoom),
                                     *              imageHeight - (int)(bbox.Value.Top * (decimal)zoom),
                                     *              (int)(bbox.Value.Width == 0 ? 1 : bbox.Value.Width * (decimal)zoom),
                                     *              (int)(bbox.Value.Height == 0 ? 1 : bbox.Value.Height * (decimal)zoom));
                                     *          graphics.DrawRectangle(greenPen, rect);
                                     *      }
                                     *  }
                                     *  else if (command is Move move)
                                     *  {
                                     *      var bbox = move.GetBoundingRectangle();
                                     *      if (bbox.HasValue)
                                     *      {
                                     *          var rect = new Rectangle(
                                     *              (int)(bbox.Value.Left * (decimal)zoom),
                                     *              imageHeight - (int)(bbox.Value.Top * (decimal)zoom),
                                     *              (int)(bbox.Value.Width == 0 ? 1 : bbox.Value.Width * (decimal)zoom),
                                     *              (int)(bbox.Value.Height == 0 ? 1 : bbox.Value.Height * (decimal)zoom));
                                     *          graphics.DrawRectangle(greenPen, rect);
                                     *      }
                                     *  }
                                     *  else
                                     *  {
                                     *      throw new NotImplementedException(command.GetType().ToString());
                                     *  }
                                     * }*/
                                }

                                var rectsPaths = RecursiveXYCutPath.Instance.GetBlocks(paths, 0, 10, 10);
                                foreach (var rectPath in rectsPaths)
                                {
                                    var rect = new Rectangle(
                                        (int)(rectPath.Left * (decimal)zoom),
                                        imageHeight - (int)(rectPath.Top * (decimal)zoom),
                                        (int)(rectPath.Width * (decimal)zoom),
                                        (int)(rectPath.Height * (decimal)zoom));
                                    graphics.DrawRectangle(aquaPen, rect);
                                }

                                bitmap.Save(Path.ChangeExtension(path, (i + 1) + "_pathsTest.png"));
                            }
                    }
                }
        }
        private static void DrawROCCurve(int[] trainActual, int[] trainPreds, int[] testActual, int[] testPreds, int predClass, int minNumOccurrences, string modelName)
        {
            // Create a new ROC curve to assess the performance of the model
            string predClassStr = predClass == 0 ? "Neutral" : predClass == 1 ? "Positive" : "Negative";

            Console.WriteLine(
                "* Building ROC curve for {0} vs. Rest",
                predClassStr
                );

            // Build ROC for Train Set
            bool[] trainExpectedClass  = trainActual.Select(x => x == predClass ? true : false).ToArray();
            int[]  trainPredictedClass = trainPreds.Select(x => x == predClass ? 1 : 0).ToArray();

            var trainRoc = new ReceiverOperatingCharacteristic(trainExpectedClass, trainPredictedClass);

            trainRoc.Compute(1000);

            // Get Train AUC
            double trainAUC = trainRoc.Area;

            double[] trainXValues = trainRoc.Points.Select(x => 1 - x.Specificity).ToArray();
            double[] trainYValues = trainRoc.Points.Select(x => x.Sensitivity).ToArray();

            // Build ROC for Test Set
            bool[] testExpectedClass  = testActual.Select(x => x == predClass ? true : false).ToArray();
            int[]  testPredictedClass = testPreds.Select(x => x == predClass ? 1 : 0).ToArray();

            var testRoc = new ReceiverOperatingCharacteristic(testExpectedClass, testPredictedClass);

            testRoc.Compute(1000);

            // Get Test AUC
            double testAUC = testRoc.Area;

            double[] testXValues = testRoc.Points.Select(x => 1 - x.Specificity).ToArray();
            double[] testYValues = testRoc.Points.Select(x => x.Sensitivity).ToArray();

            // Draw ROC Curve with both Train & Test ROC
            ScatterplotView spv = new ScatterplotView();

            spv.Dock         = DockStyle.Fill;
            spv.LinesVisible = true;

            spv.Graph.GraphPane.AddCurve(
                String.Format("Train (AUC: {0:0.00})", trainAUC),
                trainXValues, trainYValues, Color.Green, SymbolType.None
                );
            spv.Graph.GraphPane.AddCurve(
                String.Format("Test (AUC: {0:0.00})", testAUC),
                testXValues, testYValues, Color.Blue, SymbolType.None
                );
            spv.Graph.GraphPane.AddCurve("Random", testXValues, testXValues, Color.Red, SymbolType.None);

            spv.Graph.GraphPane.Title.Text = String.Format(
                "{0} ROC - {1} vs. Rest (# occurrences >= {2})",
                modelName, predClassStr, minNumOccurrences
                );
            spv.Graph.GraphPane.AxisChange();

            Form f1 = new Form();

            f1.Width  = 700;
            f1.Height = 500;
            f1.Controls.Add(spv);
            f1.ShowDialog();
        }