Esempio n. 1
0
    public static void Points(Pixbuf pixbuf, ManagedNN network, NeuralNetworkOptions opts, double threshold, ManagedArray x, int width, int height, int f1 = 0, int f2 = 0)
    {
        var m = Rows(x);

        minx = Double.MaxValue;
        maxx = Double.MinValue;

        miny = Double.MaxValue;
        maxy = Double.MinValue;

        f1 = f1 >= 0 && f1 < Cols(x) ? f1 : 0;
        f2 = f2 >= 0 && f2 < Cols(x) ? f2 : 0;

        for (var j = 0; j < m; j++)
        {
            minx = Math.Min(x[f1, j], minx);
            maxx = Math.Max(x[f1, j], maxx);

            miny = Math.Min(x[f2, j], miny);
            maxy = Math.Max(x[f2, j], maxy);
        }

        deltax = (maxx - minx) / width;
        deltay = (maxy - miny) / height;

        minx = minx - 8 * deltax;
        maxx = maxx + 8 * deltax;
        miny = miny - 8 * deltay;
        maxy = maxy + 8 * deltay;

        deltax = (maxx - minx) / width;
        deltay = (maxy - miny) / height;

        var colors = Common.Palette2();

        colors.Shuffle();

        var PlotOptions = opts;

        PlotOptions.Items = Rows(x);

        var classification = network.Classify(x, PlotOptions, threshold);

        Points(pixbuf, x, classification, colors, f1, f2);

        // Plot bounding box
        var cw     = pixbuf.Width - 1;
        var ch     = pixbuf.Height;
        var border = new Color(128, 128, 128);

        Common.Line(pixbuf, 0, 1, cw, 1, border);
        Common.Line(pixbuf, cw, 1, cw, ch, border);
        Common.Line(pixbuf, 0, ch, cw, ch, border);
        Common.Line(pixbuf, 0, 1, 0, ch, border);

        ManagedOps.Free(classification);
    }
    protected void Classify()
    {
        var test = DataTestSet.Buffer.Text.Trim();

        if (string.IsNullOrEmpty(test))
        {
            return;
        }

        if (NetworkSetuped && SetupTestData(test))
        {
            var TestOptions = Options;

            TestOptions.Items = TestData.y;

            var classification = Network.Classify(TestData, TestOptions, Threshold.Value / 100);

            Classification.Buffer.Clear();

            string text = "";

            for (var i = 0; i < classification.x; i++)
            {
                text += Convert.ToString(classification[i], ci);

                if (i < classification.x - 1)
                {
                    text += "\n";
                }
            }

            Classification.Buffer.Text = text;

            classification.Free();
        }

        DataTestSet.Buffer.Text = test;
    }