www.pudn.com > Patternrecognition.rar > ANNBP.m, change:2009-04-10,size:1776b


function [FailCount,FailIndex,net,MM]=ANNBP(Nr,Nt,xnr,xnt,xnrSize,xntSize,CountL,dem) 
 
EPOCHS=500; GOAL=0.0000001; no=4; FailIndex=zeros(xntSize,1); 
if(dem==2) 
    tr1=ones(Nr(1,1),1); tr2=-ones((xnrSize-Nr(1,1)),1); 
    tnr=[tr1 ; tr2]'; 
    tt1=ones(Nt(1,1),1); tt2=-ones((xntSize-Nt(1,1)),1); 
    tnt=[tt1 ; tt2]'; 
end; 
if(dem==3) 
    tr11=ones(Nr(1,1),1); tr12=zeros((Nr(2,1)-Nr(1,1)),1); tr13=ones((xnrSize-Nr(2,1)),1); 
    tr21=zeros(Nr(1,1),1); tr22=ones((Nr(2,1)-Nr(1,1)),1); tr23=ones((xnrSize-Nr(2,1)),1); 
    tr1=[tr11' tr12' tr13']; tr2=[tr21' tr22' tr23']; 
    tnr=[tr1;tr2]; 
    tt11=ones(Nt(1,1),1); tt12=zeros((Nt(2,1)-Nt(1,1)),1); tt13=ones((xntSize-Nt(2,1)),1); 
    tt21=zeros(Nt(1,1),1); tt22=ones((Nt(2,1)-Nt(1,1)),1); tt23=ones((xntSize-Nt(2,1)),1); 
    tt1=[tt11' tt12' tt13']; tt2=[tt21' tt22' tt23']; 
    tnt=[tt1;tt2]; 
end; 
 
pnr=xnr'; MM=minmax(pnr); 
 
net=newff(MM,[no,dem-1],{'tansig','purelin'},'trainlm'); 
      net.trainParam.epochs=EPOCHS; 
      net.trainParam.goal =GOAL; 
net=train(net,pnr,tnr); 
save net  
 
pnt=xnt'; 
k=0; 
for i=1:xntSize 
    if(CountL==2) 
        hp=[xnt(i,1);xnt(i,2)]; 
        yuce=round(sim(net,hp)); 
        if (((yuce==1)&(i>Nt))|((yuce==-1)&(i<=Nt))) 
            k=k+1; 
            FailIndex(k,1)=i; 
        end; 
    end; 
    if(CountL==3) 
        hp=[xnt(i,1);xnt(i,2);xnt(i,3)]; 
        yuce=round(sim(net,hp)); 
        FailFlag1=0;FailFlag2=0;FailFlag3=0; 
        if((yuce==[1 0]')&(i>Nt(1,1)))                FailFlag1=1; end; 
        if((yuce==[1 1]')&(i<=Nt(2,1)))               FailFlag3=1; end; 
        if((yuce==[0 1]')&((i>Nt(2,1))|(i<=Nt(1,1)))) FailFlag2=1; end; 
        if(FailFlag1|FailFlag2|FailFlag3) k=k+1; FailIndex(k,1)=i; end; 
    end; 
end; 
FailCount=k;