-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter_1.py
More file actions
84 lines (63 loc) · 1.79 KB
/
Copy pathchapter_1.py
File metadata and controls
84 lines (63 loc) · 1.79 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import numpy as np
def w_sum(a, b):
assert len(a) == len(b)
output = 0
for i in range(len(a)):
output += a[i] * b[i]
return output
# weights = [0.1, 0.2, 0]
# toes %win #fans
ih_wgt = np.array(
[[0.1, 0.2, -0.1], [-0.1, 0.1, 0.9], [0.1, 0.4, 0.1]] # hid[0] # hid[1]
) # hid[2]
# hid[0] hid[1] hid[2]
hp_wgt = np.array([[0.3, 1.1, -0.3], [0.1, 0.2, 0.0], [0.0, 1.3, 0.1]]) # hurt? # win? # sad?
weights = [ih_wgt, hp_wgt]
def vect_mat_mul(vect, matrix):
assert len(vect) == len(matrix)
output = [0, 0, 0]
for i in range(len(vect)):
output[i] = w_sum(vect, matrix[i])
return output
def neural_network(input, weights):
hid = input.dot(weights[0])
pred = hid.dot(weights[1])
return pred
toes = np.array([8.5, 9.5, 9.9, 9.0])
wlrec = np.array([0.65, 0.8, 0.8, 0.9])
nfans = np.array([1.2, 1.3, 0.5, 1.0])
# Input corresponds to every entry
# for the first game of the season.
input = np.array([toes[0], wlrec[0], nfans[0]])
pred = neural_network(input, weights)
print(pred)
"""
def average(input):
summ = sum(input)
return summ / len(input)
print(average(toes))
"""
# print(neural_network(np.array([toes[0], wlrec[0], nfans[0]]), np.array([0.1, 0.2, -0.1])))
"""
w1 = [toes[0], wlrec[0], nfans[0]]
w2 = [0.1, 0.2, -0.1]
def summ(e1, e2):
return e1 * e2
res = sum(list(map(summ, w1, w2)))
print(res)
"""
a = np.array([1, 2, 3, 4])
b = np.array([5, 6, 7, 8])
c = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
d = np.zeros((2, 4)) # Матрица 2*4 заполненная нулями
e = np.random.rand(2, 5) # Матрица 2*5 заполненная случайными числами от 0 до 1
f = np.zeros((1, 4))
g = np.zeros((4, 3))
cc = f.dot(g)
print(a)
print(b)
print(c)
print(d)
print(e)
print(a * c)
print("cc= ", cc)