コード例 #1
0
        private void Btn_Read_Click(object sender, RoutedEventArgs e)
        {
            FileReader  fr  = new FileReader();
            ListDataSet dsl = fr.ReadFile("DataSetBaru", cc);

            dsl.Normalized();

            GeneticAlgorithm ga = new GeneticAlgorithm();

            ga.Initialize(dsl, cc);
            fitChrom = ga.Run();

            for (int i = 0; i < dsl.Count; i++)
            {
                int popCount = 0;
                for (int j = 0; j < fitChrom.Length; j++)
                {
                    if (fitChrom[j] == 0)
                    {
                        dsl[i].RemoveBit(j - popCount);
                        popCount++;
                    }
                }
            }
            Stopwatch sw = Stopwatch.StartNew();

            nn.InitialiseNetwork(dsl[0].AttributeCount, dsl[0].AttributeCount / 2, cc.TargetCount);
            nn.Seed = 0;
            nn.InitialiseWeight();
            BackPropagation bp = new BackPropagation();

            bp.Initialise(nn, dsl, cc);
            bp.Run(500);
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds / 1000.0f);
        }
コード例 #2
0
        private void DoBackPropagation()
        {
            for (int i = 0; i < chromosoms.Count; i++)
            {
                ListDataSet lds = new ListDataSet(listDataSet);

                for (int j = 0; j < lds.Count; j++)
                {
                    int popCount = 0;
                    for (int k = 0; k < chromosoms[i].Length; k++)
                    {
                        if (chromosoms[i][k] == 0)
                        {
                            lds[j].RemoveBit(k - popCount);
                            popCount++;
                        }
                    }
                }

                NeuralNetwork nn = new NeuralNetwork();
                nn.InitialiseNetwork(lds[0].AttributeCount, lds[0].AttributeCount / 2, classificationClass.TargetCount);
                nn.InitialiseWeight();

                BackPropagation bp = new BackPropagation();
                bp.Initialise(nn, lds, classificationClass);
                bp.Run();

                FeedForward ff = new FeedForward();
                ff.Initialise(nn, lds);

                int totalCorrect = 0;
                for (int j = 0; j < lds.Count; j++)
                {
                    ff.Run(j);
                    //nn.Print();

                    //foreach (int ac in ff.GetActualClass())
                    //    Console.Write(ac + " ");
                    //Console.Write(" --> ");
                    //foreach (int ac in classificationClass.GetTarget(lds[j].ClassName))
                    //    Console.Write(ac + " ");
                    //Console.WriteLine();

                    bool  correct     = true;
                    int[] targetClass = classificationClass.GetTarget(lds[j].ClassName);
                    for (int k = 0; k < ff.GetActualClass().Length; k++)
                    {
                        if (targetClass[k] != ff.GetActualClass()[k])
                        {
                            correct = false;
                        }
                    }

                    if (correct)
                    {
                        totalCorrect++;
                    }
                }
                //Console.WriteLine("total: " + totalCorrect + "/" + lds.Count);
                chromosoms[i].FitnessValue = totalCorrect / (float)lds.Count;
                //chromosoms[i].Print();
            }
        }