def test_ForwardAndRecurrentConnections_feed_forward_two_samples_using_carry():
    frc = ForwardAndRecurrentConnection(1, 1)
    theta = np.ones(frc.get_param_dim())
    X = np.array([[1],[1]])
    T = np.array([[1],[2]])
    assert_equal(frc.forward_pass(theta, X[0]), T[0:1])
    assert_equal(frc.forward_pass(theta, X[1], X[0]), T[1:2])
Beispiel #2
0
def test_ForwardAndRecurrentConnections_feed_forward_two_samples_using_carry():
    frc = ForwardAndRecurrentConnection(1, 1)
    theta = np.ones(frc.get_param_dim())
    X = np.array([[1], [1]])
    T = np.array([[1], [2]])
    assert_equal(frc.forward_pass(theta, X[0]), T[0:1])
    assert_equal(frc.forward_pass(theta, X[1], X[0]), T[1:2])
def test_ForwardAndRecurrentConnections_backprop_random_example_gradient_check():
    frc = ForwardAndRecurrentConnection(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)
Beispiel #4
0
def test_ForwardAndRecurrentConnections_backprop_random_example_gradient_check(
):
    frc = ForwardAndRecurrentConnection(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)
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)
Beispiel #6
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)
def test_ForwardAndRecurrentConnections_feed_forward_single_sample():
    # single sample, the recurrent connection should not jump in
    frc = ForwardAndRecurrentConnection(1, 1)
    theta = np.ones(frc.get_param_dim())
    assert_equal(frc.forward_pass(theta, 1), 1)
Beispiel #8
0
def test_ForwardAndRecurrentConnections_feed_forward_single_sample():
    # single sample, the recurrent connection should not jump in
    frc = ForwardAndRecurrentConnection(1, 1)
    theta = np.ones(frc.get_param_dim())
    assert_equal(frc.forward_pass(theta, 1), 1)