コード例 #1
0
    public static Pixbuf Points(ManagedDNN network, NeuralNetworkOptions opts, double threshold, ManagedArray x, int width, int height, int f1 = 0, int f2 = 0)
    {
        var pixbuf = Common.Pixbuf(width, height, new Color(255, 255, 255));

        Points(pixbuf, network, opts, threshold, x, width, height, f1, f2);

        return(pixbuf);
    }
コード例 #2
0
    public static void Points(Pixbuf pixbuf, ManagedDNN 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);
    }
コード例 #3
0
    protected void OnOpenNetworkButtonClicked(object sender, EventArgs e)
    {
        if (!Paused)
        {
            return;
        }

        LoadJson(ref NetworkFileName, "Load network model", FilenameNetwork);

        if (!string.IsNullOrEmpty(NetworkFileName) && File.Exists(NetworkFileName))
        {
            Network.Free();

            Network = Utility.LoadDNN(GetDirectory(NetworkFileName), GetBaseFileName(NetworkFileName), NormalizationData);

            if (Network != null)
            {
                if (Network.Weights != null && Network.Weights.GetLength(0) > 1)
                {
                    if (Network.Weights[0].x > 0)
                    {
                        InputLayerNodes.Value = Network.Weights[0].x - 1;
                    }

                    if (Network.Weights[0].y > 0)
                    {
                        HiddenLayerNodes.Value = Network.Weights[0].y;
                    }

                    HiddenLayers.Value = Network.Weights.GetLength(0) - 1;

                    if (Network.Weights[Network.Weights.GetLength(0) - 1].y > 0)
                    {
                        Categories.Value = Network.Weights[Network.Weights.GetLength(0) - 1].y;
                    }

                    UpdateHiddenLayerWeightsSelector(HiddenLayerWeightSelector, Network.Weights);
                    UpdateHiddenLayerWeights(Network.Weights);
                    UpdateOutputLayerWeights(Network.Weights);

                    if (NormalizationData != null)
                    {
                        UpdateTextView(ViewNormalization, NormalizationData);
                    }

                    WeightsLoaded = true;
                    TrainingDone  = true;
                }
            }
            else
            {
                Network = new ManagedDNN();
            }
        }
    }
コード例 #4
0
    public static Pixbuf Contour(ManagedDNN network, NeuralNetworkOptions opts, double threshold, ManagedArray x, int width, int height, int f1 = 0, int f2 = 0)
    {
        InitializeContour(11, width, height);

        var m = Rows(x);

        var xplot = new double[width];
        var yplot = new double[height];
        var data  = new double[height, width];

        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;

        // For predict
        for (var i = 0; i < width; i++)
        {
            xplot[i] = minx + i * deltax;
        }

        for (var i = 0; i < height; i++)
        {
            yplot[i] = miny + i * deltay;
        }

        var xx = new ManagedArray(2, height);

        for (var i = 0; i < width; i++)
        {
            for (var j = 0; j < height; j++)
            {
                xx[f1, j] = xplot[i];
                xx[f2, j] = yplot[j];
            }

            var p = network.Predict(xx, opts);

            for (var j = 0; j < height; j++)
            {
                data[i, j] = p[j];
            }

            ManagedOps.Free(p);
        }

        var z = new double[] { 0.6, 0.8, 1 };

        Conrec.Contour(data, xplot, yplot, z, ContourLine);

        Points(ContourGraph, network, opts, threshold, x, width, height, f1, f2);

        ManagedOps.Free(xx);

        var border = new Color(128, 128, 128);

        // Plot bounding box
        var cw = ContourGraph.Width - 1;
        var ch = ContourGraph.Height;

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

        return(ContourGraph);
    }