Example #1
0
        static void TestANNMiner(Dataset dataset)
        {
            IClassificationMeasure measure        = new AccuracyMeasure();
            ILearningMethod        learningMethod = new BackPropagation(0.1, 10, 0.9, false);

            int hiddenUnitCount = dataset.Metadata.Attributes.Length * dataset.Metadata.Target.Length;

            IActivationFunction activationFunction = new SigmoidActivationFunction();

            ISolutionQualityEvaluator <ConnectionDC> evaluator  = new NNClassificationQualityEvaluator(measure, learningMethod, hiddenUnitCount, activationFunction);
            IHeuristicsCalculator <ConnectionDC>     calculator = new DefaultHeuristicCalculator <ConnectionDC>();
            ILocalSearch <ConnectionDC>          localSearch    = new DefaultRemovalLocalSearch <ConnectionDC>(evaluator);
            IComponentInvalidator <ConnectionDC> invalidator    = new NNConnectorInvalidator();

            Problem <ConnectionDC> problem = new Problem <ConnectionDC>(invalidator, calculator, evaluator, localSearch);

            NeuralNetwork network_before = null;
            NeuralNetwork network_final  = SingleTest.CreateNeuralNet_ANNMiner(problem, hiddenUnitCount, true, false, dataset, ref network_before);

            double quilty_before = SingleTest.TestClassifier(network_before, dataset, measure);
            double quilty_final  = SingleTest.TestClassifier(network_final, dataset, measure);

            Console.WriteLine("ANN -" + quilty_before);
            Console.WriteLine("ANN -" + quilty_final);
        }
Example #2
0
        public static void RunANNMiner_QEM()
        {
            AccuracyMeasure testMeasure = new AccuracyMeasure();

            foreach (string dataset in GetDatasetFolds("datasets.txt"))
            {
                //----------------------------------------
                Console.WriteLine("Data Table:" + dataset);
                //----------------------------------------

                foreach (IClassificationMeasure measure in GetMeasures())
                {
                    for (_currentFold = 0; _currentFold < _folds; _currentFold++)
                    {
                        //----------------------------------------
                        Console.WriteLine(dataset + " - Fold:" + _currentFold.ToString() + " - " + measure.ToString());
                        //----------------------------------------

                        DataMining.Data.Dataset[] tables      = LoadTrainingAndTestingData(dataset, _currentFold);
                        DataMining.Data.Dataset   trainingSet = tables[0];
                        DataMining.Data.Dataset   testingSet  = tables[1];

                        double quality_before = 0.0;
                        double quality_final  = 0.0;

                        double size_before = 0.0;
                        double size_final  = 0.0;

                        ILearningMethod learningMethod = new BackPropagation(0.05, 10, 0.9, false);

                        int hiddenUnitCount = (trainingSet.Metadata.Attributes.Length + trainingSet.Metadata.Target.Length);

                        IActivationFunction activationFunction = new SigmoidActivationFunction();

                        NNClassificationQualityEvaluator         evaluator   = new NNClassificationQualityEvaluator(measure, learningMethod, hiddenUnitCount, activationFunction);
                        NNConnectionHeuristicCalculator          calculator  = new NNConnectionHeuristicCalculator(0.7);
                        DefaultRemovalLocalSearch <ConnectionDC> localSearch = new DefaultRemovalLocalSearch <ConnectionDC>(evaluator);
                        NNConnectorInvalidator invalidator = new NNConnectorInvalidator();

                        Problem <ConnectionDC> problem = new Problem <ConnectionDC>(invalidator, calculator, evaluator, localSearch);

                        NeuralNetwork network_before = null;

                        try
                        {
                            NeuralNetwork network_final = SingleTest.CreateNeuralNet_ANNMiner(problem, hiddenUnitCount, true, false, trainingSet, ref network_before);

                            quality_before = SingleTest.TestClassifier(network_before, testingSet, testMeasure);
                            quality_before = Math.Round(quality_before * 100, 2);

                            quality_final = SingleTest.TestClassifier(network_final, testingSet, testMeasure);
                            quality_final = Math.Round(quality_final * 100, 2);

                            size_before = network_before.Size;
                            size_final  = network_final.Size;

                            //----------------------------------------
                            Console.WriteLine("ANNMiner - before:" + dataset + "- Fold:" + _currentFold.ToString() + "=>" + measure.ToString() + ":" + quality_before.ToString());
                            Console.WriteLine("ANNMiner - final:" + dataset + "- Fold:" + _currentFold.ToString() + "=>" + measure.ToString() + ":" + quality_final.ToString());
                            Console.WriteLine("---------------------------------------------------");
                            //----------------------------------------
                            SaveResults(dataset, "ANNMiner - before", measure.ToString(), quality_before.ToString(), size_before.ToString());
                            SaveResults(dataset, "ANNMiner - final", measure.ToString(), quality_final.ToString(), size_final.ToString());
                        }
                        catch (Exception ex)
                        {
                            LogError(ex);
                            break;
                        }
                    }
                }

                Console.WriteLine("---------------------------------------------------");
                Console.WriteLine("---------------------------------------------------");
                Console.WriteLine("---------------------------------------------------");
            }
        }
Example #3
0
        public static void RunANNMiner_NoWis()
        {
            foreach (string dataset in GetDatasetFolds("datasets.txt"))
            {
                //----------------------------------------
                Console.WriteLine("Data Table:" + dataset);
                //----------------------------------------

                double avgQualityBefore = 0;
                double avgSizeBefore    = 0;

                double avgQulityAfter = 0;
                double avgSizeAfter   = 0;

                for (_currentFold = 0; _currentFold < _folds; _currentFold++)
                {
                    //----------------------------------------
                    Console.WriteLine("Fold:" + _currentFold.ToString());
                    //----------------------------------------

                    DataMining.Data.Dataset[] tables      = LoadTrainingAndTestingData(dataset, _currentFold);
                    DataMining.Data.Dataset   trainingSet = tables[0];
                    DataMining.Data.Dataset   testingSet  = tables[1];

                    double quality_before = 0.0;
                    double quality_final  = 0.0;

                    double size_before = 0.0;
                    double size_final  = 0.0;

                    IClassificationMeasure testMeasure    = new AccuracyMeasure();
                    ILearningMethod        learningMethod = new BackPropagation(_acoLearningRateNW, _acoEpochsNW, 0.9, false);

                    //int hiddenUnitCount = trainingSet.Metadata.Attributes.Length * trainingSet.Metadata.Target.Length;
                    int hiddenUnitCount = (trainingSet.Metadata.Attributes.Length + trainingSet.Metadata.Target.Length);

                    IActivationFunction activationFunction = new SigmoidActivationFunction();

                    IClassificationMeasure                   trainingMeasure = new QLFunction();
                    NNClassificationQualityEvaluator         evaluator       = new NNClassificationQualityEvaluator(testMeasure, learningMethod, hiddenUnitCount, activationFunction);
                    NNConnectionHeuristicCalculator          calculator      = new NNConnectionHeuristicCalculator(0.7);
                    DefaultRemovalLocalSearch <ConnectionDC> localSearch     = new DefaultRemovalLocalSearch <ConnectionDC>(evaluator);
                    NNConnectorInvalidator                   invalidator     = new NNConnectorInvalidator();

                    Problem <ConnectionDC> problem = new Problem <ConnectionDC>(invalidator, calculator, evaluator, localSearch);

                    NeuralNetwork network_before = null;

                    try
                    {
                        stopWatch.Reset();
                        stopWatch.Start();
                        NeuralNetwork network_final = SingleTest.CreateNeuralNet_ANNMiner(problem, hiddenUnitCount, false, false, trainingSet, ref network_before);
                        stopWatch.Stop();

                        quality_before    = SingleTest.TestClassifier(network_before, testingSet, testMeasure);
                        quality_before    = Math.Round(quality_before * 100, 2);
                        avgQualityBefore += quality_before;

                        quality_final   = SingleTest.TestClassifier(network_final, testingSet, testMeasure);
                        quality_final   = Math.Round(quality_final * 100, 2);
                        avgQulityAfter += quality_final;

                        size_before = network_before.Size;
                        size_final  = network_final.Size;

                        avgSizeBefore += size_before;
                        avgSizeAfter  += avgSizeAfter;

                        //----------------------------------------
                        Console.WriteLine("ANNMiner - before:" + dataset + "- Fold:" + _currentFold.ToString() + "=>" + testMeasure.ToString() + ":" + quality_before.ToString());
                        Console.WriteLine("ANNMiner - final:" + dataset + "- Fold:" + _currentFold.ToString() + "=>" + testMeasure.ToString() + ":" + quality_final.ToString());
                        Console.WriteLine("---------------------------------------------------");
                        //----------------------------------------
                    }
                    catch (Exception ex)
                    {
                        LogError(ex);
                        break;
                    }
                }

                avgQualityBefore /= _folds;
                avgQulityAfter   /= _folds;

                avgSizeBefore /= _folds;
                avgSizeAfter  /= _folds;

                SaveResults(dataset, "ANNMiner - before", avgQualityBefore.ToString(), avgSizeBefore.ToString(), stopWatch.ElapsedMilliseconds.ToString());
                SaveResults(dataset, "ANNMiner - final", avgQulityAfter.ToString(), avgSizeAfter.ToString(), stopWatch.ElapsedMilliseconds.ToString());


                Console.WriteLine("---------------------------------------------------");
                Console.WriteLine("---------------------------------------------------");
                Console.WriteLine("---------------------------------------------------");
            }
        }