-
Notifications
You must be signed in to change notification settings - Fork 0
/
myCode.py
57 lines (44 loc) · 1.42 KB
/
myCode.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
import re
import numpy as np
import matplotlib.pyplot as plt
from Utils.DNN_Model import L_layer_model, predict, regularization
def ReadFile(inputPath):
file = open(inputPath, "r")
read = file.read()
file.close()
read = list(re.split(' |\n', read))
return read
def DataProcess(inputString, DIMX, DIMY):
temp = np.zeros((DIMX, DIMY))
K = 0
for i in range(0, DIMX):
for j in range(0, DIMY):
t = np.double(inputString[K])
K = K + 1
temp[i, j] = t
temp = np.reshape(temp, (DIMX, DIMY))
return temp
if __name__ == "__main__":
inputStr = ReadFile("./inputX.txt")
X = DataProcess(inputStr, 81, 2)
X = X.T
#X = regularization(X)
inputStr = ReadFile("./inputY.txt")
# it should be (9, 81) but i am a lazy input writer so i flipped it to fit my data
Y = DataProcess(inputStr, 81, 9)
Y = Y.T
layers_dims = (2, 9, 9, 9)
lr = 0.005
IterNum = 90000
param, costs = L_layer_model(X, Y, layers_dims, lr, IterNum, 1000, True)
# plot the cost
plt.rcParams['figure.figsize'] = (5.0, 4.0) # set default size of plots
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'
plt.plot(np.squeeze(costs))
plt.ylabel('cost')
plt.xlabel('iterations (per hundreds)')
plt.title("Learning rate =" + str(lr))
plt.show()
testy = predict(X, Y, param)
print(testy)