Example #1
0
        public void do_random_forest_analyse(Classifiers.IClassifier cls, double allowErr, Func <double[], double> meFunc, Func <double[], double[]> calcDerivative)
        {
            int[] count = new int[N]; for (int i = 0; i < N; i++)
            {
                count[i] = (Min[i] == Max[i]) ? 1 : NGRID;
            }
            create_grid(count);
            analyse_voronoi();
            analyse_error();


            int n = candidates.Length;

            Console.WriteLine(candidates.Length);
            //int n = grid.Node.Length;
            Classifiers.LabeledData[] ldata = new Classifiers.LabeledData[n];
            int featureCount = 0;

            for (int i = 0; i < n; i++)
            {
                // min, max in locality
                double maxNeighbours = double.MinValue;
                double minNeighbours = double.MaxValue;
                foreach (var neighbour in grid.Neighbours(candidates[i]))
                //foreach (var neighbour in grid.Neighbours(i))
                {
                    double[] calcNeighbour = (double[])grid.Node[neighbour].Clone();
                    this.func.Calculate(calcNeighbour);
                    if (calcNeighbour[calcNeighbour.Length - 1] < minNeighbours)
                    {
                        minNeighbours = calcNeighbour[calcNeighbour.Length - 1];
                    }
                    if (calcNeighbour[calcNeighbour.Length - 1] > maxNeighbours)
                    {
                        maxNeighbours = calcNeighbour[calcNeighbour.Length - 1];
                    }
                }
                // current val
                double[] cuurentNode = (double[])grid.Node[candidates[i]].Clone();
                // double[] cuurentNode = (double[])grid.Node[i].Clone();
                this.func.Calculate(cuurentNode);
                double cuurentNodeVal = cuurentNode[cuurentNode.Length - 1];
                if (cuurentNodeVal < minNeighbours)
                {
                    minNeighbours = cuurentNodeVal;
                }
                if (cuurentNodeVal > maxNeighbours)
                {
                    maxNeighbours = cuurentNodeVal;
                }

                // is real function and approximation are equal, class for point

                //derivative
                double[] derivative = calcDerivative(grid.Node[candidates[i]]);
                //double[] derivative = calcDerivative(grid.Node[i]);

                // build features vector
                double[] features = new double[5 + derivative.Length];
                features[0] = borderdist[i];
                features[1] = error[i];
                features[2] = maxNeighbours;
                features[3] = minNeighbours;
                features[4] = cuurentNodeVal;
                for (int k = 0; k < derivative.Length; k++)
                {
                    features[5 + k] = derivative[k];
                }

                ldata[i]     = new Classifiers.LabeledData(features, 0);
                featureCount = features.Length;
            }
            List <int> newCandidates = new List <int>();

            int[] y = new int[ldata.Length];
            for (int i = 0; i < ldata.Length; i++)
            {
                cls.infer(ldata[i].data, out y[i]);
                if (y[i] == 1)
                {
                    //newCandidates.Add(candidates[i]);
                    newCandidates.Add(i);
                }
            }
            candidates = newCandidates.ToArray();
            Console.WriteLine(candidates.Length);

            xfcandidates = Tools.Sub(grid.Node, candidates);
        }