assignment 3

advertisement
Image Analysis
Mandatory Assignment 3
Haroon Alam (haroon@itu.dk)
Rizwan Ali (rialf04@itu.dk)
Following is the plot of the data set given in pr.mat file representing class A and Class B
data.
1000 samples showing dataset setAclass1 and setAclass2
5
4
3
2
1
0
-1
-2
-3
-4
-3
-2
-1
0
1
2
3
4
5
We have implemented the minimum distance classifier and took the contributed sample
values in such a way each consecutive plot has the difference of 10 sample by each class
having 2 dimensional description vector.
Number of samples for each dataset: 10
3
2.5
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
-2
-1
0
1
2
3
4
3
4
Number of samples for each dataset: 20
3
2.5
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
-2
-1
0
1
2
Number of samples for each dataset: 30
3
2.5
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
-2
-1
0
1
2
3
4
3
4
Number of samples for each dataset: 40
3
2.5
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
-2
-1
0
1
2
Number of samples for each dataset: 50
3
2.5
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
-2
-1
0
1
2
3
4
3
4
Number of samples for each dataset: 60
3
2.5
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
-2
-1
0
1
2
Number of samples for each dataset: 70
3
2.5
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
-2
-1
0
1
2
3
4
Number of samples for each dataset: 80
4
3
2
1
0
-1
-2
-2
-1
0
1
2
3
4
Number of samples for each dataset: 90
4
3
2
1
0
-1
-2
-3
-2
-1
0
1
2
3
4
5
Number of samples for each dataset: 100
4
3
2
1
0
-1
-2
-3
-2
-1
0
1
2
3
4
5
It is obvious from the above experiment that as we increase the spread of the population,
we have more and more overlapping boundary hence resulting small separation between
the means of two classes.
Error Graphs
First of all we checked the test against the training set with the testing points consisting of
training set.
It produces nearly the straight line indicating that with the increase of population of
training set, we have increased error.
For the testing points that are not the part of training set produces the following error plot
We think that optimal statistical classifiers are the good option because these tend to
reduce the average loss produced due to misclassification.
Matlab Implementation
Minimum Distance Classifier
function MinDist
%Load the dataset
load('pr.mat')
figure (1);
%1000 samples
%Draw setA_class1 using the plot function
for c=1:1000
a=setA_class1(c,:);
plot(a(1),a(2),'c.')
hold on
end
%Draw setA_class2 using the plot function
for c=1:1000
a=setA_class2(c,:);
plot(a(1),a(2),'b>')
hold on
end
title('1000 samples showing dataset setAclass1 and setAclass2');
for counter=1:10
%counter=1;
NoSamples=10;
figure (1+counter);
%10 samples
A=0;
%Draw setA_class1 using the plot function
for c=1:counter*NoSamples
a=setA_class1(c,:);
A=A+a;
plot(a(1),a(2),'c.')
hold on
end
A=A/(counter*NoSamples);
plot(A(1),A(2),'c*');
B=0;
%Draw setA_class2 using the plot function
for c=1:counter*NoSamples
a=setA_class2(c,:);
B=B+a;
plot(a(1),a(2),'b>')
hold on
end
B=B/(counter*NoSamples);
plot(B(1),B(2),'b*')
x=[B(1) A(1)];
y=[B(2) A(2)];
plot(x,y,'--ks','LineWidth',1,'MarkerSize',10)
hold on
%Set X1 points for orthogonal line
p=[x(1) x(2)]
%Calculate line equeation
Ax1= B(1);
Ax2= B(2);
Ac = -1/2*B*B';
Bx1= A(1);
Bx2= A(2);
Bc = -1/2*A*A';
X1=Ax1-Bx1
X2=Ax2-Bx2
C=Ac-Bc
line=(-(X1*p)-C)/X2
plot(p,line,'-rs','LineWidth',1,'MarkerSize',10)
title(['Number of samples for each dataset: ' int2str(counter*NoSamples)])
end
Error Graph Generation (With Training Set Itself)
load('pr.mat')
for i=1:5
NoSamples=i*100;
A=0;
for c=1:NoSamples
a=setA_class1(c,:);
A=A+a;
end
A=A/(NoSamples);
B=0;
for c=1:NoSamples
a=setA_class2(c,:);
B=B+a;
end
B=B/(NoSamples);
x=[B(1) A(1)];
y=[B(2) A(2)];
p=[x(1) x(2)]
Ax1= B(1);
Ax2= B(2);
Ac = -1/2*B*B';
Bx1= A(1);
Bx2= A(2);
Bc = -1/2*A*A';
X1=Ax1-Bx1
X2=Ax2-Bx2
C=Ac-Bc
line=(-(X1*p)-C)/X2
Polynomial = [X2 X1 C]
size(setA_class1)
ValuesA = polyval(Polynomial, setA_class1);
lengths(i) = length(find(ValuesA(1:i*100)<0))/500*100;
num(i) = i*100;
end
plot(num, lengths);
clear
Error Graph (testing points training set exclusive)
load('pr.mat')
for i=1:5
NoSamples=i*100;
A=0;
for c=i+500:NoSamples+500
a=setA_class1(c,:);
A=A+a;
end
A=A/(NoSamples);
B=0;
for c=i+500:NoSamples+500
a=setA_class2(c,:);
B=B+a;
end
B=B/(NoSamples);
x=[B(1) A(1)];
y=[B(2) A(2)];
p=[x(1) x(2)]
Ax1= B(1);
Ax2= B(2);
Ac = -1/2*B*B';
Bx1= A(1);
Bx2= A(2);
Bc = -1/2*A*A';
X1=Ax1-Bx1
X2=Ax2-Bx2
C=Ac-Bc
line=(-(X1*p)-C)/X2
Polynomial = [X2 X1 C]
size(setA_class1)
ValuesA = polyval(Polynomial, setA_class1);
lengths(i) = length(find(ValuesA(500:i*100+500)<0))/1000*100;
num(i) = i*100;
end
plot(num, lengths);
clear
Download