public ListDataSet ReadFile(string path, ClassificationClass cc) { path = path.TrimEnd('\\').TrimEnd('/') + "\\"; DirectoryInfo dirInfo = new DirectoryInfo(path); FileInfo[] fileInfo = dirInfo.GetFiles("*.txt"); ListDataSet dataSetList = new ListDataSet(); foreach (FileInfo fi in fileInfo) { string className = fi.Name.Split('.')[0]; cc.Add(className); StreamReader reader = new StreamReader(path + fi.Name); List <float> attr = new List <float>(); while (!reader.EndOfStream) { attr.Add(float.Parse(reader.ReadLine())); } DataSet ds = new DataSet(attr.Count); ds.ClassName = className; for (int i = 0; i < attr.Count; i++) { ds[i] = attr[i]; } dataSetList.Add(ds); } return(dataSetList); }
public ListDataSet(ListDataSet lds) { dataSetList = new List <DataSet>(); for (int i = 0; i < lds.Count; i++) { dataSetList.Add(new DataSet(lds[i])); } }
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); }
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); }
public void Initialise(NeuralNetwork nn, ListDataSet dsl, ClassificationClass cc) { feedForward = new FeedForward(); feedForward.Initialise(nn, dsl); classificationClass = cc; }
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(); } }
public void Initialize(ListDataSet lds, ClassificationClass cc) { listDataSet = lds; classificationClass = cc; }
public void Initialise(NeuralNetwork nn, ListDataSet dsl) { neuralNetwork = nn; dataSetList = dsl; }