예제 #1
0
def predict_test(target):
    np.random.seed(1)
    X = np.random.randn(2, 3)
    parameters = {
        'W1':
        np.array([[-0.00615039, 0.0169021], [-0.02311792, 0.03137121],
                  [-0.0169217, -0.01752545], [0.00935436, -0.05018221]]),
        'W2':
        np.array([[-0.0104319, -0.04019007, 0.01607211, 0.04440255]]),
        'b1':
        np.array([[-8.97523455e-07], [8.15562092e-06], [6.04810633e-07],
                  [-2.54560700e-06]]),
        'b2':
        np.array([[9.14954378e-05]])
    }
    expected_output = np.array([[True, False, True]])

    test_cases = [{
        "name": "datatype_check",
        "input": [parameters, X],
        "expected": expected_output,
        "error": "Data type mismatch"
    }, {
        "name": "shape_check",
        "input": [parameters, X],
        "expected": expected_output,
        "error": "Wrong shape"
    }, {
        "name": "equation_output_check",
        "input": [parameters, X],
        "expected": expected_output,
        "error": "Wrong output"
    }]

    single_test(test_cases, target)
예제 #2
0
def compute_cost_with_regularization_test(target):
    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)
    parameters = {"W1": W1, "b1": b1, "W2": W2, "b2": b2, "W3": W3, "b3": b3}
    A3 = np.array([[ 0.40682402,  0.01629284,  0.16722898,  0.10118111,  0.40682402]])
    lambd = 0.1
    expected_output = np.float64(1.7864859451590758)
    test_cases = [
        {
            "name": "shape_check",
            "input": [A3, Y, parameters, lambd],
            "expected": expected_output,
            "error": "Wrong shape"
        },
        {
            "name": "equation_output_check",
            "input": [A3, Y, parameters, lambd],
            "expected": expected_output,
            "error": "Wrong output"
        }
    ]
    
    single_test(test_cases, target)
def compute_cost_test(target):
    np.random.seed(1)
    Y = (np.random.randn(1, 3) > 0)
    parameters = {'W1': np.array([[-0.00416758, -0.00056267],
        [-0.02136196,  0.01640271],
        [-0.01793436, -0.00841747],
        [ 0.00502881, -0.01245288]]),
     'W2': np.array([[-0.01057952, -0.00909008,  0.00551454,  0.02292208]]),
     'b1': np.array([[ 0.],
        [ 0.],
        [ 0.],
        [ 0.]]),
     'b2': np.array([[ 0.]])}

    A2 = (np.array([[ 0.5002307 ,  0.49985831,  0.50023963]]))

    expected_output = 0.6930587610394646
    test_cases = [
        {
            "name":"datatype_check",
            "input": [A2, Y],
            "expected": expected_output,
            "error":"Datatype mismatch"
        },
        {
            "name": "equation_output_check",
            "input": [A2, Y],
            "expected": expected_output,
            "error": "Wrong output"
        } 
    ]
    
    single_test(test_cases, target)    
예제 #4
0
def gradient_check_n_test(target, parameters, gradients, X, Y):
    expected_output_1 = 0.2850931567761623
    expected_output_2 = 1.1890913024229996e-07
    test_cases = [{
        "name": "multiple_equation_output_check",
        "input": [parameters, gradients, X, Y],
        "expected": [expected_output_1, expected_output_2],
        "error": "Wrong output"
    }]

    single_test(test_cases, target)
예제 #5
0
def forward_propagation_test(target):
    x, theta = 2, 4
    expected_output = 8
    test_cases = [{
        "name": "equation_output_check",
        "input": [x, theta],
        "expected": expected_output,
        "error": "Wrong output"
    }]

    single_test(test_cases, target)
예제 #6
0
def gradient_check_test(target):
    x, theta = 2, 4
    expected_output = 2.919335883291695e-10
    test_cases = [{
        "name": "equation_output_check",
        "input": [x, theta],
        "expected": expected_output,
        "error": "Wrong output"
    }]

    single_test(test_cases, target)
예제 #7
0
def compute_cost_test(target):
    Y = np.asarray([[1, 1, 0]])
    AL = np.array([[.8, .9, 0.4]])
    expected_output = np.array(0.27977656)

    test_cases = [{
        "name": "equation_output_check",
        "input": [AL, Y],
        "expected": expected_output,
        "error": "Wrong output"
    }]

    single_test(test_cases, target)
def compute_cost_test(target):
    np.random.seed(1)
    Y = (np.random.randn(1, 5) > 0)
    A2 = (np.array([[0.5002307, 0.49985831, 0.50023963, 0.25, 0.7]]))

    expected_output = 0.5447066599017815
    test_cases = [{
        "name": "datatype_check",
        "input": [A2, Y],
        "expected": expected_output,
        "error": "Datatype mismatch"
    }, {
        "name": "equation_output_check",
        "input": [A2, Y],
        "expected": expected_output,
        "error": "Wrong output"
    }]

    single_test(test_cases, target)
예제 #9
0
def pool_backward_test(target):

    test_cases = [{
        "name": "datatype_check",
        "input": [parameters, X],
        "expected": expected_output,
        "error": "Data type mismatch"
    }, {
        "name": "shape_check",
        "input": [parameters, X],
        "expected": expected_output,
        "error": "Wrong shape"
    }, {
        "name": "equation_output_check",
        "input": [parameters, X],
        "expected": expected_output,
        "error": "Wrong output"
    }]

    single_test(test_cases, target)
예제 #10
0
def zero_pad_test(target):
    np.random.seed(1)
    x = np.random.randn(4, 3, 3, 2)
    pad = 2
    expected_output = expected_output = np.array(
        [[[[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [1.62434536, -0.61175641],
           [-0.52817175, -1.07296862], [0.86540763, -2.3015387], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [1.74481176, -0.7612069],
           [0.3190391, -0.24937038], [1.46210794, -2.06014071], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [-0.3224172, -0.38405435],
           [1.13376944, -1.09989127], [-0.17242821, -0.87785842], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]]],
         [[[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0.04221375, 0.58281521],
           [-1.10061918, 1.14472371], [0.90159072, 0.50249434], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0.90085595, -0.68372786],
           [-0.12289023, -0.93576943], [-0.26788808,
                                        0.53035547], [0., 0.], [0., 0.]],
          [[0., 0.], [0., 0.], [-0.69166075, -0.39675353],
           [-0.6871727, -0.84520564], [-0.67124613, -0.0126646], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]]],
         [[[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [-1.11731035, 0.2344157],
           [1.65980218, 0.74204416], [-0.19183555, -0.88762896], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [-0.74715829, 1.6924546],
           [0.05080775, -0.63699565], [0.19091548, 2.10025514], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0.12015895, 0.61720311],
           [0.30017032, -0.35224985], [-1.1425182, -0.34934272], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]]],
         [[[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [-0.20889423, 0.58662319],
           [0.83898341, 0.93110208], [0.28558733, 0.88514116], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [-0.75439794, 1.25286816],
           [0.51292982, -0.29809284], [0.48851815, -0.07557171], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [1.13162939, 1.51981682],
           [2.18557541, -1.39649634], [-1.44411381, -0.50446586], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]],
          [[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.],
           [0., 0.]]]])

    test_cases = [{
        "name": "datatype_check",
        "input": [x, pad],
        "expected": expected_output,
        "error": "Datatype mismatch."
    }, {
        "name": "equation_output_check",
        "input": [x, pad],
        "expected": expected_output,
        "error": "Wrong output"
    }]

    single_test(test_cases, target)