Exemple #1
0
        public void start(GeoWave gwRoot)
        {
            calc_least_squares_proximity(inputData, Labels, gwRoot);
            gwRoot.computeNorm();
            gwRoot.level = 0;
            GeoWaveArr.Add(gwRoot);
            recursiveBSP(0);//0 is the root index

            //GeoWave gw_child1 = new GeoWave();
            //GeoWave gw_child2 = new GeoWave();
            //find two childs ()


            //lst.Minimize(,)
            //Minimize()
        }
Exemple #2
0
        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);
            }
        }