Perceptron

Created onDibuat pada
Last updated onTerakhir diperbarui
11 min read11 menit baca
IDperceptrondata-science
ContributorsKontributor
Razi Rachman Widyadhana - @zirachw

Perceptron adalah model neural network paling sederhana, terinspirasi dari cara kerja sel saraf biologis (biological neuron).

#Link to this headingA Simplified Brain Cell

Neuron biologis: dendrites menerima sinyal → cell body mengintegrasikan → axon mengirim output
Neuron biologis: dendrites menerima sinyal → cell body mengintegrasikan → axon mengirim output

McCulloch dan Pitts mendeskripsikan sebuah simple logic gate dengan binary outputs:

  • Banyak sinyal tiba di dendrites
  • Diintegrasikan dalam cell body
  • Jika sinyal akumulasi melebihi threshold tertentu, sinyal output dihasilkan melalui axon

#Link to this headingDefinisi Formal Neuron

Formal neuron: input x → weighted sum → activation function → output
Formal neuron: input x → weighted sum → activation function → output

Dalam konteks binary classification:

  • Input: real-valued x=(x1,x2,…,xm)x = (x_1, x_2, \ldots, x_m)
  • Weight vector: w=(w0,w1,w2,…,wm)w = (w_0, w_1, w_2, \ldots, w_m), di mana wiw_i merepresentasikan kontribusi input xix_i
  • Bias/threshold: w0w_0 (atau bb)
  • Net input: z=w0+w1x1+w2x2+…+wmxm=wT⋅xz = w_0 + w_1 x_1 + w_2 x_2 + \ldots + w_m x_m = \mathbf{w}^T \cdot \mathbf{x}
  • Output: 11 jika net input melebihi threshold tertentu

#Link to this headingPerceptron

Perceptron: hyperplane decision surface dalam ruang n-dimensi
Perceptron: hyperplane decision surface dalam ruang n-dimensi

Perceptron merepresentasikan hyperplane decision surface dalam ruang nn-dimensi dari instances.

o(x)=sign(wT⋅x)=sign(w0+w1x1+w2x2+…+wdxd)o(\mathbf{x}) = \text{sign}(\mathbf{w}^T \cdot \mathbf{x}) = \text{sign}(w_0 + w_1 x_1 + w_2 x_2 + \ldots + w_d x_d)

  • Linear model untuk linearly separable dataset
  • Simple neural network berbasis satu unit
  • Learning output: w∈Rd+1\mathbf{w} \in \mathbb{R}^{d+1}
  • Hypothesis space: H={w∣w∈Rd+1}H = \{ \mathbf{w} \mid \mathbf{w} \in \mathbb{R}^{d+1} \}

#Link to this headingPerceptron untuk m-of-n Functions

m-of-n functions: setidaknya mm dari nn input harus bernilai true.

FungsimmContoh
ANDm=nm = nsign(x1 + x2 - 1)
ORm=1m = 1sign(2x1 + 2x2 - 1)

Cara merepresentasikan m-of-n function:

  1. Set semua input weights ke nilai yang sama (e.g., 0.50.5)
  2. Set threshold w0w_0 yang sesuai

#Link to this headingContoh: AND Perceptron

AND Perceptron: hyperplane 0.5x1 + 0.5x2 = 0.8 memisahkan kelas +1 dan -1
AND Perceptron: hyperplane 0.5x1 + 0.5x2 = 0.8 memisahkan kelas +1 dan -1

Dengan w0=−0.8w_0 = -0.8, w1=w2=0.5w_1 = w_2 = 0.5 → merepresentasikan fungsi AND:

x0x_0x1x_1x2x_2σ=wTx\sigma = w^T xsign\text{sign}
1111110.20.2+1+1
1111−1-1−0.8-0.8−1-1
11−1-111−0.8-0.8−1-1
11−1-1−1-1−1.8-1.8−1-1

#Link to this headingAlgoritma Pembelajaran Perceptron

Tiga algoritma pembelajaran: PTR (sign), BGD (linear), SGD (linear)
Tiga algoritma pembelajaran: PTR (sign), BGD (linear), SGD (linear)

Terdapat tiga algoritma pembelajaran utama:

AlgoritmaFungsi AktivasiUpdate BobotKonvergensi
Perceptron Training Rule (PTR)SignSaat misclassifiedHanya jika linearly separable
Batch Gradient Descent (BGD)LinearSetelah semua examplesBest-fit approximation
Stochastic Gradient Descent (SGD)LinearSetelah setiap exampleBest-fit approximation

#Link to this headingPerceptron Training Rule (PTR)

PTR pseudocode: update bobot hanya saat prediksi salah, konvergen jika linearly separable
PTR pseudocode: update bobot hanya saat prediksi salah, konvergen jika linearly separable

Menggunakan fungsi aktivasi sign. Update bobot hanya saat terjadi misclassification:

Initialize each w_k to 0 or small random value
Repeat:
    E = 0
    For each example <x_i, y_i>:
        o_i = sign(w^T * x_i)
        if o_i == y_i: do nothing
        else:
            w_j = w_j + η(y_i - o_i) * x_ij   ← untuk setiap weight
            E = E + (y_i - o_i)
Until all training examples correctly classified
Return w

#Link to this headingContoh PTR

PTR: per-row update bobot saat misclassification
PTR: per-row update bobot saat misclassification

Dataset: η=0.1\eta = 0.1, fungsi aktivasi SIGN

x1x_1x2x_2x3x_3yy
110011−1-1
00−1-1−1-1+1+1
−1-1−0.5-0.5−1-1+1+1

Inisialisasi: w=[0,0,0,0]w = [0, 0, 0, 0]

Epoch 1:

iterx0x_0x1x_1x2x_2x3x_3yyw0w_0w1w_1w2w_2w3w_3σ\sigmaoio_iEE
11101−1-100000−1-10
110−1-1−1-1+1+100000−1-12
11−1-1−0.5-0.5−1-1+1+10.20−0.2−0.20.5+1+12

Setelah Epoch 1: w=[0.2,0,−0.2,−0.2]w = [0.2, 0, -0.2, -0.2]

Epoch 2:

iterx0x_0x1x_1x2x_2x3x_3yyσ\sigmaoio_iEE
21101−1-10−1-10
210−1-1−1-1+1+10.6+1+10
21−1-1−0.5-0.5−1-1+1+10.5+1+10

Terminate - Semua prediksi benar. w=[0.2,0,−0.2,−0.2]w = [0.2, 0, -0.2, -0.2]

#Link to this headingGradient Descent (Delta Rule)

Gradient Descent: mencari minimum error di landscape hipotesis menggunakan gradient
Gradient Descent: mencari minimum error di landscape hipotesis menggunakan gradient

Jika data tidak linearly separable, PTR gagal konvergen. Delta Rule (gradient descent) konvergen menuju best-fit approximation terlepas apakah data linearly separable atau tidak.

Searching strategy menggunakan gradient dari error landscape untuk menemukan minimum error:

w←w−η∇E(w)w \leftarrow w - \eta \nabla E(w)

#Link to this headingFungsi Aktivasi Linear

Pada delta rule, output menggunakan fungsi aktivasi linear (unthresholded):

o=wT⋅x=w0+w1x1+…+wdxdo = \mathbf{w}^T \cdot \mathbf{x} = w_0 + w_1 x_1 + \ldots + w_d x_d

Error menggunakan squared error:

E=∑i(yi−oi)22E = \sum_i \frac{(y_i - o_i)^2}{2}

Delta Rule: thresholded output untuk prediksi, unthresholded untuk weight update
Delta Rule: thresholded output untuk prediksi, unthresholded untuk weight update

#Link to this headingBatch Gradient Descent (BGD)

Menghitung akumulasi weight updates setelah memproses semua training examples, baru kemudian update bobot.

Initialize each w_k to 0 or small random value
Until termination condition is met:
    Initialize Δw_k = 0 for all k; E = 0
    For each example <x_i, y_i>:
        o_i = w^T * x_i   (linear activation)
        For each weight w_k:
            Δw_k = Δw_k + η(y_i - o_i) * x_ik
        E = E + (y_i - o_i)² / 2
    For each weight w_k:
        w_k = w_k + Δw_k
Return w

#Link to this headingContoh BGD

BGD: akumulasi Δw per epoch, update bobot setelah semua data
BGD: akumulasi Δw per epoch, update bobot setelah semua data

Dataset: η=0.3\eta = 0.3, fungsi aktivasi LINEAR, error threshold =0.01= 0.01

x1x_1x2x_2x3x_3yy
110011−1-1
00−1-1−1-1+1+1
−1-1−0.5-0.5−1-1+1+1

Inisialisasi: w=[0,0,0,0]w = [0, 0, 0, 0]

Epoch 1 - Akumulasi Δw\Delta w:

iterx0x_0x1x_1x2x_2x3x_3yyw0w_0w1w_1w2w_2w3w_3σ\sigmaΔw0\Delta w_0Δw1\Delta w_1Δw2\Delta w_2Δw3\Delta w_3EE
11101−1-100000−0.30-0.30−0.30-0.3000−0.30-0.300.500
110−1-1−1-1+1+10000000−0.30-0.30−0.30-0.30−0.60-0.601.000
11−1-1−0.5-0.5−1-1+1+1000000.300.30−0.60-0.60−0.45-0.45−0.90-0.901.500

Update: w=[0.30,−0.60,−0.45,−0.90]w = [0.30, -0.60, -0.45, -0.90]

Epoch 2:

iterx0x_0x1x_1x2x_2x3x_3yyσ\sigmaΔw0\Delta w_0Δw1\Delta w_1Δw2\Delta w_2Δw3\Delta w_3EE
21101−1-1−1.20-1.200.060.060.060.06000.060.060.020
210−1-1−1-1+1+11.651.65−0.14-0.140.060.060.200.200.260.260.231
21−1-1−0.5-0.5−1-1+1+12.032.03−0.44-0.440.370.370.350.350.560.560.757

Update: w=[0.30−0.14,−0.60−0.23,−0.45−0.10,−0.90−0.34]=[−0.14,−0.23,−0.10,−0.34]w = [0.30 - 0.14, -0.60 - 0.23, -0.45 - 0.10, -0.90 - 0.34] = [-0.14, -0.23, -0.10, -0.34]

Proses berlanjut hingga E<0.01E < 0.01.

#Link to this headingStochastic Gradient Descent (SGD)

Berbeda dengan BGD, SGD langsung update bobot setelah setiap training example, tidak menunggu semua data diproses.

Initialize each w_k to 0 or small random value
Until termination condition is met:
    E = 0
    For each example <x_i, y_i>:
        o_i = w^T * x_i   (linear activation)
        For each weight w_k:
            w_k = w_k + η(y_i - o_i) * x_ik   ← langsung update
        E = E + (y_i - o_i)² / 2
Return w

#Link to this headingContoh SGD

SGD: update bobot langsung setelah setiap training example
SGD: update bobot langsung setelah setiap training example

Dataset sama: η=0.3\eta = 0.3, fungsi aktivasi LINEAR, error threshold =0.01= 0.01

Epoch 1:

iterx0x_0x1x_1x2x_2x3x_3yyw0w_0w1w_1w2w_2w3w_3σ\sigmaEE
11101−1-1000000.500
110−1-1−1-1+1+1−0.30-0.30−0.30-0.3000−0.30-0.3001.000
11−1-1−0.5-0.5−1-1+1+100−0.30-0.30−0.30-0.30−0.60-0.601.051.051.001

Setelah Epoch 1: w=[−0.01,−0.29,−0.29,−0.59]w = [-0.01, -0.29, -0.29, -0.59]

Epoch 2:

iterx0x_0x1x_1x2x_2x3x_3yyσ\sigmaEE
21101−1-1−0.89-0.890.007
210−1-1−1-1+1+10.860.860.016
21−1-1−0.5-0.5−1-1+1+11.141.140.026

Setelah Epoch 2: w=[−0.05,−0.28,−0.31,−0.62]w = [-0.05, -0.28, -0.31, -0.62]

Proses berlanjut hingga epoch 4 di mana E<0.01E < 0.01 → terminate.

#Link to this headingBatch vs Stochastic Gradient Descent

Mini-batch SGD: dari true SGD (batch=1) hingga Batch GD (batch=|data|)
Mini-batch SGD: dari true SGD (batch=1) hingga Batch GD (batch=|data|)

Keduanya menggunakan fungsi aktivasi linear dan konvergen menuju best-fit approximation.

AspekBatch GDStochastic GD
Update bobotSetelah semua examplesSetelah setiap example
KonvergensiSmooth, stabilLebih noisy, bisa keluar dari local minima
Kecepatan per epochLebih lambatLebih cepat

#Link to this headingMini-batch SGD

ParameterPenjelasan
EpochIterasi untuk semua training data atau semua mini-batch
Batch size = 1True SGD (incremental)
Batch size = |data|Batch GD
1 < batch size < |data|Mini-batch SGD
StepPemrosesan satu mini-batch diakhiri dengan update bobot

#Link to this headingPerceptron: Kesimpulan

Perceptron Training Rule:

  • Linear classifier, tidak dapat membuat non-linear boundaries
  • Update bobot berdasarkan error pada thresholded perceptron output
  • Tidak konvergen jika kelas tidak linearly separable
  • Banyak solusi "optimal" dalam 0/1 loss, sebagian besar tidak optimal untuk generalisasi

Gradient Descent (Delta Rule):

  • Update bobot berdasarkan error pada unthresholded linear combination of inputs
  • Konvergen secara asimtotik menuju minimum hypothesis, terlepas dari linear separability
  • Batch / Incremental weight update