맛동산

다층 퍼셉트론의 구현(XOR) 본문

파이썬/딥러닝 구현

다층 퍼셉트론의 구현(XOR)

오지고지리고알파고포켓몬고 2017. 5. 14. 18:16

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
·¬
def·AND(x1,·x2):¬
····w1,·w2,·theta·=·0.5,·0.5,·0.99¬
····tmp·=·x1*w1·+·x2*w2¬
····result·=·0·if·tmp·<=·theta·else·1¬
¬
····return·result¬
¬
def·OR(x1,·x2):¬
····w1,·w2,·theta·=·0.5,·0.5,·0.49¬
····tmp·=·x1*w1·+·x2*w2¬
····result·=·0·if·tmp·<=·theta·else·1¬
¬
····return·result¬
¬
def·NAND(x1,·x2):¬
····#x,w,b·=·np.array([x1,·x2]),·np.array([0.5,·0.5]),·-0.99¬
····x·=·np.array([x1,·x2])¬
····w·=·np.array([-0.5,·-0.5])¬
····b·=·0.99¬
····tmp·=·np.sum(w*x)·+·b¬
····result·=·0·if·tmp·<=·0·else·1¬
¬
····return·result¬
¬
def·XOR(x1,x2):¬
····s1·=·NAND(x1,x2)¬
····s2·=·OR(x1,x2)¬
····result·=·AND(s1,s2)¬
¬
····return·result¬
¬
print(XOR(0,0))¬
print(XOR(1,0))¬
print(XOR(0,1))¬
print(XOR(1,1))¬
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

하나의 직선으로 XOR을 구분할 수 없음. 그래서 복합층으로 구현

x1

x2

s1

s2

y

0

0

1

0

0

1

0

1

1

1

0

1

1

1

1

1

1

0

1

0

Comments