Exemple #1
0
        static void TestBackProbagation(Dataset dataset)
        {
            IActivationFunction activationFunction = new SigmoidActivationFunction();
            //int hiddenUnitCount = dataset.Metadata.Attributes.Length * dataset.Metadata.Target.Length;

            int hiddenUnitCount = (dataset.Metadata.Attributes.Length + dataset.Metadata.Target.Length) / 2;

            NeuralNetwork network = SingleTest.CreateNeuralNet_BP(dataset, hiddenUnitCount, 0.9, 0.01, 1000, activationFunction);

            AccuracyMeasure measure = new AccuracyMeasure();

            double quality = SingleTest.TestClassifier(network, dataset, measure);

            Console.WriteLine(measure.ToString() + ":" + Math.Round(quality * 100, 2));
            Console.WriteLine("Size:" + network.Size);
        }
Exemple #2
0
        public static void RunBackPropagation()
        {
            foreach (string dataset in GetDatasetFolds("datasets.txt"))
            {
                //----------------------------------------
                Console.WriteLine("Data Table:" + dataset);
                //----------------------------------------

                double avgQuality = 0;
                double avgSize    = 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 = 0.0;
                    double size    = 0.0;

                    AccuracyMeasure     testMeasure        = new AccuracyMeasure();
                    IActivationFunction activationFunction = new SigmoidActivationFunction();

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

                    try
                    {
                        stopWatch.Reset();
                        stopWatch.Start();
                        NeuralNetwork network = SingleTest.CreateNeuralNet_BP(trainingSet, hiddenUnitCount, 0.9, _bpLearningRate, _bpEpochs, activationFunction);
                        stopWatch.Stop();

                        quality = SingleTest.TestClassifier(network, testingSet, testMeasure);
                        quality = Math.Round(quality * 100, 2);
                        size    = network.Size;

                        avgQuality += quality;
                        avgSize    += size;

                        //----------------------------------------
                        Console.WriteLine("Backprop:" + dataset + "- Fold:" + _currentFold.ToString() + "=>" + testMeasure.ToString() + ":" + quality.ToString());
                        Console.WriteLine("---------------------------------------------------");
                        //----------------------------------------
                    }
                    catch (Exception ex)
                    {
                        LogError(ex);
                        break;
                    }
                }

                avgQuality /= _folds;
                avgSize    /= _folds;
                SaveResults(dataset, "BackProp", avgQuality.ToString(), avgSize.ToString(), stopWatch.ElapsedMilliseconds.ToString());


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