samples[0] = (0,0), 0 samples[1] = (1,0), 0 samples[2] = (0,1), 0 samples[3] = (1,1), 1 network.learn(samples) # 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)