Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- threshold = 0.6
- learning_rate = 0.4
- weights = [1, 0, 1]
- training_set = [((1, 0, 0), 0), ((1, 0, 1), 0), ((1, 1, 0), 0), ((1, 1, 1), 1)]
- def sum_function(values):
- return sum(value * weight for value, weight in zip(values, weights))
- while True:
- print '-' * 60
- error_count = 0
- for input_vector, desired_output in training_set:
- print weights
- result = 1 if sum_function(input_vector) > threshold else 0
- error = desired_output - result
- if error != 0:
- error_count += 1
- for index, value in enumerate(input_vector):
- weights[index] += learning_rate * error * value
- if error_count == 0:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement