Esempio n. 1
0
def test_simple_perseptron_predict():
    sp = SimplePerceptron(3,1,threshold=1.0)
    assert sp.predict([0,0,0]) == [0]
    assert sp.predict([0,0,1]) == [1]
    assert sp.predict([0,1,0]) == [1]
    assert sp.predict([1,0,0]) == [1]
    assert sp.predict([0,1,1]) == [1]
    assert sp.predict([1,0,1]) == [1]
    assert sp.predict([1,1,0]) == [1]
    assert sp.predict([1,1,1]) == [1]
Esempio n. 2
0
def simple_sample():
    sp = SimplePerceptron(  input_neuron_num     = 2,
                            output_neuron_num    = 1,
                            threshold            = 1.0,
                            learning_coefficient = 0.5,
                            output_function_type = 0)
    train_data = [
            [[0,0,],[0]],
            [[0,1,],[1]],
            [[1,0,],[0]],
            [[1,1,],[1]],
            ]

    print '---- before'
    print sp.predict([0,0,])
    print sp.predict([0,1,])
    print sp.predict([1,0,])
    print sp.predict([1,1,])
    for i in range(100):
        sp.train(train_data)

    print '---- after'
    print sp.predict([0,0,])
    print sp.predict([0,1,])
    print sp.predict([1,0,])
    print sp.predict([1,1,])