コード例 #1
0
        private void Btn_GA_Click(object sender, RoutedEventArgs e)
        {
            FileReader fr = new FileReader();

            ListDataSet dsl = fr.ReadFile("DataTest", cc);

            dsl.Normalized();

            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++;
                    }
                }
            }

            FeedForward ff = new FeedForward();

            ff.Initialise(nn, dsl);
            int jumlahBenar = 0;

            for (int i = 0; i < dsl.Count; i++)
            {
                ff.Run(i);
                bool cekData = true;
                for (int j = 0; j < cc.TargetCount; j++)
                {
                    //Console.Write(ff.GetActualClass()[j] + "--> " + cc.GetTarget(dsl[i].ClassName)[j]+" ");
                    if (ff.GetActualClass()[j] != cc.GetTarget(dsl[i].ClassName)[j])
                    {
                        cekData = false;
                        break;
                    }
                }
                if (cekData)
                {
                    jumlahBenar++;
                }
                //Console.WriteLine(ce();kData);
            }
            Console.WriteLine("Dari total " + dsl.Count + " datatest, yang benar adalah " + jumlahBenar);
        }
コード例 #2
0
 public void Initialise(NeuralNetwork nn, ListDataSet dsl, ClassificationClass cc)
 {
     feedForward = new FeedForward();
     feedForward.Initialise(nn, dsl);
     classificationClass = cc;
 }
コード例 #3
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();
            }
        }