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();
            }
        }
Esempio n. 2
0
 public void Initialise(NeuralNetwork nn, ListDataSet dsl, ClassificationClass cc)
 {
     feedForward = new FeedForward();
     feedForward.Initialise(nn, dsl);
     classificationClass = cc;
 }
Esempio n. 3
0
 public void Initialise(NeuralNetwork nn, ListDataSet dsl)
 {
     neuralNetwork = nn;
     dataSetList   = dsl;
 }