Beispiel #1
0
def test_FANN_multilayer_gradient_single_sample():
    fc0 = FullConnection(4, 2)
    fc1 = FullConnection(2, 1)
    sig0 = SigmoidLayer(2)
    sig1 = SigmoidLayer(1)
    nn = FANN([fc0, sig0, fc1, sig1])
    theta = np.random.randn(nn.get_param_dim())
    for x, t in zip(X, T):
        grad_c = nn.calculate_gradient(theta, x, t)
        grad_e = approx_fprime(theta, nn.calculate_error, 1e-8, x, t)
        assert_almost_equal(grad_c, grad_e)
Beispiel #2
0
def test_FANN_error_single_sample():
    fc = FullConnection(4, 1)
    sig = SigmoidLayer(1)
    nn = FANN([fc, sig])
    for x, t, e in zip(X, T, E):
        assert_equal(nn.calculate_error(theta, x, t), 0)
        assert_equal(nn.calculate_error(theta, x, 0), e)
Beispiel #3
0
def test_FANN_feed_forward_single_sample():
    fc = FullConnection(4, 1)
    sig = SigmoidLayer(1)
    nn = FANN([fc, sig])
    for x, t in zip(X, T):
        t = np.atleast_2d(t)
        assert_equal(nn.forward_pass(theta, x), t)
Beispiel #4
0
def test_FANN_gradient_multisample():
    fc = FullConnection(4, 1)
    sig = SigmoidLayer(1)
    nn = FANN([fc, sig])
    theta = np.random.randn(nn.get_param_dim())
    grad_c = nn.calculate_gradient(theta, X, T)
    grad_e = approx_fprime(theta, nn.calculate_error, 1e-8, X, T)
    assert_almost_equal(grad_c, grad_e)
Beispiel #5
0
def test_FANN_converges_on_and_problem():
    fc = FullConnection(2, 1)
    sig = SigmoidLayer(1)
    nn = FANN([fc, sig])
    and_ = load_and()
    theta = np.array([-0.1, 0.1])
    for i in range(100):
        g = nn.calculate_gradient(theta, and_.data, and_.target)
        theta -= g * 1
    error = nn.calculate_error(theta, and_.data, and_.target)
    assert_less(error, 0.2)
def test_FullConnection_forward_pass_multi_sample():
    fc = FullConnection(4, 1)
    assert_equal(fc.forward_pass(theta, X), T)
def test_FullConnection_forward_pass_single_samples():
    fc = FullConnection(4, 1)
    for x, t in zip(X, T):
        t = np.atleast_2d(t)
        assert_equal(fc.forward_pass(theta, x), t)
def test_FullConnection_dimensions():
    fc = FullConnection(5, 7)
    assert_equal(fc.input_dim, 5)
    assert_equal(fc.output_dim, 7)
    assert_equal(fc.get_param_dim(), 5*7)
Beispiel #9
0
def test_FANN_error_multisample():
    fc = FullConnection(4, 1)
    sig = SigmoidLayer(1)
    nn = FANN([fc, sig])
    assert_equal(nn.calculate_error(theta, X, T), 0.0)
    assert_equal(nn.calculate_error(theta, X, np.zeros_like(T)), np.sum(E))
Beispiel #10
0
def test_FANN_feed_forward_multisample():
    fc = FullConnection(4, 1)
    sig = SigmoidLayer(1)
    nn = FANN([fc, sig])
    assert_equal(nn.forward_pass(theta, X), T)
Beispiel #11
0
def test_FANN_dimensions():
    fc = FullConnection(5, 1)
    nn = FANN([fc])
    assert_equal(nn.input_size, 5)
    assert_equal(nn.output_size, 1)
Beispiel #12
0
def test_FullConnection_forward_pass_multi_sample():
    fc = FullConnection(4, 1)
    assert_equal(fc.forward_pass(theta, X), T)
Beispiel #13
0
def test_FullConnection_forward_pass_single_samples():
    fc = FullConnection(4, 1)
    for x, t in zip(X, T):
        t = np.atleast_2d(t)
        assert_equal(fc.forward_pass(theta, x), t)
Beispiel #14
0
def test_FullConnection_dimensions():
    fc = FullConnection(5, 7)
    assert_equal(fc.input_dim, 5)
    assert_equal(fc.output_dim, 7)
    assert_equal(fc.get_param_dim(), 5 * 7)