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_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_converges_on_vote_problem(): fc = FullConnectionWithBias(9, 1) sig = SigmoidLayer(1) nn = FANN([fc, sig]) vote = generate_majority_vote() theta = np.zeros((10, )) for i in range(500): g = nn.calculate_gradient(theta, vote.data, vote.target) theta -= g * 1 error = nn.calculate_error(theta, vote.data, vote.target) assert_less(error, 0.2)
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_FANN_converges_on_vote_problem(): fc = FullConnectionWithBias(9, 1) sig = SigmoidLayer(1) nn = FANN([fc, sig]) vote = generate_majority_vote() theta = np.zeros((10,)) for i in range(500): g = nn.calculate_gradient(theta, vote.data, vote.target) theta -= g * 1 error = nn.calculate_error(theta, vote.data, vote.target) assert_less(error, 0.2)
def test_RANN_converges_on_ropot_problem(): frc = ForwardAndRecurrentSigmoidConnection(5, 5) nn = FANN([frc]) rpot = generate_remember_pattern_over_time() theta = np.random.randn(nn.get_param_dim()) for i in range(100): grad = np.zeros_like(theta) for X, T in seqEnum(rpot): grad += nn.calculate_gradient(theta, X, T) theta -= grad * 1 error = np.sum(nn.calculate_error(theta, X, T) for X, T in seqEnum(rpot)) assert_less(error, 10.)
def test_FANN_converges_on_xor_problem(): fc0 = FullConnectionWithBias(2, 2) fc1 = FullConnectionWithBias(2, 1) sig0 = SigmoidLayer(2) sig1 = SigmoidLayer(1) nn = FANN([fc0, sig0, fc1, sig1]) xor = load_xor() theta = np.random.randn(nn.get_param_dim()) for i in range(2000): g = nn.calculate_gradient(theta, xor.data, xor.target) theta -= g * 1 error = nn.calculate_error(theta, xor.data, xor.target) assert_less(error, 0.4)
def test_FANN_with_bias_error_multisample(): fc = FullConnectionWithBias(3, 1) sig = SigmoidLayer(1) nn = FANN([fc, sig]) assert_equal(nn.calculate_error(theta, X_nb, T), 0.0) assert_equal(nn.calculate_error(theta, X_nb, np.zeros_like(T)), np.sum(E))