%% setting the value for the parameter:

close all
clear all
clc

loadtheta

all_variabs    = strvcat('y_o','c_o','i_o','w_o','pi_o','r_o','h_o');
all_nvariabs   = {'y_o','c_o','i_o','w_o','pi_o','r_o','h_o'};
[comb]         = createcombinations(all_variabs,all_nvariabs);
combins        = [];
theta_0        = theta';


J1=0; J2=0;
% select the couple of restriction
paran           = num2str([1:1:29]');
comb0           = paran(1:5,:);
for i1=6:29
    J1 = J1 + 1;
    comb1(J1).var = [comb0; paran(i1,:)];
    for i2 = i1+1:24
        J2 = J2 + 1;
        comb2(J2).var = [comb1(J1).var; paran(i2,:)];
    end
%    disp(sprintf('Combination of observable %d',subset_variabs));    
end
save combpara comb2

wb = waitbar(0, 'Computing the rank test for 35 combinations');
for co =1:1
    waitbar(co/35, wb);
    subset  = comb(co).var; 
    subsetn = comb(co).nvar; 
    combins = [combins; subsetn];
    result6  = [];
    for cc =1:size(comb2,2)
        % compute the ABCD matrices. they are in minimal state form solution, see
        % complementary documents in Kumunijer and Ng (2011).
        [minA,minB,minC,minD,Sigma] = sw4_abcd(theta_0,comb(co).var);
        % Compute the derivatives
        [Delta_0,Delta_L,Delta_T,Delta_U] = ...
            delta_as(theta_0,minA,minB,minC,minD,Sigma,comb(1).var);
        n_x           = size(minA,1);
        n_eps         = size(minB,2);
        n_y           = size(minC,1);
        n_theta       = size(theta_0,1);
        % checks conditional identification under restrictions defined in Rmat
        Rmat{1} = str2num(comb2(cc).var)';
        tol1 = 1e-2;
        % prints the results in a table for all the restrictions in Rmat 
        % tolerance is set to tol1
        tabl_res = rank_test_res(Delta_0,n_theta,n_x,n_eps,n_y,tol1,Rmat);    
        if tabl_res(:,end)==1
            result7 = [result7; Rmat{1}];
        else 
        end
    end     
    comb(co).restr7 = result7;
end
close(wb);


paranames= {'\delta','\varepsilon_p','\varepsilon_w',' \lambda_w ',...
    'cg  ',' \beta ',' \phi_p','\psi ',' \alpha ',' h ',...
    ' \zeta_{\omega} ',' \zeta_p ',' i_{\omega} ',' i_p ',...
    ' \sigma_n ', ' \sigma_c $ ',' \varphi ', ' \rho_{\pi} ',...
    ' \rho_R ',' \rho_{y} ',' \rho_{\Delta y}',' \rho_{a} ',...
    ' \rho_{g}',' \rho_{i}',' \rho_{ga}',' \sigma_{a} ',...
    ' \sigma_{g} ',' \sigma_{i} ',' \sigma_{r} '};

[comb(1).nvar, paranames(comb(1).restr6{1,1})]
	
