Exemplo n.º 1
0
def XOR(x1, x2):

    # 第1層
    s1 = NAND(x1, x2)
    s2 = OR(x1, x2)

    # 第2層
    y = AND(s1, s2)

    # 出力
    return y
Exemplo n.º 2
0
def XOR(x1, x2):
    """
    x1 x2 | y
    ----------
    0  0  | 0
    0  1  | 1
    1  0  | 1
    1  1  | 0
    """
    s1 = NAND(x1, x2)
    s2 = OR(x1, x2)
    y = AND(s1, s2)
    return y
def XOR(x1, x2):
    s1 = NAND(x1, x2)
    s2 = OR(x1, x2)
    return AND(s1, s2)
Exemplo n.º 4
0
import numpy as np


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
    else:
        return 1

if __name__ == '__main__':
    for xs in [(0, 0), (1, 0), (0, 1), (1, 1)]:
        y = NAND(xs[0], xs[1])
        print(str(xs) + " -> " + str(y))


###########################################################
# coding: utf-8
import numpy as np


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
def XOR(x1, x2):
    s1 = NAND(x1, x2)
    s2 = OR(x1, x2)
    y = AND(s1, s2)##至少有一个,且不相同,就是异或
    return y
Exemplo n.º 6
0
def XOR(x1, x2):
    s1 = OR(x1, x2)
    s2 = NAND(x1, x2)
    y = AND(s1, s2)
    return y
def XOR(x1, x2):
    """returns x1 XOR x2"""
    s1 = NAND(x1, x2)
    s2 = OR(x1, x2)
    return AND(s1, s2)
Exemplo n.º 8
0
def XOR(x1, x2):  # multi-layer perceptron
    s1 = NAND(x1, x2)  # layer 1
    s2 = OR(x1, x2)  # layer 1
    y = AND(s1, s2)  # layer 2
    return y