Created
November 6, 2012 22:13
-
-
Save MhdSyrwan/4027967 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
threshold= 0.5; | |
learning_rate = 0.1; | |
weights = [0, 0, 0]; | |
training_set = [[[1, 0, 0], 1], [[1, 0, 1], 1], [[1, 1, 0], 1], [[1, 1, 1], 0]]; | |
P = [1,0,0; 1,0,1; 1,1,0; 1,1,1]'; | |
T = [1,1,1,0]; | |
while true | |
error_count = 0; | |
for input_index=1:size(P,1) | |
input_vector = P(:,input_index); | |
desired_output = T(input_index); | |
product = weights * input_vector ; | |
result = 0; | |
if product > threshold | |
result = 1; | |
end | |
error = desired_output - result; | |
if error ~= 0 | |
error_count = error_count + 1; | |
index = 1; | |
for value = input_vector' | |
weights(index) = weights(index) + learning_rate * error * value; | |
index = index + 1 ; | |
end | |
end | |
end | |
if error_count == 0 | |
break; | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment