CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
amanchadha

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: amanchadha/coursera-deep-learning-specialization
Path: blob/master/C1 - Neural Networks and Deep Learning/Week 3/Planar data classification with one hidden layer/testCases_v2.py
Views: 4798
1
import numpy as np
2
3
def layer_sizes_test_case():
4
np.random.seed(1)
5
X_assess = np.random.randn(5, 3)
6
Y_assess = np.random.randn(2, 3)
7
return X_assess, Y_assess
8
9
def initialize_parameters_test_case():
10
n_x, n_h, n_y = 2, 4, 1
11
return n_x, n_h, n_y
12
13
14
def forward_propagation_test_case():
15
np.random.seed(1)
16
X_assess = np.random.randn(2, 3)
17
b1 = np.random.randn(4,1)
18
b2 = np.array([[ -1.3]])
19
20
parameters = {'W1': np.array([[-0.00416758, -0.00056267],
21
[-0.02136196, 0.01640271],
22
[-0.01793436, -0.00841747],
23
[ 0.00502881, -0.01245288]]),
24
'W2': np.array([[-0.01057952, -0.00909008, 0.00551454, 0.02292208]]),
25
'b1': b1,
26
'b2': b2}
27
28
return X_assess, parameters
29
30
def compute_cost_test_case():
31
np.random.seed(1)
32
Y_assess = (np.random.randn(1, 3) > 0)
33
parameters = {'W1': np.array([[-0.00416758, -0.00056267],
34
[-0.02136196, 0.01640271],
35
[-0.01793436, -0.00841747],
36
[ 0.00502881, -0.01245288]]),
37
'W2': np.array([[-0.01057952, -0.00909008, 0.00551454, 0.02292208]]),
38
'b1': np.array([[ 0.],
39
[ 0.],
40
[ 0.],
41
[ 0.]]),
42
'b2': np.array([[ 0.]])}
43
44
a2 = (np.array([[ 0.5002307 , 0.49985831, 0.50023963]]))
45
46
return a2, Y_assess, parameters
47
48
def backward_propagation_test_case():
49
np.random.seed(1)
50
X_assess = np.random.randn(2, 3)
51
Y_assess = (np.random.randn(1, 3) > 0)
52
parameters = {'W1': np.array([[-0.00416758, -0.00056267],
53
[-0.02136196, 0.01640271],
54
[-0.01793436, -0.00841747],
55
[ 0.00502881, -0.01245288]]),
56
'W2': np.array([[-0.01057952, -0.00909008, 0.00551454, 0.02292208]]),
57
'b1': np.array([[ 0.],
58
[ 0.],
59
[ 0.],
60
[ 0.]]),
61
'b2': np.array([[ 0.]])}
62
63
cache = {'A1': np.array([[-0.00616578, 0.0020626 , 0.00349619],
64
[-0.05225116, 0.02725659, -0.02646251],
65
[-0.02009721, 0.0036869 , 0.02883756],
66
[ 0.02152675, -0.01385234, 0.02599885]]),
67
'A2': np.array([[ 0.5002307 , 0.49985831, 0.50023963]]),
68
'Z1': np.array([[-0.00616586, 0.0020626 , 0.0034962 ],
69
[-0.05229879, 0.02726335, -0.02646869],
70
[-0.02009991, 0.00368692, 0.02884556],
71
[ 0.02153007, -0.01385322, 0.02600471]]),
72
'Z2': np.array([[ 0.00092281, -0.00056678, 0.00095853]])}
73
return parameters, cache, X_assess, Y_assess
74
75
def update_parameters_test_case():
76
parameters = {'W1': np.array([[-0.00615039, 0.0169021 ],
77
[-0.02311792, 0.03137121],
78
[-0.0169217 , -0.01752545],
79
[ 0.00935436, -0.05018221]]),
80
'W2': np.array([[-0.0104319 , -0.04019007, 0.01607211, 0.04440255]]),
81
'b1': np.array([[ -8.97523455e-07],
82
[ 8.15562092e-06],
83
[ 6.04810633e-07],
84
[ -2.54560700e-06]]),
85
'b2': np.array([[ 9.14954378e-05]])}
86
87
grads = {'dW1': np.array([[ 0.00023322, -0.00205423],
88
[ 0.00082222, -0.00700776],
89
[-0.00031831, 0.0028636 ],
90
[-0.00092857, 0.00809933]]),
91
'dW2': np.array([[ -1.75740039e-05, 3.70231337e-03, -1.25683095e-03,
92
-2.55715317e-03]]),
93
'db1': np.array([[ 1.05570087e-07],
94
[ -3.81814487e-06],
95
[ -1.90155145e-07],
96
[ 5.46467802e-07]]),
97
'db2': np.array([[ -1.08923140e-05]])}
98
return parameters, grads
99
100
def nn_model_test_case():
101
np.random.seed(1)
102
X_assess = np.random.randn(2, 3)
103
Y_assess = (np.random.randn(1, 3) > 0)
104
return X_assess, Y_assess
105
106
def predict_test_case():
107
np.random.seed(1)
108
X_assess = np.random.randn(2, 3)
109
parameters = {'W1': np.array([[-0.00615039, 0.0169021 ],
110
[-0.02311792, 0.03137121],
111
[-0.0169217 , -0.01752545],
112
[ 0.00935436, -0.05018221]]),
113
'W2': np.array([[-0.0104319 , -0.04019007, 0.01607211, 0.04440255]]),
114
'b1': np.array([[ -8.97523455e-07],
115
[ 8.15562092e-06],
116
[ 6.04810633e-07],
117
[ -2.54560700e-06]]),
118
'b2': np.array([[ 9.14954378e-05]])}
119
return parameters, X_assess
120
121