Remove calls to eval.

covariance-quadratic-approximation
Stéphane Adjemian (Guts) 2023-12-15 16:33:52 +01:00
parent eb043406e6
commit 47af0cde16
Signed by: stepan
GPG Key ID: 295C1FE89E17EB3C
6 changed files with 41 additions and 37 deletions

View File

@ -56,7 +56,8 @@ elseif NumberOfPlots == 1
end end
for plt = 1:NumberOfPlots for plt = 1:NumberOfPlots
eval(['NumberOfCurves = Info.Box' int2str(plt) '.Number;']) field1 = sprintf('Box%u', plt);
NumberOfCurves = Info.(field1).Number;
NumberOfObservations = zeros(2,1); NumberOfObservations = zeros(2,1);
x = cell(NumberOfCurves,1); x = cell(NumberOfCurves,1);
y = cell(NumberOfCurves,1); y = cell(NumberOfCurves,1);
@ -66,10 +67,11 @@ for plt = 1:NumberOfPlots
binf = NaN(NumberOfCurves,1); binf = NaN(NumberOfCurves,1);
bsup = NaN(NumberOfCurves,1); bsup = NaN(NumberOfCurves,1);
for curve = 1:NumberOfCurves for curve = 1:NumberOfCurves
eval(['x{' curve '} = Info.Box' int2str(plt) '.Curve' int2str(curve) '.xdata;']) field2 = sprintf('Curve%u', curve);
eval(['y{' curve '} = Info.Box' int2str(plt) '.Curve' int2str(curve) '.ydata;']) x{curve} = Info.(field1).(field2).xdata;
eval(['name = Info.Box' int2str(plt) '.Curve' int2str(curve) '.variablename;']) y{curve} = Info.(field1).(field2).ydata;
eval(['PltType{' curve '} = Info.Box' int2str(plt) '.Curve' int2str(curve) '.type']); name = Info.(field1).(field2).variablename;
PltType{curve} = Info.(field1).(field2).type;
if length(x{curve})-length(y{curve}) if length(x{curve})-length(y{curve})
disp('MakeFigure :: The number of observations in x doesn''t match with ') disp('MakeFigure :: The number of observations in x doesn''t match with ')
disp(['the number of observation in y for ' name ]) disp(['the number of observation in y for ' name ])
@ -90,9 +92,9 @@ for plt = 1:NumberOfPlots
if isnan(ymin(plt)) if isnan(ymin(plt))
ymin = 0; ymin = 0;
end end
eval(['NAMES{' int2str(plt) '} = Info.Box' int2str(plt) '.name;']) NAMES{plt} = Info.(field1).name;
if options_.TeX if options_.TeX
eval(['TeXNAMES{' int2str(plt) '} = Info.Box' int2str(plt) '.texname;']) TeXNAMES{plt} = Info.(field1).texname;
end end
subplot(nr,nc,plt) subplot(nr,nc,plt)
hold on hold on
@ -148,22 +150,24 @@ end
if Info.SaveFormat.Eps if Info.SaveFormat.Eps
if isempty(Info.SaveFormat.Name) if isempty(Info.SaveFormat.Name)
eval(['print -depsc2 ' M_.fname Info.SaveFormat.GenericName int2str(Info.SaveFormat.Number) '.eps']); print(sprintf('%s%s%u', M_.fname, Info.SaveFormat.GenericName, Info.SaveFormat.Number), '-depsc2')
else else
eval(['print -depsc2 ' M_.fname Info.SaveFormat.GenericName Info.SaveFormat.Name '.eps']); print(sprintf('%s%s%s', M_.fname, Info.SaveFormat.GenericName, Info.SaveFormat.Name), '-depsc2')
end end
end end
if Info.SaveFormat.Pdf && ~isoctave if Info.SaveFormat.Pdf && ~isoctave
if isempty(Info.SaveFormat.Name) if isempty(Info.SaveFormat.Name)
eval(['print -dpdf ' M_.fname Info.SaveFormat.GenericName int2str(Info.SaveFormat.Number)]); print(sprintf('%s%s%u', M_.fname, Info.SaveFormat.GenericName, Info.SaveFormat.Number), '-dpdf')
else else
eval(['print -dpdf ' M_.fname Info.SaveFormat.GenericName Info.SaveFormat.Name]); print(sprintf('%s%s%s', M_.fname, Info.SaveFormat.GenericName, Info.SaveFormat.Name), '-dpdf')
end end
end end
if Info.SaveFormat.Fig && ~isoctave if Info.SaveFormat.Fig && ~isoctave
if isempty(Info.SaveFormat.Name) if isempty(Info.SaveFormat.Name)
saveas(FigHandle,[M_.fname Info.SaveFormat.GenericName int2str(Info.SaveFormat.Number) '.fig']); saveas(FigHandle, sprintf('%s%s%u.fig', M_.fname, Info.SaveFormat.GenericName, Info.SaveFormat.Number));
else else
saveas(FigHandle,[M_.fname Info.SaveFormat.GenericName Info.SaveFormat.Name '.fig']); saveas(FigHandle, sprintf('%s%s%s.fig', M_.fname, Info.SaveFormat.GenericName, Info.SaveFormat.Name));
end end
end end

View File

@ -103,6 +103,6 @@ for taper_index=1:length(taper_steps)
results_vec(1,4+taper_index*2-1)=NSE_taper; results_vec(1,4+taper_index*2-1)=NSE_taper;
results_vec(1,4+taper_index*2)=total_variance/(n_draws_used*NSE_taper^2); results_vec(1,4+taper_index*2)=total_variance/(n_draws_used*NSE_taper^2);
eval(['results_struct.nse_taper_',num2str(taper),'= NSE_taper;']); results_struct.(sprintf('nse_taper_%u', taper)) = NSE_taper;
eval(['results_struct.rne_taper_',num2str(taper),'= total_variance/(n_draws_used*NSE_taper^2);']); results_struct.(sprintf('rne_taper_%u', taper)) = total_variance/(n_draws_used*NSE_taper^2);
end % end of for mm loop end % end of for mm loop

View File

@ -72,8 +72,8 @@ if np
fprintf('%-*s %10.4f %7.4f %7.4f \n', ... fprintf('%-*s %10.4f %7.4f %7.4f \n', ...
header_width, name, xparam1(ip), stdh(ip), tstath(ip)); header_width, name, xparam1(ip), stdh(ip), tstath(ip));
end end
eval(['oo_.' field_name '_mode.parameters.' name ' = xparam1(ip);']); oo_.(sprintf('%s_mode', field_name)).parameters.(name) = xparam1(ip);
eval(['oo_.' field_name '_std_at_mode.parameters.' name ' = stdh(ip);']); oo_.(sprintf('%s_std_at_mode', field_name)).parameters.(name) = stdh(ip);
ip = ip+1; ip = ip+1;
end end
skipline() skipline()
@ -94,8 +94,8 @@ if nvx
fprintf('%-*s %10.4f %7.4f %7.4f \n', header_width, name, xparam1(ip), stdh(ip), tstath(ip)); fprintf('%-*s %10.4f %7.4f %7.4f \n', header_width, name, xparam1(ip), stdh(ip), tstath(ip));
end end
M_.Sigma_e(k,k) = xparam1(ip)*xparam1(ip); M_.Sigma_e(k,k) = xparam1(ip)*xparam1(ip);
eval(['oo_.' field_name '_mode.shocks_std.' name ' = xparam1(ip);']); oo_.(sprintf('%s_mode', field_name)).shocks_std.(name) = xparam1(ip);
eval(['oo_.' field_name '_std_at_mode.shocks_std.' name ' = stdh(ip);']); oo_.(sprintf('%s_std_at_mode', field_name)).shocks_std.(name) = stdh(ip);
ip = ip+1; ip = ip+1;
end end
skipline() skipline()
@ -116,8 +116,8 @@ if nvn
fprintf('%-*s %10.4f %7.4f %7.4f \n', header_width, name, xparam1(ip), ... fprintf('%-*s %10.4f %7.4f %7.4f \n', header_width, name, xparam1(ip), ...
stdh(ip), tstath(ip)) stdh(ip), tstath(ip))
end end
eval(['oo_.' field_name '_mode.measurement_errors_std.' name ' = xparam1(ip);']); oo_.(sprintf('%s_mode', field_name)).measurement_errors_std.(name) = xparam1(ip);
eval(['oo_.' field_name '_std_at_mode.measurement_errors_std.' name ' = stdh(ip);']); oo_.(sprintf('%s_std_at_mode', field_name)).measurement_errors_std.(name) = stdh(ip);
ip = ip+1; ip = ip+1;
end end
skipline() skipline()
@ -142,8 +142,8 @@ if ncx
end end
M_.Sigma_e(k1,k2) = xparam1(ip)*sqrt(M_.Sigma_e(k1,k1)*M_.Sigma_e(k2,k2)); M_.Sigma_e(k1,k2) = xparam1(ip)*sqrt(M_.Sigma_e(k1,k1)*M_.Sigma_e(k2,k2));
M_.Sigma_e(k2,k1) = M_.Sigma_e(k1,k2); M_.Sigma_e(k2,k1) = M_.Sigma_e(k1,k2);
eval(['oo_.' field_name '_mode.shocks_corr.' NAME ' = xparam1(ip);']); oo_.(sprintf('%s_mode', field_name)).shocks_corr.(name) = xparam1(ip);
eval(['oo_.' field_name '_std_at_mode.shocks_corr.' NAME ' = stdh(ip);']); oo_.(sprintf('%s_std_at_mode', field_name)).shocks_corr.(name) = stdh(ip);
ip = ip+1; ip = ip+1;
end end
skipline() skipline()
@ -166,8 +166,8 @@ if ncn
fprintf('%-*s %10.4f %7.4f %7.4f \n',header_width, name, xparam1(ip), ... fprintf('%-*s %10.4f %7.4f %7.4f \n',header_width, name, xparam1(ip), ...
stdh(ip), tstath(ip)); stdh(ip), tstath(ip));
end end
eval(['oo_.' field_name '_mode.measurement_errors_corr.' NAME ' = xparam1(ip);']); oo_.(sprintf('%s_mode', field_name)).measurement_errors_corr.(name) = xparam1(ip);
eval(['oo_.' field_name '_std_at_mode.measurement_errors_corr.' NAME ' = stdh(ip);']); oo_.(sprintf('%s_std_at_mode', field_name)).measurement_errors_corr.(name) = stdh(ip);
ip = ip+1; ip = ip+1;
end end
skipline() skipline()
@ -407,4 +407,4 @@ function TeXEnd(fid)
fprintf(fid,'\\end{longtable}\n '); fprintf(fid,'\\end{longtable}\n ');
fprintf(fid,'\\end{center}\n'); fprintf(fid,'\\end{center}\n');
fprintf(fid,'%% End of TeX file.\n'); fprintf(fid,'%% End of TeX file.\n');
fclose(fid); fclose(fid);

View File

@ -87,7 +87,7 @@ for i=1:NumberOfModels
end end
end end
try try
eval(['MarginalLogDensity(i) = mstruct.oo_.MarginalDensity.' type ';']) MarginalLogDensity(i) = mstruct.oo_.MarginalDensity.(type);
catch catch
if strcmpi(type,'LaplaceApproximation') if strcmpi(type,'LaplaceApproximation')
if isfield(mstruct.oo_,'mle_mode') if isfield(mstruct.oo_,'mle_mode')

View File

@ -36,24 +36,24 @@ function indx = get_new_or_existing_ei_index(substructure_name, name1, name2)
global estimation_info global estimation_info
if eval(['isempty(estimation_info.' substructure_name ')']) if isempty(estimation_info.(substructure_name))
indx = 1; indx = 1;
return return
end end
if isempty(name2) % parameter or std() statement if isempty(name2) % parameter or std() statement
indx = eval(['find(strcmp(name1, estimation_info.' substructure_name ') == 1)']); indx = find(strcmp(name1, estimation_info.(substructure_name)));
else % corr statement else % corr statement
indx = eval(['find(strcmp([''' name1 ':' name2 '''], estimation_info.' substructure_name ') == 1)']); indx = find(strcmp(sprintf('%s:%s', name1, name2), estimation_info.(substructure_name)));
if isempty(indx) if isempty(indx)
indx = eval(['find(strcmp([''' name2 ':' name1 '''], estimation_info.' substructure_name ') == 1)']); indx = find(strcmp(sprintf('%s:%s', name2, name1), estimation_info.(substructure_name)));
end end
end end
if isempty(indx) if isempty(indx)
indx = eval(['size(estimation_info.' substructure_name ', 2) + 1']); indx = size(estimation_info.(substructure_name), 2) + 1;
end end
if size(indx, 2) > 1 if size(indx, 2) > 1
error(['Error: ' name1 ' ' name2 'found more than once in estimation_info.subsamples_index']); error('Error: %s %s found more than once in estimation_info.subsamples_index', name1, name2);
end end

View File

@ -31,14 +31,14 @@ function storeGlobalVars(fname,append)
GlobalNames = who('global'); GlobalNames = who('global');
% varlist = '';
for j=1:length(GlobalNames) for j=1:length(GlobalNames)
eval(['global ',GlobalNames{j},';']); eval(['global ',GlobalNames{j},';']);
eval(['fGlobalVar.',GlobalNames{j},'=',GlobalNames{j},';']); fGlobalvar.(GlobalNames{j}) = GlobalNames{j};
end end
if nargin<2 if nargin<2
save(fname,'fGlobalVar'); save(fname,'fGlobalVar');
else else
save(fname,'fGlobalVar','-append'); save(fname,'fGlobalVar','-append');
end end