Пример #1
0
        public PoptvrModel PopLearn()
        {
            this.poptvr = new PoptvrModel(this.dataset, this.clusterSetting);
            this.poptvr.initMembership(inputCluster, outputCluster);

            this.poptvr.popLearn();
            FileWriter.WritePopLearnOutput(this.poptvr);

            return this.poptvr;
        }
Пример #2
0
        public static void WritePopLearnOutput(string filename, PoptvrModel poptvr)
        {
            Console.Write("Output InitialWeights.txt ... ");
            FileWriter.WriteToFile(AppConfig.getOutputFolder() + filename + "InitialWeights.txt", poptvr.InitialWeightsString);
            Console.WriteLine("Done!");

            Console.Write("Output SelectedWeights.txt ... ");
            FileWriter.WriteToFile(AppConfig.getOutputFolder() + filename + "SelectedWeights.txt", poptvr.SelectedWeightsString);
            Console.WriteLine("Done!");

            Console.Write("Output FuzzyRulesString.txt ... ");
            FileWriter.WriteToFile(AppConfig.getOutputFolder() + filename + "FuzzyRulesString.txt", poptvr.FuzzyRulesString);
            Console.WriteLine("Done!");
        }
Пример #3
0
        public static string POPTest(PoptvrModel poptvr, DataSet dataset)
        {
            Console.WriteLine("POPTest ....");

            string resultString = "";
            int correct = 0;

            int[] ruleNodes = new int[(int)Math.Pow(poptvr.inputClusterSize, dataset.NumberOfInputNodes)];
            int[] classTotal = new int[dataset.NumberOfOutputNodes];
            int[] classCorrect = new int[dataset.NumberOfOutputNodes];

            for (int i = 0; i < dataset.TotalNumberOfRecords; i++)
            {
                bool correctFlag = false;

                poptvr.forwardFeed(SystemFunctions.getArrayAtRow(dataset.Inputdata, i));
                poptvr.maxRuleNode(ruleNodes);

                double max = poptvr.OutputLayer[0].Output;
                int maxIndex = 0;
                for (int j = 0; j < dataset.NumberOfOutputNodes; j++)
                {
                    resultString += String.Format("{0:F3}\t", poptvr.OutputLayer[j].Output);
                    if (max < poptvr.OutputLayer[j].Output)
                    {
                        max = poptvr.OutputLayer[j].Output;
                        maxIndex = j;
                    }
                }

                for (int j = 0; j < dataset.NumberOfOutputNodes; j++)
                {
                    // calculate the total no. in each class
                    if (dataset.DesiredOutputs[i, j] == 1.0)
                    {
                        classTotal[j]++;
                    }
                    // calculate the correct no. in each class, overall correct
                    if (j == maxIndex)
                    {
                        if (dataset.DesiredOutputs[i, j] == 1.0)
                        {
                            correct++;
                            classCorrect[j]++;
                            correctFlag = true;
                        }
                    }
                }

                if (correctFlag)
                {
                    resultString += "\n";
                }
                else
                {
                    resultString += "X\n";
                }
            }

            for (int i = 0; i < dataset.NumberOfOutputNodes; i++)
            {
                resultString += String.Format("Class [{0:D}]:\t{1:F3}\tpercent\n", i, ((double)classCorrect[i] * 100.0) / (double)classTotal[i]);
            }

            resultString += String.Format("Overall:\t {0:F3}\tpercent\n", (correct * 100.0) / dataset.TotalNumberOfRecords);

            int totalRulesFired = 0;
            for (int i = 0; i < ruleNodes.Length; i++)
            {
                if (ruleNodes[i] != 0)
                {
                    totalRulesFired++;
                }

                resultString += String.Format("ruleNode {0:D}:\t{1:D}\n", i, ruleNodes[i]);
            }

            resultString += String.Format("Total Rules Fired:\t{0:D}\n", totalRulesFired);

            return resultString;
        }
Пример #4
0
        public static int POPTest(PoptvrModel poptvr, double[] data, int numberOfOutputNodes)
        {
            int[] ruleNodes = new int[(int)Math.Pow(poptvr.inputClusterSize, data.Length)];

            poptvr.forwardFeed(data);
            poptvr.maxRuleNode(ruleNodes);

            double max = poptvr.OutputLayer[0].Output;
            int maxIndex = 0;
            for (int j = 0; j < numberOfOutputNodes; j++)
            {
                if (max < poptvr.OutputLayer[j].Output)
                {
                    max = poptvr.OutputLayer[j].Output;
                    maxIndex = j;
                }
            }

            return maxIndex;
        }
Пример #5
0
 public static void WritePopLearnOutput(PoptvrModel poptvr)
 {
     WritePopLearnOutput("", poptvr);
 }
Пример #6
0
        public static PoptvrModel RuleReduction(PoptvrModel poptvr, DataSet dataset, AppConfig appConfig)
        {
            Console.WriteLine("Start RSPOP reduction ..."); 

            double[] CO = new double[dataset.NumberOfOutputNodes * poptvr.OutputClusterSize];
            double[] COr = new double[dataset.NumberOfOutputNodes * poptvr.OutputClusterSize];

            string res = "Removed from total " + poptvr.RuleLayer.Length + "\n";

            for (int k = 0; k < poptvr.RuleLayer.Length; k++)
            {          


                for (int i = 0; i < dataset.TotalNumberOfRecords; i++)
                {
                    Console.Write("at condition " + k + "\t" + "record " + i + "\n");

                    poptvr.forwardFeed(SystemFunctions.getArrayAtRow(dataset.Inputdata, i));
                    for (int j = 0; j < dataset.NumberOfOutputNodes * poptvr.OutputClusterSize; j++)
                    {
                        CO[j] = poptvr.ConsequenceLayer[j].Output;
                    }
               
                    for (int l = 0; l < poptvr.InputClusterSize; l++)
                    {
                        bool deterioration = false;
                        poptvr.RuleLayer[k].PointBlocked = true;
                        poptvr.RuleLayer[k].PointBlockedAt = l;

                        poptvr.forwardFeed(SystemFunctions.getArrayAtRow(dataset.Inputdata, i));
                        for (int j = 0; j < dataset.NumberOfOutputNodes * poptvr.OutputClusterSize; j++)
                        {
                            COr[j] = poptvr.ConsequenceLayer[j].Output;

                            if (COr[j] < CO[j])
                            {
                                deterioration = true;
                            }
                            else
                            {

                                for (int m = 0; m < CO.Length; m++)
                                {
                                    if (COr[j] > CO[m])
                                    {
                                        deterioration = true;
                                        break;
                                    }
                                }
                            }

                            if (deterioration)
                            {
                                break;
                            }
                        }

                        if (!deterioration)
                        {
                            res += (l + " is remove at " + k + "\n");
                            poptvr.RuleLayer[k].PointBlocked = false;
                        }
                        if (deterioration)
                        {
                            poptvr.RuleLayer[k].PointBlocked = false;
                        }
                    }          
                }

            }

            FileWriter fileWriter = new FileWriter(appConfig);
            fileWriter.WriteToFile(appConfig.getOutputFolder() + "Removed Rule.txt", res);
            return poptvr;
        }