Example #1
0
        private void recursiveBSP_WaveletsByConsts(List <GeoWave> geoWaveArr, int geoWaveId, int seed = 0)
        {
            //CALC APPROX_SOLUTION FOR GEO WAVE
            double error = geoWaveArr[geoWaveId].calc_MeanValueReturnError(_trainingLabel, geoWaveArr[geoWaveId].pointsIdArray);

            if (error < _rc.approxThresh ||
                geoWaveArr[geoWaveId].pointsIdArray.Count() <= _rc.minWaveSize ||
                _rc.boundDepthTree <= geoWaveArr[geoWaveId].level)
            {
                return;
            }

            int dimIndex      = -1;
            int Maingridindex = -1;

            bool IsPartitionOK = false;

            switch (_rc.split_type)
            {
            case 0:

                IsPartitionOK = getBestPartitionResult(ref dimIndex, ref Maingridindex, geoWaveArr, geoWaveId, error, _dime2Take);
                break;

            case 1:
                IsPartitionOK = getRandPartitionResult(ref dimIndex, ref Maingridindex, geoWaveArr, geoWaveId, error, seed);
                break;

            case 2:
            {
                Random ran1         = new Random(seed);
                Random ran2         = new Random(geoWaveId);
                int    one          = ran1.Next(0, int.MaxValue / 10);
                int    two          = ran2.Next(0, int.MaxValue / 10);
                bool[] Dim2TakeNode = getDim2Take(_rc, one + two);
                IsPartitionOK = getBestPartitionResult(ref dimIndex, ref Maingridindex, geoWaveArr, geoWaveId, error, Dim2TakeNode);
            }
            break;

            case 3:
                IsPartitionOK = getGiniPartitionResult(ref dimIndex, ref Maingridindex, geoWaveArr, geoWaveId, error, _dime2Take);
                break;

            case 4:
            {
                Random ran1         = new Random(seed);
                Random ran2         = new Random(geoWaveId);
                int    one          = ran1.Next(0, int.MaxValue / 10);
                int    two          = ran2.Next(0, int.MaxValue / 10);
                bool[] Dim2TakeNode = getDim2Take(_rc, one + two);
                IsPartitionOK = getGiniPartitionResult(ref dimIndex, ref Maingridindex, geoWaveArr, geoWaveId, error, Dim2TakeNode);
            }
            break;

            case 5:     //local pca at each parent node, recursion inside a case
            {
                recursiveBSP_LocalPCA(geoWaveArr, 0);
                return;
            }
                //break;
            }



            if (!IsPartitionOK)
            {
                return;
            }


            GeoWave child0 = new GeoWave(geoWaveArr[geoWaveId].boubdingBox, _trainingLabel[0].Count(), geoWaveArr[geoWaveId].rc);
            GeoWave child1 = new GeoWave(geoWaveArr[geoWaveId].boubdingBox, _trainingLabel[0].Count(), geoWaveArr[geoWaveId].rc);

            //set partition
            child0.boubdingBox[1][dimIndex] = Maingridindex;
            child1.boubdingBox[0][dimIndex] = Maingridindex;

            //DOCUMENT ON CHILDREN
            child0.dimIndex      = dimIndex;
            child0.Maingridindex = Maingridindex;
            child1.dimIndex      = dimIndex;
            child1.Maingridindex = Maingridindex;

            child0.MaingridValue = Form1.MainGrid[dimIndex][Maingridindex];
            child1.MaingridValue = Form1.MainGrid[dimIndex][Maingridindex];

            //calc norm
            //calc mean value

            if (Form1.isBoxSingular(child0.boubdingBox, _rc.dim) || Form1.isBoxSingular(child1.boubdingBox, _rc.dim))
            {
                return;
            }

            //SHOULD I VERIFY THAT THE CHILD IS NOT ITS PARENT ? (IN CASES WHERE CAN'T MODEFY THE PARTITION)

            setChildrensPointsAndMeanValue(ref child0, ref child1, dimIndex, geoWaveArr[geoWaveId].pointsIdArray);
            //SET TWO CHILDS
            child0.parentID = child1.parentID = geoWaveId;
            child0.child0   = child1.child0 = -1;
            child0.child1   = child1.child1 = -1;
            child0.level    = child1.level = geoWaveArr[geoWaveId].level + 1;

            child0.computeNormOfConsts(geoWaveArr[geoWaveId]);
            child1.computeNormOfConsts(geoWaveArr[geoWaveId]);
            geoWaveArr.Add(child0);
            geoWaveArr.Add(child1);
            geoWaveArr[geoWaveId].child0 = geoWaveArr.Count - 2;
            geoWaveArr[geoWaveId].child1 = geoWaveArr.Count - 1;



            //RECURSION STEP !!!
            recursiveBSP_WaveletsByConsts(geoWaveArr, geoWaveArr[geoWaveId].child0, seed);
            recursiveBSP_WaveletsByConsts(geoWaveArr, geoWaveArr[geoWaveId].child1, seed);
        }