Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Improving Deep Neural Networks Hyperparameter tuning, Regularization and Optimization/week5/Regularization/testCases.py
Views: 13377
import numpy as np12def compute_cost_with_regularization_test_case():3np.random.seed(1)4Y_assess = np.array([[1, 1, 0, 1, 0]])5W1 = np.random.randn(2, 3)6b1 = np.random.randn(2, 1)7W2 = np.random.randn(3, 2)8b2 = np.random.randn(3, 1)9W3 = np.random.randn(1, 3)10b3 = np.random.randn(1, 1)11parameters = {"W1": W1, "b1": b1, "W2": W2, "b2": b2, "W3": W3, "b3": b3}12a3 = np.array([[ 0.40682402, 0.01629284, 0.16722898, 0.10118111, 0.40682402]])13return a3, Y_assess, parameters1415def backward_propagation_with_regularization_test_case():16np.random.seed(1)17X_assess = np.random.randn(3, 5)18Y_assess = np.array([[1, 1, 0, 1, 0]])19cache = (np.array([[-1.52855314, 3.32524635, 2.13994541, 2.60700654, -0.75942115],20[-1.98043538, 4.1600994 , 0.79051021, 1.46493512, -0.45506242]]),21np.array([[ 0. , 3.32524635, 2.13994541, 2.60700654, 0. ],22[ 0. , 4.1600994 , 0.79051021, 1.46493512, 0. ]]),23np.array([[-1.09989127, -0.17242821, -0.87785842],24[ 0.04221375, 0.58281521, -1.10061918]]),25np.array([[ 1.14472371],26[ 0.90159072]]),27np.array([[ 0.53035547, 5.94892323, 2.31780174, 3.16005701, 0.53035547],28[-0.69166075, -3.47645987, -2.25194702, -2.65416996, -0.69166075],29[-0.39675353, -4.62285846, -2.61101729, -3.22874921, -0.39675353]]),30np.array([[ 0.53035547, 5.94892323, 2.31780174, 3.16005701, 0.53035547],31[ 0. , 0. , 0. , 0. , 0. ],32[ 0. , 0. , 0. , 0. , 0. ]]),33np.array([[ 0.50249434, 0.90085595],34[-0.68372786, -0.12289023],35[-0.93576943, -0.26788808]]),36np.array([[ 0.53035547],37[-0.69166075],38[-0.39675353]]),39np.array([[-0.3771104 , -4.10060224, -1.60539468, -2.18416951, -0.3771104 ]]),40np.array([[ 0.40682402, 0.01629284, 0.16722898, 0.10118111, 0.40682402]]),41np.array([[-0.6871727 , -0.84520564, -0.67124613]]),42np.array([[-0.0126646]]))43return X_assess, Y_assess, cache4445def forward_propagation_with_dropout_test_case():46np.random.seed(1)47X_assess = np.random.randn(3, 5)48W1 = np.random.randn(2, 3)49b1 = np.random.randn(2, 1)50W2 = np.random.randn(3, 2)51b2 = np.random.randn(3, 1)52W3 = np.random.randn(1, 3)53b3 = np.random.randn(1, 1)54parameters = {"W1": W1, "b1": b1, "W2": W2, "b2": b2, "W3": W3, "b3": b3}5556return X_assess, parameters5758def backward_propagation_with_dropout_test_case():59np.random.seed(1)60X_assess = np.random.randn(3, 5)61Y_assess = np.array([[1, 1, 0, 1, 0]])62cache = (np.array([[-1.52855314, 3.32524635, 2.13994541, 2.60700654, -0.75942115],63[-1.98043538, 4.1600994 , 0.79051021, 1.46493512, -0.45506242]]), np.array([[ True, False, True, True, True],64[ True, True, True, True, False]], dtype=bool), np.array([[ 0. , 0. , 4.27989081, 5.21401307, 0. ],65[ 0. , 8.32019881, 1.58102041, 2.92987024, 0. ]]), np.array([[-1.09989127, -0.17242821, -0.87785842],66[ 0.04221375, 0.58281521, -1.10061918]]), np.array([[ 1.14472371],67[ 0.90159072]]), np.array([[ 0.53035547, 8.02565606, 4.10524802, 5.78975856, 0.53035547],68[-0.69166075, -1.71413186, -3.81223329, -4.61667916, -0.69166075],69[-0.39675353, -2.62563561, -4.82528105, -6.0607449 , -0.39675353]]), np.array([[ True, False, True, False, True],70[False, True, False, True, True],71[False, False, True, False, False]], dtype=bool), np.array([[ 1.06071093, 0. , 8.21049603, 0. , 1.06071093],72[ 0. , 0. , 0. , 0. , 0. ],73[ 0. , 0. , 0. , 0. , 0. ]]), np.array([[ 0.50249434, 0.90085595],74[-0.68372786, -0.12289023],75[-0.93576943, -0.26788808]]), np.array([[ 0.53035547],76[-0.69166075],77[-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]]))787980return X_assess, Y_assess, cache818283