感知机算法

$$
y =
\begin{cases}
0 & (w_1x_1 + w_2x_2 \leq \theta) \\
1 & (w_1x_1 + w_2x_2 > \theta)
\end{cases}
$$

简单的逻辑电路

与门

def AND(x1, x2):
    x = np.array([x1, x2])
    w = np.array([0.5, 0.5])
    b=-0.7
    tmp = np.sum(w*x) + b
    if tmp =< 0:
        return 0
    elif tmp > 0:
        return 1
x1 x2 y
0 0 0
1 0 0
0 1 0
1 1 1

与非门

def NAND(x1, x2):
    x = np.array([x1, x2])
    w = np.array([-0.5, -0.5])
    b=0.7
    tmp = np.sum(w*x) + b
    if tmp =< 0:
        return 0
    elif tmp > 0:
        return 1
x1 x2 y
0 0 1
1 0 1
0 1 1
1 1 0

或门

def OR(x1, x2):
    x = np.array([x1, x2])
    w = np.array([0.5, 0.5])
    b=0.2
    tmp = np.sum(w*x) + b
    if tmp =< 0:
        return 0
    elif tmp > 0:
        return 1
x1 x2 y
0 0 0
1 0 1
0 1 1
1 1 1

异或门

x1 x2 y
0 0 0
1 0 1
0 1 1
1 1 0
def XOR(x1, x2):
    s1 = NAND(x1,x2)
    s2 = OR(x1,x2)
    y = AND(s1,s2)
    return y

这里由多层感应机实现,通常称之为二层感知机

Last modification:August 20th, 2020 at 04:15 am
如果觉得我的文章对你有用,请随意赞赏