function Az = EliminateEdgeStepwise(E,oldA,P)

[N,M]=size(E);
L=size(oldA,2);
Az=zeros(N,L);
AICAll=[];
for gene_=1:N
    flag_=1;
    loop_=1;
    e=E(gene_,:);
    pindex=find(oldA(gene_,:));
    psel=[];
    Lred=length(pindex);
    AIC_old=1000;
    while flag_ & loop_<=Lred
        atmp=zeros(Lred,1);
        res_=repmat(norm(e),Lred,1);
        tmp_e=[];
        for j=1:Lred
            if pindex(j)
                sub_reg=[psel;pindex(j)];
                atmp=P(sub_reg,:)'\e';
                tmp_e(j,:)=e-atmp'*P(sub_reg,:);
                res_(j,1)=norm(tmp_e(j,:),'fro');   
            end
        end
        [res_min,ind_min]=min(res_);
        if res_min
    		AIC_new=log(res_min^2/(M-0))+(M+loop_)/(M-loop_-2);            
        else
            AIC_new=-1000;
        end
        if AIC_new < AIC_old %& pindex(ind_min)~0
            psel=[psel;pindex(ind_min)];
            AIC_old=AIC_new;
            pindex(ind_min)=0;
            loop_=loop_+1;
        else
            flag_=0;
        end
    end
    AICAll(gene_,1)=AIC_old;
    Az(gene_,psel)=ones(1,length(psel));
end
