def main(): topology = [] topology.append(2) topology.append(3) topology.append(3) topology.append(1) net = Network(topology) neuron.eta = 0.09 neuron.alpha = 0.015 inputs = [[0, 0], [0, 1], [1, 0], [1, 1]] outputs = [[0], [1], [1], [0]] while True: err = 0 for i in range(len(inputs)): net.setInput(inputs[i]) net.feedForward() net.backPropagate(outputs[i]) err = err + net.getError(outputs[i]) print("Error: ", err) if err < 1.5: break while True: a = int(input("First input: ")) b = int(input("Second input: ")) net.setInput([a, b]) net.feedForward() print(net.getThResults())
def main(): result_list = [[None], [None]] topology = [] topology.append(2) topology.append(3) topology.append(3) topology.append(1) net1 = Network(topology) net2 = Network(topology) neuron.eta = 0.09 neuron.alpha = 0.015 inputs1 = [[0, 0], [0, 1]] outputs1 = [[0], [1]] inputs2 = [[1, 0], [1, 1]] outputs2 = [[1], [0]] threads = [] nets = [net1, net2] outputs = [outputs1, outputs2] inputs = [inputs1, inputs2] for i in range(2): t = threading.Thread(target=TrainNet, args=(inputs[i], [nets[i]], outputs[i], i, result_list)) threads.append(t) t.start() for i in range(2): threads[i].join() net1 = result_list[0] net2 = result_list[1] while True: a = int(input("First input: ")) b = int(input("Second input: ")) if (a > 0): net2.setInput([a, b]) net2.feedForward() print(net1.getThResults()) else: net1.setInput([a, b]) net1.feedForward() print(net1.getThResults())