| 1 | %
|
|---|
| 2 | % plot a stacked bar chart of the probabilities in the CDF.
|
|---|
| 3 | %
|
|---|
| 4 | % []=plot_prob_bars(dresp ,params)
|
|---|
| 5 | % []=plot_prob_bars(dresp,descr,params)
|
|---|
| 6 | %
|
|---|
| 7 | % where the required input is:
|
|---|
| 8 | % dresp (structure array, responses)
|
|---|
| 9 | % or
|
|---|
| 10 | % dresp (structure array, responses)
|
|---|
| 11 | % descr (cell array, list of response descriptions desired)
|
|---|
| 12 | %
|
|---|
| 13 | % the required fields of dresp are:
|
|---|
| 14 | % descriptor (char, description)
|
|---|
| 15 | % cdf(:,4) (double matrix, CDF table)
|
|---|
| 16 | %
|
|---|
| 17 | % the optional input is:
|
|---|
| 18 | % params (string/numeric, parameter names and values)
|
|---|
| 19 | %
|
|---|
| 20 | % where the optional parameters are:
|
|---|
| 21 | % ymin (numeric, minimum of y-axis)
|
|---|
| 22 | % ymax (numeric, maximum of y-axis)
|
|---|
| 23 | % xtlrot (numeric, rotation in degrees of x-tick labels)
|
|---|
| 24 | % cmap (char, 'stoplight' for 6-color stoplight colormap)
|
|---|
| 25 | % lstr (cell array, legend labels)
|
|---|
| 26 | %
|
|---|
| 27 | % for each response in the input array, this function plots
|
|---|
| 28 | % a stacked bar plot of the responses, where the bars are
|
|---|
| 29 | % stacked by the probabilities corresponding to the given
|
|---|
| 30 | % response levels in the CDF, and annotates it with the
|
|---|
| 31 | % description. the legend labels can be given or constructed
|
|---|
| 32 | % from the response levels.
|
|---|
| 33 | %
|
|---|
| 34 | % this data would typically be contained in the dakota output
|
|---|
| 35 | % file and read by dakota_out_parse.
|
|---|
| 36 | %
|
|---|
| 37 | % "Copyright 2009, by the California Institute of Technology.
|
|---|
| 38 | % ALL RIGHTS RESERVED. United States Government Sponsorship
|
|---|
| 39 | % acknowledged. Any commercial use must be negotiated with
|
|---|
| 40 | % the Office of Technology Transfer at the California Institute
|
|---|
| 41 | % of Technology. (J. Schiermeier, NTR 47078)
|
|---|
| 42 | %
|
|---|
| 43 | % This software may be subject to U.S. export control laws.
|
|---|
| 44 | % By accepting this software, the user agrees to comply with
|
|---|
| 45 | % all applicable U.S. export laws and regulations. User has the
|
|---|
| 46 | % responsibility to obtain export licenses, or other export
|
|---|
| 47 | % authority as may be required before exporting such information
|
|---|
| 48 | % to foreign countries or providing access to foreign persons."
|
|---|
| 49 | %
|
|---|
| 50 | function []=plot_prob_bars(varargin)
|
|---|
| 51 |
|
|---|
| 52 | if ~nargin
|
|---|
| 53 | help plot_prob_bars
|
|---|
| 54 | return
|
|---|
| 55 | end
|
|---|
| 56 |
|
|---|
| 57 | %% assemble the data into a matrix and calculate the increments
|
|---|
| 58 |
|
|---|
| 59 | %% process input data and assemble into matrices and increments
|
|---|
| 60 |
|
|---|
| 61 | % responses
|
|---|
| 62 |
|
|---|
| 63 | iarg=1;
|
|---|
| 64 | if isstruct(varargin{iarg})
|
|---|
| 65 | dresp=varargin{iarg};
|
|---|
| 66 | iarg=iarg+1;
|
|---|
| 67 |
|
|---|
| 68 | % if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg}))
|
|---|
| 69 | if iarg <= nargin && iscell(varargin{iarg})
|
|---|
| 70 | dresp=struc_desc(dresp,varargin{iarg});
|
|---|
| 71 | iarg=iarg+1;
|
|---|
| 72 | end
|
|---|
| 73 |
|
|---|
| 74 | descr=cell (1,length(dresp));
|
|---|
| 75 | lcdfr=zeros(1,length(dresp));
|
|---|
| 76 | for i=1:length(dresp)
|
|---|
| 77 | lcdfr(i)=size(dresp(i).cdf,1);
|
|---|
| 78 | end
|
|---|
| 79 | cdfr=zeros(length(dresp),max(lcdfr));
|
|---|
| 80 |
|
|---|
| 81 | for i=1:length(dresp)
|
|---|
| 82 | descr(i)=cellstr(dresp(i).descriptor);
|
|---|
| 83 | if ~isempty(dresp(i).cdf)
|
|---|
| 84 | cdfr(i,1)=dresp(i).cdf(1,2);
|
|---|
| 85 | for j=2:size(dresp(i).cdf,1)
|
|---|
| 86 | if (dresp(i).cdf(j,2) > dresp(i).cdf(j-1,2))
|
|---|
| 87 | cdfr(i,j)=dresp(i).cdf(j,2)-dresp(i).cdf(j-1,2);
|
|---|
| 88 | end
|
|---|
| 89 | end
|
|---|
| 90 | end
|
|---|
| 91 | end
|
|---|
| 92 | else
|
|---|
| 93 | error(['''' inputname(iarg) ''' is not a structure.']);
|
|---|
| 94 | end
|
|---|
| 95 |
|
|---|
| 96 | % convert to percentage
|
|---|
| 97 |
|
|---|
| 98 | cdfr=cdfr*100.;
|
|---|
| 99 |
|
|---|
| 100 | % parameters
|
|---|
| 101 |
|
|---|
| 102 | while (iarg <= nargin-1)
|
|---|
| 103 | if ischar(varargin{iarg})
|
|---|
| 104 | if ~isempty(strmatch(varargin{iarg},...
|
|---|
| 105 | {'ymin','ymax','xtlrot','cmap','lstr'},...
|
|---|
| 106 | 'exact'))
|
|---|
| 107 | eval([varargin{iarg} '=varargin{iarg+1};']);
|
|---|
| 108 | disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']);
|
|---|
| 109 | else
|
|---|
| 110 | warning([varargin{iarg} '=' any2str(varargin{iarg+1}) ' is not recognized.']);
|
|---|
| 111 | end
|
|---|
| 112 | else
|
|---|
| 113 | error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']);
|
|---|
| 114 | end
|
|---|
| 115 | iarg=iarg+2;
|
|---|
| 116 | end
|
|---|
| 117 |
|
|---|
| 118 | %% draw the stacked bar plot
|
|---|
| 119 |
|
|---|
| 120 | % if there's only one row, Matlab 7.5 interprets it as a column,
|
|---|
| 121 | % so add an extra row, then reduce xlim
|
|---|
| 122 |
|
|---|
| 123 | if length(dresp) == 1
|
|---|
| 124 | cdfr=[cdfr; cdfr];
|
|---|
| 125 | end
|
|---|
| 126 |
|
|---|
| 127 | figure
|
|---|
| 128 | hl1=bar(cdfr,'stacked');
|
|---|
| 129 | if exist('cmap','var')
|
|---|
| 130 | if strncmpi(cmap,'stop',4)
|
|---|
| 131 | % set(hl1(1),'FaceColor','green')
|
|---|
| 132 | % set(hl1(2),'FaceColor',[.7 1 0])
|
|---|
| 133 | % set(hl1(3),'FaceColor','yellow')
|
|---|
| 134 | % set(hl1(4),'FaceColor',[1 .7 0])
|
|---|
| 135 | % set(hl1(5),'FaceColor',[1 .5 0])
|
|---|
| 136 | % set(hl1(6),'FaceColor','red')
|
|---|
| 137 | colormap([0 1 0;.7 1 0;1 1 0;1 .7 0;1 .5 0;1 0 0]);
|
|---|
| 138 | else
|
|---|
| 139 | colormap(cmap);
|
|---|
| 140 | end
|
|---|
| 141 | end
|
|---|
| 142 |
|
|---|
| 143 | ax1=gca;
|
|---|
| 144 | if length(dresp) == 1
|
|---|
| 145 | set(ax1,'xlim',[0.5 1.5])
|
|---|
| 146 | end
|
|---|
| 147 |
|
|---|
| 148 | % set(ax1,'ylim',[0 120])
|
|---|
| 149 | % ylim('auto')
|
|---|
| 150 | % [ylims]=ylim;
|
|---|
| 151 | [ylims]=[0 120];
|
|---|
| 152 | if exist('ymin','var')
|
|---|
| 153 | ylims(1)=ymin;
|
|---|
| 154 | end
|
|---|
| 155 | if exist('ymax','var')
|
|---|
| 156 | ylims(2)=ymax;
|
|---|
| 157 | end
|
|---|
| 158 | ylim(ylims)
|
|---|
| 159 |
|
|---|
| 160 | set(ax1,'xtick',1:length(descr))
|
|---|
| 161 | set(ax1,'xticklabel',descr)
|
|---|
| 162 | if exist('xtlrot','var')
|
|---|
| 163 | htl=rotateticklabel(ax1,xtlrot);
|
|---|
| 164 | tlext=zeros(length(htl),4);
|
|---|
| 165 | for i=1:length(htl)
|
|---|
| 166 | tlext(i,:)=get(htl(i),'Extent');
|
|---|
| 167 | end
|
|---|
| 168 | end
|
|---|
| 169 |
|
|---|
| 170 | % add the annotation
|
|---|
| 171 |
|
|---|
| 172 | title('Probabilities for Specified Response Levels (RIA)')
|
|---|
| 173 | xlabel('Response')
|
|---|
| 174 | if exist('xtlrot','var')
|
|---|
| 175 | xlext=get(get(ax1,'xlabel'),'Extent');
|
|---|
| 176 | nskip=ceil(max(tlext(:,4))/xlext(4));
|
|---|
| 177 | xlabel(cellstr([repmat(' ',nskip,1);'Response']));
|
|---|
| 178 | clear nskip xlext tlext
|
|---|
| 179 | end
|
|---|
| 180 | ylabel('Percent Below Level')
|
|---|
| 181 |
|
|---|
| 182 | if ~exist('lstr','var') || isempty(lstr)
|
|---|
| 183 | lstr=cell(1,max(lcdfr));
|
|---|
| 184 | for i=1:max(lcdfr)
|
|---|
| 185 | lstr(i)=cellstr(sprintf('%g',...
|
|---|
| 186 | dresp(find(lcdfr == max(lcdfr),1,'first')).cdf(i,1)));
|
|---|
| 187 | end
|
|---|
| 188 | if ~isempty(find(lcdfr < max(lcdfr)))
|
|---|
| 189 | warning('Variable number of levels for responses.');
|
|---|
| 190 | end
|
|---|
| 191 | end
|
|---|
| 192 |
|
|---|
| 193 | hleg1=legend(ax1,lstr,'Location','EastOutside',...
|
|---|
| 194 | 'Orientation','vertical','Interpreter','none');
|
|---|
| 195 |
|
|---|
| 196 | end
|
|---|