Exemplo n.º 1
0
def test_forward_prop_small_network():
    '''testing forward prop in 4-3-3-1 network'''
    x = np.array([1, 1, 1, 1])  #input
    y = [0.94533048]  #preknown output
    node_list = [4, 3, 3, 1]
    activations = ['sigmoid', 'sigmoid', 'sigmoid']
    nn_test1 = NeuralNetwork(node_list, activations)
    weights_init(nn_test1)  #Setting weights to constant value = 1
    y_test = nn_test1.forward_prop(x)
    assert np.isclose(y_test, y)
Exemplo n.º 2
0
def test_gradient_checking_big_neural_network_2():
    node_list = [70, 15, 7, 1]
    activations = ['sigmoid', 'sigmoid', 'sigmoid']
    x1 = np.full((1, 70), 5).reshape(1, node_list[0])
    y1 = np.array([1000]).reshape(1, node_list[-1])
    nn_test_2 = NeuralNetwork(node_list, activations)
    e_nn = nn_test_2.forward_prop(x1)
    derivative_analytical = nn_test_2.analytical_gradients(x1, e_nn, y1)
    derivative_numerical = numerical_gradients(nn_test_2, x1, e_nn, y1)
    assert np.allclose(derivative_analytical, derivative_numerical, atol=1e-5)
Exemplo n.º 3
0
def test_forward_prop_big_network_3():
    '''testing forward prop in 70-2-2-1 network
    sigmoid--sigmoid--linear'''
    x = np.ones((1, 70))  #input
    y = [1.76159416]  #preknown output
    node_list = [70, 2, 2, 1]
    activations = ['sigmoid', 'sigmoid', 'linear']
    nn_test4 = NeuralNetwork(node_list, activations)
    weights_init(nn_test4)  #Setting weights to constant value = 1
    y_test = nn_test4.forward_prop(x)
    assert np.isclose(y_test, y)
Exemplo n.º 4
0
def test_forward_prop_big_network_2():
    '''testing forward prop in 70-10-10-1 network
    sigmoid--sigmoid--linear'''
    x = np.ones((1, 70))  #input
    y = [9.99954602]  #preknown output
    node_list = [70, 10, 10, 1]
    activations = ['sigmoid', 'sigmoid', 'linear']
    nn_test3 = NeuralNetwork(node_list, activations)
    weights_init(nn_test3)  #Setting weights to constant value = 1
    y_test = nn_test3.forward_prop(x)
    assert abs(y_test - y) < 1e-8
Exemplo n.º 5
0
def test_gradient_checking_small_neural_network_1():
    #declare structure of the neural network(no of nodes,activations of layers)
    node_list = [2, 3, 3, 1]
    activations = ['ReLU', 'ReLU', 'ReLU']
    #set inputs and output
    x = np.array([1, 2]).reshape(1, node_list[0])
    y = np.array([10]).reshape(1, node_list[-1])
    nn_test_1 = NeuralNetwork(node_list, activations)
    e_nn = nn_test_1.forward_prop(x)
    derivative_analytical = nn_test_1.analytical_gradients(x, e_nn, y)
    derivative_numerical = numerical_gradients(nn_test_1, x, e_nn, y)
    assert np.isclose(derivative_analytical, derivative_numerical).all()
Exemplo n.º 6
0
def test_forward_prop_big_network_1():
    '''testing forward prop in 70-10-10-1 network
    sigmoid--sigmoid--sigmoid'''

    x = np.ones((1, 70))  #input
    y = [0.99995458]  #preknown output
    node_list = [70, 10, 10, 1]
    activations = ['sigmoid', 'sigmoid', 'sigmoid']
    nn_test2 = NeuralNetwork(node_list, activations)
    weights_init(nn_test2)  #Setting weights to constant value = 1
    y_test = nn_test2.forward_prop(x)
    assert np.isclose(y_test, y)
Exemplo n.º 7
0
def test_forward_prop_big_network_4():
    '''testing forward prop in 70-10-10-1 network
    linear--linear--linear'''
    x = np.ones((1, 70))  #input
    y = [
        3500
    ]  #preknown output(when input and weights are array of ones and activation is linear,the output will be the product of number of nodes in each layer)
    node_list = [70, 5, 10, 1]
    activations = ['linear', 'linear', 'linear']
    nn_test5 = NeuralNetwork(node_list, activations)
    weights_init(nn_test5)  #Setting weights to constant value = 1
    y_test = nn_test5.forward_prop(x)
    assert np.isclose(y_test, y)