clear all %#ok<*CLALL>
close all
clc

global x
global d

x = [0 0; 0 1; 1 0; 1 1];
d = [0; 1; 1; 1];

[M,N] = size(x);
x = [x ones(M,1)];
nVariables = N+1;
coefs = ga(@myFitnessPerceptron,nVariables);

y=x*coefs' >0;

coefs

TP=0; TN=0; FP=0; FN=0;

for k=1:M
    if d(k)==0 && y(k)==0
        TN = TN+1;
    elseif d(k)==0 && y(k)==1
        FP = FP+1;
    elseif d(k)==1 && y(k)==0
        FN = FN+1;
    else
        TP = TP+1;
    end
end

ACC = (TP+TN) / M * 100;
SEN = TP/(TP+FN)*100;
SPE = TN/(TN+FP)*100;
SEL = TP/(TP+FP)*100;
NEG = TN/(TN+FN)*100;
[ACC SEN SPE SEL NEG]