public void do_random_forest_analyse(IClassifierML rg, Func <double[], IFunction, Grid, double[], double[][], int, double[]> build_features) { 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(); //int n = candidates.Length; int n = grid.Node.Length; LabeledData[] ldata = new LabeledData[n]; for (int i = 0; i < grid.Node.Length; i++) { ldata[i] = new LabeledData(build_features(grid.Node[i], this.func, grid, this.dist, xf, i), 0); } candidates = new int[grid.Node.Length]; List <Tuple <double, int> > improveDiffs = new List <Tuple <double, int> >(); for (int i = 0; i < grid.Node.Length; ++i) { Object dist; rg.infer(ldata[i].data, out dist); improveDiffs.Add(new Tuple <double, int>(Convert.ToDouble(dist), i)); } var sortedImproveDiffs = improveDiffs.OrderByDescending((t) => t.Item1).ToList(); for (int i = 0; i < grid.Node.Length; i++) { candidates[i] = sortedImproveDiffs[i].Item2; } xfcandidates = Tools.Sub(grid.Node, candidates); }
public void do_random_forest_analyse(IClassifierML 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_all_error(); int n = grid.Node.Length; LabeledData[] ldata = new LabeledData[n]; LabeledData[] ldata1 = new 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(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[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 int pointClass = 0; if (Math.Abs(meFunc(grid.Node[i]) - cuurentNodeVal) > allowErr) { pointClass = 1; } //derivative double[] derivative = calcDerivative(grid.Node[i]); // build features vector double[] features = new double[2]; features[0] = Math.Abs(cuurentNodeVal - maxNeighbours); features[1] = Math.Abs(minNeighbours - cuurentNodeVal); ldata[i] = new LabeledData(features, 0); ldata1[i] = new LabeledData(features, pointClass); featureCount = features.Length; } List <int> newCandidates = new List <int>(); Object[] y = new Object[ldata.Length]; for (int i = 0; i < ldata.Length; i++) { cls.infer(ldata[i].data, out y[i]); if ((int)y[i] == 1) { newCandidates.Add(i); } } candidates = newCandidates.ToArray(); xfcandidates = Tools.Sub(grid.Node, candidates); }