// Train Network private void button2_Click(object sender, EventArgs e) { if (nn3SO == null) { errorForm = new ErrorForm(); errorForm.setError("Kein Netz gefunden"); errorForm.Visible = true; } else { targets = new double[onodes]; string target; bool error = false; if (checkBox1.Checked) { for (int i = 0; i < onodes; i++) { if (dataGridView1.Rows[i].Cells[6].Value != null) { target = dataGridView1.Rows[i].Cells[6].Value.ToString(); targets[i] = Convert.ToDouble(target); // Console.WriteLine("input : " + targets[i]); } else { error = true; } } readInputs(); if (error == false) { nn3SO.train(inputs, targets); displayResults(); } else { errorForm = new ErrorForm(); errorForm.setError("Keine Targets gefunden"); errorForm.Visible = true; } } else { if (Properties.Settings.Default.ReadAsync == true) { //Console.WriteLine("Async"); _ = ProcessReadAsync(true); } else { for (int i = 0; i < (int)numericUpDown1.Value; i++) { readData(true); displayResults(); } } } } }
// Query Network private void button3_Click(object sender, EventArgs e) { if (nn3SO == null) { errorForm = new ErrorForm(); errorForm.setError("Kein Netz gefunden"); errorForm.Visible = true; } else { if (checkBox1.Checked) { if (checkBox3.Checked) { zeichnen.queryZeichnung(); if (zeichnen.Input != null) { if (zeichnen.CheckColor == true) { int target = readInputs(zeichnen.Input, true); for (int i = 0; i < onodes; i++) { targets[i] = 0.01; } targets[target] = 0.99; nn3SO.queryNN(inputs); displayResults(); performance(target); zeichnen.CheckColor = false; } else { errorForm = new ErrorForm(); errorForm.setError("Es wurde kein Zeichen im Zeichenfeld gefunden!"); errorForm.Visible = true; } } else { errorForm = new ErrorForm(); errorForm.setError("Kein Bild gefunden!"); errorForm.Visible = true; } } else { readInputs(); nn3SO.queryNN(inputs); displayResults(); } anzahlquery++; } else { readData(false); } } }
private async Task ProcessReadAsync(bool train) { if (File != null) { for (int n = 0; n < (int)numericUpDown1.Value; n++) { StreamReader sr = new StreamReader(File); string line; int intTarget; progressBar1.Maximum = System.IO.File.ReadAllLines(File).Length; // Console.WriteLine(System.IO.File.ReadAllLines(File).Length); progressBar1.Visible = true; progressBar1.Step = 1; progressBar1.Value = 0; int uj = 0; while ((line = await sr.ReadLineAsync()) != null && (line != "")) { //Console.WriteLine(uj); uj++; //Console.WriteLine(line); intTarget = readInputs(line, false); for (int i = 0; i < onodes; i++) { targets[i] = 0.01; } targets[intTarget] = 0.99; if (train == true) { nn3SO.train(inputs, targets); displayResults(); } else { nn3SO.queryNN(inputs); displayResults(); } if (checkBox2.Checked) { MessageBox.Show("Next"); } progressBar1.PerformStep(); } progressBar1.Visible = false; progressBar1.Value = 0; } } else { errorForm = new ErrorForm(); errorForm.setError("Keine Daten vorhanden!"); errorForm.Visible = true; } }
private void weightMatritzenToolStripMenuItem_Click(object sender, EventArgs e) { if (nn3SO != null) { weightForm = new WeightMatrForm(); weightForm.viewMatr(nn3SO.WIH, nn3SO.WHO, nn3SO.WeightList); weightForm.Visible = true; } else { errorForm = new ErrorForm(); errorForm.setError("Kein Netz gefunden"); errorForm.Visible = true; } }
private void readMatrData() { if (matrFile != null) { StreamReader sr = new StreamReader(matrFile); string line; List <string> inputlist = new List <string>(); int i, j; double[,] matrix; progressBar1.Maximum = System.IO.File.ReadAllLines(matrFile).Length; // Console.WriteLine(System.IO.File.ReadAllLines(matrFile).Length); progressBar1.Visible = true; progressBar1.Step = 1; progressBar1.Value = 0; while ((line = sr.ReadLine()) != null && (line != "")) { string[] input; input = line.Split('.'); for (i = 0; i < input.Length; i++) { //Console.WriteLine(input[i]); inputlist.Add(input[i]); } progressBar1.PerformStep(); } if (inputlist[0].Equals("Neuronales Netz von Arne Brandt: Matritzen")) { hiddenLayers = Convert.ToInt32(inputlist[1]); // Console.WriteLine("hidden " + hiddenLayers); hnodes = Convert.ToInt32(inputlist[2]); // Console.WriteLine("hnodes " + hnodes); inodes = Convert.ToInt32(inputlist[3]); onodes = Convert.ToInt32(inputlist[4]); createNetwork(); // Console.WriteLine("count " + inputlist.Count()); targets = new double[onodes]; int z = 6; progressBar1.Maximum = hnodes * inodes; progressBar1.Value = 0; for (i = 0; i < hnodes; i++) { for (j = 0; j < inodes; j++) { nn3SO.WIH[i, j] = Convert.ToDouble(inputlist[z]); z++; progressBar1.PerformStep(); } } progressBar1.Maximum = onodes * hnodes; progressBar1.Value = 0; for (i = 0; i < onodes; i++) { for (j = 0; j < hnodes; j++) { nn3SO.WHO[i, j] = Convert.ToDouble(inputlist[z]); z++; progressBar1.PerformStep(); } } progressBar1.Value = 0; if (hiddenLayers != 0) { nn3SO.WeightList.Clear(); progressBar1.Maximum = hnodes * hnodes * hiddenLayers; } else { progressBar1.Maximum = hnodes * hnodes; } for (int k = 0; k < hiddenLayers; k++) { matrix = new double[hnodes, hnodes]; for (i = 0; i < hnodes; i++) { for (j = 0; j < hnodes; j++) { matrix[i, j] = Convert.ToDouble(inputlist[z]); z++; progressBar1.PerformStep(); } } nn3SO.WeightList.Add(matrix); } progressBar1.Value = 0; progressBar1.Visible = false; } else { progressBar1.Value = 0; progressBar1.Visible = false; errorForm = new ErrorForm(); errorForm.setError("Die ausgewählte Datei hat ein falsches Format!"); errorForm.Visible = true; } } }