Exemple #1
0
def test_compute_cost():
    y = np.asarray([[1, 1, 1]])
    al = np.array([[.8, .9, 0.4]])

    nn = NeuralNetwork(layer_dims=(3, 1), params_ok=True)
    cost = nn.compute_cost(al, y)
    assert_eq(cost, 0.41493159961539694)
Exemple #2
0
def test_cost_regulation():
    np.random.seed(1)
    y = np.array([[1, 1, 0, 1, 0]])
    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)
    a3 = np.array(
        [[0.40682402, 0.01629284, 0.16722898, 0.10118111, 0.40682402]])

    nn = NeuralNetwork(w=[w1, w2, w3],
                       b=[b1, b2, b3],
                       lambd=0.1,
                       params_ok=True)
    cost = nn.compute_cost(a3, y)
    assert_eq(cost, 1.78648594516)