Changeset 3092
- Timestamp:
- 02/23/10 15:30:16 (15 years ago)
- Location:
- issm/trunk/src/m/solutions/dakota
- Files:
-
- 9 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/m/solutions/dakota/dakota_in_params.m
r2166 r3092 26 26 % acknowledged. Any commercial use must be negotiated with 27 27 % the Office of Technology Transfer at the California Institute 28 % of Technology. ( NTR 47078)28 % of Technology. (J. Schiermeier, NTR 47078) 29 29 % 30 30 % This software may be subject to U.S. export control laws. … … 66 66 % or result from the response level lists 67 67 68 if ~isfield(params,'compute') 69 params.compute='probabilities'; 70 end 68 71 if ~isfield(params,'distribution') 69 72 params.distribution='cumulative'; … … 172 175 173 176 if ~isfield(params,'numerical_gradients') 174 params.numerical_gradients= true;177 params.numerical_gradients=false; 175 178 end 176 179 if ~isfield(params,'method_source') … … 198 201 % hessians not fully implemented 199 202 if ~isfield(params,'numerical_hessians') 200 params.numerical_ gradients=true;203 params.numerical_hessians=true; 201 204 end 202 205 if ~isfield(params,'hessian_gradient_step_size') -
issm/trunk/src/m/solutions/dakota/dakota_in_write.m
r2166 r3092 2 2 % write a Dakota .in input file. 3 3 % 4 % []=dakota_in_write(method,dmeth,dvar,dresp,params,filei,varargin) 4 % []=dakota_in_write(method,dvar,dresp,params,filei,varargin) 5 % []=dakota_in_write(dmeth ,dvar,dresp,params,filei,varargin) 5 6 % 6 7 % where the required input is: … … 12 13 % filei (character, name of .in file) 13 14 % 14 % the method , dmeth, and filei will be prompted if empty.15 % paramsmay be empty, in which case defaults will be used.15 % the method and filei will be prompted if empty. params 16 % may be empty, in which case defaults will be used. 16 17 % 17 18 % the optional varargin are not yet used. … … 30 31 % acknowledged. Any commercial use must be negotiated with 31 32 % the Office of Technology Transfer at the California Institute 32 % of Technology. ( NTR 47078)33 % of Technology. (J. Schiermeier, NTR 47078) 33 34 % 34 35 % This software may be subject to U.S. export control laws. … … 39 40 % to foreign countries or providing access to foreign persons." 40 41 % 41 function []=dakota_in_write(method,d meth,dvar,dresp,params,filei,varargin)42 function []=dakota_in_write(method,dvar,dresp,params,filei,varargin) 42 43 43 44 if ~nargin … … 51 52 method=input('Method? ','s'); 52 53 end 53 54 if ~exist('dmeth' ,'var') || isempty(dmeth) 54 if ischar(method) 55 55 dmeth=dakota_method(method); 56 elseif isa(method,'dakota_method') 57 dmeth=method; 58 else 59 error(['Method ''' inputname(1) ''' is unrecognized class ''' class(method) '''.']); 56 60 end 57 61 … … 134 138 % write response levels 135 139 136 if strcmp(dmeth.type,'nond') && isfield(dresp,'rf') 137 param_write(fidi,'\t ','distribution',' ','\n',params); 138 [respl,probl,rell,grell]=prop_levels(dresp.rf); 139 if ~isempty(respl) 140 rlev_write(fidi,'response_levels',respl); 141 param_write(fidi,'\t ','compute',' ','\n',params); 142 end 143 if ~isempty(probl) 144 rlev_write(fidi,'probability_levels',probl); 145 end 146 if ~isempty(rell) 147 rlev_write(fidi,'reliability_levels',rell); 148 end 149 if ~isempty(grell) 150 rlev_write(fidi,'gen_reliability_levels',grell); 151 end 152 end 153 fprintf(fidi,'\n'); 154 155 end 156 157 %% function to write response levels 158 159 function []=rlev_write(fidi,ltype,levels) 160 161 fprintf(fidi,'\t num_%s =',ltype); 162 for i=1:length(levels) 163 fprintf(fidi,' %d',length(levels{i})); 164 end 165 fprintf(fidi,'\n'); 166 167 fprintf(fidi,'\t %s =\n',ltype); 168 169 for i=1:length(levels) 170 if ~isempty(levels{i}) 171 vector_write(fidi,sprintf('\t '),levels{i},8,76); 172 end 173 end 140 if strcmp(dmeth.type,'nond') 141 for i=1:length(dmeth.responses) 142 fhresp=str2func([dmeth.responses{i} '.dakota_rlev_write']); 143 fhresp(fidi,dresp,params); 144 end 145 end 146 fprintf(fidi,'\n'); 174 147 175 148 end … … 196 169 % variables vary by method 197 170 198 vsets_write(fidi,dvar,dmeth.variables); 171 for i=1:length(dmeth.variables) 172 fhvar=str2func([dmeth.variables{i} '.dakota_write']); 173 fhvar(fidi,dvar); 174 end 199 175 200 176 % linear constraints vary by method 201 177 202 lcsets_write(fidi,dvar,dmeth.lcspec); 203 204 fprintf(fidi,'\n'); 205 206 end 207 208 %% function to write variable sets 209 210 function []=vsets_write(fidi,dvar,variables) 211 212 for i=1:length(variables) 213 switch(variables{i}) 214 case 'cdv' 215 cstring='continuous_design'; 216 case 'nuv' 217 cstring='normal_uncertain'; 218 case 'csv' 219 cstring='continuous_state'; 220 otherwise 221 warning('vsets_write:unrec_var',... 222 'Unrecognized variable ''%s''.',variables{i}); 223 end 224 225 if isfield(dvar,variables{i}) 226 vlist_write(fidi,cstring,variables{i},dvar.(variables{i})); 227 end 228 end 229 230 end 231 232 %% function to write variable list 233 234 function []=vlist_write(fidi,cstring,cstring2,dvar) 235 236 % put variables into lists for writing 237 238 pinitpt=prop_initpt(dvar); 239 plower =prop_lower (dvar); 240 pupper =prop_upper (dvar); 241 pmean =prop_mean (dvar); 242 pstddev=prop_stddev(dvar); 243 pinitst=prop_initst(dvar); 244 pstype =prop_stype (dvar); 245 pscale =prop_scale (dvar); 246 pdesc =prop_desc (dvar); 247 248 % write variables 249 % (using Dakota 4.1 syntax for backward compatability) 250 251 disp(sprintf(' Writing %d %s variables.',length(dvar),class(dvar))); 252 253 fprintf(fidi,'\t%s = %d\n',cstring,length(dvar)); 254 if ~isempty(pinitpt) 255 fprintf(fidi,'\t %s_initial_point =\n',cstring2); 256 vector_write(fidi,sprintf('\t '),pinitpt,6,76); 257 end 258 if ~isempty(plower) 259 fprintf(fidi,'\t %s_lower_bounds =\n',cstring2); 260 vector_write(fidi,sprintf('\t '),plower ,6,76); 261 end 262 if ~isempty(pupper) 263 fprintf(fidi,'\t %s_upper_bounds =\n',cstring2); 264 vector_write(fidi,sprintf('\t '),pupper ,6,76); 265 end 266 if ~isempty(pmean) 267 fprintf(fidi,'\t %s_means =\n',cstring2); 268 vector_write(fidi,sprintf('\t '),pmean ,6,76); 269 end 270 if ~isempty(pstddev) 271 fprintf(fidi,'\t %s_std_deviations =\n',cstring2); 272 vector_write(fidi,sprintf('\t '),pstddev,6,76); 273 end 274 if ~isempty(pinitst) 275 fprintf(fidi,'\t %s_initial_state =\n',cstring2); 276 vector_write(fidi,sprintf('\t '),pinitst,6,76); 277 end 278 if ~isempty(pstype) 279 fprintf(fidi,'\t %s_scale_types =\n',cstring2); 280 vector_write(fidi,sprintf('\t '),pstype ,6,76); 281 end 282 if ~isempty(pscale) 283 fprintf(fidi,'\t %s_scales =\n',cstring2); 284 vector_write(fidi,sprintf('\t '),pscale ,6,76); 285 end 286 if ~isempty(pdesc) 287 fprintf(fidi,'\t %s_descriptors =\n',cstring2); 288 vector_write(fidi,sprintf('\t '),pdesc ,6,76); 289 end 290 291 end 292 293 %% function to write linear constraint sets 294 295 function []=lcsets_write(fidi,dvar,lcspec) 296 297 for i=1:length(lcspec) 298 switch(lcspec{i}) 299 case 'lic' 300 cstring ='linear_inequality_constraints'; 301 cstring2='linear_inequality'; 302 case 'lec' 303 cstring ='linear_equality_constraints'; 304 cstring2='linear_equality'; 305 otherwise 306 warning('lcspec_write:unrec_lcspec',... 307 'Unrecognized linear constraint ''%s''.',lcspec{i}); 308 end 309 310 if isfield(dvar,lcspec{i}) 311 lclist_write(fidi,cstring,cstring2,dvar.(lcspec{i})); 312 end 313 end 314 315 end 316 317 %% function to write linear constraint list 318 319 function []=lclist_write(fidi,cstring,cstring2,dvar) 320 321 % put linear constraints into lists for writing 322 323 pmatrix=prop_matrix(dvar); 324 plower =prop_lower (dvar); 325 pupper =prop_upper (dvar); 326 ptarget=prop_target(dvar); 327 pstype =prop_stype (dvar); 328 pscale =prop_scale (dvar); 329 330 % write linear constraints 331 332 disp(sprintf(' Writing %d %s linear constraints.',... 333 length(dvar),class(dvar))); 334 335 if ~isempty(pmatrix) 336 fprintf(fidi,'\t %s_matrix =\n',cstring2); 337 vector_write(fidi,sprintf('\t '),pmatrix,6,76); 338 end 339 if ~isempty(plower) 340 fprintf(fidi,'\t %s_lower_bounds =\n',cstring2); 341 vector_write(fidi,sprintf('\t '),plower ,6,76); 342 end 343 if ~isempty(pupper) 344 fprintf(fidi,'\t %s_upper_bounds =\n',cstring2); 345 vector_write(fidi,sprintf('\t '),pupper ,6,76); 346 end 347 if ~isempty(ptarget) 348 fprintf(fidi,'\t %s_targets =\n',cstring2); 349 vector_write(fidi,sprintf('\t '),ptarget,6,76); 350 end 351 if ~isempty(pstype) 352 fprintf(fidi,'\t %s_scale_types =\n',cstring2); 353 vector_write(fidi,sprintf('\t '),pstype ,6,76); 354 end 355 if ~isempty(pscale) 356 fprintf(fidi,'\t %s_scales =\n',cstring2); 357 vector_write(fidi,sprintf('\t '),pscale ,6,76); 358 end 178 for i=1:length(dmeth.lcspec) 179 fhvar=str2func([dmeth.lcspec{i} '.dakota_write']); 180 fhvar(fidi,dvar); 181 end 182 183 fprintf(fidi,'\n'); 359 184 360 185 end … … 407 232 param_write(fidi,'\t','direct','','\n',params); 408 233 param_write(fidi,'\t ','analysis_driver',' = ''','''\n',params); 409 [pathstr,name,ext,versn] = fileparts(params.analysis_components); 410 if isempty(ext) 411 ext='.m'; 412 end 413 params.analysis_components=fullfile(pathstr,[name ext versn]); 414 param_write(fidi,'\t ','analysis_components',' = ''','''\n',params); 234 if ~isempty(params.analysis_components) 235 [pathstr,name,ext,versn] = fileparts(params.analysis_components); 236 if isempty(ext) 237 ext='.m'; 238 end 239 params.analysis_components=fullfile(pathstr,[name ext versn]); 240 param_write(fidi,'\t ','analysis_components',' = ''','''\n',params); 241 end 415 242 if ~isempty(params.input_filter) 416 243 param_write(fidi,'\t ','input_filter',' = ''','''\n',params); … … 421 248 param_write(fidi,'\t ','failure_capture',' ','\n',params); 422 249 param_write(fidi,'\t ','deactivate',' ','\n',params); 423 param_write(fidi,'\t ','output',' ','\n',params);424 250 param_write(fidi,'\t ','processors_per_analysis',' = ''','''\n',params); 425 251 end … … 439 265 % functions, gradients, and hessians vary by method 440 266 441 rsets_write(fidi,dresp,dmeth.responses);442 ghspec_write(fidi,params,dmeth.ghspec);443 444 fprintf(fidi,'\n');445 446 end447 448 %% function to write response sets449 450 function []=rsets_write(fidi,dresp,responses)451 452 267 rdesc={}; 453 268 454 for i=1:length(responses) 455 switch(responses{i}) 456 case 'of' 457 cstring ='objective_functions'; 458 cstring2='objective_function'; 459 case 'lst' 460 cstring ='least_squares_terms'; 461 cstring2='least_squares_term'; 462 case 'nic' 463 cstring ='nonlinear_inequality_constraints'; 464 cstring2='nonlinear_inequality'; 465 case 'nec' 466 cstring ='nonlinear_equality_constraints'; 467 cstring2='nonlinear_equality'; 468 case 'rf' 469 cstring ='response_functions'; 470 cstring2='response_function'; 471 otherwise 472 warning('rsets_write:unrec_resp',... 473 'Unrecognized response ''%s''.',responses{i}); 474 end 475 476 if isfield(dresp,responses{i}) 477 [rdesc]=rlist_write(fidi,cstring,cstring2,dresp.(responses{i}),rdesc); 478 end 479 end 480 481 % write response descriptors 269 for i=1:length(dmeth.responses) 270 fhresp=str2func([dmeth.responses{i} '.dakota_write']); 271 [rdesc]=fhresp(fidi,dresp,rdesc); 272 end 273 274 % write accumulated response descriptors for all response classes 482 275 483 276 if ~isempty(rdesc) … … 486 279 end 487 280 488 end 489 490 %% function to write response list 491 492 function [rdesc]=rlist_write(fidi,cstring,cstring2,dresp,rdesc) 493 494 % put responses into lists for writing 495 496 pstype =prop_stype (dresp); 497 pscale =prop_scale (dresp); 498 pweight=prop_weight(dresp); 499 plower =prop_lower (dresp); 500 pupper =prop_upper (dresp); 501 ptarget=prop_target(dresp); 502 503 % accumulate descriptors into list for subsequent writing 504 505 rdesc(end+1:end+numel(dresp))=prop_desc (dresp); 506 507 % write responses 508 509 disp(sprintf(' Writing %d %s responses.',length(dresp),class(dresp))); 510 511 fprintf(fidi,'\tnum_%s = %d\n',cstring,length(dresp)); 512 if ~isempty(pstype) 513 fprintf(fidi,'\t %s_scale_types =\n',cstring2); 514 vector_write(fidi,sprintf('\t '),pstype ,6,76); 515 end 516 if ~isempty(pscale) 517 fprintf(fidi,'\t %s_scales =\n',cstring2); 518 vector_write(fidi,sprintf('\t '),pscale ,6,76); 519 end 520 if ~isempty(pweight) 521 switch cstring2 522 case 'objective_function' 523 fprintf(fidi,'\t %s_weights =\n','multi_objective'); 524 vector_write(fidi,sprintf('\t '),pweight,6,76); 525 case 'least_squares_term' 526 fprintf(fidi,'\t %s_weights =\n','least_squares'); 527 vector_write(fidi,sprintf('\t '),pweight,6,76); 528 end 529 end 530 if ~isempty(plower) 531 fprintf(fidi,'\t %s_lower_bounds =\n',cstring2); 532 vector_write(fidi,sprintf('\t '),plower ,6,76); 533 end 534 if ~isempty(pupper) 535 fprintf(fidi,'\t %s_upper_bounds =\n',cstring2); 536 vector_write(fidi,sprintf('\t '),pupper ,6,76); 537 end 538 if ~isempty(ptarget) 539 fprintf(fidi,'\t %s_targets =\n',cstring2); 540 vector_write(fidi,sprintf('\t '),ptarget,6,76); 541 end 281 ghspec_write(fidi,params,dmeth.ghspec); 282 283 fprintf(fidi,'\n'); 542 284 543 285 end … … 550 292 551 293 if find_string(ghspec,'grad') 294 if ~params.numerical_gradients && ~params.analytic_gradients 295 params.numerical_gradients=true; 296 elseif (params.numerical_gradients+params.analytic_gradients > 1) 297 error('Too many gradients selected.') 298 end 299 552 300 if params.numerical_gradients 553 301 param_write(fidi,'\t','numerical_gradients','','\n',params); … … 572 320 573 321 end 574 575 %% function to write a parameter576 577 function []=param_write(fidi,sbeg,pname,smid,send,params)578 579 if ~isfield(params,pname)580 warning('param_write:param_not_found',...581 'Parameter ''%s'' not found in structure.',pname);582 return583 end584 585 if islogical(params.(pname)) && ~params.(pname)586 return587 end588 589 if islogical(params.(pname))590 fprintf(fidi,[sbeg '%s' send],pname);591 elseif ischar (params.(pname))592 fprintf(fidi,[sbeg '%s' smid '%s' send],pname,params.(pname));593 elseif isnumeric(params.(pname))594 fprintf(fidi,[sbeg '%s' smid '%g' send],pname,params.(pname));595 end596 597 end598 599 %% function to write a vector on multiple lines600 601 function []=vector_write(fidi,sbeg,vec,nmax,cmax)602 603 if ~exist('nmax','var') || isempty(nmax)604 nmax=Inf;605 end606 if ~exist('cmax','var') || isempty(cmax)607 cmax=Inf;608 end609 610 % set up first iteration611 612 svec =[];613 nitem=nmax;614 lsvec=cmax;615 616 % transpose vector from column-wise to row-wise617 618 vec=vec';619 620 % assemble each line, flushing when necessary621 622 for i=1:numel(vec)623 if isnumeric(vec(i))624 sitem=sprintf('%g' ,vec(i));625 else626 sitem=sprintf('''%s''',char(vec(i)));627 end628 nitem=nitem+1;629 lsvec=lsvec+1+length(sitem);630 631 if (nitem <= nmax) && (lsvec <= cmax)632 svec=[svec ' ' sitem];633 else634 if ~isempty(svec)635 fprintf(fidi,'%s\n',svec);636 end637 svec=[sbeg sitem];638 nitem=1;639 lsvec=length(svec);640 end641 end642 643 % flush buffer at end, if necessary644 645 if ~isempty(svec)646 fprintf(fidi,'%s\n',svec);647 end648 649 end -
issm/trunk/src/m/solutions/dakota/dakota_out_parse.m
r2351 r3092 88 88 [ntokens,tokens]=fltokens(fline); 89 89 method=tokens{1}{3}; 90 display(sprintf('Dakota method =%s.',method));90 display(sprintf('Dakota methodName=''%s''.',method)); 91 91 92 92 dresp=struct([]); … … 96 96 prcm=struct([]); 97 97 98 %% loop through the file to find the iterator completion 99 100 [fline]=findline(fidi,['<<<<< Iterator ' method ' completed.']); 101 if ~ischar(fline) 102 return 103 end 104 % display([' ' deblank(fline)]); 105 98 %% loop through the file to find the function evaluation summary 99 100 fline=''; 101 [nfeval]=nfeval_read(fidi,fline); 106 102 fline=fgetl(fidi); 107 103 … … 110 106 while ischar(fline) 111 107 % ipos=ftell(fidi); 112 if strncmp(fline,'<<<<< Function evaluation summary',33) 108 if isempty(fline) 109 elseif strncmp(fline,'<<<<< Function evaluation summary',33) 113 110 [nfeval]=nfeval_read(fidi,fline); 114 111 elseif strncmp(fline,'Statistics based on ',20) … … 134 131 elseif strncmp(fline,'The following lists volumetric uniformity measures',50) 135 132 [dresp]=vum_read(fidi,dresp,fline); 133 elseif strncmp(fline,'<<<<< Iterator ',15) && ... 134 (length(fline) > 26) && ... 135 ~isempty(strfind(fline(16:end),' completed.')) 136 [method]=itcomp_read(fidi,fline); 136 137 elseif strncmp(fline,'-----',5) 137 elseif isempty(fline)138 138 else 139 139 display(['Unexpected line: ' deblank(fline)]); … … 678 678 end 679 679 680 % read and add best residual norms 681 682 elseif strncmpi(cellstr(tokens{1}{3}),'residual', 8) && ... 683 strncmpi(cellstr(tokens{1}{4}),'norm' , 4) 684 display([' ' deblank(fline)]); 685 dresp.best.norm = tokens{1}{ 6}; 686 dresp.best.hnormsq= tokens{1}{11}; 687 688 fline=fgetl(fidi); 689 690 while ischar(fline) && ~isempty(fline) && ... 691 ~strncmpi(fline,'<<<<< Best ',11) 692 fline=fgetl(fidi); 693 end 694 680 695 % read and add best residual term(s) 681 696 … … 715 730 strncmpi(cellstr(tokens{1}{4}),'captured', 8) 716 731 display([' ' deblank(fline)]); 717 [ntokens,tokens]=fltokens(fline);718 732 dresp.best.eval= tokens{1}{8}; 719 733 720 734 fline=fgetl(fidi); 721 735 722 while ischar(fline) && ~strncmpi(fline,'<<<<< Best ',11) 723 fline=fgetl(fidi); 724 end 725 726 % read until next best or end 736 while ischar(fline) && ~isempty(fline) && ... 737 ~strncmpi(fline,'<<<<< Best ',11) 738 fline=fgetl(fidi); 739 end 740 741 % read until next best or blank or end 727 742 728 743 else 729 display([' ' deblank(fline) ' (not processed)']); 730 731 fline=fgetl(fidi); 732 733 while ischar(fline) && ~strncmpi(fline,'<<<<< Best ',11) 744 display([' ' deblank(fline) ' (ignored)']); 745 746 fline=fgetl(fidi); 747 748 while ischar(fline) && ~isempty(fline) && ... 749 ~strncmpi(fline,'<<<<< Best ',11) 734 750 fline=fgetl(fidi); 735 751 end … … 775 791 end 776 792 793 %% function to find and read the iterator completion 794 795 function [method]=itcomp_read(fidi,fline) 796 797 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 798 while 1 799 [fline]=findline(fidi,'<<<<< Iterator '); 800 if ~ischar(fline) 801 return 802 end 803 if (length(fline) > 26) && ... 804 ~isempty(strfind(fline(16:end),' completed.')) 805 break 806 end 807 end 808 end 809 810 [ntokens,tokens]=fltokens(fline); 811 method=tokens{1}{3}; 812 display(sprintf('Dakota iterator ''%s'' completed.',method)); 813 814 end 815 777 816 %% function to find a file line starting with a specified string 778 817 -
issm/trunk/src/m/solutions/dakota/plot_boxplot.m
r1013 r3092 2 2 % plot a box plot of the responses. 3 3 % 4 % []=plot_boxplot(dresp) 4 % []=plot_boxplot(dresp ,params) 5 % []=plot_boxplot(dresp,descr,params) 6 % []=plot_boxplot(sampr,descr,params) 5 7 % 6 8 % where the required input is: 7 9 % dresp (structure array, responses) 10 % or 11 % dresp (structure array, responses) 12 % descr (cell array, list of response descriptions desired) 13 % or 14 % sampr (double array, lists of response samples) 15 % descr (cell array, list of response descriptions) 8 16 % 9 17 % the required fields of dresp are: … … 11 19 % sample (double vector, list of samples) 12 20 % 13 % for each response in the input array, this functionplots a 21 % the optional input is: 22 % params (string/numeric, parameter names and values) 23 % 24 % where the optional parameters are: 25 % ymin (numeric, minimum of y-axis) 26 % ymax (numeric, maximum of y-axis) 27 % 28 % for each response in the input array, this function plots a 14 29 % matlab box plot of the list of samples and annotates it 15 30 % with the description. the lists of samples need not all be … … 23 38 % acknowledged. Any commercial use must be negotiated with 24 39 % the Office of Technology Transfer at the California Institute 25 % of Technology. ( NTR 47078)40 % of Technology. (J. Schiermeier, NTR 47078) 26 41 % 27 42 % This software may be subject to U.S. export control laws. … … 32 47 % to foreign countries or providing access to foreign persons." 33 48 % 34 function []=plot_boxplot( dresp)49 function []=plot_boxplot(varargin) 35 50 36 51 if ~nargin … … 39 54 end 40 55 41 %% assemble the data into a matrix56 %% process input data and assemble into matrices as needed 42 57 43 desc=cell (1,length(dresp)); 44 for i=1:length(dresp) 45 ldata(i)=length(dresp(i).sample); 46 end 47 data=zeros(max(ldata),length(dresp)); 58 % responses 48 59 49 for i=1:length(dresp) 50 desc(i)=cellstr(dresp(i).descriptor); 51 data(1:ldata(i),i)=dresp(i).sample; 60 iarg=1; 61 if isstruct(varargin{iarg}) 62 dresp=varargin{iarg}; 63 iarg=iarg+1; 64 65 % if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg})) 66 if iarg <= nargin && iscell(varargin{iarg}) 67 dresp=struc_desc(dresp,varargin{iarg}); 68 iarg=iarg+1; 69 end 70 71 descr=cell (1,length(dresp)); 72 lsamp=zeros(1,length(dresp)); 73 for i=1:length(dresp) 74 lsamp(i)=length(dresp(i).sample); 75 end 76 sampr=zeros(max(lsamp),length(dresp)); 77 sampr(:,:)=NaN; 78 79 for i=1:length(dresp) 80 descr(i)=cellstr(dresp(i).descriptor); 81 sampr(1:lsamp(i),i)=dresp(i).sample; 82 end 83 else 84 sampr=varargin{iarg}; 85 iarg=iarg+1; 86 87 if iarg <= nargin && iscell(varargin{iarg}) 88 descr=varargin{iarg}; 89 iarg=iarg+1; 90 % elseif iarg <= nargin && ischar(varargin{iarg}) 91 % descr=cellstr(varargin{iarg}); 92 % iarg=iarg+1; 93 else 94 descr=cell(1,size(sampr,2)); 95 end 52 96 end 53 97 98 for i=1:length(descr) 99 if isempty(descr{i}) 100 descr(i)={['resp_' num2str(i)]}; 101 end 102 end 103 104 % parameters 105 106 while (iarg <= nargin-1) 107 if ischar(varargin{iarg}) 108 eval([varargin{iarg} '=varargin{iarg+1};']); 109 disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']); 110 else 111 error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']); 112 end 113 iarg=iarg+2; 114 end 115 54 116 %% draw the plot 55 117 56 118 % draw box plot 57 119 58 boxplot(data,'labels',desc,'notch','on') 120 figure 121 boxplot(sampr,'labels',descr,'notch','on') 59 122 ax1=gca; 60 123 61 124 % add the annotation 62 125 63 title('Box Plot of Variables and/or Responses') 64 xlabel('Variable or Response') 65 ylabel('Value') 126 ylim('auto') 127 [ylims]=ylim; 128 if exist('ymin','var') 129 ylims(1)=ymin; 130 end 131 if exist('ymax','var') 132 ylims(2)=ymax; 133 end 134 ylim(ylims) 135 136 if (size(sampr,2) == 1) 137 tlabc=descr{1}; 138 else 139 tlabc='Responses'; 140 end 141 title(['Box Plot of ' tlabc],'Interpreter','none'); 142 xlabel('Response','Interpreter','none'); 143 ylabel('Value' ,'Interpreter','none'); 66 144 67 145 end -
issm/trunk/src/m/solutions/dakota/plot_if_bars.m
r1013 r3092 2 2 % plot a stacked bar chart of the importance factors. 3 3 % 4 % []=plot_if_bars(dresp,ifmin,isort) 4 % []=plot_if_bars(dresp ,params) 5 % []=plot_if_bars(dresp,descr,params) 5 6 % 6 7 % where the required input is: 7 8 % dresp (structure array, responses) 8 % 9 % and the optional input is: 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 % var (cell array, variables) 16 % impfac (double array, importance factors) 17 % 18 % the optional input is: 19 % params (string/numeric, parameter names and values) 20 % 21 % where the optional parameters are: 22 % ymin (numeric, minimum of y-axis) 23 % ymax (numeric, maximum of y-axis) 10 24 % ifmin (double, minimum importance factor) 11 25 % isort (numeric, sort flag: 0, no sorting; 12 26 % 1, highest at bottom; 13 27 % -1, lowest at bottom) 14 % 15 % the required fields of dresp are: 16 % descriptor (char, description) 17 % var (cell array, variables) 18 % impfac (double array, importance factors) 28 % xtlrot (numeric, rotation in degrees of x-tick labels) 19 29 % 20 30 % for each response in the input array, this function plots … … 32 42 % acknowledged. Any commercial use must be negotiated with 33 43 % the Office of Technology Transfer at the California Institute 34 % of Technology. ( NTR 47078)44 % of Technology. (J. Schiermeier, NTR 47078) 35 45 % 36 46 % This software may be subject to U.S. export control laws. … … 41 51 % to foreign countries or providing access to foreign persons." 42 52 % 43 function []=plot_if_bars( dresp,ifmin,isort)53 function []=plot_if_bars(varargin) 44 54 45 55 if ~nargin … … 48 58 end 49 59 60 %% process input data and assemble into matrices 61 62 % responses 63 64 iarg=1; 65 if isstruct(varargin{iarg}) 66 dresp=varargin{iarg}; 67 iarg=iarg+1; 68 69 % if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg})) 70 if iarg <= nargin && iscell(varargin{iarg}) 71 dresp=struc_desc(dresp,varargin{iarg}); 72 iarg=iarg+1; 73 end 74 75 descr=cell (1,length(dresp)); 76 lifr =zeros(1,length(dresp)); 77 for i=1:length(dresp) 78 lifr(i)=length(dresp(i).impfac); 79 end 80 ifr =zeros(length(dresp),max(lifr)); 81 dvar=dresp(find(lifr == max(lifr),1,'first')).var; 82 83 for i=1:length(dresp) 84 descr(i)=cellstr(dresp(i).descriptor); 85 ifr(i,1:lifr(i))=dresp(i).impfac; 86 end 87 else 88 error(['''' inputname(iarg) ''' is not a structure.']); 89 end 90 91 % parameters 92 93 while (iarg <= nargin-1) 94 if ischar(varargin{iarg}) 95 eval([varargin{iarg} '=varargin{iarg+1};']); 96 disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']); 97 else 98 error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']); 99 end 100 iarg=iarg+2; 101 end 102 50 103 if ~exist('ifmin','var') || isempty(ifmin) 51 104 ifmin=0; … … 56 109 end 57 110 58 %% assemble the data into a matrix59 60 desc=cell (1,length(dresp));61 for i=1:length(dresp)62 ldata(i)=length(dresp(i).impfac);63 end64 data=zeros(length(dresp),max(ldata));65 dvar=dresp(find(ldata == max(ldata),1,'first')).var;66 67 for i=1:length(dresp)68 desc(i)=cellstr(dresp(i).descriptor);69 data(i,1:ldata(i))=dresp(i).impfac;70 end71 72 111 %% sort the data, if necessary 73 112 74 113 if (isort) 75 ifmean=mean( data,1);114 ifmean=mean(ifr,1); 76 115 if (isort > 0) 77 116 [ifmean,index]=sort(ifmean,'descend'); … … 82 121 83 122 dvar=dvar(index); 84 data=data(:,index);123 ifr =ifr (:,index); 85 124 end 86 125 … … 90 129 nif=length(dvar); 91 130 dvar(nif+1,1)=cellstr(sprintf('others < %f',ifmin)); 92 data(:,nif+1)=0.;131 ifr (:,nif+1)=0.; 93 132 94 133 nif2=0; 95 134 dvar2=cell (size(dvar)); 96 data2=zeros(size(data));135 ifr2 =zeros(size(ifr )); 97 136 98 137 % sum filtered rows and copy unfiltered rows 99 138 100 139 for i=1:nif 101 if (max( data(:,i)) < ifmin)102 data(:,nif+1)=data(:,nif+1)+data(:,i);140 if (max(ifr(:,i)) < ifmin) 141 ifr(:,nif+1)=ifr(:,nif+1)+ifr(:,i); 103 142 else 104 143 nif2=nif2+1; 105 144 dvar2(nif2) =dvar(i); 106 data2(:,nif2)=data(:,i);145 ifr2 (:,nif2)=ifr (:,i); 107 146 end 108 147 end … … 111 150 112 151 dvar2(nif2+1) =dvar(nif+1); 113 data2(:,nif2+1)=data(:,nif+1);152 ifr2 (:,nif2+1)=ifr (:,nif+1); 114 153 115 154 % copy back and truncate filtered rows 116 155 117 clear dvar data156 clear dvar ifr 118 157 if (isort >= 0) 119 158 dvar(1:nif2+1) =dvar2(1:nif2+1); 120 data(:,1:nif2+1)=data2(:,1:nif2+1);159 ifr (:,1:nif2+1)=ifr2 (:,1:nif2+1); 121 160 else 122 161 dvar(1 ) =dvar2( nif2+1); 123 162 dvar(2:nif2+1) =dvar2(1:nif2 ); 124 data(:,1 )=data2(:, nif2+1);125 data(:,2:nif2+1)=data2(:,1:nif2 );126 end 127 clear nif nif2 dvar2 data2163 ifr (:,1 )=ifr2 (:, nif2+1); 164 ifr (:,2:nif2+1)=ifr2 (:,1:nif2 ); 165 end 166 clear nif nif2 dvar2 ifr2 128 167 end 129 168 … … 134 173 135 174 if length(dresp) == 1 136 data=[data; data]; 137 end 138 139 hl1=bar(data,'stacked'); 175 ifr=[ifr; ifr]; 176 end 177 178 figure 179 hl1=bar(ifr,'stacked'); 140 180 141 181 ax1=gca; 142 set(ax1,'ylim',[0 1.2])143 182 if length(dresp) == 1 144 183 set(ax1,'xlim',[0.5 1.5]) 145 184 end 146 set(ax1,'xticklabel',desc) 185 186 % set(ax1,'ylim',[0 1.2]) 187 % ylim('auto') 188 % [ylims]=ylim; 189 [ylims]=[0 1.2]; 190 if exist('ymin','var') 191 ylims(1)=ymin; 192 end 193 if exist('ymax','var') 194 ylims(2)=ymax; 195 end 196 ylim(ylims) 197 198 set(ax1,'xtick',1:length(descr)) 199 set(ax1,'xticklabel',descr) 200 if exist('xtlrot','var') 201 htl=rotateticklabel(ax1,xtlrot); 202 tlext=zeros(length(htl),4); 203 for i=1:length(htl) 204 tlext(i,:)=get(htl(i),'Extent'); 205 end 206 end 147 207 148 208 % add the annotation … … 150 210 title('Importance Factors') 151 211 xlabel('Response') 212 if exist('xtlrot','var') 213 xlext=get(get(ax1,'xlabel'),'Extent'); 214 nskip=ceil(max(tlext(:,4))/xlext(4)); 215 xlabel(cellstr([repmat(' ',nskip,1);'Response'])); 216 clear nskip xlext tlext 217 end 152 218 ylabel('Importance Factor Value') 153 219 -
issm/trunk/src/m/solutions/dakota/plot_normdist_bars.m
r1013 r3092 2 2 % plot a stacked bar chart of the sample distributions. 3 3 % 4 % []=plot_normdist_bars(dresp,plev,lstr) 4 % []=plot_normdist_bars(dresp ,params) 5 % []=plot_normdist_bars(dresp,descr,params) 6 % []=plot_normdist_bars(sampr,descr,params) 5 7 % 6 8 % where the required input is: 7 9 % dresp (structure array, responses) 8 % 9 % and the optional input is: 10 % plev (double vector, probability levels) 11 % lstr (cell array, legend labels) 10 % or 11 % dresp (structure array, responses) 12 % descr (cell array, list of response descriptions desired) 13 % or 14 % sampr (double array, lists of response samples) 15 % descr (cell array, list of response descriptions) 12 16 % 13 17 % the required fields of dresp are: … … 18 22 % mean (double, mean of sample) 19 23 % stddev (double, standard deviation of sample) 24 % 25 % the optional input is: 26 % params (string/numeric, parameter names and values) 27 % 28 % where the optional parameters are: 29 % prob (double vector, probability levels) 30 % ymin (numeric, minimum of y-axis) 31 % ymax (numeric, maximum of y-axis) 32 % xtlrot (numeric, rotation in degrees of x-tick labels) 33 % lstr (cell array, legend labels) 20 34 % 21 35 % for each response in the input array, this function plots … … 35 49 % acknowledged. Any commercial use must be negotiated with 36 50 % the Office of Technology Transfer at the California Institute 37 % of Technology. ( NTR 47078)51 % of Technology. (J. Schiermeier, NTR 47078) 38 52 % 39 53 % This software may be subject to U.S. export control laws. … … 44 58 % to foreign countries or providing access to foreign persons." 45 59 % 46 function []=plot_normdist_bars( dresp,plev,lstr)60 function []=plot_normdist_bars(varargin) 47 61 48 62 if ~nargin … … 51 65 end 52 66 53 if ~exist('plev','var') || isempty(plev) 54 plev=[0.01 0.25 0.50 0.75 0.99]; 55 end 56 57 %% assemble the data into a matrix and calculate the increments 58 59 desc=cell (1,length(dresp)); 60 data=zeros(length(dresp),5); 67 %% process input data and assemble into dresp as needed 68 69 % responses 70 71 iarg=1; 72 if isstruct(varargin{iarg}) 73 dresp=varargin{iarg}; 74 iarg=iarg+1; 75 76 % if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg})) 77 if iarg <= nargin && iscell(varargin{iarg}) 78 dresp=struc_desc(dresp,varargin{iarg}); 79 iarg=iarg+1; 80 end 81 else 82 sampr=varargin{iarg}; 83 iarg=iarg+1; 84 85 if iarg <= nargin && iscell(varargin{iarg}) 86 descr=varargin{iarg}; 87 iarg=iarg+1; 88 % elseif iarg <= nargin && ischar(varargin{iarg}) 89 % descr=cellstr(varargin{iarg}); 90 % iarg=iarg+1; 91 else 92 descr=cell(1:size(sampr,2)); 93 end 94 95 dresp=struct([]); 96 for i=1:size(sampr,2) 97 dresp(end+1).sample=samp(:,i); 98 if ~isempty(descr) 99 dresp(i).descriptor=descr{i}; 100 else 101 dresp(i).descriptor=['dresp_' num2str(i)]; 102 end 103 end 104 end 105 106 % parameters 107 108 while (iarg <= nargin-1) 109 if ischar(varargin{iarg}) 110 eval([varargin{iarg} '=varargin{iarg+1};']); 111 disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']); 112 else 113 error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']); 114 end 115 iarg=iarg+2; 116 end 117 118 %% calculate any missing information (noting that dresp is local) 61 119 62 120 if ~isfield(dresp,'mean') || ~isfield(dresp,'stddev') 63 121 for i=1:length(dresp) 64 % calculate 95% confidence intervals (same as dakota) 65 [dresp(i).mean,dresp(i).stddev,... 66 dresp(i).meanci,dresp(i).stddevci]=... 67 normfit(dresp(i).sample,0.05); 68 end 69 end 122 [dresp(i).mean,dresp(i).stddev]=normfit(dresp(i).sample); 123 end 124 end 125 126 %% assemble the data into a matrix and calculate the increments 127 128 if ~exist('prob','var') || isempty(prob) 129 prob=[0.01 0.25 0.50 0.75 0.99]; 130 end 131 132 descr=cell (1,length(dresp)); 133 data =zeros(length(dresp),length(prob)); 70 134 71 135 for i=1:length(dresp) 72 desc (i)=cellstr(dresp(i).descriptor);73 data(i,:)=norminv(p lev,dresp(i).mean,dresp(i).stddev);74 end 75 76 for j=length(p lev):-1:2136 descr(i)=cellstr(dresp(i).descriptor); 137 data(i,:)=norminv(prob,dresp(i).mean,dresp(i).stddev); 138 end 139 140 for j=length(prob):-1:2 77 141 data(:,j)=data(:,j)-data(:,j-1); 78 142 end … … 87 151 end 88 152 153 figure 89 154 hl1=bar(data,'stacked'); 90 155 % set barseries properties for lowest value … … 97 162 set(ax1,'xlim',[0.5 1.5]) 98 163 end 99 set(ax1,'xtick',1:1:max(length(dresp),2)); 100 set(ax1,'xticklabel',desc) 164 165 ylim('auto') 166 [ylims]=ylim; 167 if exist('ymin','var') 168 ylims(1)=ymin; 169 end 170 if exist('ymax','var') 171 ylims(2)=ymax; 172 end 173 ylim(ylims) 174 175 set(ax1,'xtick',1:length(descr)) 176 set(ax1,'xticklabel',descr) 177 if exist('xtlrot','var') 178 htl=rotateticklabel(ax1,xtlrot); 179 tlext=zeros(length(htl),4); 180 for i=1:length(htl) 181 tlext(i,:)=get(htl(i),'Extent'); 182 end 183 end 101 184 102 185 % add the annotation 103 186 104 title('Normal Distributions of Variables and/or Responses') 105 xlabel('Variable or Response') 187 title('Normal Distributions of Responses') 188 xlabel('Response') 189 if exist('xtlrot','var') 190 xlext=get(get(ax1,'xlabel'),'Extent'); 191 nskip=ceil(max(tlext(:,4))/xlext(4)); 192 xlabel(cellstr([repmat(' ',nskip,1);'Response'])); 193 clear nskip xlext tlext 194 end 106 195 ylabel('Value') 107 196 108 197 if ~exist('lstr','var') || isempty(lstr) 109 lstr=cell(1,length(p lev));110 for i=1:length(p lev)111 lstr(i)=cellstr(sprintf('%g%%',100*p lev(i)));198 lstr=cell(1,length(prob)); 199 for i=1:length(prob) 200 lstr(i)=cellstr(sprintf('%g%%',100*prob(i))); 112 201 end 113 202 end -
issm/trunk/src/m/solutions/dakota/plot_normplot.m
r1013 r3092 2 2 % plot a normal probability plot of the responses. 3 3 % 4 % []=plot_normplot(dresp) 4 % []=plot_normplot(dresp ,params) 5 % []=plot_normplot(dresp,descr,params) 6 % []=plot_normplot(sampr,descr,params) 5 7 % 6 8 % where the required input is: 7 9 % dresp (structure array, responses) 10 % or 11 % dresp (structure array, responses) 12 % descr (cell array, list of response descriptions desired) 13 % or 14 % sampr (double array, lists of response samples) 15 % descr (cell array, list of response descriptions) 8 16 % 9 17 % the required fields of dresp are: 10 18 % descriptor (char, description) 11 19 % sample (double vector, list of samples) 20 % 21 % the optional input is: 22 % params (string/numeric, parameter names and values) 23 % 24 % where the optional parameters are: 25 % xmin (numeric, minimum of x-axis) 26 % xmax (numeric, maximum of x-axis) 12 27 % 13 28 % for each response in the input array, this function plots … … 23 38 % acknowledged. Any commercial use must be negotiated with 24 39 % the Office of Technology Transfer at the California Institute 25 % of Technology. ( NTR 47078)40 % of Technology. (J. Schiermeier, NTR 47078) 26 41 % 27 42 % This software may be subject to U.S. export control laws. … … 32 47 % to foreign countries or providing access to foreign persons." 33 48 % 34 function []=plot_normplot( dresp)49 function []=plot_normplot(varargin) 35 50 36 51 if ~nargin … … 39 54 end 40 55 41 %% assemble the data into a matrix56 %% process input data and assemble into matrices as needed 42 57 43 desc=cell (1,length(dresp)); 44 for i=1:length(dresp) 45 ldata(i)=length(dresp(i).sample); 46 end 47 data=zeros(max(ldata),length(dresp)); 58 % responses 48 59 49 for i=1:length(dresp) 50 desc(i)=cellstr(dresp(i).descriptor); 51 data(1:ldata(i),i)=dresp(i).sample; 60 iarg=1; 61 if isstruct(varargin{iarg}) 62 dresp=varargin{iarg}; 63 iarg=iarg+1; 64 65 % if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg})) 66 if iarg <= nargin && iscell(varargin{iarg}) 67 dresp=struc_desc(dresp,varargin{iarg}); 68 iarg=iarg+1; 69 end 70 71 descr=cell (1,length(dresp)); 72 lsamp=zeros(1,length(dresp)); 73 for i=1:length(dresp) 74 lsamp(i)=length(dresp(i).sample); 75 end 76 sampr=zeros(max(lsamp),length(dresp)); 77 sampr(:,:)=NaN; 78 79 for i=1:length(dresp) 80 descr(i)=cellstr(dresp(i).descriptor); 81 sampr(1:lsamp(i),i)=dresp(i).sample; 82 end 83 else 84 sampr=varargin{iarg}; 85 iarg=iarg+1; 86 87 if iarg <= nargin && iscell(varargin{iarg}) 88 descr=varargin{iarg}; 89 iarg=iarg+1; 90 % elseif iarg <= nargin && ischar(varargin{iarg}) 91 % descr=cellstr(varargin{iarg}); 92 % iarg=iarg+1; 93 else 94 descr=cell(1,size(sampr,2)); 95 end 52 96 end 53 97 98 for i=1:length(descr) 99 if isempty(descr{i}) 100 descr(i)={['resp_' num2str(i)]}; 101 end 102 end 103 104 % parameters 105 106 while (iarg <= nargin-1) 107 if ischar(varargin{iarg}) 108 eval([varargin{iarg} '=varargin{iarg+1};']); 109 disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']); 110 else 111 error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']); 112 end 113 iarg=iarg+2; 114 end 115 54 116 %% draw the plot 55 117 56 118 % draw normal probability plot 57 119 58 normplot(data) 120 figure 121 normplot(sampr) 59 122 ax1=gca; 60 123 61 124 % add the annotation 62 125 63 title('Normal Probability Plot of Variables and/or Responses') 64 xlabel('Value') 65 ylabel('Probability') 126 xlim('auto') 127 [xlims]=xlim; 128 if exist('xmin','var') 129 xlims(1)=xmin; 130 end 131 if exist('xmax','var') 132 xlims(2)=xmax; 133 end 134 xlim(xlims) 66 135 67 hleg1=legend(ax1,desc,'Location','EastOutside',... 136 if (size(sampr,2) == 1) 137 tlabc=descr{1}; 138 else 139 tlabc='Responses'; 140 end 141 title(['Normal Probability Plot of ' tlabc],'Interpreter','none'); 142 xlabel('Value' ,'Interpreter','none'); 143 ylabel('Probability','Interpreter','none'); 144 145 hleg1=legend(ax1,descr,'Location','EastOutside',... 68 146 'Orientation','vertical','Interpreter','none'); 69 147 -
issm/trunk/src/m/solutions/dakota/plot_prob_bars.m
r1013 r3092 2 2 % plot a stacked bar chart of the probabilities in the CDF. 3 3 % 4 % []=plot_prob_bars(dresp,lstr) 4 % []=plot_prob_bars(dresp ,params) 5 % []=plot_prob_bars(dresp,descr,params) 5 6 % 6 7 % where the required input is: 7 8 % dresp (structure array, responses) 8 % 9 % and the optional input is:10 % lstr (cell array, legend labels)9 % or 10 % dresp (structure array, responses) 11 % descr (cell array, list of response descriptions desired) 11 12 % 12 13 % the required fields of dresp are: 13 14 % descriptor (char, description) 14 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) 15 26 % 16 27 % for each response in the input array, this function plots … … 28 39 % acknowledged. Any commercial use must be negotiated with 29 40 % the Office of Technology Transfer at the California Institute 30 % of Technology. ( NTR 47078)41 % of Technology. (J. Schiermeier, NTR 47078) 31 42 % 32 43 % This software may be subject to U.S. export control laws. … … 37 48 % to foreign countries or providing access to foreign persons." 38 49 % 39 function []=plot_prob_bars( dresp,lstr)50 function []=plot_prob_bars(varargin) 40 51 41 52 if ~nargin … … 46 57 %% assemble the data into a matrix and calculate the increments 47 58 48 desc=cell (1,length(dresp));49 for i=1:length(dresp)50 ldata(i)=size(dresp(i).cdf,1);51 end52 data=zeros(length(dresp),max(ldata));53 59 54 for i=1:length(dresp) 55 desc(i)=cellstr(dresp(i).descriptor); 56 if ~isempty(dresp(i).cdf) 57 data(i,1)=dresp(i).cdf(1,2); 58 for j=2:size(dresp(i).cdf,1) 59 if (dresp(i).cdf(j,2) > dresp(i).cdf(j-1,2)) 60 data(i,j)=dresp(i).cdf(j,2)-dresp(i).cdf(j-1,2); 60 %% process input data and assemble into matrices and increments 61 62 % responses 63 64 iarg=1; 65 if isstruct(varargin{iarg}) 66 dresp=varargin{iarg}; 67 iarg=iarg+1; 68 69 % if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg})) 70 if iarg <= nargin && iscell(varargin{iarg}) 71 dresp=struc_desc(dresp,varargin{iarg}); 72 iarg=iarg+1; 73 end 74 75 descr=cell (1,length(dresp)); 76 lcdfr=zeros(1,length(dresp)); 77 for i=1:length(dresp) 78 lcdfr(i)=size(dresp(i).cdf,1); 79 end 80 cdfr=zeros(length(dresp),max(lcdfr)); 81 82 for i=1:length(dresp) 83 descr(i)=cellstr(dresp(i).descriptor); 84 if ~isempty(dresp(i).cdf) 85 cdfr(i,1)=dresp(i).cdf(1,2); 86 for j=2:size(dresp(i).cdf,1) 87 if (dresp(i).cdf(j,2) > dresp(i).cdf(j-1,2)) 88 cdfr(i,j)=dresp(i).cdf(j,2)-dresp(i).cdf(j-1,2); 89 end 61 90 end 62 91 end 63 92 end 93 else 94 error(['''' inputname(iarg) ''' is not a structure.']); 64 95 end 65 96 66 97 % convert to percentage 67 98 68 data=data*100.; 99 cdfr=cdfr*100.; 100 101 % parameters 102 103 while (iarg <= nargin-1) 104 if ischar(varargin{iarg}) 105 eval([varargin{iarg} '=varargin{iarg+1};']); 106 disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']); 107 else 108 error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']); 109 end 110 iarg=iarg+2; 111 end 69 112 70 113 %% draw the stacked bar plot … … 74 117 75 118 if length(dresp) == 1 76 data=[data; data];119 cdfr=[cdfr; cdfr]; 77 120 end 78 121 79 hl1=bar(data,'stacked'); 80 % set(hl1(1),'FaceColor','green') 81 % set(hl1(2),'FaceColor','blue') 82 % set(hl1(3),'FaceColor','yellow') 83 % set(hl1(4),'FaceColor','cyan') 84 % set(hl1(5),'FaceColor','magenta') 85 % set(hl1(6),'FaceColor','red') 122 figure 123 hl1=bar(cdfr,'stacked'); 124 if exist('cmap','var') 125 if strncmpi(cmap,'stop',4) 126 % set(hl1(1),'FaceColor','green') 127 % set(hl1(2),'FaceColor',[.7 1 0]) 128 % set(hl1(3),'FaceColor','yellow') 129 % set(hl1(4),'FaceColor',[1 .7 0]) 130 % set(hl1(5),'FaceColor',[1 .5 0]) 131 % set(hl1(6),'FaceColor','red') 132 colormap([0 1 0;.7 1 0;1 1 0;1 .7 0;1 .5 0;1 0 0]); 133 else 134 colormap(cmap); 135 end 136 end 86 137 87 138 ax1=gca; 88 set(ax1,'ylim',[0 120])89 139 if length(dresp) == 1 90 140 set(ax1,'xlim',[0.5 1.5]) 91 141 end 92 set(ax1,'xticklabel',desc) 142 143 % set(ax1,'ylim',[0 120]) 144 % ylim('auto') 145 % [ylims]=ylim; 146 [ylims]=[0 120]; 147 if exist('ymin','var') 148 ylims(1)=ymin; 149 end 150 if exist('ymax','var') 151 ylims(2)=ymax; 152 end 153 ylim(ylims) 154 155 set(ax1,'xtick',1:length(descr)) 156 set(ax1,'xticklabel',descr) 157 if exist('xtlrot','var') 158 htl=rotateticklabel(ax1,xtlrot); 159 tlext=zeros(length(htl),4); 160 for i=1:length(htl) 161 tlext(i,:)=get(htl(i),'Extent'); 162 end 163 end 93 164 94 165 % add the annotation … … 96 167 title('Probabilities for Specified Response Levels (RIA)') 97 168 xlabel('Response') 169 if exist('xtlrot','var') 170 xlext=get(get(ax1,'xlabel'),'Extent'); 171 nskip=ceil(max(tlext(:,4))/xlext(4)); 172 xlabel(cellstr([repmat(' ',nskip,1);'Response'])); 173 clear nskip xlext tlext 174 end 98 175 ylabel('Percent Below Level') 99 176 100 177 if ~exist('lstr','var') || isempty(lstr) 101 lstr=cell(1,max(l data));102 for i=1:max(l data)178 lstr=cell(1,max(lcdfr)); 179 for i=1:max(lcdfr) 103 180 lstr(i)=cellstr(sprintf('%g',... 104 dresp(find(l data == max(ldata),1,'first')).cdf(i,1)));181 dresp(find(lcdfr == max(lcdfr),1,'first')).cdf(i,1))); 105 182 end 106 if ~isempty(find(l data < max(ldata)))183 if ~isempty(find(lcdfr < max(lcdfr))) 107 184 warning('Variable number of levels for responses.'); 108 185 end -
issm/trunk/src/m/solutions/dakota/plot_rlev_bars.m
r1013 r3092 2 2 % plot a stacked bar chart of the response levels in the cdf. 3 3 % 4 % []=plot_rlev_bars(dresp,lstr) 4 % []=plot_rlev_bars(dresp ,params) 5 % []=plot_rlev_bars(dresp,descr,params) 5 6 % 6 7 % where the required input is: 7 8 % dresp (structure array, responses) 8 % 9 % and the optional input is:10 % lstr (cell array, legend labels)9 % or 10 % dresp (structure array, responses) 11 % descr (cell array, list of response descriptions desired) 11 12 % 12 13 % the required fields of dresp are: 13 14 % descriptor (char, description) 14 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 % lstr (cell array, legend labels) 15 25 % 16 26 % for each response in the input array, this function plots … … 28 38 % acknowledged. Any commercial use must be negotiated with 29 39 % the Office of Technology Transfer at the California Institute 30 % of Technology. ( NTR 47078)40 % of Technology. (J. Schiermeier, NTR 47078) 31 41 % 32 42 % This software may be subject to U.S. export control laws. … … 37 47 % to foreign countries or providing access to foreign persons." 38 48 % 39 function []=plot_rlev_bars( dresp,lstr)49 function []=plot_rlev_bars(varargin) 40 50 41 51 if ~nargin … … 44 54 end 45 55 46 %% assemble the data into a matrix and calculate theincrements56 %% process input data and assemble into matrices and increments 47 57 48 desc=cell (1,length(dresp)); 49 for i=1:length(dresp) 50 ldata(i)=size(dresp(i).cdf,1); 51 end 52 data=zeros(length(dresp),max(ldata)); 58 % responses 53 59 54 for i=1:length(dresp) 55 desc(i)=cellstr(dresp(i).descriptor); 56 if ~isempty(dresp(i).cdf) 57 data(i,1)=dresp(i).cdf(1,1); 58 for j=2:size(dresp(i).cdf,1) 59 if (dresp(i).cdf(j,1) > dresp(i).cdf(j-1,1)) 60 data(i,j)=dresp(i).cdf(j,1)-dresp(i).cdf(j-1,1); 60 iarg=1; 61 if isstruct(varargin{iarg}) 62 dresp=varargin{iarg}; 63 iarg=iarg+1; 64 65 % if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg})) 66 if iarg <= nargin && iscell(varargin{iarg}) 67 dresp=struc_desc(dresp,varargin{iarg}); 68 iarg=iarg+1; 69 end 70 71 descr=cell (1,length(dresp)); 72 lcdfr=zeros(1,length(dresp)); 73 for i=1:length(dresp) 74 lcdfr(i)=size(dresp(i).cdf,1); 75 end 76 cdfr=zeros(length(dresp),max(lcdfr)); 77 78 for i=1:length(dresp) 79 descr(i)=cellstr(dresp(i).descriptor); 80 if ~isempty(dresp(i).cdf) 81 cdfr(i,1)=dresp(i).cdf(1,1); 82 for j=2:size(dresp(i).cdf,1) 83 if (dresp(i).cdf(j,1) > dresp(i).cdf(j-1,1)) 84 cdfr(i,j)=dresp(i).cdf(j,1)-dresp(i).cdf(j-1,1); 85 end 61 86 end 62 87 end 63 88 end 89 else 90 error(['''' inputname(iarg) ''' is not a structure.']); 91 end 92 93 % parameters 94 95 while (iarg <= nargin-1) 96 if ischar(varargin{iarg}) 97 eval([varargin{iarg} '=varargin{iarg+1};']); 98 disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']); 99 else 100 error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']); 101 end 102 iarg=iarg+2; 64 103 end 65 104 … … 70 109 71 110 if length(dresp) == 1 72 data=[data; data];111 cdfr=[cdfr; cdfr]; 73 112 end 74 113 75 hl1=bar(data,'stacked'); 114 figure 115 hl1=bar(cdfr,'stacked'); 76 116 % set barseries properties for lowest value 77 117 whitebg('white') … … 83 123 set(ax1,'xlim',[0.5 1.5]) 84 124 end 85 set(ax1,'xticklabel',desc) 125 126 ylim('auto') 127 [ylims]=ylim; 128 if exist('ymin','var') 129 ylims(1)=ymin; 130 end 131 if exist('ymax','var') 132 ylims(2)=ymax; 133 end 134 ylim(ylims) 135 136 set(ax1,'xtick',1:length(descr)) 137 set(ax1,'xticklabel',descr) 138 if exist('xtlrot','var') 139 htl=rotateticklabel(ax1,xtlrot); 140 tlext=zeros(length(htl),4); 141 for i=1:length(htl) 142 tlext(i,:)=get(htl(i),'Extent'); 143 end 144 end 86 145 87 146 % add the annotation 88 147 89 148 title('Response Levels for Specified Probabilities (PMA)') 90 xlabel('Response') 149 xlabel('Response'); 150 if exist('xtlrot','var') 151 xlext=get(get(ax1,'xlabel'),'Extent'); 152 nskip=ceil(max(tlext(:,4))/xlext(4)); 153 xlabel(cellstr([repmat(' ',nskip,1);'Response'])); 154 clear nskip xlext tlext 155 end 91 156 ylabel('Response Level') 92 157 93 158 if ~exist('lstr','var') || isempty(lstr) 94 lstr=cell(1,max(l data));95 for i=1:max(l data)159 lstr=cell(1,max(lcdfr)); 160 for i=1:max(lcdfr) 96 161 lstr(i)=cellstr(sprintf('%g%%',... 97 100*dresp(find(l data == max(ldata),1,'first')).cdf(i,2)));162 100*dresp(find(lcdfr == max(lcdfr),1,'first')).cdf(i,2))); 98 163 end 99 if ~isempty(find(l data < max(ldata)))164 if ~isempty(find(lcdfr < max(lcdfr),1)) 100 165 warning('Variable number of probabilities for responses.'); 101 166 end -
issm/trunk/src/m/solutions/dakota/plot_sampdist_bars.m
r1013 r3092 2 2 % plot a stacked bar chart of the sample distributions. 3 3 % 4 % []=plot_sampdist_bars(dresp,lstr) 4 % []=plot_sampdist_bars(dresp ,params) 5 % []=plot_sampdist_bars(dresp,descr,params) 6 % []=plot_sampdist_bars(sampr,descr,params) 5 7 % 6 8 % where the required input is: 7 9 % dresp (structure array, responses) 8 % 9 % and the optional input is: 10 % lstr (cell array, legend labels) 10 % or 11 % dresp (structure array, responses) 12 % descr (cell array, list of response descriptions desired) 13 % or 14 % sampr (double array, lists of response samples) 15 % descr (cell array, list of response descriptions) 11 16 % 12 17 % the required fields of dresp are: … … 21 26 % max (double, maximum of sample) 22 27 % 28 % the optional input is: 29 % params (string/numeric, parameter names and values) 30 % 31 % where the optional parameters are: 32 % ymin (numeric, minimum of y-axis) 33 % ymax (numeric, maximum of y-axis) 34 % xtlrot (numeric, rotation in degrees of x-tick labels) 35 % lstr (cell array, legend labels) 36 % 23 37 % for each response in the input array, this function plots 24 38 % a stacked bar plot of the list of samples, where the bars … … 34 48 % acknowledged. Any commercial use must be negotiated with 35 49 % the Office of Technology Transfer at the California Institute 36 % of Technology. ( NTR 47078)50 % of Technology. (J. Schiermeier, NTR 47078) 37 51 % 38 52 % This software may be subject to U.S. export control laws. … … 43 57 % to foreign countries or providing access to foreign persons." 44 58 % 45 function []=plot_sampdist_bars( dresp,lstr)59 function []=plot_sampdist_bars(varargin) 46 60 47 61 if ~nargin … … 50 64 end 51 65 52 %% assemble the data into a matrix and calculate the increments 53 54 desc=cell (1,length(dresp)); 55 data=zeros(length(dresp),5); 66 %% process input data and assemble into dresp as needed 67 68 % responses 69 70 iarg=1; 71 if isstruct(varargin{iarg}) 72 dresp=varargin{iarg}; 73 iarg=iarg+1; 74 75 % if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg})) 76 if iarg <= nargin && iscell(varargin{iarg}) 77 dresp=struc_desc(dresp,varargin{iarg}); 78 iarg=iarg+1; 79 end 80 else 81 sampr=varargin{iarg}; 82 iarg=iarg+1; 83 84 if iarg <= nargin && iscell(varargin{iarg}) 85 descr=varargin{iarg}; 86 iarg=iarg+1; 87 % elseif iarg <= nargin && ischar(varargin{iarg}) 88 % descr=cellstr(varargin{iarg}); 89 % iarg=iarg+1; 90 else 91 descr=cell(1:size(sampr,2)); 92 end 93 94 dresp=struct([]); 95 for i=1:size(sampr,2) 96 dresp(end+1).sample=sampr(:,i); 97 if ~isempty(descr) 98 dresp(i).descriptor=descr{i}; 99 else 100 dresp(i).descriptor=['dresp_' num2str(i)]; 101 end 102 end 103 end 104 105 % parameters 106 107 while (iarg <= nargin-1) 108 if ischar(varargin{iarg}) 109 eval([varargin{iarg} '=varargin{iarg+1};']); 110 disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']); 111 else 112 error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']); 113 end 114 iarg=iarg+2; 115 end 116 117 %% calculate any missing information (noting that dresp is local) 56 118 57 119 if ~isfield(dresp,'min') || ~isfield(dresp,'quart1') || ... … … 67 129 end 68 130 131 %% assemble the data into a matrix and calculate the increments 132 133 descr=cell (1,length(dresp)); 134 data =zeros(length(dresp),5); 135 69 136 for i=1:length(dresp) 70 desc (i)=cellstr(dresp(i).descriptor);137 descr(i)=cellstr(dresp(i).descriptor); 71 138 data(i,1)=dresp(i).min; 72 139 data(i,2)=dresp(i).quart1-dresp(i).min; … … 85 152 end 86 153 154 figure 87 155 hl1=bar(data,'stacked'); 88 156 % set barseries properties for lowest value … … 95 163 set(ax1,'xlim',[0.5 1.5]) 96 164 end 97 set(ax1,'xtick',1:1:max(length(dresp),2)); 98 set(ax1,'xticklabel',desc) 165 166 ylim('auto') 167 [ylims]=ylim; 168 if exist('ymin','var') 169 ylims(1)=ymin; 170 end 171 if exist('ymax','var') 172 ylims(2)=ymax; 173 end 174 ylim(ylims) 175 176 set(ax1,'xtick',1:length(descr)) 177 set(ax1,'xticklabel',descr) 178 if exist('xtlrot','var') 179 htl=rotateticklabel(ax1,xtlrot); 180 tlext=zeros(length(htl),4); 181 for i=1:length(htl) 182 tlext(i,:)=get(htl(i),'Extent'); 183 end 184 end 99 185 100 186 % add the annotation 101 187 102 title('Sample Distributions of Variables and/or Responses') 103 xlabel('Variable or Response') 188 title('Sample Distributions of Responses') 189 xlabel('Response') 190 if exist('xtlrot','var') 191 xlext=get(get(ax1,'xlabel'),'Extent'); 192 nskip=ceil(max(tlext(:,4))/xlext(4)); 193 xlabel(cellstr([repmat(' ',nskip,1);'Response'])); 194 clear nskip xlext tlext 195 end 104 196 ylabel('Value') 105 197
Note:
See TracChangeset
for help on using the changeset viewer.