예제 #1
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;
        }
예제 #2
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;
        }