print("Target:\t" + str(sin_desired_output[i]) + "\t\tOutput:\t" + str(mlp.o) + "\n") f.write('Target:\t' + str(sin_desired_output[i]) + '\t\tOutput:\t' + str(mlp.o) + '\n') f.write('MLP Size\t\t\t(' + str(INPUTS) + ', ' + str(HIDDEN) + ', ' + str(OUTPUTS) + ')\n') f.write('Epochs:\t\t\t\t' + str(MAX_EPOCHS) + '\n') f.write('Learning Rate:\t\t' + str(LEARNING_RATE) + '\n\n') print("Training:\n") f.write('Training:\n') for i in range(0, MAX_EPOCHS): error = 0 mlp.forward(sin_inputs[:len(sin_inputs) - 10], True) error = mlp.backwards(sin_inputs[:(len(sin_inputs) - 10)], sin_desired_output[:len(sin_inputs) - 10], True) mlp.update_weights(LEARNING_RATE) if (i + 1) % (MAX_EPOCHS / 10) == 0: print("Epoch:\t" + str(i + 1) + "\tError:\t" + str(error)) f.write('Epoch:\t' + str(i + 1) + '\tError:\t' + str(error) + '\n') print("\nTesting:\n") f.write('\nTesting:\n') for i in range(len(sin_inputs) - 10, len(sin_inputs)): mlp.forward(sin_inputs[i], True) print("Target:\t" + str(sin_desired_output[i]) + "\t\tOutput:\t" + str(mlp.o) + "\n") f.write('Target:\t' + str(sin_desired_output[i]) + '\t\tOutput:\t' + str(mlp.o) + '\n') # print(mlp)
print("Target:\t" + str(xor_desired_output[i]) + "\t\tOutput:\t" + str(mlp.o) + "\n") f.write('Target:\t' + str(xor_desired_output[i]) + '\t\tOutput:\t' + str(mlp.o) + '\n') f.write('MLP Size\t(' + str(INPUTS) + ', ' + str(HIDDEN) + ', ' + str(OUTPUTS) + ')\n\n') f.write('Epochs:\t\t' + str(MAX_EPOCHS) + '\n') f.write('Learning Rate:\t' + str(LEARNING_RATE) + '\n\n') print("Training:\n") f.write('Training:\n') for i in range(0, MAX_EPOCHS): error = 0 mlp.forward(xor_inputs, False) error = mlp.backwards(xor_inputs, xor_desired_output, False) mlp.update_weights(LEARNING_RATE) if (i + 1) % (MAX_EPOCHS / 10) == 0: length = len(str(i)) print("Epoch:\t" + str(i + 1) + "\tError:\t" + str(error)) f.write('Epoch:\t' + str(i + 1) + '\tError:\t' + str(error) + '\n') print("\nTesting:\n") f.write('\nTesting:\n') for i in range(len(xor_inputs)): mlp.forward(xor_inputs[i], False) print("Target:\t" + str(xor_desired_output[i]) + "\t\tOutput:\t" + str(mlp.o) + "\n") f.write('Target:\t' + str(xor_desired_output[i]) + '\t\tOutput:\t' + str(mlp.o) + '\n')