When will you grow up?

Perceptron Learning Algorithm 본문

02. Study/Deep Learning

Perceptron Learning Algorithm

미카이 2017. 3. 13. 15:37

Perceptron Learning Algorithm?

->McCulloch와 Pitts(1943)가 제안한 인공 신경망으로, 여기에서 학습은 입력된 패턴을 한 번에 하나씩 비교하면서 요구된 출력이 일어날 때까지 가중치를 조절하는 과정을 통해 일어난다. 일련의 입력들에 대하여 가중치를 부여한 레이어로 구성되어 있다

[네이버 지식백과] 퍼셉트론 학습 [perceptron learning] (실험심리학용어사전, 2008., 시그마프레스㈜)






-Python Code

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import matplotlib.pyplot as plt
import numpy as np
 
 
#Perceptron algorithm을 적용시키기위한 적절한 데이터 초기화
# shape = 20 * 2 (data,label)
datasetD = np.array([
((1-0.40.3), -1),
((10.50.8), -1),
((1-0.3-0.1), -1),
((1-1.20.2), -1),
((10.30.9), -1),
((10.50.7), -1),
((1-0.5-0.1), -1),
((1-0.51.5), -1),
((1-0.80.9), -1),
((1-2.01.0), -1),
((10.9-0.5), 1),
((10.7-0.9), 1),
((10.80.2), 1),
((10.90.2), 1),
((10.5-0.4), 1),
((10.2-0.9), 1),
((10.4-0.7), 1),
((11.5-1.0), 1),
((10.880.2), 1),
((10.4-0.6), 1)])
 
def misclassified(w, datasetD):
    result = None
    error = 0
    for x, s in datasetD:
        x = np.array(x)
        if int(np.sign(w.T.dot(x))) != s:
            result =  x, s
            error += 1
    print  ("error=%s" % error)
    return result
 
def perceptron_implements(datasetD):
    w = np.array([np.random.uniform(-11), np.random.uniform(-11), np.random.uniform(-11)])
    k = 0 #Parameter k is required to complete the learning
    while misclassified(w, datasetD) is not None:
        x, y = misclassified(w, datasetD) #misclassified
        w += y * x #update the weight vector
        ps = [v[0for v in datasetD]
        #데이터 그리기
        fig = plt.figure()
        line = fig.add_subplot(111)
        line.scatter([v[1for v in ps[:10]], [v[2for v in ps[:10]], s=20, c='g', marker="o", label='O')
        line.scatter([v[1for v in ps[10:]], [v[2for v in ps[10:]], s=20, c='r', marker="*", label='X')
        l = np.linspace(-2,2)
        a,b = -w[1]/w[2], -w[0]/w[2]
        line.plot(l, a*+ b, 'b-')
        plt.legend(loc='upper left');
        plt.show()
        k += 1 
    return w,k
#실행
w,k = perceptron_implements(datasetD)
print(k)
cs


Comments