% Minimum Distance Classifier
% Determine the decision boundary equation coefficients
% "md_classifer.m"
% Dr. W.D.Pan for EE 604, UAH

load fisheriris
% Display two classes: Setosa and Versicolor
% Diplay two measurements: Petal Length and Petal Width
gscatter(meas(1:100,3), meas(1:100,4), species(1:100),'rb','ox');
xlabel('Petal length (cm)');
ylabel('Petal width');

% x: Petal Length; y: Petal Width
seto_x = zeros(1, 50); 
seto_y = zeros(1, 50);
seto_x = meas(1:50,3);
seto_y = meas(1:50,4);
% Find the means
mean_seto_x = mean(seto_x)
mean_seto_y = mean(seto_y)
% Plot the mean
hold on;
plot(mean_seto_x, mean_seto_y, 'sr')

versi_x = zeros(1, 50); 
versi_y = zeros(1, 50);
versi_x = meas(51:100,3);
versi_y = meas(51:100,4);
% Find the means
mean_versi_x = mean(versi_x);
mean_versi_y = mean(versi_y);
% Plot the mean
hold on;
plot(mean_versi_x, mean_versi_y, 'sb')

% Calculate the coefficients for the decision boundary line
% Straight line equation: ax + by + c = 0
a = mean_versi_x - mean_seto_x;
b = mean_versi_y - mean_seto_y;
c = -0.5*(mean_versi_x^2 - mean_seto_x^2 + ...
    mean_versi_y^2 - mean_seto_y^2);

% Plot the decision boundary
y = min(meas(1:100,4)): 0.01: max(meas(1:100,4));
x = (-b/a)*y - c/a;
hold on;
plot(x, y, 'g');