private void TrainBtn_Click(object sender, EventArgs e) { UserInput.Clear(); length = Input1.GetArray().Length; hfm = new HopfieldModel(length, inputN); for (int i = 1; i <= inputN; i++) { DrawControl.DrawBox d = (DrawControl.DrawBox) this.Controls.Find("Input" + i, true)[0]; bool[] array = d.GetArray(); int[] n = new int[array.Length]; Console.WriteLine(array.Length); for (int j = 0; j < array.Length; j++) { if (array[j]) { n[j] = 1; } else { n[j] = -1; } } hfm.pushData(n); } hfm.GenerateWeight(); DisplayUser(true); //int[] n4 = new int[] { 1, 1, 1, -1, 1, -1 }; //hfm.SetInput(n4); }
private void TrainBtn_Click(object sender, EventArgs e) { if (locked) { return; } double a; double t; try { a = Convert.ToDouble(Tb1.Text); t = Convert.ToDouble(Tb2.Text); } catch { ErrorAnimator.ShowSync(error); return; } error.Hide(); locked = true; pm = new PerceptronModel(t, a, Input1.GetArray().Length, output1.GetArray().Length, this); for (int i = 1; i <= MAX; i++) { double[] tmpIN = new double[Input1.GetArray().Length]; double[] tmpOUT = new double[output1.GetArray().Length]; bool[] tmp; DrawControl.DrawBox d1 = (DrawControl.DrawBox) this.Controls.Find("Input" + i, true)[0]; DrawControl.DrawBox d2 = (DrawControl.DrawBox) this.Controls.Find("output" + i, true)[0]; d1.locked = true; d2.locked = true; Log.AppendText("Pattern " + i + " \n"); tmp = d1.GetArray(); for (int j = 0; j < tmp.Length; j++) { tmpIN[j] = (tmp[j]) ? 1 : 0; } tmp = d2.GetArray(); for (int j = 0; j < tmp.Length; j++) { tmpOUT[j] = (tmp[j]) ? 1 : -1; } Log.AppendText("(" + String.Join(",", tmpIN) + ")\n(" + String.Join(",", tmpOUT) + ")\n\n"); Data d = new Data(tmpIN, tmpOUT); pm.q.Enqueue(d); } pm.GenerateWeight(); pm.Train(); }