Exemple #1
0
    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
    x,y = samples['x'],samples['y']
    #plt.plot(x,y,color='b',lw=1)
    # Draw network approximated function
    for i in range(samples.shape[0]):
        y[i] = network.propagate_forward(x[i])
    
    #plt.plot(x,y,color='r',lw=3)
    #plt.axis([0,1,0,1])
    #plt.show()
    
    
    # Example 5: Learning game 3 spike training data