% generate data
clear all
clc

tol = 1e-8;
freq = inf;
maxiter = inf;
repeat = 50;

% parameter for DR
ratio = 10; 
ratio_1 = 30;
ratio_2 = 50;
% ratio_1 = 50; 
% ratio_2 = 70; 
% parameter for PR
eta = 0.93;
beta = 2.2;

% noise factor
nf = 0.01; 

randn('seed',100); % fix seed % previously using 200
rand('seed',100);


fid = fopen('easy_357.txt','w');

for m = 100:100:500
  for n = 4000:1000:6000

    k = ceil(m/10); % easy problem
     time0 = 0; time1 = 0;  time2 = 0; time3 = 0; time4 = 0; time_PR = 0;
     iter0 = 0; iter1 = 0;  iter2 = 0; iter3 = 0; iter4 = 0; iter_PR = 0;
     fval0 = 0; fval1 = 0;  fval2 = 0; fval3 = 0; fval4 = 0; fval_PR = 0;

    for ii = 1:repeat

      A = randn(m,n);
      for j = 1:n
        A(:,j) = A(:,j)/norm(A(:,j));
      end
      x0 = randn(k,1);
      x1 = zeros(n,1);
      I = randperm(n); x1(I(1:k)) = x0;
      noise = nf*randn(m,1);
      b = A*x1 + noise;
     


      fprintf(' Start DR 10\n')
      tDR0 = tic;
      [fval,z,x,y,iter] = DR_ls(A,b,k,tol,maxiter,ratio);
      time0 = time0 + toc(tDR0);
      iter0 = iter0 + iter;
      fval0 = fval0 + fval;
      
      
      fprintf(' Start DR 30\n')
      tDR1 = tic;
      [fval_1,z1,x1,y1,iter_1] = DR_ls(A,b,k,tol,maxiter,ratio_1);
      time1 = time1 + toc(tDR1);
      iter1 = iter1 + iter_1;
      fval1 = fval1 + fval_1;
      
            
      fprintf(' Start DR 50\n')
      tDR2 = tic;
      [fval_2,z2,x2,y2,iter_2] = DR_ls(A,b,k,tol,maxiter,ratio_2);
      time2 = time2 + toc(tDR2);
      iter2 = iter2 + iter_2;
      fval2 = fval2 + fval_2;
      
      
     fprintf(' Start PR 9.3 2.2\n')
      tPR = tic;
      [fvalPR,zPR,xPR,yPR,iterPR] = PR_ls(A,b,k,tol,maxiter,beta,eta);
      time_PR = time_PR + toc(tPR);
      iter_PR = iter_PR + iterPR;
      fval_PR = fval_PR + fvalPR;
      
  
      
    end
    
    fprintf(fid,' %5d & %5d &  %6.0f & %4.2e &  %6.0f & %4.2e & %6.0f & %4.2e & %6.0f & %4.2e\n',...
      m, n, iter0/repeat, fval0/repeat, iter1/repeat, fval1/repeat, iter2/repeat, fval2/repeat, iter_PR/repeat, fval_PR/repeat);
  end

end


fclose(fid);