function [tree,p]=PNF_createRoot() tree.T=[0]; tree.D(1).isLeaf=1; p=1; S=load('training.mat'); tree.D(1).remaining_samples=1:size(S.X,1); end function [tree,p1,p2]=add2nodes(tree,p) tree.T=[tree.T p p]; p1=length(tree.T)-1; p2=length(tree.T); tree.D(p).isLeaf=0; tree.D(p1).isLeaf=1; tree.D(p2).isLeaf=1; tree.D(p1).remaining_samples=[]; tree.D(p2).remaining_samples=[]; for n=tree.D(p).remaining_samples s=tree.D(p).sign; l=tree.D(p).lambda; test=(x(tree.D(p).feature)*s<=l*s); if test tree.D(p1).remaining_samples=[tree.D(p1).remaining_samples n]; else tree.D(p2).remaining_samples=[tree.D(p1).remaining_samples n]; end end tree.D(p1).remaining_samples end function tree=PNF_fillNode(tree,p,feature,lambda,s) tree.D(p).isLeaf=0; tree.D(p).feature=feature; tree.D(p).sign=s; tree.D(p).lambda=lambda; end function tree=PNF_fillLeaf(tree,p,class) tree.D(p).class=class; tree.D(p).isLeaf=1; end function p=PNF_findRoot(tree) p=find(tree.T==0); end function [test,c]=PNF_isLeaf(tree,p) if tree.D(p).isLeaf test=1; c=tree.D(p).class; else test=0; c=NaN; end end function p_new=PNF_child_of(tree,p,x) s=tree.D(p).sign; l=tree.D(p).lambda; test=(x(tree.D(p).feature)*s<=l*s); p_l=find(tree.T==p); if test p_new=min(p_l); else p_new=max(p_l); end end function info=PNF_train1() [tree,p]=PNF_createRoot(); S=load('training.mat'); counter=0; while(1) counter=counter+1; if counter>50 break; end p=ceil(rand(1)*length(tree.T)); if ~PNF_isLeaf(tree,p) continue, end if length(tree.T(p).remaining_samples)<=3 continue, end lambda_min=min(S.X(tree.T(p).remaining_samples)); lambda_max=max(S.X(tree.T(p).remaining_samples)); lambda=lambda_min+rand(1)*(lambda_max-lambda_min); tree=PNF_fillNode(tree,p,ceil(rand(1)*S.metadata.F),lambda,ceil(rand(1)>0.5)); end for p=1:length(tree.T) if PNF_isLeaf(tree,p) Y=S.Y(tree.T(p).remaining_samples); labels=unique(Y); count=zeros(1,length(labels)); for l=1:length(labels) count(l)=sum(Y==labels(l)); end [val,c_]=max(count); tree.D(p).class=labels(c_); end end info.tree=tree; end function y_hat=PNF_predict1(info,x) p=PNF_find_root(info.tree); while (1) [test,c]=PNF_isLeaf(tree,p); if test y_hat=c; break; end p=PNF_child_of(tree,p,x); end end function score=PNF_score1(info,name_of_file,predict_function) S=load([name_of_file,'.mat']); Y_hat=zeros(size(S.X,1),1); Y=S.Y; for n=1:size(S.X,1) Y_hat(n)=PNF_predict1(info,x); end .... end function info=PNF_train2() score_OA_max=-Inf; info_best=[]; exp_n=500; for exp=1:exp_n info=PNF_train1(); score=PNF_score1(info,'training',@PNF_predict1) if score.overall_accuracy>score_OA_max score_OA_max=score.overall_accuracy; info_best=info; end end info=info_best; end