Nano'nun Günlüğü…

Ideallerimi gerceklestirmek icin arastiriyorum, Unutmamak icin yaziyorum!

  • Bulundugunuz Sayfa: 
  • Ana Sayfa
  • Yapay Sinir Aglari Karakter Tanima Uygulamasi

Yapay Sinir Aglari Karakter Tanima Uygulamasi

Gönderim Aralık 26th, 2012

Bu makale iceriginde Suleyman Demirel Universitesi – Bilgisayar Muhendisligi bolumu’nun Yapay Zeka dersi icin gelistirilen Yapay Sinir Aglari uygulamasinin .Net’de C# programlama dili kullanilarak yapilmis bir ornegini paylasiyor olacagim. Yapay sinir aglari uzerinde incelemis oldugumuz formul ve bilgileri Yapay Sinir Aglari isimli makale icerisinden bilgilere ulasabilirsiniz. Bu makale ise daha cok yapay sinir aglari uzerine calisilmis bir uygulamanin kodlari bulunmaktadir.

Uygulamamizi Visual Studio’nun Windows Form Application ortamini kullanarak yapiyor olacagiz. Oncesinde her bir harfin karsiligi olan bilgileri bir veritabaninda toparlayalim.

Oncelikle SqlServer uzerinde Karakter isminde bir veritabani olusturuyor ve icerisine Karakter isminde bir Tablo olusturuyoruz.

 

 

 

 

 

Icerisine asagidaki gibi verileri giriyoruz.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Karakter.Sql Kaynak Kodlari ;

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Karakter]’) AND type in (N’U’))
DROP TABLE [dbo].[Karakter]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Karakter]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[Karakter](
[KarakterAdi] [nchar](1) COLLATE Turkish_CI_AS NOT NULL,
[KarBinary] [nchar](35) COLLATE Turkish_CI_AS NOT NULL,
[KarCikis] [nchar](35) COLLATE Turkish_CI_AS NOT NULL
)
END
GO
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’A’, N’01110100011000111111100011000110001′, N’00001                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’B’, N’11110100011000111110100011000111110′, N’00010                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’C’, N’01111100001000010000100001000001111′, N’00011                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’D’, N’11100100101000110001100011001011100′, N’00100                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’E’, N’11111100001000011110100001000011111′, N’00101                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’F’, N’11111100001111110000100001000010000′, N’00110                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’G’, N’01110100011000011110100011000101110′, N’00111                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’H’, N’10001100011000111111100011000110001′, N’01000                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’I’, N’00100001000010000100001000010000100′, N’01001                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’J’, N’01110001000010000100001001010001000′, N’01010                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’K’, N’10001100101010011000101001001010001′, N’01011                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’L’, N’10000100001000010000100001000011111′, N’01100                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’M’, N’11011101011010110001100011000110001′, N’01101                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’N’, N’10001110011010110101101011001110001′, N’01110                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’O’, N’01110100011000110001100011000101110′, N’01111                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’P’, N’11110100011000111110100001000010000′, N’10000                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’R’, N’11110100011000111110101001001010001′, N’10001                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’S’, N’01110100011000001110000011000101110′, N’10010                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’T’, N’11111001000010000100001000010000100′, N’10011                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’U’, N’10001100011000110001100011000101110′, N’10100                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’V’, N’10001100011000110001100010101000100′, N’10101                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’Y’, N’10001010100010000100001000010000100′, N’10110                              ‘)
INSERT [dbo].[Karakter] ([KarakterAdi], [KarBinary], [KarCikis]) VALUES (N’Z’, N’11111000010001000100010001000011111′, N’10111                              ‘)

Form1.Cs Kaynak Kodlari ;

using System;
using System.Drawing;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace YapaySinirAgi
{
public partial class Form1 : Form
{ public  SqlConnection con;
public  SqlCommand cmd;
public static System.Random rast = new System.Random();
public string[] HarfVeri = new string[23];
public int [,] GirisVeri=new int[23,35];
public int [,] CikisVeri=new int[23,5];

public double [,] GirisKatmanAgirlik=new double[5,35];
public double[,] AraKatmanY = new double[23,5];
public double[,] AraKatmanAgirlik = new double[5, 5];
public double[,] CikisY = new double[23,5];
public double[] CikisHata = new double[5];
public double[] AraKatmanHata = new double[5];
public double[] GirisHata = new double[35];
public int[] TestVeri = new int[35];
public double[] TestAraY = new double[5];
public double[] TestCikisY = new double[5];
public int adim = 0,iterasyon=0;
public double alfa=0.2,E;
public Button[] BtnArr = new Button[35];

public static double deger()
{
return rast.Next(-100, 100)/100.0;
}

private void Form1_Load(object sender, EventArgs e)
{
con = new SqlConnection(@”Data Source=SEVDANUR-PC\NANO;Initial Catalog=Karakter;Integrated Security=True”);
cmd = new SqlCommand(“Select KarakterAdi,KarBinary,KarCikis from Karakter”, con);
}
public Form1()
{
InitializeComponent();
}

private void tikla(object sender, EventArgs e)
{
Button buton = (Button)sender;
buton.BackColor = (buton.BackColor == Color.White) ? Color.Black : Color.White;
}

private void button36_Click(object sender, EventArgs e)
{
VerileriCekme();
AgirlikDegerAtama();
listBox1.Items.Add(“GirisVeri—————————————–“);
for (int i = 0; i < GirisVeri.GetLength(0); i++)
listBox1.Items.Add(GirisVeri[i, 0] + ” ” + GirisVeri[i, 1] + ” ” + GirisVeri[i, 2] + ” ” + GirisVeri[i, 3] + ” ” + GirisVeri[i, 4] + ” ” + GirisVeri[i, 5] + ” ” + GirisVeri[i, 6] + ” ” + GirisVeri[i, 7] + ” ” + GirisVeri[i, 8] + ” ” + GirisVeri[i, 9] + ” ” + GirisVeri[i, 10] + ” ” + GirisVeri[i, 11] + ” ” + GirisVeri[i, 12] + ” ” + GirisVeri[i, 13] + ” ” + GirisVeri[i, 14] + ” ” + GirisVeri[i, 15] + ” ” + GirisVeri[i, 16] + ” ” + GirisVeri[i, 17] + ” ” + GirisVeri[i, 18] + ” ” + GirisVeri[i, 19] + ” ” + GirisVeri[i, 20] + ” ” + GirisVeri[i, 21] + ” ” + GirisVeri[i, 22] + ” ” + GirisVeri[i, 23] + ” ” + GirisVeri[i, 24] + ” ” + GirisVeri[i, 25] + ” ” + GirisVeri[i, 26] + ” ” + GirisVeri[i, 27] + ” ” + GirisVeri[i, 28] + ” ” + GirisVeri[i, 29] + ” ” + GirisVeri[i, 30] + ” ” + GirisVeri[i, 31] + ” ” + GirisVeri[i, 32] + ” ” + GirisVeri[i, 33] + ” ” + GirisVeri[i, 34]);
listBox1.Items.Add(“Cikisveri—————————————–“);
for (int i = 0; i < CikisVeri.GetLength(0); i++)
listBox1.Items.Add(CikisVeri[i, 0] + ” ” + CikisVeri[i, 1] + ” ” + CikisVeri[i, 2] + ” ” + CikisVeri[i, 3] + ” ” + CikisVeri[i, 4]);
do
{
adim = 0;
do
{
listBox1.Items.Add(“GirisKatmanAgirlik—————————————–“);
for (int i = 0; i < GirisKatmanAgirlik.GetLength(0); i++)
listBox1.Items.Add(GirisKatmanAgirlik[i, 0] + ” ” +GirisKatmanAgirlik[i, 1] + ” ” + GirisKatmanAgirlik[i, 2] + ” ” + GirisKatmanAgirlik[i, 3] + ” ” + GirisKatmanAgirlik[i, 4] + ” ” + GirisKatmanAgirlik[i, 5] + ” ” + GirisKatmanAgirlik[i, 6] + ” ” + GirisKatmanAgirlik[i, 7] + ” ” + GirisKatmanAgirlik[i, 8] + ” ” + GirisKatmanAgirlik[i, 9] + ” ” + GirisKatmanAgirlik[i, 10] + ” ” + GirisKatmanAgirlik[i, 11] + ” ” + GirisKatmanAgirlik[i, 12] + ” ” + GirisKatmanAgirlik[i, 13] + ” ” + GirisKatmanAgirlik[i, 14] + ” ” + GirisKatmanAgirlik[i, 15] + ” ” + GirisKatmanAgirlik[i, 16] + ” ” + GirisKatmanAgirlik[i, 17] + ” ” + GirisKatmanAgirlik[i, 18] + ” ” + GirisKatmanAgirlik[i, 19] + ” ” + GirisKatmanAgirlik[i,20] + ” ” + GirisKatmanAgirlik[i,21] + ” ” + GirisKatmanAgirlik[i,22] + ” ” + GirisKatmanAgirlik[i,23] + ” ” + GirisKatmanAgirlik[i,24] + ” ” + GirisKatmanAgirlik[i,25] + ” ” + GirisKatmanAgirlik[i,26] + ” ” + GirisKatmanAgirlik[i,27] + ” ” + GirisKatmanAgirlik[i,28] + ” ” + GirisKatmanAgirlik[i,29] + ” ” + GirisKatmanAgirlik[i,30] + ” ” + GirisKatmanAgirlik[i,31] + ” ” + GirisKatmanAgirlik[i,32] + ” ” + GirisKatmanAgirlik[i,33] + ” ” + GirisKatmanAgirlik[i,34]);
listBox1.Items.Add(“AraKatmanAgirlik—————————————–“);
for (int i = 0; i < AraKatmanAgirlik.GetLength(0); i++)
listBox1.Items.Add(AraKatmanAgirlik[i,0]+” “+ AraKatmanAgirlik[i,1]+” “+ AraKatmanAgirlik[i,2]+” “+ AraKatmanAgirlik[i,3]+” “+AraKatmanAgirlik[i,4]);
YDegerleri();
listBox1.Items.Add(“AraKatmanY—————————————–“);
for (int i = 0; i < AraKatmanY.GetLength(1); i++)
listBox1.Items.Add(AraKatmanY[adim,i]);
listBox1.Items.Add(“CikisY—————————————–“);
for (int i = 0; i < CikisY.GetLength(1); i++)
listBox1.Items.Add(CikisY[adim,i]);
E = CikisHataMetod();
listBox1.Items.Add(” E” + E);
listBox1.Items.Add(” CikisHata—————————————–“);
for (int i = 0; i < CikisHata.Length; i++)
listBox1.Items.Add(CikisHata[i]);
AraKatmanHataMetod();
listBox1.Items.Add(” AraKatmanHata—————————————–“);
for (int j = 0; j < AraKatmanHata.Length; j++)
listBox1.Items.Add(AraKatmanHata[j]);
AraKatmanYeniAgirlik();
listBox1.Items.Add(“AraKatmanAgirlik—————————————–“);
for (int i = 0; i < AraKatmanAgirlik.GetLength(0); i++)
listBox1.Items.Add(AraKatmanAgirlik[i, 0] + ” ” + AraKatmanAgirlik[i, 1] + ” ” + AraKatmanAgirlik[i, 2] + ” ” + AraKatmanAgirlik[i, 3] + ” ” + AraKatmanAgirlik[i, 4]);
GirisKatmanYeniAgirlik();
listBox1.Items.Add(“GirisKatmanAgirlik—————————————–“);
for (int i = 0; i < GirisKatmanAgirlik.GetLength(0); i++)
listBox1.Items.Add(GirisKatmanAgirlik[i, 0] + ” ” + GirisKatmanAgirlik[i, 1] + ” ” + GirisKatmanAgirlik[i, 2] + ” ” + GirisKatmanAgirlik[i, 3] + ” ” + GirisKatmanAgirlik[i, 4] + ” ” + GirisKatmanAgirlik[i, 5] + ” ” + GirisKatmanAgirlik[i, 6] + ” ” + GirisKatmanAgirlik[i, 7] + ” ” + GirisKatmanAgirlik[i, 8] + ” ” + GirisKatmanAgirlik[i, 9] + ” ” + GirisKatmanAgirlik[i, 10] + ” ” + GirisKatmanAgirlik[i, 11] + ” ” + GirisKatmanAgirlik[i, 12] + ” ” + GirisKatmanAgirlik[i, 13] + ” ” + GirisKatmanAgirlik[i, 14] + ” ” + GirisKatmanAgirlik[i, 15] + ” ” + GirisKatmanAgirlik[i, 16] + ” ” + GirisKatmanAgirlik[i, 17] + ” ” + GirisKatmanAgirlik[i, 18] + ” ” + GirisKatmanAgirlik[i, 19] + ” ” + GirisKatmanAgirlik[i, 20] + ” ” + GirisKatmanAgirlik[i, 21] + ” ” + GirisKatmanAgirlik[i, 22] + ” ” + GirisKatmanAgirlik[i, 23] + ” ” + GirisKatmanAgirlik[i, 24] + ” ” + GirisKatmanAgirlik[i, 25] + ” ” + GirisKatmanAgirlik[i, 26] + ” ” + GirisKatmanAgirlik[i, 27] + ” ” + GirisKatmanAgirlik[i, 28] + ” ” + GirisKatmanAgirlik[i, 29] + ” ” + GirisKatmanAgirlik[i, 30] + ” ” + GirisKatmanAgirlik[i, 31] + ” ” + GirisKatmanAgirlik[i, 32] + ” ” + GirisKatmanAgirlik[i, 33] + ” ” + GirisKatmanAgirlik[i, 34]);
adim++;
} while (adim < 23 && E > 0.1);
iterasyon++;
} while (E > 0.1);
}
public void VerileriCekme()
{   con.Open();
SqlDataReader reader = cmd.ExecuteReader();
int sayac=0;
while (reader.Read())
{
String a = Convert.ToString(reader[“KarakterAdi”]);
HarfVeri[sayac] =a;
a=Convert.ToString(reader[“KarBinary”]);
for (int i = 0; i < GirisVeri.GetLength(1); i++)
GirisVeri[sayac, i] = Convert.ToInt32(a.Substring(i,(1)));
a = Convert.ToString(reader[“KarCikis”]);
for (int i = 0; i < CikisVeri.GetLength(1); i++)
CikisVeri[sayac, i] = Convert.ToInt32(a.Substring(i, (1)));
sayac++;
}
reader.Close();
con.Close();
}
public void AgirlikDegerAtama()
{
for (int i = 0; i < GirisKatmanAgirlik.GetLength(0); i++)
for (int j = 0; j < GirisKatmanAgirlik.GetLength(1); j++)
GirisKatmanAgirlik[i, j] = deger();
for (int i = 0; i < AraKatmanAgirlik.GetLength(0); i++)
for (int j = 0; j < AraKatmanAgirlik.GetLength(1); j++)
AraKatmanAgirlik[i, j] = deger();
}
public void YDegerleri()
{
for (int i = 0; i <AraKatmanY.GetLength(1); i++)
{
double net = 0.0;
for (int j = 0; j < GirisKatmanAgirlik.GetLength(1); j++)
net += (Convert.ToInt16(GirisVeri[adim, j]) * GirisKatmanAgirlik[i, j]);
AraKatmanY[adim,i] = Math.Round((1.0 / (1.0 + Math.Round((Math.Exp(-net)),2))), 2);
}
for (int i = 0; i < CikisY.GetLength(1); i++)
{
double net = 0;
for (int j = 0; j < AraKatmanAgirlik.GetLength(1); j++)
net += (AraKatmanY[adim,j] * AraKatmanAgirlik[i, j]);
CikisY[adim,i] =Math.Round((1 / (1 + Math.Exp(-Math.Round(net,2)))),2);
}
}
public double CikisHataMetod()
{
double toplam = 0;
int a=0;
double b=0.0;
for (int i = 0; i < CikisHata.Length; i++)
{
CikisHata[i] =Math.Round(( CikisY[adim,i] * (1 – CikisY[adim,i]) * (Convert.ToInt16(CikisVeri[adim, i]) – CikisY[adim,i])),2);
a=CikisVeri[0, i];
b=CikisY[adim,i];
toplam += Math.Round((Math.Pow((Convert.ToInt16(CikisVeri[adim, i]) – CikisY[adim,i]),2)),2);
}
listBox1.Items.Add( 0.5 * toplam);
E=0.5 * toplam;
return E;
}
public void AraKatmanHataMetod()
{
for (int j = 0; j < AraKatmanHata.Length; j++)
{
double toplam = 0;
for (int i = 0; i <CikisHata.Length; i++)
{
toplam += CikisHata[i] * AraKatmanAgirlik[i, j];
}
AraKatmanHata[j]=Math.Round(( AraKatmanY[adim,j] * (1 – AraKatmanY[adim,j])*toplam),2);
}
}
public void AraKatmanYeniAgirlik()
{
for (int i = 0; i < AraKatmanAgirlik.GetLength(0); i++)
{
for (int j = 0; j < AraKatmanAgirlik.GetLength(1); j++)
{AraKatmanAgirlik[i,j]=Math.Round((AraKatmanAgirlik[i,j]+(alfa*CikisHata[i]*AraKatmanY[adim,j])),2);
}
}
}
public void GirisKatmanYeniAgirlik()
{
for (int i = 0; i < GirisKatmanAgirlik.GetLength(0); i++)
{
for (int j = 0; j < GirisKatmanAgirlik.GetLength(1); j++)
{
GirisKatmanAgirlik[i, j] = Math.Round((GirisKatmanAgirlik[i, j] + (alfa * AraKatmanHata[i] * GirisVeri[adim,j])),2);
}
}
}
public void TestHesabi()
{
for (int i = 0; i < TestAraY.Length; i++)
{
double net = 0.0;
for (int j = 0; j < GirisKatmanAgirlik.GetLength(1); j++)
net += (TestVeri[j] * GirisKatmanAgirlik[i, j]);
TestAraY[i] = Math.Round((1.0 / (1.0 + Math.Round((Math.Exp(-net)), 2))), 2);
Console.Write(TestAraY[i]+” “);
}
for (int i = 0; i < TestCikisY.Length; i++)
{
double net = 0;
for (int j = 0; j < AraKatmanAgirlik.GetLength(1); j++)
net += (TestAraY[j] * AraKatmanAgirlik[i, j]);
TestCikisY[i] = Math.Round((1 / (1 + Math.Exp(-Math.Round(net, 2)))), 2);
Console.Write(TestCikisY[i] + ” “);
}
}
public void Karsilastirma()
{
for (int i = 0; i < AraKatmanY.GetLength(0); i++)
{
int sayac = 0;
for (int j = 0; j < AraKatmanY.GetLength(1); j++)
{
if (AraKatmanY[i, j] == TestAraY[j]) sayac++;
if (CikisY[i,j] == TestCikisY[j]) sayac++;
}
listBox2.Items.Add(HarfVeri[i] + “= % ” + (sayac * 10));
}
}
private void button37_Click(object sender, EventArgs e)
{
TestDegerleri();
for (int i = 0; i < 35; i++)
{
TestVeri[i] = BtnArr[i].BackColor == Color.Black ? 1 : 0;
listBox1.Items.Add(TestVeri[i]);
}
listBox2.Items.Clear();
TestHesabi();
Karsilastirma();
}
public void TestDegerleri()
{
BtnArr[0] = button1;            BtnArr[1] = button2;            BtnArr[2] = button3;
BtnArr[3] = button4;            BtnArr[4] = button5;            BtnArr[5] = button6;
BtnArr[6] = button7;            BtnArr[7] = button8            BtnArr[8] = button9;
BtnArr[9] = button10;            BtnArr[10] = button11;            BtnArr[11] = button12;
BtnArr[12] = button13;            BtnArr[13] = button14;            BtnArr[14] = button15;
BtnArr[15] = button16;            BtnArr[16] = button17;            BtnArr[17] = button18;
BtnArr[18] = button19;            BtnArr[19] = button20;            BtnArr[20] = button21;
BtnArr[21] = button22;            BtnArr[22] = button23;            BtnArr[23] = button24;
BtnArr[24] = button25;            BtnArr[25] = button26;            BtnArr[26] = button27;
BtnArr[27] = button28;            BtnArr[28] = button29;            BtnArr[29] = button30;
BtnArr[30] = button31;            BtnArr[31] = button32;            BtnArr[32] = button33;
BtnArr[33] = button34;            BtnArr[34] = button35;
}
}
}

Uygulamanin Ekran Goruntusu ;

 

 

 

 

 

 

 

 

 

 

 

Keyifli Calismalar Dilerim…

Etiketler: , , , ,
Bulundugu Konu Etiketleri Visual Studio, Yapay Zeka, Yazilim |

Lutfen Yorumlarinizi Burdan Ulastiriniz!...

You must be Kullanici Adiniz : to post a comment.

Istatistik

  • 1 Uye
  • 334 Yazi
  • 16 Yorum Var