-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial_3.py
60 lines (48 loc) · 1.66 KB
/
tutorial_3.py
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
import numpy as np
from algorithms.activation_functions import heaviside_function
from algorithms.delta_learning_algorithms import sequential_delta_learning_rule
from algorithms.delta_learning_algorithms import batch_delta_learning_rule
def question_2():
w = np.array([[0.1, -0.5, 0.4]])
x1 = np.array([[0.1], [-0.5], [0.4]])
print(heaviside_function(np.matmul(w, x1)))
x2 = np.array([[0.1], [0.5], [0.4]])
print(heaviside_function(np.matmul(w, x2)))
def question_3():
samples = [np.array([[1], [0]]), np.array([[1], [1]])]
labels = [1, 0]
weights = np.array([[-1.5, 2]])
sequential_delta_learning_rule(weights, samples, labels)
def question_4():
samples = [np.array([[1], [0]]), np.array([[1], [1]])]
labels = [1, 0]
weights = np.array([[-1.5, 2]])
batch_delta_learning_rule(weights, samples, labels, epochs=7)
def question_5():
samples = [
np.array([[1], [0], [0]]),
np.array([[1], [0], [1]]),
np.array([[1], [1], [0]]),
np.array([[1], [1], [1]])
]
labels = [0, 0, 0, 1]
weights = np.array([[0.5, 1, 1]])
sequential_delta_learning_rule(weights, samples, labels, epochs=5)
def question_6():
samples = [
np.array([[1], [0], [2]]),
np.array([[1], [1], [2]]),
np.array([[1], [2], [1]]),
np.array([[1], [-3], [1]]),
np.array([[1], [-2], [-1]]),
np.array([[1], [-3], [-2]])
]
labels = [1, 1, 1, 0, 0, 0]
weights = np.array([[1, 0, 0]])
sequential_delta_learning_rule(weights, samples, labels, epochs=3)
if __name__ == "__main__":
# question_2()
# question_3()
# question_4()
# question_5()
question_6()