Anda di halaman 1dari 7

PERCEPTRON

• Metode pelatihan Perceptron lebih kuat dari metode Hebb terutama dalam iterasi
yang dapat membuat output dari bobot menjadi konvergen.
• Perbedaan tipe Perceptron pertama kali dikemukakan oleh Rosenblatt (1962) dan
Minsky (1969) .dan Papert (1988).
• Aktivasi yang digunakan dalam pereptron adalah aktivasi bipolar, yaitu -1, 0, 1.
 1 if y _ in > θ

f ( y _ in) =  0 if − θ ≤ y _ in ≤ θ
 − 1 if y _ in < −θ

Arsitektur
• Arsitektur Perceptron sederhana adalah terdiri dari beberapa input dan sebuah output.
• Tujuan dari jaringan adalah untuk mengklasifikasikan masing-masing pola input dan pola output baik
yang bernilai +1 atau yang bernilai -1.

Gambar 1 Perceptron untuk penggolongan tunggal

Algoritma
Algoritma berlaku untuk input bipolar atau input biner dengan nilai target bipolar dan nilai threshold yang
tetap serta nilai bias yang dapat diatur.

X1
Langkah 1 :
Inisialisasi bobot dan bias (untuk sederhananya, set bobos dan bias dengan angka 0)
Set learning rate α (0 < α ≤ 1) (untuk sederhananya, set α dengan angka 1)
Langkah 2:
Selama kondisi berhenti bernilai salah, lakukan langkah berikut :
Untuk masing-masing pasangan s dan t, kerjakan :
a : set aktivasi dari unit input : xi = si
b : hitung respon untuk unit output :
n
y _ in = b + ∑ xi wi
i =1

Jaringan Syaraf Tiruan – Perceptron

. 1
 1 if y _ in > θ

f ( y _ in) =  0 if − θ ≤ y _ in ≤ θ
 − 1 if y _ in < −θ

c : perbaiki bobot dan bias, jika terjadi kesalahan pada pola ini :
jika y ≠ t, maka
wi (baru) = wi (lama) + αtxi
b(baru) = b(lama) + αt
jika tidak, maka
wi (baru) = wi (lama)
b(baru) = b(lama)
d : jika masih ada bobot yang berubah maka kondisi dilanjutkan, jika tidak maka proses berhenti.

Implementasi
• Untuk mengaplikasikan Perceptron, akan dicoba untuk mengaplikasikan fungsi logika AND dengan
input biner dan target bipolar.
• Data pelatihan masalah fungsi logika AND seperti pada tabel 1.

Tabel 1 Fungsi logika AND


Input
Target
x1 x2 b
1 1 1 1
1 0 1 -1
0 1 1 -1
0 0 1 -1

• Set α = 1, bobot = 0, θ = 0.2


• Untuk setiap input (dari keempat input) dihitung dan bobot diperbaharui dan diulang lagi mulai dari
input pertama sampai tidak terjadi kesalahan (y = t) dan hasilnya adalah sebagai berikut :

Tabel 2 Hasil perhitungan implementasi fungsi AND

Jaringan Syaraf Tiruan – Perceptron 2


• Garis pembatas (separating line) dari daerah (region) positif adalah : w1x1 + w2x2 + b > θ
• Garis pembatas (separating line) dari daerah negatif adalah : w1x1 + w2x2 + b < -θ
• Untuk θ = 0.2 kita bisa melihat daerah yang dibentuk dari setiap tahap pelatihan :
Untuk epoh (epoch) 1 sample 1 :
INPUT NET OUT TARGET WEIGHT CHANGES WEIGHT
(x1 x2 1) (w1 w2 b)
(0 0 0)
1 1 1 0 0 1 (1 1 1) (1 1 1)

Garis pembatasnya adalah : x1 + x2 + 1 = 0.2 dan x1 + x2 + 1 = -0.2

Gambar 2 Garis pembatas setelah epoh 1 sample 1

Untuk epoh (epoch) 1 sample 2 :


INPUT NET OUT TARGET WEIGHT CHANGES WEIGHT
(x1 x2 1) (w1 w2 b
(1 1 1)
1 0 1 2 1 -1 (-1 0 -1) (0 1 0)

Garis pembatasnya adalah : x2 = 0.2 dan x2 = -0.2

Gambar 3 Garis pembatas setelah epoh 1 sample 2

Sample 3 dan 4 pada epoh 1 memberi respon negatif (atau nol).


Untuk epoh (epoch) 2 sample 1 :
INPUT NET OUT TARGET WEIGHT CHANGES WEIGHT
(x1 x2 1) (w1 w2 b
(0 0 -1)
1 1 1 -1 -1 1 (1 1 1) (1 1 0)

Garis pembatasnya adalah : x1 + x2 = 0.2 dan x1 + x2 = -0.2

Jaringan Syaraf Tiruan – Perceptron 3


Gambar 4 Garis pembatas setelah epoh 2 sample 1

Setelah epoh ke 10 hasil akhirnya adalah :


INPUT NET OUT TARGET WEIGHT CHANGES WEIGHT
(x1 x2 1) (w1 w2 b
(2 3 -4)
0 0 1 -4 -1 -1 (0 0 0) (2 3 -4)

Garis pembatasnya adalah : 2x1 + 3x2 – 4 = 0.2 dan 2x1 + 3x2 – 4 = -0.2

Gambar 5 Garis pembatas setelah epoh 10 sample 4

Perceptron tidak dapat mengenali dan membuat region untuk fungsi Exclusive OR (XOR) seperti tabel 2
Tabel 3 Fungsi logika AND
Input
Target
x1 x2 b
1 1 1 -1
1 0 1 1
0 1 1 1
0 0 1 -1

Gambar 5 Diagram fungsi XOR

Jaringan Syaraf Tiruan – Perceptron 4


Coding
Inisialisasi
• Inisialisasi tipe data : ditempatkan di MainModule
Type DataSample
Inp() As Double
Net() As Double
Out() As Double
End Type
• Inisialisasi Sample
Private Sample() As DataSample
• Inisialisasi Weight
Private Weight() As Double
• Inisialisasi variabel parameter
Private SampleAmt As Integer
Private InputAmt As Integer
Private OutputAmt As Integer
Private Threshold As Double
Private LearningRate As Double
• Fungsi Aktivasi
Private Function Activate(net As Double) As Double
Dim res As Double

If net > Threshold Then


res = 1
ElseIf net <= Threshold And net >= -Threshold Then
res = 0
Else
res = -1
End If

Activate = res
End Function

Setting Data
• Variabel parameter
SampleAmt = 4
InputAmt = 2
OutputAmt =1
Threshold = 0.2
LearningRate = 1
• Redim Sample
Dim i As Integer, j As Integer

Redim Sample (SampleAmt)


For i = 1 to SampleAmt
Redim Sample (i).Inp (InputAmt)
Redim Sample (i).Net (OutputAmt)
Redim Sample (i).Out (OutputAmt)
Next i

Jaringan Syaraf Tiruan – Perceptron 5


• Entri data Sample
Sample (1).Inp (1) = 1
Sample (1).Inp (2) = 1
Sample (1).Out (1) = 1

Sample (2).Inp (1) = 1


Sample (2).Inp (2) = 0
Sample (2).Out (1) = -1

Sample (3).Inp (1) = 0


Sample (3).Inp (2) = 1
Sample (3).Out (1) = -1

Sample (4).Inp (1) = 0


Sample (4).Inp (2) = 0
Sample (4).Out (1) = -1
• Redim Weight
Redim Weight (InputAmt, OutputAmt)
• Entri data Weight : pertama diset 0 – termasuk bias
Dim i As Integer, j As Integer

For i = 0 To InputAmt
For j = 1 To OutputAmt
Weight(i, j) = 0
Next j
Next i

Proses Pelatihan
Dim i As Integer, j As Integer, k As Integer
Dim Error As Double, GlobalError As Double, Epzilon As Double
Dim Delta As Double
Dim str As String, strn As String, stro As String, strt As String
Dim iteration As Long

GlobalError = 1
Epzilon = 0
While GlobalError > Epzilon
GlobalError = 0
For i = 1 To SampleAmt
'searching sigma
For j = 1 To OutputAmt
Sample(i).Net(j) = Weight(0, j) 'bias unit
For k = 1 To InputAmt
Sample(i).Net(j) = Sample(i).Net(j) + Sample(i).Inp(k) * Weight(k, j)
Next k
Next j

'update weight
Error = 0
For j = 1 To OutputAmt
If Activate(Sample(i).Net(j)) <> Sample(i).Out(j) Then 'update weight if any change

Jaringan Syaraf Tiruan – Perceptron 6


Error = Error + Abs(Activate(Sample(i).Net(j)) - Sample(i).Out(j))
For k = 1 To InputAmt
Delta = LearningRate * Sample(i).Out(j) * Sample(i).Inp(k)
Weight(k, j) = Weight(k, j) + Delta
Next k
Delta = LearningRate * Sample(i).Out(j) 'for bias
Weight(0, j) = Weight(0, j) + Delta
End If
Next j
GlobalError = GlobalError + Error

txtError.Text = GlobalError
txtError.Refresh
Next i

DoEvents

iteration = iteration + 1
Wend

Tes Data
Dim Implementation As DataSample
ReDim Implementation.Inp(InputAmt)
ReDim Implementation.Net(OutputAmt)
ReDim Implementation.Out(OutputAmt)
Dim i As Integer, j As Integer

Implementation.Inp(1) = txtInput1.Text
Implementation.Inp(2) = txtInput2.Text

For i = 1 To OutputAmt
Implementation.Net(i) = Weight(0, i) 'for bias first
For j = 1 To InputAmt
Implementation.Net(i) = Implementation.Net(i) + Implementation.Inp(j) * Weight(j, i)
Next j
Implementation.Out(i) = Activate(Implementation.Net(i))
Next i

txtOutput.Text = Implementation.Out(1)

Jaringan Syaraf Tiruan – Perceptron 7

Anda mungkin juga menyukai