예제 #1
0
        private double CalculateFitnessOf(Individual_GA individual, double[][] inputData)
        {
            // Chỗ này chính là chỗ cần dùng với RBF đây
            RadialNetwork rn      = new RadialNetwork(m_RadialNetwork);
            double        fitness = 0.0;

            rn.SetWeights(individual.values);
            fitness            = rn.Accuracy(inputData);
            individual.Fitness = fitness;
            return(fitness);
        }
예제 #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            //Get input from Form
            //Get testing rate
            if (!StringIsNull(txtTestingRate.Text))
            {
                testingRate = double.Parse(txtTestingRate.Text);
            }

            //Get window size
            if (!StringIsNull(txtWindowSize.Text))
            {
                windowSize = int.Parse(txtWindowSize.Text);
            }

            //Step1: Get inputTrain, idealTrain, inputTest, idealTest
            //GetTrainTest(data, out train, out test, testingRate);
            //GetInputIdeal(train, out inputTrain, out idealTrain, windowSize);
            //GetInputIdeal(train, out inputTest, out idealTest, windowSize);
            GetAllData(data, out allData, windowSize);
            double[][] trainData = null;
            double[][] testData  = null;
            int        seed      = 8; // gives a good demo

            GetTrainTest(allData, seed, out trainData, out testData, testingRate);

            Console.WriteLine("\nCreating a 4-5-3 radial basis function network");
            int           numInput  = windowSize;
            int           numHidden = 2 * numInput;
            int           numOutput = 1;
            RadialNetwork rn        = new RadialNetwork(numInput, numHidden, numOutput);

            Console.WriteLine("\nBeginning RBF training\n");
            int maxIterations  = 50;   // max for GA
            int maxEvaluations = 1000; // max for NSGAII
            //double[] bestWeights = rn.TrainWithPSO(trainData, maxIterations);
            //double[] bestWeights = rn.TrainWithGA(trainData, maxIterations);
            Population_NSGA bestPopulation = rn.TrainWithNSGAII(trainData, maxEvaluations);

            Console.WriteLine("\nEvaluating result RBF classification accuracy on the test data");
            //rn.SetWeights(bestWeights);

            double acc = rn.Accuracy(testData);

            //Set Textbox
            SetText(txtTestErr, acc.ToString("F5"));

            Console.WriteLine("Complete Program!");
        }