← Back to Index
Research & Engineering Archive

D2L 4.1 Multilayer Perceptron

By Jingnan Huang · December 20, 2024 · 2588 Words

Last Edit: 12/20/24

“如果微妙的边界条件很重要,我们很可能是在研究数学而非工程”

Perceptron 感知机
#

Binary Classification 二分类问题
#

Training 训练
#

initialize w = 0 and b = 0
repeat
    for each (xi, yi) in the training data:
        if yi * (⟨w, xi⟩ + b) ≤ 0 then
            w ← w + yi * xi
            b ← b + yi
        end if
    end for
until all points are classified correctly
import numpy as np

w = np.zeros(2) 
b = 0.0
n_epoch = 11

X = np.array([
    [0.5, 1.5],
    [1.0, 1.0],
    [1.5, 0.5],
    [2.0, 1.0],
    [2.5, 1.5],
    [3.0, 3.0],
    [3.5, 3.5],
    [4.0, 4.5],
    [4.5, 5.0],
    [5.0, 5.5]])

y = np.array([-1, -1, -1, -1, -1, 1, 1, 1, 1, 1])
for epoch in range(n_epochs):
    for i in range(len(X)):
        if y[i] * (np.dot(w, X[i]) + b) <= 0:
            w += y[i] * X[i]
            b += y[i]
        else:
            continue   

def predict(X, w, b):
    return np.sign(np.dot(X, w) + b)

predictions = predict(X, w, b)

print("Predictions:", predictions)
print("Actual labels:", y)

> Predictions: [-1. -1. -1. -1. -1.  1.  1.  1.  1.  1.]
> Actual labels: [-1 -1 -1 -1 -1  1  1  1  1  1]

XOR Problem
#

XOR(异或)逻辑门是一个二输入逻辑门,其输出只在两个输入不同时为1(即当输入是(0,1)或(1,0)时)。其逻辑如下:

单调假设与线性模型的局限性
#

Hidden Layer 隐藏层
#

Activation Function 激活函数
#

Weierstrass Approximation Theorem
#

Activation Function that has Tyler Series
#

$$F(x) = \underbrace{\sigma(b_1) \cdot \alpha_1}_{\text{常数项}} + \underbrace{\sigma(w_2x + b_2) \cdot \alpha_2}_{\text{线性项}} + \underbrace{\sigma(w_{3,1}x + b_{3,1}) \cdot \alpha_{3,1} + \sigma(w_{3,2}x + b_{3,2}) \cdot \alpha_{3,2}}_{\text{二次项}}$$

Activation Function that doesn’t have Tyler Series
#

Img

5分钟理解激活函数让神经网络能拟合任何函数 - 知乎