예제 #1
0
 public FCMSolution(MethodInputResponse input, int clustersNumber)
     : base(input, clustersNumber)
 {
     // random initialization:
     Random gen = new Random();
     // initialize random cluster prototypes:
     for (int j = 0; j < clustersNumber; j++)
     {
         InputObject prototype = new InputObject("");
         foreach (string dimension in input.dimensionsLowerBounds.Keys)
         {
             prototype.Dimensions.Add(dimension, input.dimensionsLowerBounds[dimension] + gen.NextDouble() * (input.dimensionsUpperBounds[dimension] - input.dimensionsLowerBounds[dimension]));
         }
         clusterPrototypes[j] = prototype;
     }
     // initialize random primary memberships:
     for (int j = 0; j < input.InputObjects.Count; j++)
     {
         double[] fuzzyMarkers = new double[clustersNumber + 1];
         fuzzyMarkers[0] = 0;
         fuzzyMarkers[clustersNumber] = 1;
         for (int mcount = 1; mcount < clustersNumber; mcount++)
             do
             {
                 fuzzyMarkers[mcount] = gen.NextDouble();
             } while (fuzzyMarkers[mcount] <= fuzzyMarkers[mcount - 1]);
         for (int mcount = 0; mcount < clustersNumber; mcount++)
             primaryMemberships[mcount, j] = fuzzyMarkers[mcount + 1] - fuzzyMarkers[mcount];
     }
     setTarget();
 }
예제 #2
0
        public CurrentSolution(MethodInputResponse input, int clustersNumber)
        {
            if (input == null)
            {
                Debug.WriteLine("Invalid method input.");
                return;
            }

            methodInput = input;
            this.clustersNumber = clustersNumber;
            primaryMemberships = new double[clustersNumber, input.InputObjects.Count];
               // secondaryMemberships = new Interval[c, n];
            clusterPrototypes = new InputObject[clustersNumber];
            m = 1.05;
        }
예제 #3
0
 public PCMSolution(FCMSolution init, MethodInputResponse input, int clustersCount)
     : base(input, clustersCount)
 {
     eta = new double[clustersNumber];
     D = new double[clustersNumber, methodInput.InputObjects.Count];
     // initialize cluster prototypes (as a result of FCM):
     for (int i = 0; i < clustersNumber; i++)
     {
         clusterPrototypes[i] = new InputObject("");
         clusterPrototypes[i].Dimensions = init.ClusterPrototypes[i].Dimensions;
     }
     // initialize primary memberships (the same way):
     for (int i = 0; i < methodInput.InputObjects.Count; i++)
         for (int j = 0; j < clustersNumber; j++)
             primaryMemberships[j, i] = init.PrimaryMemberships[j, i];
     setD();
     setTarget();
 }
예제 #4
0
        private void ShowResults(CurrentSolution results, int clustersNumber,  MethodInputResponse inputParams, int offset, string title)
        {
            myExcel.Worksheet currentWorkSheet = (myExcel.Worksheet)m_ObjWorkBook.Sheets[clustersNumber];
            currentWorkSheet.Name = clustersNumber.ToString() + " clusters";
            //FCM output
            //Membership values output:
            currentWorkSheet.Cells[offset + 1, 1] = title;
            for (int i = 0; i < clustersNumber; i++)
            {
                currentWorkSheet.Cells[offset + 2, 2 * (i + 1) + 1] = "Cluster " + (i + 1).ToString();
            }
            for (int i = 0; i < inputParams.InputObjects.Count; i++)
            {
                currentWorkSheet.Cells[offset + i + 3, 1] = inputParams.InputObjects[i].Name;
                for (int j = 0; j < clustersNumber; j++)
                {
                    currentWorkSheet.Cells[offset + i + 3, 2 * (j + 1) + 1] = string.Format("{0:0.##########}", results.PrimaryMemberships[j, i]);
                }
            }

            //DSE-s output:
            for (int i = 0; i < clustersNumber; i++)
            {
                currentWorkSheet.Cells[offset + 2, 2 * (i + 1)] = "DSE " + (i + 1).ToString();
            }
            for (int i = 0; i < inputParams.InputObjects.Count; i++)
            {

                for (int j = 0; j < clustersNumber; j++)
                {
                    currentWorkSheet.Cells[offset + i + 3, 2 * (j + 1)] = results.GetSignedEuclidean(inputParams.InputObjects[i], results.ClusterPrototypes[j]);
                }
            }

            //Cluster centres output:
            currentWorkSheet.Cells[offset + inputParams.InputObjects.Count + 4, 1] = "Clusters prototypes:";
            //column captions:
            int rowCount = offset + inputParams.InputObjects.Count + 5;
            foreach (string dimensionName in inputParams.dimensionsLowerBounds.Keys)
            {
                currentWorkSheet.Cells[rowCount, 1] = dimensionName;
                rowCount ++;
            }

            //actual values now:
            for (int i = 0; i < clustersNumber; i++)
            {
                int j = 0;
                foreach (string dimension in inputParams.dimensionsLowerBounds.Keys)
                {
                    currentWorkSheet.Cells[offset + inputParams.InputObjects.Count + 5 + j, i + 2] = results.ClusterPrototypes[i].Dimensions[dimension];
                    j++;
                }
            }
            //currentWorkSheet.Cells[offset + inputParams.InputObjects.Count + 6 + inputParams.dimensionsLowerBounds.Count, 1] = "Iterations count:     " + iterationsCount.ToString();

              //  currentWorkSheet.Columns.AutoFit();
            m_ObjExcel.Visible = true;
            m_ObjExcel.UserControl = true;
        }
예제 #5
0
        private MethodInputResponse GetInput()
        {
            try
            {
                MethodInputResponse inputParameters = new MethodInputResponse();

                //count objects:
                myExcel.Range nameCell = m_ObjWorkSheet1.get_Range("A2", "A2");
                int rowNumber = 2;
                while (nameCell.Text.ToString() != "")
                {
                    //inputParameters.ObjectsQuantity++;
                    InputObject newInputObject = new InputObject(nameCell.Text.ToString());// What's in the A column starting row 2

                    //get the dimensions now; start with the B1 (C1?) and go on along row 1 till run into an empty cell
                   // myExcel.Range dimensionCell = m_ObjWorkSheet1.get_Range("B2", "B2");
                    int columnNumber = 2;
                    myExcel.Range dimensionCell = m_ObjWorkSheet1.get_Range(MethodInputResponse.ALPHABET[columnNumber] + rowNumber.ToString(), MethodInputResponse.ALPHABET[columnNumber] + rowNumber.ToString());

                    while (!String.IsNullOrEmpty(dimensionCell.Text.ToString()))
                    {
                        string dimensionName = "Dimension" + (columnNumber-1);
                        newInputObject.Dimensions.Add(dimensionName, double.Parse(dimensionCell.Text.ToString()));

                        //handle bounds
                        double dimensionLowestValue, dimensionHighestValue;
                        if (inputParameters.dimensionsLowerBounds.TryGetValue(dimensionName, out dimensionLowestValue))
                        {
                            if (dimensionLowestValue > newInputObject.Dimensions[dimensionName])
                            {
                                inputParameters.dimensionsLowerBounds[dimensionName] = newInputObject.Dimensions[dimensionName];
                            }
                        }
                        else
                        {
                            inputParameters.dimensionsLowerBounds.Add(dimensionName, double.PositiveInfinity);
                        }

                        if (inputParameters.dimensionsUpperBounds.TryGetValue(dimensionName, out dimensionHighestValue))
                        {
                            if (dimensionHighestValue < newInputObject.Dimensions[dimensionName])
                            {
                                inputParameters.dimensionsUpperBounds[dimensionName] = newInputObject.Dimensions[dimensionName];
                            }
                        }
                        else
                        {
                            inputParameters.dimensionsUpperBounds.Add(dimensionName, double.NegativeInfinity);
                        }

                        columnNumber++;
                        dimensionCell = m_ObjWorkSheet1.get_Range(MethodInputResponse.ALPHABET[columnNumber] + rowNumber.ToString(), MethodInputResponse.ALPHABET[columnNumber] + rowNumber.ToString());
                    }

                    inputParameters.InputObjects.Add(newInputObject);
                    rowNumber++;
                    nameCell = m_ObjWorkSheet1.get_Range("A" + rowNumber.ToString(), "A" + rowNumber.ToString());
                }

                return inputParameters;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception occured while reading input data " + ex.ToString());
                return new MethodInputResponse();
            }
        }