CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
y33-j3T

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: y33-j3T/Coursera-Deep-Learning
Path: blob/master/Improving Deep Neural Networks Hyperparameter tuning, Regularization and Optimization/week5/Regularization/testCases.py
Views: 13377
1
import numpy as np
2
3
def compute_cost_with_regularization_test_case():
4
np.random.seed(1)
5
Y_assess = np.array([[1, 1, 0, 1, 0]])
6
W1 = np.random.randn(2, 3)
7
b1 = np.random.randn(2, 1)
8
W2 = np.random.randn(3, 2)
9
b2 = np.random.randn(3, 1)
10
W3 = np.random.randn(1, 3)
11
b3 = np.random.randn(1, 1)
12
parameters = {"W1": W1, "b1": b1, "W2": W2, "b2": b2, "W3": W3, "b3": b3}
13
a3 = np.array([[ 0.40682402, 0.01629284, 0.16722898, 0.10118111, 0.40682402]])
14
return a3, Y_assess, parameters
15
16
def backward_propagation_with_regularization_test_case():
17
np.random.seed(1)
18
X_assess = np.random.randn(3, 5)
19
Y_assess = np.array([[1, 1, 0, 1, 0]])
20
cache = (np.array([[-1.52855314, 3.32524635, 2.13994541, 2.60700654, -0.75942115],
21
[-1.98043538, 4.1600994 , 0.79051021, 1.46493512, -0.45506242]]),
22
np.array([[ 0. , 3.32524635, 2.13994541, 2.60700654, 0. ],
23
[ 0. , 4.1600994 , 0.79051021, 1.46493512, 0. ]]),
24
np.array([[-1.09989127, -0.17242821, -0.87785842],
25
[ 0.04221375, 0.58281521, -1.10061918]]),
26
np.array([[ 1.14472371],
27
[ 0.90159072]]),
28
np.array([[ 0.53035547, 5.94892323, 2.31780174, 3.16005701, 0.53035547],
29
[-0.69166075, -3.47645987, -2.25194702, -2.65416996, -0.69166075],
30
[-0.39675353, -4.62285846, -2.61101729, -3.22874921, -0.39675353]]),
31
np.array([[ 0.53035547, 5.94892323, 2.31780174, 3.16005701, 0.53035547],
32
[ 0. , 0. , 0. , 0. , 0. ],
33
[ 0. , 0. , 0. , 0. , 0. ]]),
34
np.array([[ 0.50249434, 0.90085595],
35
[-0.68372786, -0.12289023],
36
[-0.93576943, -0.26788808]]),
37
np.array([[ 0.53035547],
38
[-0.69166075],
39
[-0.39675353]]),
40
np.array([[-0.3771104 , -4.10060224, -1.60539468, -2.18416951, -0.3771104 ]]),
41
np.array([[ 0.40682402, 0.01629284, 0.16722898, 0.10118111, 0.40682402]]),
42
np.array([[-0.6871727 , -0.84520564, -0.67124613]]),
43
np.array([[-0.0126646]]))
44
return X_assess, Y_assess, cache
45
46
def forward_propagation_with_dropout_test_case():
47
np.random.seed(1)
48
X_assess = np.random.randn(3, 5)
49
W1 = np.random.randn(2, 3)
50
b1 = np.random.randn(2, 1)
51
W2 = np.random.randn(3, 2)
52
b2 = np.random.randn(3, 1)
53
W3 = np.random.randn(1, 3)
54
b3 = np.random.randn(1, 1)
55
parameters = {"W1": W1, "b1": b1, "W2": W2, "b2": b2, "W3": W3, "b3": b3}
56
57
return X_assess, parameters
58
59
def backward_propagation_with_dropout_test_case():
60
np.random.seed(1)
61
X_assess = np.random.randn(3, 5)
62
Y_assess = np.array([[1, 1, 0, 1, 0]])
63
cache = (np.array([[-1.52855314, 3.32524635, 2.13994541, 2.60700654, -0.75942115],
64
[-1.98043538, 4.1600994 , 0.79051021, 1.46493512, -0.45506242]]), np.array([[ True, False, True, True, True],
65
[ True, True, True, True, False]], dtype=bool), np.array([[ 0. , 0. , 4.27989081, 5.21401307, 0. ],
66
[ 0. , 8.32019881, 1.58102041, 2.92987024, 0. ]]), np.array([[-1.09989127, -0.17242821, -0.87785842],
67
[ 0.04221375, 0.58281521, -1.10061918]]), np.array([[ 1.14472371],
68
[ 0.90159072]]), np.array([[ 0.53035547, 8.02565606, 4.10524802, 5.78975856, 0.53035547],
69
[-0.69166075, -1.71413186, -3.81223329, -4.61667916, -0.69166075],
70
[-0.39675353, -2.62563561, -4.82528105, -6.0607449 , -0.39675353]]), np.array([[ True, False, True, False, True],
71
[False, True, False, True, True],
72
[False, False, True, False, False]], dtype=bool), np.array([[ 1.06071093, 0. , 8.21049603, 0. , 1.06071093],
73
[ 0. , 0. , 0. , 0. , 0. ],
74
[ 0. , 0. , 0. , 0. , 0. ]]), np.array([[ 0.50249434, 0.90085595],
75
[-0.68372786, -0.12289023],
76
[-0.93576943, -0.26788808]]), np.array([[ 0.53035547],
77
[-0.69166075],
78
[-0.39675353]]), np.array([[-0.7415562 , -0.0126646 , -5.65469333, -0.0126646 , -0.7415562 ]]), np.array([[ 0.32266394, 0.49683389, 0.00348883, 0.49683389, 0.32266394]]), np.array([[-0.6871727 , -0.84520564, -0.67124613]]), np.array([[-0.0126646]]))
79
80
81
return X_assess, Y_assess, cache
82
83