Example #1
0
def test_model_forward():
    np.random.seed(6)
    x = np.random.randn(5, 4)
    w1 = np.random.randn(4, 5)
    b1 = np.random.randn(4, 1)
    w2 = np.random.randn(3, 4)
    b2 = np.random.randn(3, 1)
    w3 = np.random.randn(1, 3)
    b3 = np.random.randn(1, 1)

    nn = NeuralNetwork(w=[w1, w2, w3], b=[b1, b2, b3], params_ok=True)
    al = nn.model_forward(x)
    nt.eq_(len(nn.cache), 3)
    assert_eq(al, [[0.03921668, 0.70498921, 0.19734387, 0.04728177]])
Example #2
0
def test_forward_propagation_dropout():
    np.random.seed(1)
    x = np.random.randn(3, 5)
    w1 = np.random.randn(2, 3)
    b1 = np.random.randn(2, 1)
    w2 = np.random.randn(3, 2)
    b2 = np.random.randn(3, 1)
    w3 = np.random.randn(1, 3)
    b3 = np.random.randn(1, 1)

    np.random.seed(1)
    nn = NeuralNetwork(w=[w1, w2, w3], b=[b1, b2, b3], params_ok=True)
    a3 = nn.model_forward(x, keep_prop=0.7)
    assert_eq(a3,
              [[0.36974721, 0.00305176, 0.04565099, 0.49683389, 0.36974721]],
              rtol=1e-5)