Jaringan Saraf Tiruan Propagasi Balik Tiga Faktor Dalam Pengenalan Sidik Jari
LAMPIRAN A. LISTING PROGRAM Form Login.vb
Imports MySql Imports MySql.Data Imports MySql.Data.MySqlClient Public Class FormLogIn Private Sub BtnLoginClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLogin.Click If UsernameTxt.Text = String.Empty Then MsgBox("Username tidak boleh kosong..") UsernameTxt.Focus() Exit Sub End If Dim dr As MySqlDataReader dr = fetchData("SELECT COUNT(*) FROM user WHERE username='" & UsernameTxt.Text & "' AND password=MD5('" & PassTxt.Text & "');") dr.Read() If dr.GetValue(0) > 0 Then FormUtama.StatusLbl.Text = UsernameTxt.Text buttonCond(True) Me.Close() Else MsgBox("Username tidak cocok dengan password") End If dr.Close() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Close() End Sub End Class
Form Image Processing.vb
Module ImageProcessing Dim xMask(,) As Single = New Single(,) {{-1, 0, 1}, _ {-2, 0, 2}, _ {-1, 0, 1}} Dim yMask(,) As Single = New Single(,) {{1, 2, 1}, _ {0, 0, 0}, _ {-1, -2, -1}} Public Function mini(ByVal a As Integer, ByVal b As Integer) As Integer Return IIf(a > b, b, a) End Function Public Function maks(ByVal a As Integer, ByVal b As Integer) As Integer Return IIf(a > b, a, b) End Function Public Function SobelDetect(ByVal inImg As Bitmap) As Bitmap Dim out As New Bitmap(inImg.Width, inImg.Height, Imaging.PixelFormat.Format32bppArgb) For y As Integer = 0 To inImg.Height - 1 For x As Integer = 0 To inImg.Width - 1 Dim gradX As Single = 0 Dim gradY As Single = 0 Dim grad As Single = 0 If x = 0 Or y = 0 Or x = inImg.Width - 1 Or y = inImg.Height - 1 Then grad = 0 Else For i As Integer = -1 To 1 For j As Integer = -1 To 1 Dim p As Color = inImg.GetPixel(x + i, y + j)
Dim intensity As Single = 0.333F * (CInt(p.R) + p.G + p.B) gradX += intensity * xMask(i + 1, j + 1) gradY += intensity * yMask(i + 1, j + 1) Next Next ‘Menghitung gradient deteksi tepi grad = (Math.Abs(gradX) + Math.Abs(gradY)) End If grad = Math.Max(0, grad) grad = Math.Min(255, grad) out.SetPixel(x, y, Color.FromArgb(CInt(grad), CInt(grad), CInt(grad))) Next Next Return out End Function ‘Membuat Rumus Binerisasi Public Function Binerisasi(ByVal inImg As Bitmap) As Bitmap Dim x, y, y2, x2 As Integer Dim gray As Integer Dim out As New Bitmap(inImg.Width, inImg.Height, Imaging.PixelFormat.Format32bppArgb) Dim localthreshold As Integer For y = 0 To inImg.Height - 1 Step For x = 0 To inImg.Width - 1 Step 16 localthreshold = 0 With inImg.GetPixel(x2, y2) gray = 0.3 * .R + 0.3 * .G + 0.3 * .B End With Next Next gray = 0.3 * .R + 0.3 * .G + 0.3 * .B End With If gray <= localthreshold Then out.SetPixel(x2, y2, Color.FromArgb(255, 0, 0, 0)) Else out.SetPixel(x2, y2, Color.FromArgb(255, 255, 255, 255)) End If Next Next Next Next Return out End Function ‘Matriks Tampilan buat Ekstraksi Fitur Private Sub updateMat(ByRef m1 As Integer(,), ByRef m2 As Integer(,), ByVal h As Long, ByVal w As Long) For y = 0 To h - 1 For x = 0 To w - 1 m1(y, x) = m2(y, x) Next Next End Sub ‘Ekstraksi Fitur Public Function Haar(ByVal inImg As Bitmap) Dim out As New Bitmap(inImg.Width, inImg.Height, Imaging.PixelFormat.Format24bppRgb) Dim minS, maxS As Integer Dim threshold As Integer threshold = 0 minS = 255 maxS = 0 Dim gambar As Bitmap = inImg Dim matriks = New Integer(inImg.Height + 2, inImg.Width + 2) {} Dim res = New Integer(inImg.Height + 2, inImg.Width + 2) {} Dim s As Integer For y = 0 To inImg.Height - 1 For x = 0 To inImg.Width - 1
With gambar.GetPixel(x, y) s = (CInt(.R) + .G + .B) * 0.3 matriks(y, x) = s End With Next Next ‘Menentukan level wavelet yang diinginkan Dim lv As Integer lv = 4 ‘Perhitungan wavelet For h = 0 To lv For y = 0 To inImg.Height / Math.Pow(2, h) - 1 Dim half As Long half = inImg.Width / Math.Pow(2, h) If half Mod 2 <> 0 Then half += 1 End If For x = 0 To half Step 2 res(y, x / 2) = (matriks(y, x) + matriks(y, x + 1)) / 2 Next Dim c As Integer For x = half To 2 * half Step 2 res(y, x / 2) = (res(y, c) - matriks(y, c * 2)) Next Next updateMat(matriks, res, inImg.Height, inImg.Width) For x = 0 To inImg.Width / Math.Pow(2, h) - 1 Dim half As Long half = inImg.Height / Math.Pow(2, h) If half Mod 2 <> 0 Then half -= 1 End If For y = 0 To half Step 2 res(y / 2, x) = (matriks(y, x) + matriks(y + 1, x)) / 2 Next Dim c As Integer c = 0 Next Next updateMat(matriks, res, inImg.Height, inImg.Width) Next For y = 0 To inImg.Height - 1 For x = 0 To inImg.Width - 1 Dim tmp As Integer tmp = res(y, x) out.SetPixel(x, y, Color.FromArgb(255, tmp, tmp, tmp)) Next Next Dim k As Single Dim m As Integer Dim n As Integer m = 0 n = 0 For y = 0 To inImg.Height / Math.Pow(2, lv) - 1 For x = 0 To inImg.Width / Math.Pow(2, lv) - 1 If res(y, x) > 0 Then m += res(y, x) Else n += -res(y, x) End If Next Next k = maks(Math.Abs(m), Math.Abs(n)) FormSidik.HasilTxt.Clear() THasil = "" For y = 0 To inImg.Height / Math.Pow(2, lv) - 1 For x = 0 To inImg.Width / Math.Pow(2, lv) - 1
Dim tmp As Single tmp = Math.Round(res(y, x) / k, 6) FormSidik.HasilTxt.Text &= tmp & " " THasil &= tmp & " " Next Next 'Return out FormSidikUji.HasilTxt.Clear() THasil2 = "" For y = 0 To inImg.Height / Math.Pow(2, lv) - 1 For x = 0 To inImg.Width / Math.Pow(2, lv) - 1 Dim tmp As Single tmp = Math.Round(res(y, x) / k, 6) FormSidikUji.HasilTxt.Text &= tmp & " " THasil2 &= tmp & " " Next Next Return out End Function End Module
Form Pengguna.vb
Imports MySql Imports MySql.Data Imports MySql.Data.MySqlClient Public Class FormPengguna Public Sub buttonState1() SimpanBtn.Enabled = True UbahBtn.Enabled = False BatalBtn.Enabled = False HapusBtn.Enabled = False End Sub Public Sub buttonState2() SimpanBtn.Enabled = False UbahBtn.Enabled = True BatalBtn.Enabled = True HapusBtn.Enabled = True End Sub Public Sub newId() Dim ds As New DataSet Dim dr As MySqlDataReader dr = fetchData("SELECT COUNT(*) FROM user;") dr.Read() Dim n As Integer Dim temp As Boolean = False n = dr.Item(0) dr.Close() While temp = False Dim kd As String kd = "U" & n.ToString dr = fetchData("SELECT COUNT(*) FROM user WHERE id='" & kd & "'") dr.Read() If (dr.Item(0) > 0) Then Else temp = True End If dr.Close() End While KdPenggunaTxt.Text = "U" & n.ToString End Sub Public Sub fillDG(ByVal q As String) Dim dt As DataTable dt = FetchDataTable(q) If dt.Rows.Count = 0 Then MsgBox("Data pengguna tidak ditemukan") End If DataGridView1.DataSource = dt End Sub Private Sub FormPengguna_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load newId() buttonState1() fillDG("SELECT * FROM user") End Sub Private Sub BatalBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BatalBtn.Click newId() UsernameTxt.Clear() PassTxt.Clear() ConfPassTxt.Clear() buttonState1() DataGridView1.ClearSelection() UsernameTxt.Focus() End Sub Private Sub SimpanBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpanBtn.Click If UsernameTxt.Text = "" Then MsgBox("Isikan nama pengguna") UsernameTxt.Focus() ElseIf ConfPassTxt.Text <> PassTxt.Text Then MsgBox("Password tidak sesuai") ConfPassTxt.Focus() Else Dim dr As MySqlDataReader dr = fetchData("SELECT COUNT(*) FROM user WHERE username='" & UsernameTxt.Text & "'") dr.Read() If (dr.Item(0) > 0) Then MsgBox("Nama pengguna sudah terdaftar") Exit Sub End If dr.Close() RunQuery("INSERT INTO user(id, username, password) VALUES ('" & KdPenggunaTxt.Text & "','" & UsernameTxt.Text & "',MD5('" & PassTxt.Text & "'))") newId() UsernameTxt.Clear() PassTxt.Clear() ConfPassTxt.Clear() UsernameTxt.Focus() End If End Sub Private Sub UbahBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UbahBtn.Click If UsernameTxt.Text = "" Then MsgBox("Nama pengguna tidak boleh kosong") Else RunQuery("UPDATE user SET username='" & UsernameTxt.Text & "', password=MD5('" & PassTxt.Text & "') WHERE id='" & KdPenggunaTxt.Text & "'") fillDG("SELECT * FROM user") newId() UsernameTxt.Clear() PassTxt.Clear() ConfPassTxt.Clear() buttonState1() UsernameTxt.Focus() End If End Sub Private Sub HapusBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HapusBtn.Click If MsgBox("Apakah anda benar - benar yakin ingin menghapus user ini ?", MsgBoxStyle.YesNo) = vbYes Then RunQuery("DELETE FROM user WHERE id='" & KdPenggunaTxt.Text & "'")
fillDG("SELECT * FROM user") newId() UsernameTxt.Clear() PassTxt.Clear() ConfPassTxt.Clear() buttonState1() UsernameTxt.Focus() End If End Sub Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick buttonState2() KdPenggunaTxt.Text = DataGridView1.SelectedRows(0).Cells(0).Value UsernameTxt.Text = DataGridView1.SelectedRows(0).Cells(1).Value PassTxt.Focus() End Sub End ClassForm Sidik Jari.vb
Imports MySql Imports MySql.Data Imports MySql.Data.MySqlClient Public Class FormSidik Private Sub resetState() btn_start() ClearBtn.PerformClick() OpenFileDialog1.FileName = "" NamaPemilikTxt.Clear() AlamatTxt.Clear() JenisKelaminCombo.SelectedIndex = -1 fillDG("SELECT * FROM identitas") TxtOutput.Clear() BrowseBtn.Focus() End Sub Public Sub newId() Dim ds As New DataSet Dim dr As MySqlDataReader dr = fetchData("SELECT COUNT(*) FROM identitas;") dr.Read() Dim n As Integer Dim temp As Boolean = False n = dr.Item(0) + 1 dr.Close() While temp = False Dim kd As String kd = "ID" & n.ToString dr = fetchData("SELECT COUNT(*) FROM identitas WHERE id='" & kd & "'") dr.Read() If (dr.Item(0) > 0) Then n = n + 1 Else temp = True End If dr.Close() End While End Sub Public Sub fillDG(ByVal q As String) Dim dt As DataTable dt = FetchDataTable(q) If dt.Rows.Count = 0 Then MsgBox("Data Sidik jari tidak ditemukan") End If DataGridView1.DataSource = dt End Sub
Private Sub txt_clear()
IDTxt.Clear() NamaFileTxt.Clear() NamaPemilikTxt.Clear() JenisKelaminCombo.SelectedIndex = -1 AlamatTxt.Clear() HasilTxt.Clear() TxtOutput.Clear() End Sub Private Sub btn_start() BrowseBtn.Enabled = True ClearBtn.Enabled = True ProsesBtn.Enabled = False SimpanBtn.Enabled = False UbahBtn.Enabled = False BatalBtn.Enabled = False HapusBtn.Enabled = False End Sub Public Sub buttonState1() ClearBtn.Enabled = True BrowseBtn.Enabled = False ProsesBtn.Enabled = False SimpanBtn.Enabled = True UbahBtn.Enabled = False BatalBtn.Enabled = False HapusBtn.Enabled = False End Sub Public Sub buttonState2() ClearBtn.Enabled = False BrowseBtn.Enabled = False ProsesBtn.Enabled = False SimpanBtn.Enabled = False UbahBtn.Enabled = True BatalBtn.Enabled = True HapusBtn.Enabled = True End Sub Private Sub BrowseBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrowseBtn.Click With OpenFileDialog1 .CheckFileExists = True .CheckPathExists = True .ShowHelp = False .Filter = "Gambar Bitmap (*.bmp)|*.bmp|Gambar Jpeg (*.jpg)|*.jpg|Gambar Gift (*.gif)|*.gif" .ShowDialog() End With End Sub Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk OriginalPic.ImageLocation = OpenFileDialog1.FileName FileNameLbl.Text = OpenFileDialog1.FileName ProsesBtn.Enabled = True End Sub Private Sub ProsesBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProsesBtn.Click SobelPic.Image = SobelDetect(OriginalPic.Image) BinaryPic.Image = Binerisasi(SobelPic.Image) HaarPic.Image = Haar(BinaryPic.Image) BrowseBtn.Enabled = False SimpanBtn.Enabled = True End Sub Private Sub ClearBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearBtn.Click btn_start() txt_clear() OriginalPic.Image = Nothing FileNameLbl.Text = "- No File Selected -"
SobelPic.Image = Nothing BinaryPic.Image = Nothing HaarPic.Image = Nothing End Sub Private Sub SimpanBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpanBtn.Click If Not CekOutput() Then MsgBox("Target Output dari sidik jari tidak valid, silahkan periksa kembali") TxtOutput.Focus() Exit Sub End If If NamaPemilikTxt.Text = "" Then MsgBox("Isi nama pemilik sidik jari") NamaPemilikTxt.Focus() ElseIf AlamatTxt.Text = "" Then MsgBox("Isi alamat dari pemilik sidik jari") AlamatTxt.Focus() ElseIf JenisKelaminCombo.Text = "" Then MsgBox("Pilih jenis kelamin dari pemilik sidik jari") JenisKelaminCombo.Focus() Else Dim Dr As MySql.Data.MySqlClient.MySqlDataReader Dim tid As String = "" Dr = fetchData("select id from identitas where nilai_fitur='" & HasilTxt.Text & "'") If Dr.HasRows Then MsgBox("Nilai fitur telah terdaftar sebelumnya, pastikan anda tidak memasukkan gambar yang sama berulang kali!") Dr.Close() Exit Sub End If Dr.Close() Dr = fetchData("select id from identitas order by id desc limit 0,1") If Dr.HasRows Then Dr.Read() tid = Dr(0) + 1 End If Dr.Close() NamaFileTxt.Text = tid & "SidikJari.bmp" RunQuery("INSERT INTO identitas(nama,alamat,jenis_kelamin,nilai_fitur,nama_file,target) VALUES ('" & NamaPemilikTxt.Text & "','" & AlamatTxt.Text & "','" & JenisKelaminCombo.Text & "','" & HasilTxt.Text & "','" & NamaFileTxt.Text & "','" & TxtOutput.Text & "')") My.Computer.FileSystem.CopyFile(OpenFileDialog1.FileName, "images/" & NamaFileTxt.Text) resetState() End If End Sub Private Function CekOutput() As Boolean CekOutput = False Dim cek As String If TxtOutput.Text = String.Empty Then Return False Else For i = 1 To Len(TxtOutput.Text) cek = Mid(TxtOutput.Text, i, 1) If (cek <> "0") And (cek <> "1") Then Return False End If Next Return True End If End Function Private Sub FormSidik_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load btn_start() 'newId() fillDG("SELECT * FROM identitas") End Sub Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick buttonState2()
IDTxt.Text = DataGridView1.SelectedRows(0).Cells(0).Value NamaPemilikTxt.Text = DataGridView1.SelectedRows(0).Cells(1).Value AlamatTxt.Text = DataGridView1.SelectedRows(0).Cells(2).Value JenisKelaminCombo.SelectedItem = DataGridView1.SelectedRows(0).Cells(3).Value HasilTxt.Text = DataGridView1.SelectedRows(0).Cells(4).Value NamaFileTxt.Text = DataGridView1.SelectedRows(0).Cells(5).Value FileNameLbl.Text = NamaFileTxt.text OriginalPic.ImageLocation = "images/" & NamaFileTxt.Text TxtOutput.Text = DataGridView1.SelectedRows(0).Cells(6).Value NamaFileTxt.Focus() End Sub Private Sub BatalBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BatalBtn.Click resetState() End Sub Private Sub HapusBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HapusBtn.Click If MsgBox("Apakah anda benar - benar yakin ingin menghapus data identitas ini ?", MsgBoxStyle.YesNo) = vbYes Then My.Computer.FileSystem.DeleteFile("images/" & NamaFileTxt.Text) RunQuery("DELETE FROM identitas WHERE id='" & IDTxt.Text & "'") fillDG("SELECT * FROM identitas") resetState() End If End Sub Private Sub UbahBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UbahBtn.Click If NamaPemilikTxt.Text = "" Then MsgBox("Isi nama pemilik sidik jari") NamaPemilikTxt.Focus() ElseIf AlamatTxt.Text = "" Then MsgBox("Isi alamat dari pemilik sidik jari") AlamatTxt.Focus() ElseIf JenisKelaminCombo.Text = "" Then MsgBox("Pilih jenis kelamin dari pemilik sidik jari") JenisKelaminCombo.Focus() Else RunQuery("UPDATE identitas SET nama='" & NamaPemilikTxt.Text & "', alamat='" & AlamatTxt.Text & "', jenis_kelamin='" & JenisKelaminCombo.Text & "', target='" & TxtOutput.Text & "' WHERE id='" & IDTxt.Text & "'") resetState() End If End Sub End Class
Form Sidik Uji.vb
Imports MySql Imports MySql.Data Imports MySql.Data.MySqlClient Public Class FormSidikUji Private Sub resetState() btn_start() ClearBtn.PerformClick() OpenFileDialog1.FileName = "" NamaPemilikTxt.Clear() AlamatTxt.Clear() JenisKelaminCombo.SelectedIndex = -1 fillDG("SELECT * FROM identitas_uji") TxtOutput.Clear() BrowseBtn.Focus() End Sub Public Sub newId() Dim ds As New DataSet Dim dr As MySqlDataReader dr = fetchData("SELECT COUNT(*) FROM identitas_uji;") dr.Read()
Dim n As Integer Dim temp As Boolean = False n = dr.Item(0) + 1 dr.Close() While temp = False Dim kd As String kd = "ID" & n.ToString dr = fetchData("SELECT COUNT(*) FROM identitas_uji WHERE id='" & kd & "'") dr.Read() If (dr.Item(0) > 0) Then n = n + 1 Else temp = True End If dr.Close() End While
IDTxt.Text = "SJ" & n.ToString NamaFileTxt.Text = IDTxt.Text & "SidikJari.bmp" End Sub Public Sub fillDG(ByVal q As String) Dim dt As DataTable dt = FetchDataTable(q) If dt.Rows.Count = 0 Then MsgBox("Data Sidik jari tidak ditemukan") End If DataGridView1.DataSource = dt End Sub Private Sub txt_clear()
IDTxt.Clear() NamaFileTxt.Clear() NamaPemilikTxt.Clear() JenisKelaminCombo.SelectedIndex = -1 AlamatTxt.Clear() HasilTxt.Clear() TxtOutput.Clear() End Sub Private Sub btn_start() BrowseBtn.Enabled = True ClearBtn.Enabled = True ProsesBtn.Enabled = False
SimpanBtn.Enabled = False UbahBtn.Enabled = False BatalBtn.Enabled = False HapusBtn.Enabled = False End Sub Public Sub buttonState1() ClearBtn.Enabled = True BrowseBtn.Enabled = False ProsesBtn.Enabled = False SimpanBtn.Enabled = True UbahBtn.Enabled = False BatalBtn.Enabled = False HapusBtn.Enabled = False End Sub Public Sub buttonState2() ClearBtn.Enabled = False BrowseBtn.Enabled = False ProsesBtn.Enabled = False SimpanBtn.Enabled = False UbahBtn.Enabled = True BatalBtn.Enabled = True HapusBtn.Enabled = True End Sub Private Sub BrowseBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrowseBtn.Click With OpenFileDialog1 .CheckFileExists = True .CheckPathExists = True .ShowHelp = False .Filter = "Gambar Bitmap (*.bmp)|*.bmp|Gambar Jpeg (*.jpg)|*.jpg|Gambar Gift (*.gif)|*.gif" .ShowDialog() End With End Sub Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk OriginalPic.ImageLocation = OpenFileDialog1.FileName FileNameLbl.Text = OpenFileDialog1.FileName ProsesBtn.Enabled = True End Sub Private Sub ProsesBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProsesBtn.Click SobelPic.Image = SobelDetect(OriginalPic.Image) BinaryPic.Image = Binerisasi(SobelPic.Image) HaarPic.Image = Haar(BinaryPic.Image) HasilTxt.Text = THasil2 BrowseBtn.Enabled = False SimpanBtn.Enabled = True End Sub Private Sub ClearBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearBtn.Click btn_start() txt_clear() OriginalPic.Image = Nothing FileNameLbl.Text = "- No File Selected -" SobelPic.Image = Nothing BinaryPic.Image = Nothing HaarPic.Image = Nothing newId() End Sub Private Sub SimpanBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpanBtn.Click If Not CekOutput() Then MsgBox("Target Output dari sidik jari tidak valid, silahkan periksa kembali") TxtOutput.Focus() Exit Sub End If If NamaPemilikTxt.Text = "" Then MsgBox("Isi nama pemilik sidik jari") NamaPemilikTxt.Focus() ElseIf AlamatTxt.Text = "" Then MsgBox("Isi alamat dari pemilik sidik jari") AlamatTxt.Focus() ElseIf JenisKelaminCombo.Text = "" Then MsgBox("Pilih jenis kelamin dari pemilik sidik jari") JenisKelaminCombo.Focus() Else Dim Dr As MySql.Data.MySqlClient.MySqlDataReader Dim tid As String = "" Dr = fetchData("select id from identitas_uji where nilai_fitur='" & HasilTxt.Text & "'") If Dr.HasRows Then MsgBox("Nilai fitur telah terdaftar sebelumnya, pastikan anda tidak memasukkan gambar yang sama berulang kali!") Dr.Close() Exit Sub End If Dr.Close() Dr = fetchData("select id from identitas_uji order by id desc limit 0,1") If Dr.HasRows Then Dr.Read() tid = Dr(0) + 1 End If Dr.Close()
RunQuery("INSERT INTO identitas_uji(nama,alamat,jenis_kelamin,nilai_fitur,nama_file,target) VALUES ('" & NamaPemilikTxt.Text & "','" & AlamatTxt.Text & "','" & JenisKelaminCombo.Text & "','" & HasilTxt.Text & "','" & NamaFileTxt.Text & "','" & TxtOutput.Text & "')") My.Computer.FileSystem.CopyFile(OpenFileDialog1.FileName, "image_uji/" & NamaFileTxt.Text) resetState() End If End Sub Private Function CekOutput() As Boolean CekOutput = False Dim cek As String If TxtOutput.Text = String.Empty Then Return False Else For i = 1 To Len(TxtOutput.Text) cek = Mid(TxtOutput.Text, i) Next Return True End If End Function
Form Memorisasi.vb
Public Class FormMemorisasi Private Sub FormMemorisasi_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim DT As New System.Data.DataTable DT = FetchDataTable("select * from memorisasi") DataGridView1.DataSource = DT Dim DR As MySql.Data.MySqlClient.MySqlDataReader Dim tCount As Long = 0 Dim tBenar As Long = 0 DR = fetchData("select count(*) from memorisasi") If DR.HasRows Then DR.Read() tCount = DR(0) End If DR.Close() DR = fetchData("select count(*) from memorisasi where hasil='Benar'") If DR.HasRows Then DR.Read() tBenar = DR(0) End If DR.Close() If tCount > 0 Then tCount = (tBenar / tCount) * 100 Else tCount = 0 End If ToolStripLabel1.Text = "Persentase Memorisasi : " & tCount & " %" End Sub End Class
Form Generalisasi.vb
Public Class FormGeneralisasi Private Sub FormGeneralisasi_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim DT As New System.Data.DataTable DT = FetchDataTable("select * from generalisasi") DataGridView1.DataSource = DT Dim DR As MySql.Data.MySqlClient.MySqlDataReader Dim tCount As Long = 0 Dim tBenar As Long = 0
DR = fetchData("select count(*) from generalisasi") If DR.HasRows Then DR.Read() tCount = DR(0) End If DR.Close() DR = fetchData("select count(*) from generalisasi where hasil='Benar'") If DR.HasRows Then DR.Read() tBenar = DR(0) End If DR.Close() If tCount > 0 Then tCount = (tBenar / tCount) * 100 Else tCount = 0 End If ToolStripLabel1.Text = "Persentase Generalisasi : " & tCount & " %" End Sub End Class
Form TCValidation.vb
Public Class FormTCValidation Private Structure ArrGroup Dim ID As Integer Dim Nilai As String Dim Target As String Dim Pemilik As String End Structure Private Structure ArrError Dim Group As Integer Dim nError As Double End Structure Private DataCount As Integer Private GCount As Integer Private ArrE1 As List(Of ArrError) Private ArrG1 As List(Of ArrGroup) Private ArrG2 As List(Of ArrGroup) Private ArrG3 As List(Of ArrGroup) Private ArrG4 As List(Of ArrGroup) Private ArrG5 As List(Of ArrGroup) Private ArrG6 As List(Of ArrGroup) Private ArrG7 As List(Of ArrGroup) Private ArrG8 As List(Of ArrGroup) Private ArrG9 As List(Of ArrGroup) Private ArrG10 As List(Of ArrGroup) Private ArrAll As List(Of ArrGroup) Private ArrGAll() As List(Of ArrGroup) Private ProgressCount As Integer Private Sub FormTCValidation_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Clear() Label2.Text = ActiveTrain End Sub Private Sub Clear() Dim DR1 As MySql.Data.MySqlClient.MySqlDataReader DR1 = fetchData("select count(id) from identitas") DataCount = 0 If DR1.HasRows Then DR1.Read() DataCount = DR1(0) End If DR1.Close()
If DataCount < 1 Then MsgBox("Data identitas kosong, proses ten fold cross validation tidak dapat dilakukan") Exit Sub End If ArrG1 = New List(Of ArrGroup) ArrG2 = New List(Of ArrGroup) ArrG3 = New List(Of ArrGroup) ArrG4 = New List(Of ArrGroup) ArrG5 = New List(Of ArrGroup) ArrG6 = New List(Of ArrGroup) ArrG7 = New List(Of ArrGroup) ArrG8 = New List(Of ArrGroup) ArrG9 = New List(Of ArrGroup) ArrG10 = New List(Of ArrGroup) ArrAll = New List(Of ArrGroup) Me.Cursor = Cursors.WaitCursor DR1 = fetchData("select * from identitas") Dim ArrTamp As ArrGroup If DR1.HasRows Then Do While DR1.Read ArrTamp = New ArrGroup ArrTamp.ID = DR1("id") ArrTamp.Nilai = DR1("nilai_fitur") ArrTamp.Target = DR1("target") ArrTamp.Pemilik = DR1("nama") ArrAll.Add(ArrTamp) Loop End If DR1.Close() Me.Cursor = Cursors.Default LVError.Items.Clear() LVS.Items.Clear() Label3.Text = "" Label4.Text = "" Label5.Text = "" Label6.Text = "" End Sub Private Sub ButtonE(ByVal Stat As Boolean) Button1.Enabled = Stat Button2.Enabled = Stat Button3.Enabled = Stat End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If DataCount < 1 Then MsgBox("Data identitas kosong, proses ten fold cross validation tidak dapat dilakukan") Exit Sub End If ButtonE(False) Dim RND As New Random Dim RND2 As New Random Dim i As Integer = 1 Dim j As Integer = 1 Do While i <= ArrAll.Count ulang: j = Int(RND2.Next(10)) Select Case j Case 1 If ArrG1.Count >= GCount Then GoTo ulang End If ArrG1.Add(ArrAll(i - 1)) Case 2 If ArrG2.Count >= GCount Then
GoTo ulang End If ArrG2.Add(ArrAll(i - 1)) Case 3 If ArrG3.Count >= GCount Then GoTo ulang End If ArrG3.Add(ArrAll(i - 1)) Case 4 If ArrG4.Count >= GCount Then GoTo ulang End If ArrG4.Add(ArrAll(i - 1)) Case 5 If ArrG5.Count >= GCount Then GoTo ulang End If ArrG5.Add(ArrAll(i - 1)) Case 6 If ArrG6.Count >= GCount Then GoTo ulang End If ArrG6.Add(ArrAll(i - 1)) Case 7 If ArrG7.Count >= GCount Then GoTo ulang End If ArrG7.Add(ArrAll(i - 1)) Case 8 If ArrG8.Count >= GCount Then GoTo ulang End If ArrG8.Add(ArrAll(i - 1)) Case 9 If ArrG9.Count >= GCount Then GoTo ulang End If ArrG9.Add(ArrAll(i - 1)) Case Else If ArrG10.Count >= GCount Then GoTo ulang End If ArrG10.Add(ArrAll(i - 1)) End Select i += 1 Loop j = 1 For i = 1 To 10 ShowListGroup(i, j) Next ButtonE(True) End Sub Private Sub ShowListGroup(ByVal tIndeks As Integer, ByRef tNo As Integer) Dim i As Integer Dim ArrT As New List(Of ArrGroup) Select Case tIndeks Case 1 ArrT = ArrG1 Case 2 ArrT = ArrG2 Case 3 ArrT = ArrG3 Case 4 ArrT = ArrG4 Case 5 ArrT = ArrG5 Case 6 ArrT = ArrG6 Case 7 ArrT = ArrG7 Case 8
ArrT = ArrG8 Case 9 ArrT = ArrG9 Case 10 ArrT = ArrG10 End Select Dim LVI As ListViewItem For i = 0 To ArrT.Count - 1 LVI = LVS.Items.Add(tNo) LVI.SubItems.Add("S" & tIndeks) LVI.SubItems.Add(ArrT(i).ID) LVI.SubItems.Add(ArrT(i).Nilai) LVI.SubItems.Add(ArrT(i).Target) LVI.SubItems.Add(ArrT(i).Pemilik) tNo += 1 Next End Sub Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick ProgressBar1.Value = ProgressCount Label3.Text = "Step : " & ProgressCount / 10 End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ProgressBar1.Visible = True ArrE1 = New List(Of ArrError) ReDim ArrGAll(9) ArrGAll(0) = ArrG1 ArrGAll(1) = ArrG2 ArrGAll(2) = ArrG3 ArrGAll(3) = ArrG4 ArrGAll(4) = ArrG5 ArrGAll(5) = ArrG6 ArrGAll(6) = ArrG7 ArrGAll(7) = ArrG8 ArrGAll(8) = ArrG9 ArrGAll(9) = ArrG10 ProgressCount = 0 Timer1.Start() ButtonE(False) BackgroundWorker1.RunWorkerAsync() End Sub Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Dim i As Long Dim j As Long Dim Hasil As String Dim ArrTE As ArrError Dim tStep As Integer tStep = 1 Do While tStep <= 10 RunValidation(tStep) ProgressCount = Int((tStep / 10)) tStep += 1 Loop End Sub Private Sub RunValidation(ByVal nStep As Integer) Dim BL As Integer = (10 - nStep) Dim i As Integer Dim j As Integer Dim ArrTE As ArrError = New ArrError Dim Hasil As String Dim tTarget(4) As String Dim Avg_Error As Double = 0
Dim ProcCount As String = 0 For i = 0 To 9 If i <> BL Then For j = 1 To ArrGAll(i).Count tTarget(0) = Mid(ArrGAll(i)(j - 1).Target, 1, 1) tTarget(1) = Mid(ArrGAll(i)(j - 1).Target, 2, 1) tTarget(2) = Mid(ArrGAll(i)(j - 1).Target, 3, 1) tTarget(3) = Mid(ArrGAll(i)(j - 1).Target, 4, 1) tTarget(4) = Mid(ArrGAll(i)(j - 1).Target, 5, 1) Hasil = identify2(ArrGAll(i)(j - 1).Nilai, ActiveTrain, tTarget) Avg_Error += Hasil ProcCount += 1 Next End If Next ArrTE.nError = Avg_Error ArrTE.Group = nStep ArrE1.Add(ArrTE) End Sub Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted Dim i As Integer Dim LVI As ListViewItem Dim BestE As Double = 1 Dim WorstE As Double = 0 Dim AvgE As Double = 0 For i = 1 To ArrE1.Count LVI = LVError.Items.Add(i) LVI.SubItems.Add("V" & i) LVI.SubItems.Add(ArrE1(i - 1).nError) If ArrE1(i - 1).nError < BestE Then BestE = ArrE1(i - 1).nError End If If ArrE1(i - 1).nError > WorstE Then WorstE = ArrE1(i - 1).nError End If AvgE += ArrE1(i - 1).nError Next Label3.Text = "Step : 10" Label4.Text = "Best Error Rate : " & Math.Round(BestE, 9) & ".." Label5.Text = "Worst Error Rate : " & Math.Round(WorstE, 9) & ".." Label6.Text = "Average Error Rate : " & Math.Round(AvgE / 10, 7) & ".." ProgressBar1.Visible = False Timer1.Enabled = False ButtonE(True) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Clear() End Sub End Class
JST.vb
Imports System.Data Imports System.IO Imports System.IO.File Imports MySql Imports MySql.Data Imports MySql.Data.MySqlClient Module JST
Public time As New DateTime 'deklarasi input node, hidden node dan output node Public input_node As Long Public hidden_node As Long Public output_node As Long 'deklarasi nilai input,hidden dan output Public input_output(input_node) As Double Public output_output(output_node) As Double Public hidden_output(hidden_node) As Double 'deklarasi bobot pada hidden dan output Public hidden_weight(,) As Double Public output_weight(,) As Double 'kesalahan pada hidden dan output Public output_error(output_node) As Double Public hidden_error(hidden_node) As Double 'deklarasi laju pembelajaran, momentum dan faktor proporsional Public alpha As Double Public beta As Double Public gamma As Double Public biasHm(,) As Double Public biasYm(,) As Double Public biasY() As Double Public biasH() As Double Public avg_err As Double Public ek As Double Public epoch_attr As Long Public max_epoch As Long Public target_error As Double Public c As Double 'momentum Public momentum As Double = 0.1 Public momentum_ih(,,) As Double Public momentum_ho(,,) As Double Public usemomentum, activation_func As Boolean Private Function sigmoid(ByVal x As Double) x = 1.0 / (1.0 + Math.Exp(-x)) Return x End Function Private Function sigmoidBipolar(ByVal x As Double) x = (2.0 / (1.0 + Math.Exp(-x))) - 1.0 Return x End Function Public Sub train_forward(ByVal kode As Long) Dim acc As Double Dim input_str As String Dim input_str_arr() As String Dim dr As MySqlDataReader dr = fetchData("SELECT nilai_fitur FROM identitas WHERE id='" & kode.ToString & "'") If dr.HasRows Then dr.Read() input_str = dr(0) Else MsgBox("Database gagal!") dr.Close() Exit Sub End If dr.Close() input_str_arr = Split(input_str) For i = 0 To input_node - 1 input_output(i) = Val(input_str_arr(i).Replace(",", "."))
Next For j = 0 To hidden_node - 1 acc = 0 For i = 0 To input_node - 1 acc += input_output(i) * hidden_weight(j, i) Next If activation_func Then 'biner hidden_output(j) = sigmoid(acc) Else 'bipolar hidden_output(j) = sigmoidBipolar(acc) End If Next For j = 0 To output_node - 1 acc = 0 For i = 0 To hidden_node - 1 acc += (hidden_output(i) * output_weight(j, i)) Next If activation_func Then 'biner output_output(j) = sigmoid(acc) Else 'bipolar output_output(j) = sigmoidBipolar(acc) End If Next End Sub Public Sub train_backward(ByVal kode As Long) Dim target_output(output_node) As Long Dim Tamp As String Dim dr As MySqlDataReader dr = fetchData("SELECT target FROM identitas WHERE id='" & kode.ToString & "'") If dr.HasRows Then dr.Read() Tamp = dr(0) For i = 1 To Len(Tamp) target_output(i - 1) = Mid(Tamp, i, 1) Next End If dr.Close() Dim output As Double avg_err = 0.0 ek = 0.0 If activation_func Then 'biner For i = 0 To output_node - 1 output = output_output(i) Next c += (avg_err) Else 'bipolar For i = 0 To output_node - 1 output = output_output(i) output_error(i) = (((1.0 + output) * (1.0 - output)) / 2) * (target_output(i) - output) avg_err += Math.Pow(output_output(i) - target_output(i), 2) ek += output_output(i) - target_output(i) Next c += (avg_err) End If ek /= 100 End Sub Public Sub update_weight() Dim weight_correct As Double For j = 0 To output_node - 1
For i = 0 To hidden_node - 1 weight_correct = alpha * output_error(j) * hidden_output(i) output_weight(j, i) = output_weight(j, i) + weight_correct Next biasY(j) -= alpha * output_error(j) Next Dim acc As Double Dim output As Double If activation_func Then For i = 0 To hidden_node - 1 acc = 0 For j = 0 To output_node - 1 acc = acc + (output_error(j) * output_weight(j, i)) Next Else For i = 0 To hidden_node - 1 acc = 0 For j = 0 To output_node - 1 acc = acc + (output_error(j) * output_weight(j, i)) Next output = hidden_output(i) hidden_error(i) = (((1 + output) * (1 - output)) / 2) * acc Next End If For j = 0 To hidden_node - 1 For i = 0 To input_node - 1 weight_correct = alpha * hidden_error(j) * input_output(i) hidden_weight(j, i) = hidden_weight(j, i) + weight_correct Next biasH(j) -= alpha * hidden_error(j) Next End Sub Public Sub update_weight_momentum(ByVal epoch As Long) If epoch = 1 Then For j = 0 To output_node - 1 For i = 0 To hidden_node – 1 momentum_ho(j, i, 1) = output_weight(j, i) Next Dim acc As Double Dim output As Double If activation_func Then For i = 0 To hidden_node - 1 acc = 0 For j = 0 To output_node - 1 Next output = hidden_output(i) hidden_error(i) = output * (1 - output) * acc Next Else For i = 0 To hidden_node - 1 acc = 0 For j = 0 To output_node - 1 acc = acc + (output_error(j) * output_weight(j, i)) Next output = hidden_output(i) Next End If For j = 0 To hidden_node - 1 For i = 0 To input_node - 1 momentum_ih(j, i, 1) = hidden_weight(j, i) biasHm(j, 1) = biasH(j) biasH(j) -= alpha * hidden_error(j) biasHm(j, 0) = biasH(j) Next Else For j = 0 To output_node - 1 For i = 0 To hidden_node - 1 output_weight(j, i) = momentum_ho(j, i, 0) + (alpha * output_error(j) * hidden_output(i)) + (momentum * (momentum_ho(j, i, 0) - momentum_ho(j, i, 1)))
Next biasY(j) = biasYm(j, 0) - alpha * output_error(j) + momentum * (biasYm(j, 0) - biasYm(j, 1)) biasYm(j, 1) = biasYm(j, 0) biasYm(j, 0) = biasY(j) Next Dim acc As Double Dim output As Double If activation_func Then For i = 0 To hidden_node - 1 acc = 0 For j = 0 To output_node - 1 acc = acc + (output_error(j) * output_weight(j, i)) Next output = hidden_output(i) hidden_error(i) = output * (1 - output) * acc Next Else For i = 0 To hidden_node - 1 acc = 0 For j = 0 To output_node - 1 Next output = hidden_output(i) hidden_error(i) = (((1 + output) * (1 - output)) / 2) * acc Next End If For j = 0 To hidden_node - 1 For i = 0 To input_node – 1 hidden_weight(j, i) = momentum_ih(j, i, 0) + (alpha * hidden_error(j) * input_output(i)) + (momentum * (momentum_ih(j, i, 0) - momentum_ih(j, i, 1))) + gamma
- ek Next biasHm(j, 1) = biasHm(j, 0) biasHm(j, 0) = biasH(j) Next End If End Sub Public Function identify(ByVal inp_str As String, ByVal tLabel As String) As String Dim i, j As Long Dim acc As Double Dim input_str As String Dim input_str_arr() As String input_str = inp_str input_str_arr = Split(input_str) Dim hw(hidden_node, input_node) As Double hidden_weight = hw Dim ow(output_node, hidden_node) As Double output_weight = ow Dim inputout(input_node) As Double
input_output = inputout Dim outputout(output_node) As Double output_output = outputout biasY = outputout Dim bym(output_node, 2) As Double biasYm = bym Dim outerr(output_node) As Double output_error = outerr Dim hiddenout(hidden_node) As Double hidden_output = hiddenout biasH = hiddenout Dim bhm(hidden_node, 2) As Double biasHm = bhm Dim hiddenerr(hidden_node) As Double hidden_error = hiddenerr For i = 0 To input_node - 1 input_output(i) = Val(input_str_arr(i).Replace(",", ".")) Next
Dim tCount As Integer Dim dr As MySqlDataReader dr = fetchData("select count(id) from toutput where label='" & tLabel & "'") If dr.HasRows Then dr.Read() tCount = dr(0) End If dr.Close() If tCount > 0 Then dr = fetchData("select hidden from thidden where label='" & tLabel & "' order by id asc") i = 0 j = 0 If dr.HasRows Then While dr.Read hidden_weight(j, i) = dr(0) i = i + 1 If i Mod input_node = 0 Then j += 1 i = 0 End If End While End If dr.Close() dr = fetchData("select output from toutput where label='" & tLabel & "' order by id asc") i = 0 j = 0 If dr.HasRows Then While dr.Read output_weight(j, i) = dr(0) i = i + 1 If i Mod hidden_node = 0 Then j += 1 i = 0 End If End While End If dr.Close() dr = fetchData("select biash from tbiash where label='" & tLabel & "' order by id asc") i = 0 If dr.HasRows Then While dr.Read biasH(i) = dr(0) i = i + 1 End While End If dr.Close() dr = fetchData("select biasy from tbiasy where label='" & tLabel & "' order by id asc") i = 0 If dr.HasRows Then While dr.Read biasY(i) = dr(0) i = i + 1 End While End If dr.Close() For j = 0 To hidden_node - 1 acc = 0 For i = 0 To input_node - 1 Next hidden_output(j) = acc If activation_func Then hidden_output(j) = sigmoid(acc) Else hidden_output(j) = sigmoidBipolar(acc) End If
Next For j = 0 To output_node - 1 acc = 0 For i = 0 To hidden_node - 1 acc = acc + (hidden_output(i) * output_weight(j, i)) Next output_output(j) = acc If activation_func Then output_output(j) = sigmoid(acc - biasY(j)) output_output(j) = sigmoid(acc) Else output_output(j) = sigmoidBipolar(acc - biasY(j)) output_output(j) = sigmoidBipolar(acc) End If Next Dim maks As Double Dim ans As String ans = "" maks = -100000 For i = 0 To output_node-1 End If Next Return ans Else Return "-1" End If End Function Public Function identify2(ByVal inp_str As String, ByVal tLabel As String, ByVal tTarget() As String) As String Dim i, j As Long Dim acc As Double Dim input_str As String Dim input_str_arr() As String input_str = inp_str input_str_arr = Split(input_str) Dim hw(hidden_node, input_node) As Double hidden_weight = hw Dim ow(output_node, hidden_node) As Double output_weight = ow Dim inputout(input_node) As Double input_output = inputout Dim outputout(output_node) As Double output_output = outputout biasY = outputout Dim bym(output_node, 2) As Double biasYm = bym Dim outerr(output_node) As Double output_error = outerr Dim hiddenout(hidden_node) As Double hidden_output = hiddenout biasH = hiddenout Dim bhm(hidden_node, 2) As Double biasHm = bhm Dim hiddenerr(hidden_node) As Double hidden_error = hiddenerr For i = 0 To input_node - 1 input_output(i) = Val(input_str_arr(i).Replace(",", ".")) Next Dim tCount As Integer Dim dr As MySqlDataReader dr = fetchData("select count(id) from toutput where label='" & tLabel & "'") If dr.HasRows Then dr.Read() tCount = dr(0) End If dr.Close() activation_func = True dr = fetchData("select output from toutput where label='" & tLabel & "' order by id asc") i = 0 j = 0 If dr.HasRows Then While dr.Read output_weight(j, i) = dr(0) i = i + 1 If i Mod hidden_node = 0 Then j += 1 i = 0 End If End While End If dr.Close() dr = fetchData("select biash from tbiash where label='" & tLabel & "' order by id asc") i = 0 If dr.HasRows Then While dr.Read biasH(i) = dr(0) i = i + 1 End While End If dr.Close() dr = fetchData("select biasy from tbiasy where label='" & tLabel & "' order by id asc") i = 0 If dr.HasRows Then While dr.Read biasY(i) = dr(0) i = i + 1 End While End If dr.Close() For j = 0 To hidden_node - 1 acc = 0 For i = 0 To input_node - 1 acc += input_output(i) * hidden_weight(j, i) Next hidden_output(j) = acc If activation_func Then hidden_output(j) = sigmoid(acc) Else hidden_output(j) = sigmoidBipolar(acc) End If Next For j = 0 To output_node - 1 acc = 0 For i = 0 To hidden_node - 1 acc = acc + (hidden_output(i) * output_weight(j, i)) Next output_output(j) = acc If activation_func Then output_output(j) = sigmoid(acc) Else output_output(j) = sigmoidBipolar(acc) End If Next Dim maks As Double Dim ans As String ans = "" maks = -100000 avg_err = 0 For i = 0 To output_node - 1 avg_err += Math.Pow(tTarget(i) - output_output(i), 2) Next ans = avg_err
Return ans Else Return "-1" End If End Function End Module
Form Latih.vb
Imports MySql Imports MySql.Data Imports MySql.Data.MySqlClient Imports System.Data Imports System.IO Imports System.IO.File Public Class FormLatih Public avg_err_1 As Double = 1.0 Dim ErrT As String Dim GenCount As Long Public tLabel As String Dim dbLearning As String Dim dbError As String Dim dbEpoch As String Dim dbMomentum As String Dim dbGamma As String Dim dbUMomentum As String Private Sub MulaiBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MulaiBtn.Click If LearningRateTxt.Text = "" Then MsgBox("Pilih laju pembelajaran") LearningRateTxt.Focus() Exit Sub ElseIf TargetErrorTxt.Text = "" Then MsgBox("Pilih target error yang diinginkan") TargetErrorTxt.Focus() Exit Sub ElseIf MaxEpochTxt.Text = "" Then MsgBox("Pilih banyak epoch maksimum") MaxEpochTxt.Focus() Exit Sub End If activation_func = BinerRadio.Checked usemomentum = MomentumChk.Checked If MomentumTxt.Text <> "" Then momentum = Val(MomentumTxt.Text) End If hidden_node = Val(HiddenNodeTxt.Text) input_node = Val(InputNodeTxt.Text) output_node = Val(OutputNodeTxt.Text) alpha = Val(LearningRateTxt.Text) max_epoch = Val(MaxEpochTxt.Text) target_error = Val(TargetErrorTxt.Text) gamma = Val(GammaTxt.Text) GammaTxt.Enabled = False MulaiBtn.Enabled = False LearningRateTxt.Enabled = False TargetErrorTxt.Enabled = False MaxEpochTxt.Enabled = False HiddenNodeTxt.Enabled = False MomentumTxt.Enabled = False ErrorRateTxt.Clear() EpochTxt.Clear() TimeTxt.Clear() Button1.Enabled = True ProgressBar1.Style = ProgressBarStyle.Marquee time = DateTime.Now RunQuery("delete from error") Timer1.Start() tLabel = ComboBox1.Text dbLearning = LearningRateTxt.Text dbError = TargetErrorTxt.Text dbEpoch = MaxEpochTxt.Text dbMomentum = MomentumTxt.Text dbGamma = GammaTxt.Text If MomentumChk.Checked Then dbUMomentum = "T" Else dbUMomentum = "F" End If BackgroundWorker1.RunWorkerAsync() End Sub Private Sub FormLatih_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim dr As MySqlDataReader dr = fetchData("SELECT COUNT(*) FROM identitas;") dr.Read() Dim n As Integer n = dr.Item(0) dr.Close() OutputNodeTxt.Text = 5 TotalSubjectTxt.Text = n TotalPatternTxt.Text = n Dim input_str As String = "" Dim input_str_arr() As String dr = fetchData("SELECT nilai_fitur FROM identitas order by id asc limit 0,1") If dr.HasRows Then dr.Read() input_str = dr.Item(0) Else dr.Close() MsgBox("Data Sidik Jari kosong, silahkan masukkan data terlebih dahulu..") End If dr.Close() ComboBox1.Items.Clear() dr = fetchData("select label from toutput group by label") If dr.HasRows Then Do While dr.Read ComboBox1.Items.Add(dr(0)) Loop End If dr.Close() input_str_arr = input_str.Substring(0, Len(input_str) - 1).Split(" ") InputNodeTxt.Text = input_str_arr.Length HiddenNodeTxt.Text = Math.Round(Math.Sqrt(Val(InputNodeTxt.Text) * Val(OutputNodeTxt.Text)), 0) Button1.Enabled = False End Sub Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Randomize() Dim dr As MySqlDataReader Dim hw(hidden_node, input_node) As Double hidden_weight = hw Dim mihw(hidden_node, input_node, 2) As Double momentum_ih = mihw Dim ow(output_node, hidden_node) As Double output_weight = ow Dim mhow(output_node, hidden_node, 2) As Double momentum_ho = mhow Dim inputout(input_node) As Double input_output = inputout Dim outputout(output_node) As Double output_output = outputout biasY = outputout Dim bym(output_node, 2) As Double biasYm = bym Dim outerr(output_node) As Double output_error = outerr
Dim hiddenout(hidden_node) As Double hidden_output = hiddenout biasH = hiddenout Dim bhm(hidden_node, 2) As Double biasHm = bhm Dim hiddenerr(hidden_node) As Double hidden_error = hiddenerr Dim i, j As Long Dim FaktorSkala As Double = 0 Dim tJumlah As Double = 0 Dim tRandom As New Random Dim tCount As Integer dr = fetchData("select count(id) from toutput where label='" & tLabel & "'") If dr.HasRows Then dr.Read() tCount = dr(0) End If dr.Close() If tCount > 0 Then dr = fetchData("select hidden from thidden where label='" & tLabel & "' order by id asc") i = 0 j = 0 If dr.hasrows Then Do While dr.Read hidden_weight(j, i) = dr(0) i = i + 1 If i Mod input_node = 0 Then j += 1 i = 0 End If Loop End If dr.Close() dr = fetchData("select output from toutput where label='" & tLabel & "' order by id asc") i = 0 j = 0 If dr.hasrows Then Do While dr.Read output_weight(j, i) = dr(0) i = i + 1 If i Mod hidden_node = 0 Then j += 1 i = 0 End If Loop End If dr.Close() dr = fetchData("select biash from tbiash where label='" & tLabel & "' order by id asc") i = 0 If dr.hasrows Then Do While dr.Read biasH(i) = dr(0) i = i + 1 Loop End If dr.Close() dr = fetchData("select biasy from tbiasy where label='" & tLabel & "' order by id asc") i = 0 If dr.hasrows Then Do While dr.Read biasY(i) = dr(0) i = i + 1 Loop End If dr.Close()