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)
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)
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)
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)
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)
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))
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)
def test_FANN_dimensions(): fc = FullConnection(5, 1) nn = FANN([fc]) assert_equal(nn.input_size, 5) assert_equal(nn.output_size, 1)
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)