Home > solver > DSA_BD_PlotRunHistory.m

DSA_BD_PlotRunHistory

PURPOSE ^

PlotRunHistory: Generate plots illustrating the performance

SYNOPSIS ^

function [h,legends] = DSA_BD_PlotRunHistory(h,legends,runhist, OPTIONS)

DESCRIPTION ^

PlotRunHistory: Generate plots illustrating the  performance
%
% DSA-BD:
% C. Ortiz
% Last modified: 3/31/2011
%********************************************************************

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %PlotRunHistory: Generate plots illustrating the  performance
0002 %%
0003 %% DSA-BD:
0004 %% C. Ortiz
0005 %% Last modified: 3/31/2011
0006 %%********************************************************************
0007 function [h,legends] = DSA_BD_PlotRunHistory(h,legends,runhist, OPTIONS)
0008 dimtext = [' (n=',num2str(OPTIONS.n),',m=',num2str(OPTIONS.m),')'];
0009 legend_append =  DSA_BD_LegendAppend( OPTIONS);
0010 objhist = [];
0011 if isfield(runhist,'pobj')
0012     objhist(1,:) = runhist.pobj;
0013     objhist(2,:) = runhist.dobj;
0014 end
0015 
0016 resnorm = [];
0017 if isfield(runhist,'resnorm')
0018     resnorm = runhist.resnorm;
0019 end
0020 
0021 cputime = [];
0022 if isfield(runhist,'cputime')
0023     cputime = runhist.cputime;
0024 end
0025 
0026 feashist = [];
0027 if isfield(runhist,'pfeas') && isfield(runhist,'dfeas')
0028     feashist(1,:) = runhist.pfeas;
0029     feashist(2,:) = runhist.dfeas;
0030 end
0031 
0032 
0033 epshist = [];
0034 if isfield(runhist,'epsilon')
0035     epshist = runhist.epsilon;
0036 end
0037 
0038 lambdaratio = [];
0039 if isfield(runhist,'lambdaratio')
0040     lambdaratio = runhist.lambdaratio;
0041 end
0042 
0043 lambdahist = [];
0044 if isfield(runhist,'plambda')
0045     lambdahist = sqrt(runhist.dlambda./runhist.plambda);
0046 end
0047 [h,legends] = plotvalues(h,legends,legend_append,objhist,resnorm,feashist, ...
0048     epshist, lambdaratio,lambdahist,dimtext,cputime);
0049 end
0050 
0051 
0052 function  [h,legends] = plotvalues(h,legends,legend_append,Obj,Res,Feas,Eps,lRatio,lambdas,dtext,ctime)
0053 
0054 %clf;
0055 set(0,'defaultaxesfontsize',12);
0056 set(0,'defaultlinemarkersize',2);
0057 set(0,'defaulttextfontsize',12);
0058 group = 0;
0059 lines{1} = '-g';
0060 lines{2} = '-k';
0061 lines{3} = '--r';
0062 lines{4} = '--b';
0063 lines{5} = '-.y';
0064 lines{6} = '-.c';
0065 
0066 [h,legends] = plotPrimalDual(nargin,1,Obj,'duality gap',group,h,legends,legend_append,lines,dtext,'# iterations','{ p_{OBJ} & d_{OBJ} }');
0067 %%
0068 %% get axis scale for plotting residual
0069 %%
0070 [h,legends] = plotNorm(nargin,2,Res,'norm of residual measure',group,h,'point',legends,legend_append,lines,dtext,'# iterations','(p_{err}^2+d_{err}^2)^{1/2}');
0071 
0072 %%
0073 %% get axis scale for plotting infeasibiliy
0074 %%
0075 [h,legends] = plotPrimalDual(nargin,3,Feas,'infeasibility measure',group,h,legends,legend_append,lines,dtext);
0076 
0077 %%
0078 %% get axis scale for plotting epsilon of aprox subdifferential
0079 %%
0080 [h,legends] = plotNorm(nargin,4,Eps,'\epsilon-subdifferential param',group,h,'point',legends,legend_append,lines,dtext);
0081 
0082 %%
0083 %% get axis scale for plotting lambda ratio for adaptive lambda
0084 %%
0085 [h,legends] = plotNormNoLog(nargin,5,lRatio,'Adaptive lambda ratio: \lambda_k/\lambda_0',group,h,'ratio',legends,legend_append,lines,dtext);
0086 
0087 %%
0088 %% get axis scale for plotting wieghted lambdas
0089 %%
0090 [h,legends] = plotNormNoLog(nargin,6,lambdas,'weigthed lambdas (\theta)',group,h,'\theta',legends,legend_append,lines,dtext);
0091 %%
0092 %% get axis scale for plotting residual vs time
0093 %%
0094 [h,legends] = plotNormVsTime(nargin,7,Res,'norm of residual measure in time',group,h,'point',legends,legend_append,lines,dtext,ctime,'time (secs)','(p_{err}^2+d_{err}^2)^{1/2}');
0095 
0096 %%
0097 %% get axis scale for plotting -log10(|p_obj-dobj|) vs time
0098 %%
0099 [h,legends] = plotAbsGapVsTime(nargin,8,Obj,'norm of gap in time',group,h,'point',legends,legend_append,lines,dtext,ctime,'time (secs)','-log10(|p_{OBJ} - d_{OBJ}|)');
0100 end
0101 
0102 function [h,legends] = plotPrimalDual(narg,arg,arrays,titl,group,h,legends,legend_append,lines,dtext,xtext,ytext)
0103 if narg >= arg && ~isempty(arrays);
0104     figure(arg+group);
0105     if isempty(legends) || length(legends)<arg || isempty(legends{arg})
0106         lgnd{1}=['primal ',legend_append];
0107         lgnd{2}=['dual ',legend_append];
0108         legends{arg}=lgnd;
0109         index = 1;
0110         hold off;
0111     else
0112         lgnd = legends{arg};
0113         index = length(lgnd)+1;
0114         lgnd{index}=['primal ',legend_append];
0115         lgnd{index+1}=['dual ',legend_append];
0116         legends{arg}=lgnd;
0117         hold on;
0118     end;
0119 
0120     index2 = length(h)+1;
0121     h(index2)= plot(1:size(arrays,2),arrays(1,:),lines{index});
0122     hold on;
0123     h(index2+1) = plot(1:size(arrays,2),arrays(2,:),lines{index+1});
0124     title([titl,dtext]);
0125     if nargin>=11; SetAxis(xtext,ytext); end;
0126     SetLegend(lgnd);
0127     hold off;
0128 end
0129 end
0130 
0131 function [h,legends] = plotNorm(narg,arg,arrays,titl,group,h,newlegend,legends,legend_append,lines,dtext,xtext,ytext)
0132 if narg >= arg && ~isempty(arrays);
0133     figure(arg+group);
0134     if isempty(legends) || length(legends)<arg || isempty(legends{arg})
0135         lgnd{1}=[newlegend,' ',legend_append];
0136         legends{arg}=lgnd;
0137         index = 1;
0138         hold off;
0139     else
0140         lgnd = legends{arg};
0141         index = length(lgnd)+1;
0142         lgnd{index}=[newlegend,' ',legend_append];
0143         legends{arg}=lgnd;
0144         hold on;
0145     end;
0146     index2 = length(h)+1;
0147     h(index2) = plot(1:size(arrays,2),-log10(arrays),lines{index});
0148     title(['-LOG10  ',titl,dtext]);
0149     if nargin>=13; SetAxis(xtext,ytext); end;
0150     SetLegend(lgnd);
0151     hold off;
0152 end
0153 end
0154 
0155 function [h,legends] = plotNormVsTime(narg,arg,arrays,titl,group,h,newlegend,legends,legend_append,lines,dtext,ctime,xtext,ytext)
0156 if narg >= arg && ~isempty(arrays)&& ~isempty(ctime);
0157     figure(arg+group);
0158     legend_append = [legend_append,' (it=',num2str(length(ctime)),')'];
0159     if isempty(legends) || length(legends)<arg || isempty(legends{arg})
0160         lgnd{1}=[newlegend,' ',legend_append];
0161         legends{arg}=lgnd;
0162         index = 1;
0163         hold off;
0164     else
0165         lgnd = legends{arg};
0166         index = length(lgnd)+1;
0167         lgnd{index}=[newlegend,' ',legend_append];
0168         legends{arg}=lgnd;
0169         hold on;
0170     end;
0171     index2 = length(h)+1;
0172     h(index2) = plot([0,ctime],[0,-log10(arrays)],lines{index});
0173     title(['-LOG10  ',titl,dtext]);
0174     if nargin>=14; SetAxis(xtext,ytext); end;
0175     SetLegend(lgnd);
0176     hold off;
0177 end
0178 end
0179 function [h,legends] = plotAbsGapVsTime(narg,arg,arrays,titl,group,h,newlegend,legends,legend_append,lines,dtext,ctime,xtext,ytext)
0180 if narg >= arg && ~isempty(arrays)&& ~isempty(ctime);
0181     figure(arg+group);
0182     legend_append = [legend_append,' (it=',num2str(length(ctime)),')'];
0183     if isempty(legends) || length(legends)<arg || isempty(legends{arg})
0184         lgnd{1}=[newlegend,' ',legend_append];
0185         legends{arg}=lgnd;
0186         index = 1;
0187         hold off;
0188     else
0189         lgnd = legends{arg};
0190         index = length(lgnd)+1;
0191         lgnd{index}=[newlegend,' ',legend_append];
0192         legends{arg}=lgnd;
0193         hold on;
0194     end;
0195     index2 = length(h)+1;
0196     h(index2) = plot([0,ctime],[0,-log10(abs(arrays(1,:)-arrays(2,:))./(1+abs(arrays(1,:))+abs(arrays(2,:))))],lines{index});
0197     title(['-LOG10  ',titl,dtext]);
0198     if nargin>=14; SetAxis(xtext,ytext); end;
0199     SetLegend(lgnd);
0200     hold off;
0201 end
0202 end
0203 
0204 function [h,legends] = plotNormNoLog(narg,arg,arrays,titl,group,h,newlegend,legends,legend_append,lines,dtext)
0205 if narg >= arg && ~isempty(arrays);
0206     figure(arg+group);
0207     if isempty(legends) || length(legends)<arg || isempty(legends{arg})
0208         lgnd{1}=[newlegend,' ',legend_append];
0209         legends{arg}=lgnd;
0210         index = 1;
0211         hold off;
0212     else
0213         lgnd = legends{arg};
0214         index = length(lgnd)+1;
0215         lgnd{index}=[newlegend,' ',legend_append];
0216         legends{arg}=lgnd;
0217         hold on;
0218     end;
0219     index2 = length(h)+1;
0220     h(index2) = plot(1:size(arrays,2),arrays,lines{index});
0221     title([titl,dtext]);
0222     SetLegend(lgnd);
0223     hold off;
0224 end
0225 end
0226 
0227 function SetLegend(lgnd)
0228 s = ['''',lgnd{1},''''];
0229 for i = 2 : length(lgnd)
0230     s = [s,',''',lgnd{i},''''];
0231 end
0232 s = ['legend(',s,')'];
0233 eval(s);
0234 end
0235 
0236 function SetAxis(xtext,ytext)
0237 xlabel(xtext);
0238 ylabel(ytext);
0239 end

Generated on Mon 19-Sep-2011 21:41:33 by m2html © 2005