%%%%%script of c_OS.m function OS=c_OS(tree,p,method) M=(tree,p,method); [p1,p2]=find_children(tree,p); M1=(tree,p1,method); M2=(tree,p2,method); proba_pass=length(tree.D(p1).n_l)/length(tree.D(p).n_l); proba_fail=length(tree.D(p2).n_l)/length(tree.D(p).n_l); OS=M-proba_pass*M1-proba_fail*M2; end function M=(tree,p,method) n_l=tree.D(p).n_l; S=load('training.mat'); Y=S.Y; y_p=Y(n_l); labels=unique(y_p); count=zeros(1,length(labels)); for l=1:length(labels) count(l)=sum(Y==labels(l)); end M=c_M(count/sum(count),method); end function [p1,p2]=find_children(tree,p) ind=find(tree.T==p); p1=ind(1); p2=ind(2); end function M=c_M(proba,method) if strcmp(method,'entropy') M=c_H(proba); else M=c_GI(proba); end end function H=c_H(proba) H=sum(-proba.*log2(proba)); end function GI=c_GI(proba) GI=1-sum(proba.^2); end %%%%%script of PNF_train3.m function info=PNF_train3(method,displaying_function) [tree,p]=PNF_createRoot(); OS=c_OS(tree,p,method); tree.D(p).OS=OS; while (1) p=find_node_for_split(tree); if OS_max<0 info.tree=tree; return; end [tree,p1,p2]=add2nodes(tree,p); OS1=c_OS(tree,p1,method); tree.D(p1).OS=OS1; tree.D(p1).c=c_class(tree.D(p1).n_l); OS2=c_OS(tree,p2,method); tree.D(p2).OS=OS2; tree.D(p2).c=c_class(tree.D(p2).n_l); info.tree=tree; displaying_function(info); end end function c=c_class(n_l) Y=S.Y(n_l); labels=unique(Y); count=zeros(1,length(labels)); for l=1:length(labels) count(l)=sum(Y==labels(l)); end [val,c_]=max(count); c=labels(c_); end function [p_best,OS_max]=find_node_for_split(tree) OS_max=-Inf; p_best; for p=1:length(tree.T) if tree.D(p).isleaf OS=tree.D(p).OS; if OS>OS_max OS_max=OS; p_best=p; end end end end function displaying_function(info) %figure(1); treeplot(tree.T); global tab_OA_training; global tab_OA_testing; global tab_counter; if isempty(tab_OA_training) tab_OA_training=[]; if isempty(tab_OA_testing) tab_OA_testing=[]; if isempty(tab_counter) tab_counter=0; tab_counter=tab_counter+1; score_training=PNF_score1(info,'training',@PNF_predict1); score_testing=PNF_score1(info,'testing',@PNF_predict1); tab_OA_training(tab_counter)=score_training.overall_accuracy; tab_OA_testing(tab_counter)=score_testing.overall_accuracy; figure(1); plot(1:length(tab_OA_training),tab_OA_training,'b',1:length(tab_OA_testing),tab_OA_testing,'r'); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% imHI=load('specialX.png'); imHI=imread('specialX.png'); imGT=imread('specialY.png'); figure(1); imshow(imHI) figure(2); imshow(imGT) X=zeros(size(imHI,1)*size(imHT,2),2); X=zeros(size(imHI,1)*size(imHI,2),2); Y=zeros(size(imHI,1)*size(imHI,2),1); X(:,1)=reshape(imHI(:,:,1)',size(imHI,1)*size(imHT,2),1); X(:,1)=reshape(imHI(:,:,1)',size(imHI,1)*size(imHI,2),1); X(:,2)=reshape(imHI(:,:,2)',size(imHI,1)*size(imHI,2),1); Y=reshape(imGT(:,:)',size(imHI,1)*size(imHI,2),1); figure(2); plot(X(Y==0,1),X(Y==0,2),'b.') figure(2); plot(X(Y==0,1),X(Y==0,2),'b.',X(Y==1,1),X(Y==1,2),'r.') sum(Y==1) figure(2); plot(X(Y==0,1),X(Y==0,2),'b.',X(Y>0,1),X(Y>0,2),'r.') figure(3); plot(X(Y==0,1),X(Y==0,2),'b.',X(Y>0,1),X(Y>0,2),'r.') figure(1); imshow(imHI) figure(2); imshow(imGT) Xt=zeros(size(X)); Xt(:,1)=sin(X(:,1)/32*2*pi); Xt(:,2)=sin(X(:,2)/32*2*pi); figure(4); plot(Xt(Y==0,1),Xt(Y==0,2),'b.',Xt(Y>0,1),Xt(Y>0,2),'r.') Xt(:,1)=sin(X(:,1)/64*2*pi); Xt(:,2)=sin(X(:,2)/64*2*pi); figure(4); plot(Xt(Y==0,1),Xt(Y==0,2),'b.',Xt(Y>0,1),Xt(Y>0,2),'r.') ind=randperm(size(X,1)); k_l=ind(1:10); RBF=@(X,gamma,x_special)exp(-gamma*(X(:,1)-x_special(1)).^2-gamma*(X(:,2)-x_special(2)).^2); for k=1:length(k_l) end k_l=ind(1:10); >> RBF=@(X,gamma,x_special)exp(-gamma*(X(:,1)-x_special(1)).^2-gamma*(X(:,2)-x_special(2)).^2); >> for k=1:length(k_l) end k_l=ind(1:10); RBF=@(X,gamma,x_special)exp(-gamma*(X(:,1)-x_special(1)).^2-gamma*(X(:,2)-x_special(2)).^2); Xt2=zeros(size(X)); for k=1:length(k_l) Xt2(:,1)=Xt2(:,1)+RBF(X,X(k_l(k))*(Y(k_l(k))>0); Xt2(:,2)=Xt2(:,2)+RBF(X,X(k_l(k))*(Y(k_l(k))==0); end Xt2(:,1)=Xt2(:,1)+RBF(X,X(k_l(k)).*(Y(k_l(k))>0); Xt2(:,1)=Xt2(:,1)+RBF(X,X(k_l(k))).*(Y(k_l(k))>0); max(max(X)) k_l=ind(1:10); RBF=@(X,gamma,x_special)exp(-gamma*(X(:,1)-x_special(1)).^2-gamma*(X(:,2)-x_special(2)).^2); Xt2=zeros(size(X)); gamma=1/255^2 for k=1:length(k_l) Xt2(:,1)=Xt2(:,1)+RBF(X,gamma,X(k_l(k))).*(Y(k_l(k))>0); Xt2(:,2)=Xt2(:,2)+RBF(X,gamma,X(k_l(k))).*(Y(k_l(k))==0); end k_l=ind(1:10); RBF=@(X,gamma,x_special)exp(-gamma*(X(:,1)-x_special(1)).^2-gamma*(X(:,2)-x_special(2)).^2); Xt2=zeros(size(X)); gamma=1/255^2 for k=1:length(k_l) Xt2(:,1)=Xt2(:,1)+RBF(X,gamma,X(k_l(k),:)).*(Y(k_l(k))>0); Xt2(:,2)=Xt2(:,2)+RBF(X,gamma,X(k_l(k),:)).*(Y(k_l(k))==0); end figure(5); plot(Xt2(Y==0,1),Xt2(Y==0,2),'b.',Xt2(Y>0,1),Xt2(Y>0,2),'r.') k_l=ind(1:10); RBF=@(X,gamma,x_special)exp(-gamma*(X(:,1)-x_special(1)).^2-gamma*(X(:,2)-x_special(2)).^2); Xt2=zeros(size(X)); gamma=1/255 for k=1:length(k_l) Xt2(:,1)=Xt2(:,1)+RBF(X,gamma,X(k_l(k),:)).*(Y(k_l(k))>0); Xt2(:,2)=Xt2(:,2)+RBF(X,gamma,X(k_l(k),:)).*(Y(k_l(k))==0); end figure(5); plot(Xt2(Y==0,1),Xt2(Y==0,2),'b.',Xt2(Y>0,1),Xt2(Y>0,2),'r.') %%%%%%%%%%%%%%%%%%%%%%% k_l=ind(1:10); RBF=@(X,gamma,x_special)exp(-gamma*(X(:,1)-x_special(1)).^2-gamma*(X(:,2)-x_special(2)).^2); Xt2=zeros(size(X)); gamma=1/255 for k=1:length(k_l) Xt2(:,1)=Xt2(:,1)+RBF(X,gamma,X(k_l(k),:)).*(Y(k_l(k))>0); Xt2(:,2)=Xt2(:,2)+RBF(X,gamma,X(k_l(k),:)).*(Y(k_l(k))==0); end