예제 #1
0
        public void Run()
        {
            MethodInputResponse inputParams = GetInput();

            //get offsets for output
            int afterPcmOffset = inputParams.InputObjects.Count + inputParams.dimensionsLowerBounds.Count + 10;

            for( int clustersNumber = 3; clustersNumber <= MAX_CLUSTERS_NUMBER; clustersNumber++)
            {
                ShowIndicesTitles(afterPcmOffset * 2, clustersNumber);

                //run FCM to tune initial clusters centers and type-1 memberships
                FCMSolution FCM = new FCMSolution(inputParams, clustersNumber);
                FCM.DegreeOfFuzziness = 1.5;
                int fcmIterationsCounter = 0;
                double oldFcmTarget = double.PositiveInfinity;
                // start FCM iterations
                while (oldFcmTarget > FCM.Target)
                {
                    FCM.UpdateClusterPrototypes();
                    oldFcmTarget = FCM.Target;
                    FCM.UpdatePrimaryMemberships();
                    fcmIterationsCounter++;
                    Application.DoEvents();
                }

                //have some output after FCM
                //ShowResults(FCM, clustersNumber, inputParams, fcmIterationsCounter, 0, "Best FCM with m = " + FCM.DegreeOfFuzziness);

                //run PCM now, using the FCM output
                PCMSolution PCM = new PCMSolution(FCM, inputParams, clustersNumber);
                PCM.estimateEta();
                // iterate m:
                PCM.DegreeOfFuzziness = MIN_M_VALUE;
                int finalIterationsCounter = 0;

                ValidityIndex kwonIndex = new ValidityIndex(IndexType.Kwon);
                ValidityIndex partitionIndex = new ValidityIndex(IndexType.PartitionIndex);
                ValidityIndex xieBeniIndex = new ValidityIndex(IndexType.XieBeni);
                ValidityIndex xieBeni2Index = new ValidityIndex(IndexType.XieBeni2);

                kwonIndex.SetCurrentValue(PCM.GetKwonIndex(), PCM.DegreeOfFuzziness);
                partitionIndex.SetCurrentValue(PCM.GetPartitionIndex(), PCM.DegreeOfFuzziness);
                xieBeniIndex.SetCurrentValue(PCM.GetXieBeniIndex(), PCM.DegreeOfFuzziness);
                xieBeni2Index.SetCurrentValue(PCM.GetXieBeni2Index(), PCM.DegreeOfFuzziness);

                while (PCM.DegreeOfFuzziness < MAX_M_VALUE)
                {
                    RunPcm(PCM, ref finalIterationsCounter);

                    kwonIndex.SetCurrentValue(PCM.GetKwonIndex(), PCM.DegreeOfFuzziness);
                    partitionIndex.SetCurrentValue(PCM.GetPartitionIndex(), PCM.DegreeOfFuzziness);
                    xieBeniIndex.SetCurrentValue(PCM.GetXieBeniIndex(), PCM.DegreeOfFuzziness);
                    xieBeni2Index.SetCurrentValue(PCM.GetXieBeni2Index(), PCM.DegreeOfFuzziness);

                    ShowIndex(afterPcmOffset*2, clustersNumber, 1, PCM.DegreeOfFuzziness, PCM.DegreeOfFuzziness);//m
                    ShowIndex(afterPcmOffset*2, clustersNumber, (int)kwonIndex.IndexType, kwonIndex.CurrentValue, PCM.DegreeOfFuzziness);
                    //ShowIndex(afterPcmOffset, clustersNumber, (int)IndexType.PartitionCoefficient, PCM.GetPartitionCoefficient(), PCM.DegreeOfFuzziness);
                    ShowIndex(afterPcmOffset*2, clustersNumber, (int)partitionIndex.IndexType, partitionIndex.CurrentValue, PCM.DegreeOfFuzziness);
                    ShowIndex(afterPcmOffset*2, clustersNumber, (int)xieBeniIndex.IndexType, xieBeniIndex.CurrentValue, PCM.DegreeOfFuzziness);
                    //ShowIndex(afterPcmOffset, clustersNumber, (int)IndexType.ExtendedXieBeni, PCM.GetExtendedXBIndex(), PCM.DegreeOfFuzziness);
                    //ShowIndex(afterPcmOffset, clustersNumber, (int)IndexType.ExtendedKwon, PCM.GetExtendedKwonIndex(), PCM.DegreeOfFuzziness);
                    ShowIndex(afterPcmOffset*2, clustersNumber, (int)xieBeni2Index.IndexType, xieBeni2Index.CurrentValue, PCM.DegreeOfFuzziness);
                    PCM.DegreeOfFuzziness += DEGREE_OF_FUZZINESS_STEP;
                }

                kwonIndex.SummarizeBounds();
                xieBeniIndex.SummarizeBounds();
                partitionIndex.SummarizeBounds();
                //get upper and lower bounds
                //double ultimateUpper = Math.Min(Math.Min(kwonIndex.UpperBound, xieBeniIndex.UpperBound), partitionIndex.UpperBound);
               // double ultimateLower = Math.Max(Math.Max(kwonIndex.LowerBound, xieBeniIndex.LowerBound), partitionIndex.LowerBound);

                double ultimateUpper = Math.Max(Math.Max(kwonIndex.UpperBound, xieBeniIndex.UpperBound), partitionIndex.UpperBound);
                double ultimateLower = Math.Min(Math.Min(kwonIndex.LowerBound, xieBeniIndex.LowerBound), partitionIndex.LowerBound);

                //display the bounds of m:
                ShowBounds(clustersNumber, xieBeniIndex, kwonIndex, partitionIndex, ultimateLower, ultimateUpper);

                //boundary solutions:
                // left:
                PCMSolution leftSolution = new PCMSolution(FCM, inputParams, clustersNumber);
                leftSolution.estimateEta();
                leftSolution.DegreeOfFuzziness = ultimateLower;
                RunPcm(leftSolution, ref finalIterationsCounter);
                // right:
                PCMSolution rightSolution = new PCMSolution(FCM, inputParams, clustersNumber);
                rightSolution.estimateEta();
                rightSolution.DegreeOfFuzziness = ultimateUpper;
                RunPcm(rightSolution, ref finalIterationsCounter);

                double avgUZoneArea = 0;
                int baseOffset = (int) Math.Round(afterPcmOffset * 2 + Enum.GetNames(typeof(IndexType)).Count() + (MAX_M_VALUE - MIN_M_VALUE)/DEGREE_OF_FUZZINESS_STEP);
                for (int currentCluster = 0; currentCluster < clustersNumber; currentCluster++)
                {
                    double uZoneArea = PCMSolution.GetUZoneArea(leftSolution.PrimaryMemberships, rightSolution.PrimaryMemberships, currentCluster);
                    ShowUZoneArea(baseOffset + currentCluster, currentCluster.ToString(), clustersNumber, uZoneArea);
                    avgUZoneArea += uZoneArea;
                }
                ShowUZoneArea(baseOffset + clustersNumber, "avg", clustersNumber, avgUZoneArea / clustersNumber);

                ShowResults(leftSolution, clustersNumber, inputParams, Enum.GetValues(typeof(IndexType)).Length, "Left bound. m = " + leftSolution.DegreeOfFuzziness);
                ShowResults(rightSolution, clustersNumber, inputParams, afterPcmOffset + Enum.GetValues(typeof(IndexType)).Length, "Right bound. m = " + rightSolution.DegreeOfFuzziness);
            }
            ReleaseExcelStuff();
        }
예제 #2
0
        private void ShowBounds(int clustersNumber, ValidityIndex xb, ValidityIndex kwon, ValidityIndex pi, double resLower, double resUpper)
        {
            myExcel.Worksheet currentWorkSheet = (myExcel.Worksheet)m_ObjWorkBook.Sheets[clustersNumber];
            currentWorkSheet.Name = clustersNumber.ToString() + " clusters";
            currentWorkSheet.Cells[1, 2] = "Lower";
            currentWorkSheet.Cells[1, 3] = "Upper";

            currentWorkSheet.Cells[2, 1] = "XieBeni";
            currentWorkSheet.Cells[2, 2] = xb.LowerBound;
            currentWorkSheet.Cells[2, 3] = xb.UpperBound;

            currentWorkSheet.Cells[3, 1] = "Kwon";
            currentWorkSheet.Cells[3, 2] = kwon.LowerBound;
            currentWorkSheet.Cells[3, 3] = kwon.UpperBound;

            currentWorkSheet.Cells[4, 1] = "PartitionIndex";
            currentWorkSheet.Cells[4, 2] = pi.LowerBound;
            currentWorkSheet.Cells[4, 3] = pi.UpperBound;

            currentWorkSheet.Cells[5, 1] = "Resulting";
            currentWorkSheet.Cells[5, 2] = resLower;
            currentWorkSheet.Cells[5, 3] = resUpper;
        }