def _test_train_urls(): mynet = Network(3, 4, 3) mynet.create_connections() #mynet.feed_forward([1,1,1]) #print(mynet.output_ouputs) print(mynet.matrix_wih) print(mynet.matrix_who) for i in range(1000): #print('='*20) mynet.train([1, 0, 1], [1, 0, 0]) #print(mynet.matrix_wih) #print(mynet.matrix_who) # print('='*30) # for i in range(30): mynet.train([0, 1, 1], [0, 1, 0]) # print('='*30) # for i in range(30): mynet.train([1, 0, 0], [0, 0, 1]) print('Results:') mynet.feed_forward([1, 0, 1]) print('{} expected {}'.format(mynet.output_ouputs, [1, 0, 0])) mynet.feed_forward([0, 1, 1]) print('{} expected {}'.format(mynet.output_ouputs, [0, 1, 0])) mynet.feed_forward([1, 0, 1]) print('{} expected {}'.format(mynet.output_ouputs, [1, 0, 0])) mynet.feed_forward([0, 0, 1]) print('{} expected {}'.format(mynet.output_ouputs, [1, 0, 0]))
def _test_train_xor_1o(): mynet = Network(2, 3, 1) mynet.create_connections() # print(mynet.matrix_wih) # print(mynet.matrix_who) for i in range(1000): # 1 xor 1 = 0 [prob 0, prob1] mynet.train([1, 1], [0], learning_rate=1) # print(mynet.matrix_wih) # print(mynet.matrix_who)https://stevenmiller888.github.io/mind-how-to-build-a-neural-network/ mynet.train([1, 0], [1], learning_rate=1) mynet.train([0, 0], [0], learning_rate=1) # mynet.train([0, 1], [1], learning_rate=1) mynet.feed_forward([1, 1]) print('[1,1]= %s' % mynet.output_ouputs) mynet.feed_forward([0, 0]) print('[0,0]= %s' % mynet.output_ouputs) mynet.feed_forward([1, 0]) print('[1,0]= %s' % mynet.output_ouputs) mynet.feed_forward([0, 1]) print('[0,1]= %s' % mynet.output_ouputs) mynet.feed_forward([1, 1]) print('[1,1]= %s' % mynet.output_ouputs)
def _test_train_31(): mynet = Network(3, 3, 1) mynet.create_connections() print(mynet.matrix_wih) print(mynet.matrix_who) for i in range(10000): mynet.train([0, 0, 1], [0], learning_rate=1) # print(mynet.matrix_wih) # print(mynet.matrix_who) mynet.train([1, 1, 1], [1], learning_rate=1) mynet.train([1, 0, 1], [1], learning_rate=1) mynet.train([0, 1, 1], [0], learning_rate=1) mynet.feed_forward([1, 0, 0]) print('[1,0,0]= %s' % mynet.output_ouputs) mynet.feed_forward([1, 0, 0]) print('[0,0,0]= %s' % mynet.output_ouputs)