% wei=WEIGHT;
% FileIsRead=0;
% reference order the paper used
refm1=[3 4 5 3 4 5             %(ref 1)
      4 5 2 4 5 2
      5 2 3 5 2 3
      2 3 4 2 3 4];

% other references
refm2=[4 5 3 4 5 3             %(ref 2)
      5 2 4 5 2 4
      2 3 5 2 3 5
      3 4 2 3 4 2];
refm3=[5 3 4 5 3 4               %(ref 3)
      2 4 5 2 4 5
      3 5 2 3 5 2
      4 2 3 4 2 3];
  
% missions=[3 5 2 4];
% passes=[5 5 3 3];
% D=zeros(4,6);
% FA=zeros(4,6);

% for nw=size(x1,1):size(x1,1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%     This part is feature selecting part. It tries to cut the weight short
%     to see if better result can be achieved

%     [w id]=sort(abs(wei),'descend');
%     nx=size(xx,2);
%     nx1=size(x1,2);
%     nx2=size(x2,2);
%     clear xx1 xx2 xxx
%     xxx=zeros(nw,nx);
%     xx1=zeros(nw,nx1);
%     xx2=zeros(nw,nx2);
%     for i=1:nx1
%         xx1(1:nw,i)=x1(id(1:nw),i);
%     end
%     for i=1:nx2
%         xx2(1:nw,i)=x2(id(1:nw),i);
%     end
%     xxx=[xx1 xx2];
%     clear history weight;
%     [weit, history] = IRELIEF(xxx, targ, para);
%     yyy=weit'*xxx;
%     minyyy=min(yyy);
%     maxyyy=max(yyy);
%     weight=zeros(size(wei));
%     weight(id(1:nw))=weit(1:nw);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%     weight=WEIGHT; %use the weights learned in learning phase directly
% fn=sprintf('learned_wnd%d_ref1.mat',2*r+1);
% load(fn);
% fn=sprintf('learned_wnd%d_ref2.mat',2*r+1);
% load(fn);
% fn=sprintf('learned_wnd%d_ref3.mat',2*r+1);
% load(fn);
    idx_th=1;
    clear A D FA;
    for thresh=3:3;%0.4:0.2:4%2.875:2.875%1:0.5:7%1.65:1.65
        for mis=2:5
            for pas=1:6
                fn=sprintf('Mission%d\\Targets.txt',mis);
                deploy=VHF_read_target_list(fn);
                fn=sprintf('DistanceRatio_wnd%d_ref1\\Mission%dpass%d.mat',2*r+1,mis,pas);
                load(fn,'result_1');
                fn=sprintf('DistanceRatio_wnd%d_ref2\\Mission%dpass%d.mat',2*r+1,mis,pas);
                load(fn,'result_2');
                fn=sprintf('DistanceRatio_wnd%d_ref3\\Mission%dpass%d.mat',2*r+1,mis,pas);
                load(fn,'result_3');      
                disp(sprintf('\nTesting mission %d pass %d thresh %f...',mis,pas,thresh));
                Testing_fromFile;
                fn=sprintf('Output\\Mission%dPass%d.bmp',mis,pas);
                imwrite(result2,fn);
                A(idx_th,mis-1,pas)=nDetected;
                D(idx_th,mis-1,pas)=nTrueTarg;
                FA(idx_th,mis-1,pas)=nFalseAlarm;
                pA(idx_th,mis-1,pas)=pDetected;
                pD(idx_th,mis-1,pas)=pTrueTarg;
                pFA(idx_th,mis-1,pas)=pFalseAlarm;
                clear im1
            end
        end
        idx_th=idx_th+1;
    end
% end
% fn=sprintf('result_MV_wnd%d.mat',2*r+1);
% save(fn,'A','D','FA');