-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
105 lines (90 loc) · 5.03 KB
/
test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# %%
import numpy as np
import scipy.io as scio
data = scio.loadmat('./data_set/Dataset_NN.mat')
# for k in data:
# print(k)
# print (type(data['Dataset']['Climate']))
# print (data['Dataset']['Climate'])
datasetNN = np.array(data['Dataset'])
np.save('./data_set/DatasetNN', datasetNN)
# %%
import numpy as np
dataNo = 1
datasets = ['Statlog_Australian', 'Climate', 'Statlog_German', 'Connectionist_bench_Sonar']
dataname = datasets[dataNo]
datasetNN = np.load('./data_set/DatasetNN.npy', allow_pickle=True)
data = datasetNN[dataname][0][0]
print(np.shape(data))
# print(datasetNN['Climate'])
# print(type(datasetNN))
# print(np.shape(datasetNN))
# print(np.shape(datasetNN['Climate']))
# %%
import numpy as np
a = np.array([1, 2, 3, 2, 3, 4, 4, 15, 6])
# a = np.array([[1, 2, 3], [2, 3, 4], [4, 15, 6]])
b = np.reshape(a, (3, 3))
print(a[:2])
print(a[2:])
# b = (np.mean(a, axis=1, keepdims=True))
# print(a, b)
# print(a - b)
# %%
import numpy as np
def predict(x, w1, w2):
n = np.shape(x)[0]
Y = 1 - 2 / (1 + np.exp(2 * np.matmul(np.concatenate([np.ones((n, 1)), x], 1), w1)))
Z = 1 / (1 + np.exp(np.matmul(-np.concatenate([np.ones((np.shape(Y)[0], 1)), Y], 1), w2)))
return Z, Y
x = np.random.rand(3, 14)
print('x', x)
w1 = np.random.rand(15, 20)
print('w1', w1)
w2 = np.random.rand(21, 1)
print('w2', w2)
z, y = predict(x, w1, w2)
print('z', z)
# %%
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = a * a
c = np.matmul(a, a)
print(c)
#%%
[[0.84074415 0.61854318 0.35071503 0.65419992 0.31666789 0.90209979 0.5463329 0.42785865 0.58014728 0.53690295 0.19562066 0.43113695 0.12692343 0.82841422 0.75559719 0.04464747 0.94513612 0.08241144 0.66789143 0.15712592];
[0.20654762 0.26073954 0.31960949 0.88953848 0.75791578 0.25162634 0.69204482 0.90995969 0.24819993 0.14936679 0.38024932 0.73723799 0.20761442 0.49472907 0.98317552 0.47415875 0.70446673 0.42164014 0.94514426 0.08111804];
[0.47889874 0.10998952 0.62706068 0.54086163 0.03741315 0.22707145 0.4174488 0.53985536 0.48348534 0.8544483 0.60203144 0.45211533 0.56636316 0.99823754 0.95459428 0.83837235 0.84279477 0.18120898 0.18618631 0.14456248];
[0.85424609 0.83098531 0.90035229 0.23072778 0.81420127 0.78062959 0.59332267 0.96954124 0.00431636 0.38924931 0.17016896 0.54021753 0.43689789 0.56736021 0.79063873 0.39354486 0.44179045 0.86937648 0.39546148 0.38974498];
[0.16775598 0.10460027 0.97010342 0.44793292 0.0272172 0.76019171 0.64741583 0.32782253 0.95396376 0.41910076 0.11455881 0.38927983 0.6417747 0.18347783 0.96102656 0.23666428 0.73318586 0.27755523 0.85232885 0.27520753];
[0.21262654 0.52907974 0.08125138 0.6426489 0.12761522 0.06637813 0.57967654 0.36964337 0.35424605 0.10169441 0.93124796 0.02200119 0.21370195 0.82831674 0.12956849 0.09258646 0.97817778 0.65812116 0.95352794 0.77972508];
[0.58580721 0.012224 0.19599798 0.17180204 0.09292449 0.8543479 0.63553565 0.27916034 0.43002031 0.15626352 0.70259549 0.52332201 0.19630184 0.13370205 0.67631295 0.41486542 0.48319195 0.79205109 0.01271036 0.15967578];
[0.58333296 0.40437039 0.55456351 0.46819157 0.98201664 0.01653074 0.85658132 0.06222541 0.67552933 0.91131115 0.36200195 0.44088656 0.79537054 0.88415546 0.45279789 0.0963721 0.84186152 0.78096121 0.3955108 0.906088 ];
[0.35372322 0.08875332 0.98488613 0.78112108 0.10586936 0.84888028 0.38982789 0.96059896 0.82933852 0.91272334 0.01198429 0.50391017 0.61994643 0.74848505 0.4207427 0.68858795 0.1380235 0.60419984 0.28519729 0.60403683];
[0.94449259 0.55749202 0.5108468 0.69576196 0.83885255 0.12253193 0.81495457 0.06951348 0.73155518 0.71510371 0.67973211 0.91691486 0.87959715 0.4857944 0.39685275 0.13291441 0.47335043 0.09388468 0.13868676 0.86179728];
[0.86555187 0.77116439 0.28144945 0.03646502 0.8306164 0.84086598 0.75966928 0.96172013 0.42337717 0.09735321 0.13410317 0.38990439 0.3650922 0.68282643 0.38771312 0.56310604 0.24527304 0.8327434 0.88309496 0.06273324];
[0.06425954 0.28562237 0.73806561 0.66514306 0.98603777 0.62677568 0.98801068 0.4175724 0.00738195 0.18802544 0.92889412 0.16696411 0.02111045 0.7619474 0.08538908 0.80318379 0.5392194 0.65431885 0.37579347 0.30353028];
[0.61615097 0.06129264 0.60861841 0.72410235 0.41314219 0.35349507 0.46043338 0.0537107 0.32105976 0.77551093 0.20782535 0.55569737 0.46415234 0.50007752 0.98302525 0.52458171 0.10322906 0.80581235 0.86039009 0.88858671];
[0.08934702 0.04189209 0.60470314 0.87898402 0.03147113 0.22428097 0.72998094 0.3110799 0.37791272 0.83460733 0.78861666 0.91172184 0.45834541 0.9203435 0.77662781 0.27797652 0.18496603 0.8700697 0.97136248 0.69064534];
[0.66869703 0.21259185 0.54673865 0.2044444 0.04119406 0.77064059 0.49700481 0.00135684 0.19495408 0.59892812 0.51519758 0.58211165 0.86629275 0.06269867 0.30801888 0.34870977 0.7977465 0.81933633 0.68680605 0.34201485]]
[[0.89598867];
[0.97840932];
[0.7968314 ];
[0.58691273];
[0.78488474];
[0.89063344];
[0.12289742];
[0.38521156];
[0.73279793];
[0.85507771];
[0.2359711 ];
[0.18844327];
[0.16079693];
[0.37856646];
[0.2651625 ];
[0.33792127];
[0.56621353];
[0.76159705];
[0.00825455];
[0.57795607];
[0.17822697]]