160 likes | 277 Views
Pattern recognition lab 6. TA : Nouf Al-Harbi :: nouf200@hotmail.com. Lab objective:. Applying General Bayesian Decision Theory Classify an input feature value into one of three classes. Quick review of General Bayesian Decision Theory. General Bayesian Decision Theory. Quick review .
E N D
Pattern recognition lab 6 TA : Nouf Al-Harbi :: nouf200@hotmail.com
Lab objective: • Applying General Bayesian Decision Theory • Classify an input feature value into one of three classes
General Bayesian Decision Theory Quick review
General Bayesian Decision Theory Quick review
General Bayesian Decision Theory Quick review
Part 1 Classify a given input feature value into one of three classes (using General Bayesian Decision Theory)
part 1 Practical Learning 1 • Make a Matlab function that classify a feature value x into one of classes w1,w2, and w3 if you know these info: • P(w1)=P(w2)=P(w3)=1/3 • P(x|w1) ≈N(20,4) • P(x|w2) ≈N(30,3) • P(x|w3) ≈N(40,2) • The loss function is
Full code for i=1:C Pwx(i) = pxw(i) * Pw(i); sum = sum + Pwx(i); end Px = sum; Pwx = Pwx / Px; lamda = zeros(A,C); lamda = [0 1 2; 1 0 1; 2 1 0]; R = zeros(1,A); for i = 1:A sum = 0; for j = 1:C sum = sum + lamda(i,j)*Pwx(j); end R(i) = sum; End mn = R(1); wi = 1; for i = 2:A if( mn > R(i)) mn = R(i); wi = i; end End Result = sprintf('\nAction %d will be taken for x = %d \n', wi, x) • function BayesClassifier3 (x) • C= 3 • A = 3 • Pw = zeros(1,C); • Pw = [ 1/3 1/3 1/3]; • mu = [ 20 30 40]; • sigma = [4 3 2 ]; • pxw = zeros(1,C); • for i=1:C • pxw(i) = normalfn( x, mu(i), sigma(i)); • End • pwx = zeros(1,C); • sum =0;
output Action 1 will be taken for x = 10 Action 3 will be taken for x = 50 Action 2will be taken for x = 30
Part 2 Using of the 4thform of general Bayesian classification (in terms of the likelihoods ratios)
general Bayesian classification (in terms of the likelihoods ratios)
Appling part 1 Practical Learning 1 • Make a Matlab function that draw the relation between likelihood ratios and the threshold value (4th form of BC rule) • P(w1)=2/3 • P(w2)=1/3 • P(x|w1) ≈N(20,4) • P(x|w2) ≈N(15,2)
Full code • function likelihoodsRatios() • pw1=2/3; pw2=1/3; • mu1=20; mu2=15; • s1=4; s2=2; • x=min(mu1-4*s1,mu2-4*s2):0.1:max(mu1+4*s1,mu2+4*s2); • n=length(x); • pxw1=zeros(1,n); • pxw2=zeros(1,n); • ratio=zeros(1,n); • for i=1:n • pxw1(i)=NormalFun(x(i),mu1,s1); • pxw2(i)=NormalFun(x(i),mu2,s2); • ratio(i)=pxw1(i)/pxw2(i); • end • lamda=[1 2 ; 3 1]; • theta=((lamda(1,2)-lamda(2,2))*pw2)/((lamda(2,1)-lamda(1,1))*pw1) • plot(x,ratio,'m-',x,theta,'g-'); • axis([0 max(x) 0 3]);
H.W 4 Using the same data of the part1, modify the code of part1 to : Draw a relation between the conditional risk probability for each action Deadline: Next Lab