Home > matlab > ident_bruteforce.m

ident_bruteforce

PURPOSE ^

function [pars, cosnJ] = ident_bruteforce(J,n,TeX, pnames_TeX)

SYNOPSIS ^

function [pars, cosnJ] = ident_bruteforce(J,n,TeX, pnames_TeX)

DESCRIPTION ^

 function [pars, cosnJ] = ident_bruteforce(J,n,TeX, pnames_TeX)

 given the Jacobian matrix J of moment derivatives w.r.t. parameters
 computes, for  each column of  J, the groups of columns from 1 to n that
 can repliate at best the derivatives of that column

 OUTPUTS
  pars  : cell array with groupf of params for each column of J for 1 to n
  cosnJ : the cosn of each column with the selected group of columns

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [pars, cosnJ] = ident_bruteforce(J,n,TeX, pnames_TeX)
0002 % function [pars, cosnJ] = ident_bruteforce(J,n,TeX, pnames_TeX)
0003 %
0004 % given the Jacobian matrix J of moment derivatives w.r.t. parameters
0005 % computes, for  each column of  J, the groups of columns from 1 to n that
0006 % can repliate at best the derivatives of that column
0007 %
0008 % OUTPUTS
0009 %  pars  : cell array with groupf of params for each column of J for 1 to n
0010 %  cosnJ : the cosn of each column with the selected group of columns
0011 
0012 % Copyright (C) 2009 Dynare Team
0013 %
0014 % This file is part of Dynare.
0015 %
0016 % Dynare is free software: you can redistribute it and/or modify
0017 % it under the terms of the GNU General Public License as published by
0018 % the Free Software Foundation, either version 3 of the License, or
0019 % (at your option) any later version.
0020 %
0021 % Dynare is distributed in the hope that it will be useful,
0022 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0023 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0024 % GNU General Public License for more details.
0025 %
0026 % You should have received a copy of the GNU General Public License
0027 % along with Dynare.  If not, see <http://www.gnu.org/licen
0028 global M_ options_
0029 
0030 OutputDirectoryName = CheckPath('Identification',M_.dname);
0031 
0032 k = size(J,2); % number of parameters
0033 
0034 if nargin<2 || isempty(n)
0035     n = 4; % max n-tuple
0036 end
0037 if nargin<3 || isempty(TeX)
0038     TeX = 0; % max n-tuple
0039 end
0040 
0041 cosnJ=zeros(k,n);
0042 pars{k,n}=[];
0043 for ll = 1:n,
0044     h = dyn_waitbar(0,['Brute force collinearity for ' int2str(ll) ' parameters.']);
0045     for ii = 1:k
0046         tmp = find([1:k]~=ii);
0047         tmp2  = nchoosek(tmp,ll);
0048         cosnJ2=zeros(size(tmp2,1),1);
0049         b=[];
0050         for jj = 1:size(tmp2,1)
0051             [cosnJ2(jj,1), b(:,jj)] = cosn([J(:,ii),J(:,tmp2(jj,:))]);
0052         end
0053         cosnJ(ii,ll) = max(cosnJ2(:,1));
0054         if cosnJ(ii,ll)>1.e-8,
0055             if ll>1 && ((cosnJ(ii,ll)-cosnJ(ii,ll-1))<1.e-8),
0056                 pars{ii,ll} = [pars{ii,ll-1} NaN];
0057                 cosnJ(ii,ll) = cosnJ(ii,ll-1);
0058             else
0059                 pars{ii,ll} = tmp2(find(cosnJ2(:,1)==max(cosnJ2(:,1))),:);
0060             end
0061         else
0062             pars{ii,ll} = NaN(1,ll);
0063         end
0064         dyn_waitbar(ii/k,h)
0065     end
0066     dyn_waitbar_close(h);
0067     if TeX
0068         filename = [OutputDirectoryName '/' M_.fname '_collinearity_patterns' int2str(ll) '.TeX'];
0069         fidTeX = fopen(filename,'w');
0070         fprintf(fidTeX,'%% TeX-table generated by ident_bruteforce (Dynare).\n');
0071         fprintf(fidTeX,['%% Collinearity patterns with ',int2str(ll),' parameter(s)\n']);
0072         fprintf(fidTeX,['%% ' datestr(now,0)]);
0073         fprintf(fidTeX,' \n');
0074         fprintf(fidTeX,' \n');
0075         fprintf(fidTeX,'{\\tiny \n');
0076         fprintf(fidTeX,'\\begin{table}\n');
0077         fprintf(fidTeX,'\\centering\n');
0078         fprintf(fidTeX,'\\begin{tabular}{l|lc} \n');
0079         fprintf(fidTeX,'\\hline\\hline \\\\ \n');
0080         fprintf(fidTeX,'  Parameter & Explanatory & cosn \\\\ \n');
0081         fprintf(fidTeX,'            & parameter(s)   &  \\\\ \n');
0082         fprintf(fidTeX,'\\hline \\\\ \n');
0083         for i=1:k,
0084             plist='';
0085             for ii=1:ll,
0086                 plist = [plist ' $' pnames_TeX(pars{i,ll}(ii),:) '$ '];
0087             end
0088             fprintf(fidTeX,'$%s$ & [%s] & %7.3f \\\\ \n',...
0089                 pnames_TeX(i,:),...
0090                 plist,...
0091                 cosnJ(i,ll));
0092         end
0093         fprintf(fidTeX,'\\hline\\hline \n');
0094         fprintf(fidTeX,'\\end{tabular}\n ');
0095         fprintf(fidTeX,['\\caption{Collinearity patterns with ',int2str(ll),' parameter(s)}\n ']);
0096         fprintf(fidTeX,['\\label{Table:CollinearityPatterns:',int2str(ll),'}\n']);
0097         fprintf(fidTeX,'\\end{table}\n');
0098         fprintf(fidTeX,'} \n');
0099         fprintf(fidTeX,'%% End of TeX file.\n');
0100         fclose(fidTeX);
0101     end
0102 end

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005