Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # OR
- input = [-1 0 0; -1 0 1; -1 1 0; -1 1 1];
- desired_out = [-1; 1; 1; 1];
- number_of_inputs = rows(input);
- bias = -1;
- coeff = 0.05;
- # Get weights between -0.5 and 0.5
- weights = rand(3,1) .- 0.5;
- iterations = 10000;
- out = zeros(4,1);
- for i = 1:iterations
- for j = 1:number_of_inputs
- h = input(j,:) * weights;
- out(j) = sign(h);
- delta = desired_out(j) - out(j);
- # Update weights -> Wnew = Wold + DeltaW
- for k = 1:3
- weights(k,1) = weights(k, 1) + coeff * delta * input(j, k);
- end
- end
- end
- disp(out);
- # AND
- input = [-1 0 0; -1 0 1; -1 1 0; -1 1 1];
- desired_out = [-1; -1; -1; 1];
- number_of_inputs = rows(input);
- bias = -1;
- coeff = 0.05;
- # Get weights between -0.5 and 0.5
- weights = rand(3,1) .- 0.5;
- iterations = 10000;
- out = zeros(4,1);
- for i = 1:iterations
- for j = 1:number_of_inputs
- h = input(j,:) * weights;
- out(j) = sign(h);
- delta = desired_out(j) - out(j);
- # Update weights -> Wnew = Wold + DeltaW
- for k = 1:3
- weights(k,1) = weights(k, 1) + coeff * delta * input(j, k);
- end
- end
- end
- disp(out);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement