コード例 #1
0
ファイル: testMLP.py プロジェクト: ErwinHaasnoot/axongame
    # Example 3 : XOR logical function
    # -------------------------------------------------------------------------
    print "Learning the XOR logical function"
    network.reset()
    samples[0] = (0,0), 0
    samples[1] = (1,0), 1
    samples[2] = (0,1), 1
    samples[3] = (1,1), 0
    network.learn(samples)
    network.storeWeights('XORWeight.p')
    
    network.reset()
    network.loadWeights('XORWeight.p')
    
    network.test(samples)
    # Example 4 : Learning sin(x)
    # -------------------------------------------------------------------------
    print "Learning the sin function"
    network = MLP(1,10,1)
    samples = np.zeros(500, dtype=[('x',  float, 1), ('y', float, 1)])
    samples['x'] = np.linspace(0,1,500)
    samples['y'] = np.sin(samples['x']*np.pi)

    for i in range(10000):
        n = np.random.randint(samples.size)
        network.propagate_forward(samples['x'][n])
        network.propagate_backward(samples['y'][n])

    #plt.figure(figsize=(10,5))
    # Draw real function