Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # input[0] works has bias
- input = [
- [1, 0, 0],
- [1, 0, 1],
- [1, 1, 0],
- [1, 1, 1]
- ]
- output = [
- 0,
- 1,
- 1,
- 1
- ]
- weights = [
- 0.0,
- 0.0,
- 0.0
- ]
- learning_tax = 0.5
- remaining_error = 0.0
- def calculate_output(c_input, desired_output):
- obtained_output = weights[0] * c_input[0] + \
- weights[1] * c_input[1] + \
- weights[2] * c_input[2]
- output_error = desired_output - obtained_output
- if output_error != 0.0:
- for s in range(0, 3):
- weights[s] += learning_tax * output_error * c_input[s]
- return output_error
- for b in range(0, 100):
- for c in range(0, 4):
- remaining_error = calculate_output(input[c], output[c])
- if b % 10 == 0:
- print('\nWeights: {} - {} - {}\nRemainingError: {}'
- .format(weights[0], weights[1], weights[2], remaining_error))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement