public partial class Form1 : Form { public Form1() { InitializeComponent(); tx0.Text = "1"; tx1.Text = "0"; } private void button1_Click(object sender, EventArgs e) { double a = 0, b = 0; bool k1 = double.TryParse(tx0.Text, out a); bool k2 = double.TryParse(tx1.Text, out b); if (k1 && k2) { Random rnd = new Random(); double w1 = rnd.NextDouble(), w2 = rnd.NextDouble(), w3 = rnd.NextDouble(), w4 = rnd.NextDouble(), w5 = rnd.NextDouble(); double wa = rnd.NextDouble(), wb = rnd.NextDouble();//0.0-1.0 arasında ondalıklı rastgele sayilar üretiliyor int[] x1 = { 0, 0, 1, 1 }; int[] x2 = { 0, 1, 0, 1 }; int[] d = { 0, 1, 1, 0 }; double alfa = 0.03; double E = 1; int sayac = 0; double[] A = new double[4]; double[] B = new double[4]; double[] C = new double[4]; double[] Y = new double[4];//Cıktılar double[] ee = new double[4];//Cıktıların hata degerleri while (E != 0) { sayac += 1; for (int i = 0; i < x1.Length; i++) { A[i] = w1 * x1[i] + w2 * x2[i] + a * wa; if (A[i] > 0) C[i] = 1; else C[i] = 0; B[i] = w3 * x1[i] + w4 * x2[i] + C[i] * w5 + b * wb; if (B[i] > 0) Y[i] = 1; else Y[i] = 0; ee[i] = d[i] - Y[i]; double delta_w1 = ee[i] * x1[i] * w5; double delta_w2 = ee[i] * x2[i] * w5; double delta_w3 = ee[i] * x1[i]; double delta_w4 = ee[i] * x2[i]; double delta_w5 = ee[i] * C[i]; double delta_wa = ee[i] * w5; double delta_wb = ee[i]; w1 = w1 + alfa * delta_w1; w2 = w2 + alfa * delta_w2; w3 = w3 + alfa * delta_w3; w4 = w4 + alfa * delta_w4; w5 = w5 + alfa * delta_w5; wa = wa + alfa * delta_wa; wb = wb + alfa * delta_wb; } double net = a * wa + b * wb;//Fnet fonksiyoun double z = 1 / (1 + (Math.Pow(2.718, -net)));//Sigmoid fonksiyonu listBox1.Items.Add(z); double sonuc = 0; for (int j = 0; j < ee.Length; j++) sonuc += Math.Pow(ee[j], 2); E = sonuc; } for (int i = 0; i < listBox1.Items.Count; i++)//Sigmoid fonksiyonun grafiği çiziliyor { this.chart1.Series["İterasyon"].Points.Add((double)listBox1.Items[i]); this.chart1.Series["İterasyon"].Points[i].AxisLabel = i + 1 + ""; } label1.Text = sayac + ""; for (int i = 0; i < Y.Length; i++)//Oluşan son çıktının grafği çiziliyor { this.chart2.Series["İterasyon"].Points.Add(Y[i]); this.chart2.Series["İterasyon"].Points[i].AxisLabel = i + 1 + ""; } for (int i = 0; i < Y.Length; i++) { richTextBox1.Text += ("Beklenen deger=" + d[i] + " " + "Cıktı degeri=" + Y[i] + "\n"); } } } }