예제 #1
0
def test_ForwardAndRecurrentConnections_backprop_gradient_check():
    frc = ForwardAndRecurrentConnection(1, 1)
    theta = np.ones(frc.get_param_dim())
    X = [[1.], [1.]]
    Y = [[1.], [2.]]
    T = np.array([[0.], [0.]])
    out_error = [[-1.], [-2.]]
    error, grad = frc.backprop(theta, X, Y, out_error)
    f = lambda t : error_function(T - frc.forward_pass(t, X))
    assert_almost_equal(approx_fprime(theta, f, 1e-8), grad)
예제 #2
0
def test_ForwardAndRecurrentConnections_backprop_gradient_check():
    frc = ForwardAndRecurrentConnection(1, 1)
    theta = np.ones(frc.get_param_dim())
    X = [[1.], [1.]]
    Y = [[1.], [2.]]
    T = np.array([[0.], [0.]])
    out_error = [[-1.], [-2.]]
    error, grad = frc.backprop(theta, X, Y, out_error)
    f = lambda t: error_function(T - frc.forward_pass(t, X))
    assert_almost_equal(approx_fprime(theta, f, 1e-8), grad)
예제 #3
0
def test_ForwardAndRecurrentSigmoidConnections_backprop_random_example_gradient_check():
    frc = ForwardAndRecurrentSigmoidConnection(4, 3)
    theta = np.random.randn(frc.get_param_dim())
    X = np.random.randn(10, 4)
    Y = frc.forward_pass(theta, X)
    T = np.zeros((10, 3))
    out_error = (T - Y)
    error, grad_c = frc.backprop(theta, X, Y, out_error)
    f = lambda t : error_function(T - frc.forward_pass(t, X))
    grad_e = approx_fprime(theta, f, 1e-8)
    assert_allclose(grad_c, grad_e, rtol=1e-3, atol=1e-5)
예제 #4
0
def test_ForwardAndRecurrentSigmoidConnections_backprop_random_example_gradient_check(
):
    frc = ForwardAndRecurrentSigmoidConnection(4, 3)
    theta = np.random.randn(frc.get_param_dim())
    X = np.random.randn(10, 4)
    Y = frc.forward_pass(theta, X)
    T = np.zeros((10, 3))
    out_error = (T - Y)
    error, grad_c = frc.backprop(theta, X, Y, out_error)
    f = lambda t: error_function(T - frc.forward_pass(t, X))
    grad_e = approx_fprime(theta, f, 1e-8)
    assert_allclose(grad_c, grad_e, rtol=1e-3, atol=1e-5)