private void DecomposeData(DataTable inputData, DataTable labels, double[,] boundingBox) { getBoundingBox(inputData, boundingBox); extendBox(boundingBox, domain_extantion); //SET SURFACEARR List <Surface> SurfaceArr = new List <Surface>(); InitBoundingSurfacesFromBoundingBox(boundingBox, SurfaceArr); setsegments(segments, boundingBox); //SET ROOT WAVELETE GeoWave gwRoot = new GeoWave(); gwRoot.SurfaceArr = Surface.CopyList(SurfaceArr); Form1.setMatrix(gwRoot.boubdingBox, boundingBox); //SET REGION POINTS IDS for (int i = 0; i < inputData.Rows.Count; i++) { gwRoot.pointsIdArray.Add(i); } //BSP BSP bsp = new BSP(inputData, labels, SurfaceArr); bsp.start(gwRoot); }
public GeoWave(double[,] BOX) { parentID = -1; child0 = -1; child1 = -1; level = -1; norm = -1; approx_solution = new double[DecisionTreeForm.dataDim, DecisionTreeForm.labelDim]; boubdingBox = new double[BOX.GetLength(0), BOX.GetLength(1)]; Form1.setMatrix(boubdingBox, BOX); }
private void recursiveBSP(int BSP_Index) { //CALC APPROX_SOLUTION FOR GEO WAVE bool ContinueBSP = calc_least_squares_proximity(inputData, Labels, GeoWaveArr[BSP_Index]); long debog; if (BSP_Index == 10) { debog = 15; } if (ContinueBSP) { //FIND BEST SURFACE (PARTITION) - //SUGGEST SURFACE SurfaceFactory surface_fact = new SurfaceFactory(GeoWaveArr[BSP_Index].SurfaceArr, GeoWaveArr[BSP_Index].boubdingBox); Surface surface = new Surface(); Surface best_surface = new Surface(); GeoWave child0 = new GeoWave(GeoWaveArr[BSP_Index].boubdingBox); GeoWave child1 = new GeoWave(GeoWaveArr[BSP_Index].boubdingBox); GeoWave best_child0 = new GeoWave(); GeoWave best_child1 = new GeoWave(); double error_size = double.MaxValue;; int coordinate_index = -1; int best_coordinate_index = -1; while (surface_fact.getNextSurface(surface, ref coordinate_index)) { //find error size double error = evaluateErrorWithPartition(surface, child0, child1, BSP_Index); //SET BETTER SURFACE - TO REMAIN WITH THE BEST if (error < error_size) { error_size = error; surface.pnt.CopyTo(best_surface.pnt, 0); surface.normal.CopyTo(best_surface.normal, 0); Form1.setMatrix(best_child0.approx_solution, child0.approx_solution); Form1.setMatrix(best_child1.approx_solution, child1.approx_solution); best_child0.proximity = child0.proximity; best_child1.proximity = child1.proximity; best_child0.pointsIdArray.Clear(); best_child1.pointsIdArray.Clear(); best_child0.pointsIdArray = child0.pointsIdArray.ToList(); best_child1.pointsIdArray = child1.pointsIdArray.ToList(); best_coordinate_index = coordinate_index; } } if (error_size < DecisionTreeForm.ApproximationThreshold) { return; } //ADD SURFACE TO SURFACE LIST //int surfaceID = SurfaceArr.Count; //SurfaceArr.Add(best_surface); //AT THIS POINT INEED TO IMPROVE PERFORMANCE SIGNIFICANTLY BY SWITHCING SURFACES IN WAVELETS OR //PASSING SURFACES BY REFERENCE (SAVING MEMORY) //because I might like to ermove surfaces in future code - copy surfaces by value child1.SurfaceArr = Surface.CopyList(GeoWaveArr[BSP_Index].SurfaceArr); child1.SurfaceArr.Add(new Surface(best_surface)); //switch normal direction (for child0) best_surface.normal = best_surface.normal.Multiply(-1); child0.SurfaceArr = Surface.CopyList(GeoWaveArr[BSP_Index].SurfaceArr); child0.SurfaceArr.Add(new Surface(best_surface)); //VERIFY THAT THE NEW SURFACE IS NOT TRIVIAL if (child0.boubdingBox[1, best_coordinate_index] == best_surface.pnt[best_coordinate_index] || child1.boubdingBox[0, best_coordinate_index] == best_surface.pnt[best_coordinate_index]) { return; } //ADJUST BOUNDING BOX child0.boubdingBox[1, best_coordinate_index] = best_surface.pnt[best_coordinate_index]; child1.boubdingBox[0, best_coordinate_index] = best_surface.pnt[best_coordinate_index]; child0.pointsIdArray.Clear(); child1.pointsIdArray.Clear(); child0.pointsIdArray = best_child0.pointsIdArray.ToList(); child1.pointsIdArray = best_child1.pointsIdArray.ToList(); Form1.setMatrix(child0.approx_solution, best_child0.approx_solution); Form1.setMatrix(child1.approx_solution, best_child1.approx_solution); child0.proximity = best_child0.proximity; child1.proximity = best_child1.proximity; //SET TWO CHILDS child0.parentID = child1.parentID = BSP_Index; child0.child0 = child1.child0 = -1; child0.child1 = child1.child1 = -1; child0.level = child1.level = GeoWaveArr[BSP_Index].level + 1; child0.computeNorm(GeoWaveArr[BSP_Index]); child1.computeNorm(GeoWaveArr[BSP_Index]); //set ids of surfs... - tbd !!!! GeoWaveArr.Add(child0); GeoWaveArr.Add(child1); GeoWaveArr[BSP_Index].child0 = GeoWaveArr.Count - 2; GeoWaveArr[BSP_Index].child1 = GeoWaveArr.Count - 1; //RECURSION STEP !!! recursiveBSP(GeoWaveArr[BSP_Index].child0); recursiveBSP(GeoWaveArr[BSP_Index].child1); } }
private double evaluateErrorWithPartition(Surface surface, GeoWave child0, GeoWave child1, int BSP_Index) { //SET TOW MATRICES ACCORDING TO POINTS BISECTIONS //CLEAR LIST BEFORE ITS NEW SETTING child0.pointsIdArray.Clear(); child1.pointsIdArray.Clear(); //GO OVER ALL POINTS int n_points = GeoWaveArr[BSP_Index].pointsIdArray.Count; double[,] upperMatrix = new double[n_points, dim]; double[,] lowerMatrix = new double[n_points, dim]; double[,] upperB = new double[n_points, Labels.Columns.Count]; double[,] lowerB = new double[n_points, Labels.Columns.Count]; int low_row_counter = 0; int up_row_counter = 0; for (int i = 0; i < n_points; i++) { //GET POINT BY INDEX int index = GeoWaveArr[BSP_Index].pointsIdArray[i]; double[] point = new double[inputData.Columns.Count]; Form1.setdataRow(inputData.Rows[index], point); double[] lbl = new double[Labels.Columns.Count]; Form1.setdataRow(Labels.Rows[index], lbl); if (surface.IsPntBelow(point)) { lowerMatrix.SetRow(low_row_counter, point); lowerB.SetRow(low_row_counter, lbl); child0.pointsIdArray.Add(index); low_row_counter++; } else { upperMatrix.SetRow(up_row_counter, point); upperB.SetRow(up_row_counter, lbl); child1.pointsIdArray.Add(index); up_row_counter++; } } double lower_error = 0; double upper_error = 0; if (low_row_counter > 0) { double[,] lower_matrix = new double[low_row_counter, dim]; Form1.setMatrix(lower_matrix, lowerMatrix); double[,] lower_B = new double[low_row_counter, Labels.Columns.Count]; Form1.setMatrix(lower_B, lowerB); lower_error = calc_least_squares_proximity(lower_matrix, lower_B, child0); } if (up_row_counter > 0) { double[,] upper_matrix = new double[up_row_counter, dim]; Form1.setMatrix(upper_matrix, upperMatrix); double[,] upper_B = new double[up_row_counter, Labels.Columns.Count]; Form1.setMatrix(upper_B, upperB); upper_error = calc_least_squares_proximity(upper_matrix, upper_B, child1); } return(lower_error + upper_error); }