Changeset 3092


Ignore:
Timestamp:
02/23/10 15:30:16 (15 years ago)
Author:
jschierm
Message:

Dakota: major update to Matlab interface scripts.

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  
    2626%  acknowledged. Any commercial use must be negotiated with
    2727%  the Office of Technology Transfer at the California Institute
    28 %  of Technology.  (NTR 47078)
     28%  of Technology.  (J. Schiermeier, NTR 47078)
    2929%
    3030%  This software may be subject to U.S. export control laws.
     
    6666%  or result from the response level lists
    6767
     68if ~isfield(params,'compute')
     69    params.compute='probabilities';
     70end
    6871if ~isfield(params,'distribution')
    6972    params.distribution='cumulative';
     
    172175
    173176if ~isfield(params,'numerical_gradients')
    174     params.numerical_gradients=true;
     177    params.numerical_gradients=false;
    175178end
    176179if ~isfield(params,'method_source')
     
    198201%  hessians not fully implemented
    199202if ~isfield(params,'numerical_hessians')
    200     params.numerical_gradients=true;
     203    params.numerical_hessians=true;
    201204end
    202205if ~isfield(params,'hessian_gradient_step_size')
  • issm/trunk/src/m/solutions/dakota/dakota_in_write.m

    r2166 r3092  
    22%  write a Dakota .in input file.
    33%
    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)
    56%
    67%  where the required input is:
     
    1213%    filei         (character, name of .in file)
    1314%
    14 %  the method, dmeth, and filei will be prompted if empty.
    15 params may be empty, in which case defaults will be used.
     15%  the method and filei will be prompted if empty.  params
     16may be empty, in which case defaults will be used.
    1617%
    1718%  the optional varargin are not yet used.
     
    3031%  acknowledged. Any commercial use must be negotiated with
    3132%  the Office of Technology Transfer at the California Institute
    32 %  of Technology.  (NTR 47078)
     33%  of Technology.  (J. Schiermeier, NTR 47078)
    3334%
    3435%  This software may be subject to U.S. export control laws.
     
    3940%  to foreign countries or providing access to foreign persons."
    4041%
    41 function []=dakota_in_write(method,dmeth,dvar,dresp,params,filei,varargin)
     42function []=dakota_in_write(method,dvar,dresp,params,filei,varargin)
    4243
    4344if ~nargin
     
    5152    method=input('Method?  ','s');
    5253end
    53 
    54 if ~exist('dmeth' ,'var') || isempty(dmeth)
     54if     ischar(method)
    5555    dmeth=dakota_method(method);
     56elseif isa(method,'dakota_method')
     57    dmeth=method;
     58else
     59    error(['Method ''' inputname(1) ''' is unrecognized class ''' class(method) '''.']);
    5660end
    5761
     
    134138%  write response levels
    135139
    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
     140if 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
     145end
     146fprintf(fidi,'\n');
    174147
    175148end
     
    196169%  variables vary by method
    197170
    198 vsets_write(fidi,dvar,dmeth.variables);
     171for i=1:length(dmeth.variables)
     172    fhvar=str2func([dmeth.variables{i} '.dakota_write']);
     173    fhvar(fidi,dvar);
     174end
    199175
    200176%  linear constraints vary by method
    201177
    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
     178for i=1:length(dmeth.lcspec)
     179    fhvar=str2func([dmeth.lcspec{i}    '.dakota_write']);
     180    fhvar(fidi,dvar);
     181end
     182
     183fprintf(fidi,'\n');
    359184
    360185end
     
    407232    param_write(fidi,'\t','direct','','\n',params);
    408233    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
    415242    if ~isempty(params.input_filter)
    416243        param_write(fidi,'\t  ','input_filter','    = ''','''\n',params);
     
    421248    param_write(fidi,'\t  ','failure_capture','   ','\n',params);
    422249    param_write(fidi,'\t  ','deactivate','        ','\n',params);
    423     param_write(fidi,'\t  ','output','        ','\n',params);
    424250    param_write(fidi,'\t  ','processors_per_analysis',' = ''','''\n',params);
    425251end
     
    439265%  functions, gradients, and hessians vary by method
    440266
    441 rsets_write(fidi,dresp,dmeth.responses);
    442 ghspec_write(fidi,params,dmeth.ghspec);
    443 
    444 fprintf(fidi,'\n');
    445 
    446 end
    447 
    448 %%  function to write response sets
    449 
    450 function []=rsets_write(fidi,dresp,responses)
    451 
    452267rdesc={};
    453268
    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
     269for i=1:length(dmeth.responses)
     270    fhresp=str2func([dmeth.responses{i} '.dakota_write']);
     271    [rdesc]=fhresp(fidi,dresp,rdesc);
     272end
     273
     274%  write accumulated response descriptors for all response classes
    482275
    483276if ~isempty(rdesc)
     
    486279end
    487280
    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
     281ghspec_write(fidi,params,dmeth.ghspec);
     282
     283fprintf(fidi,'\n');
    542284
    543285end
     
    550292
    551293if 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
    552300    if     params.numerical_gradients
    553301        param_write(fidi,'\t','numerical_gradients','','\n',params);
     
    572320
    573321end
    574 
    575 %%  function to write a parameter
    576 
    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     return
    583 end
    584 
    585 if islogical(params.(pname)) && ~params.(pname)
    586     return
    587 end
    588 
    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 end
    596 
    597 end
    598 
    599 %%  function to write a vector on multiple lines
    600 
    601 function []=vector_write(fidi,sbeg,vec,nmax,cmax)
    602 
    603 if ~exist('nmax','var') || isempty(nmax)
    604     nmax=Inf;
    605 end
    606 if ~exist('cmax','var') || isempty(cmax)
    607     cmax=Inf;
    608 end
    609 
    610 %  set up first iteration
    611 
    612 svec =[];
    613 nitem=nmax;
    614 lsvec=cmax;
    615 
    616 %  transpose vector from column-wise to row-wise
    617 
    618 vec=vec';
    619 
    620 %  assemble each line, flushing when necessary
    621 
    622 for i=1:numel(vec)
    623     if isnumeric(vec(i))
    624         sitem=sprintf('%g'    ,vec(i));
    625     else
    626         sitem=sprintf('''%s''',char(vec(i)));
    627     end
    628     nitem=nitem+1;
    629     lsvec=lsvec+1+length(sitem);
    630    
    631     if (nitem <= nmax) && (lsvec <= cmax)
    632         svec=[svec ' ' sitem];
    633     else
    634         if ~isempty(svec)
    635             fprintf(fidi,'%s\n',svec);
    636         end
    637         svec=[sbeg sitem];
    638         nitem=1;
    639         lsvec=length(svec);
    640     end
    641 end
    642 
    643 %  flush buffer at end, if necessary
    644 
    645 if ~isempty(svec)
    646     fprintf(fidi,'%s\n',svec);
    647 end
    648 
    649 end
  • issm/trunk/src/m/solutions/dakota/dakota_out_parse.m

    r2351 r3092  
    8888[ntokens,tokens]=fltokens(fline);
    8989method=tokens{1}{3};
    90 display(sprintf('Dakota method=%s.',method));
     90display(sprintf('Dakota methodName=''%s''.',method));
    9191
    9292dresp=struct([]);
     
    9696prcm=struct([]);
    9797
    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
     100fline='';
     101[nfeval]=nfeval_read(fidi,fline);
    106102fline=fgetl(fidi);
    107103
     
    110106while ischar(fline)
    111107%     ipos=ftell(fidi);
    112     if     strncmp(fline,'<<<<< Function evaluation summary',33)
     108    if     isempty(fline)
     109    elseif strncmp(fline,'<<<<< Function evaluation summary',33)
    113110        [nfeval]=nfeval_read(fidi,fline);
    114111    elseif strncmp(fline,'Statistics based on ',20)
     
    134131    elseif strncmp(fline,'The following lists volumetric uniformity measures',50)
    135132        [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);
    136137    elseif strncmp(fline,'-----',5)
    137     elseif isempty(fline)
    138138    else
    139139        display(['Unexpected line: ' deblank(fline)]);
     
    678678        end
    679679
     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
    680695%  read and add best residual term(s)
    681696
     
    715730           strncmpi(cellstr(tokens{1}{4}),'captured', 8)
    716731        display(['  ' deblank(fline)]);
    717         [ntokens,tokens]=fltokens(fline);
    718732        dresp.best.eval=        tokens{1}{8};
    719733
    720734        fline=fgetl(fidi);
    721735
    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
    727742
    728743    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)
    734750            fline=fgetl(fidi);
    735751        end
     
    775791end
    776792
     793%%  function to find and read the iterator completion
     794
     795function [method]=itcomp_read(fidi,fline)
     796
     797if ~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
     808end
     809
     810[ntokens,tokens]=fltokens(fline);
     811method=tokens{1}{3};
     812display(sprintf('Dakota iterator ''%s'' completed.',method));
     813
     814end
     815
    777816%%  function to find a file line starting with a specified string
    778817
  • issm/trunk/src/m/solutions/dakota/plot_boxplot.m

    r1013 r3092  
    22%  plot a box plot of the responses.
    33%
    4 %  []=plot_boxplot(dresp)
     4%  []=plot_boxplot(dresp      ,params)
     5%  []=plot_boxplot(dresp,descr,params)
     6%  []=plot_boxplot(sampr,descr,params)
    57%
    68%  where the required input is:
    79%    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)
    816%
    917%  the required fields of dresp are:
     
    1119%    sample        (double vector, list of samples)
    1220%
    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
    1429%  matlab box plot of the list of samples and annotates it
    1530%  with the description.  the lists of samples need not all be
     
    2338%  acknowledged. Any commercial use must be negotiated with
    2439%  the Office of Technology Transfer at the California Institute
    25 %  of Technology.  (NTR 47078)
     40%  of Technology.  (J. Schiermeier, NTR 47078)
    2641%
    2742%  This software may be subject to U.S. export control laws.
     
    3247%  to foreign countries or providing access to foreign persons."
    3348%
    34 function []=plot_boxplot(dresp)
     49function []=plot_boxplot(varargin)
    3550
    3651if ~nargin
     
    3954end
    4055
    41 %%  assemble the data into a matrix
     56%%  process input data and assemble into matrices as needed
    4257
    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
    4859
    49 for i=1:length(dresp)
    50     desc(i)=cellstr(dresp(i).descriptor);
    51     data(1:ldata(i),i)=dresp(i).sample;
     60iarg=1;
     61if 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
     83else
     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
    5296end
    5397
     98for i=1:length(descr)
     99    if isempty(descr{i})
     100        descr(i)={['resp_' num2str(i)]};
     101    end
     102end
     103
     104%  parameters
     105
     106while (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;
     114end
     115   
    54116%%  draw the plot
    55117
    56118%  draw box plot
    57119
    58 boxplot(data,'labels',desc,'notch','on')
     120figure
     121boxplot(sampr,'labels',descr,'notch','on')
    59122ax1=gca;
    60123
    61124%  add the annotation
    62125
    63 title('Box Plot of Variables and/or Responses')
    64 xlabel('Variable or Response')
    65 ylabel('Value')
     126ylim('auto')
     127[ylims]=ylim;
     128if exist('ymin','var')
     129    ylims(1)=ymin;
     130end
     131if exist('ymax','var')
     132    ylims(2)=ymax;
     133end
     134ylim(ylims)
     135
     136if (size(sampr,2) == 1)
     137    tlabc=descr{1};
     138else
     139    tlabc='Responses';
     140end
     141title(['Box Plot of ' tlabc],'Interpreter','none');
     142xlabel('Response','Interpreter','none');
     143ylabel('Value'   ,'Interpreter','none');
    66144
    67145end
  • issm/trunk/src/m/solutions/dakota/plot_if_bars.m

    r1013 r3092  
    22%  plot a stacked bar chart of the importance factors.
    33%
    4 %  []=plot_if_bars(dresp,ifmin,isort)
     4%  []=plot_if_bars(dresp      ,params)
     5%  []=plot_if_bars(dresp,descr,params)
    56%
    67%  where the required input is:
    78%    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)
    1024%    ifmin         (double, minimum importance factor)
    1125%    isort         (numeric, sort flag:  0, no sorting;
    1226%                                        1, highest at bottom;
    1327%                                       -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)
    1929%
    2030%  for each response in the input array, this function plots
     
    3242%  acknowledged. Any commercial use must be negotiated with
    3343%  the Office of Technology Transfer at the California Institute
    34 %  of Technology.  (NTR 47078)
     44%  of Technology.  (J. Schiermeier, NTR 47078)
    3545%
    3646%  This software may be subject to U.S. export control laws.
     
    4151%  to foreign countries or providing access to foreign persons."
    4252%
    43 function []=plot_if_bars(dresp,ifmin,isort)
     53function []=plot_if_bars(varargin)
    4454
    4555if ~nargin
     
    4858end
    4959
     60%%  process input data and assemble into matrices
     61
     62%  responses
     63
     64iarg=1;
     65if 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
     87else
     88    error(['''' inputname(iarg) ''' is not a structure.']);
     89end
     90
     91%  parameters
     92
     93while (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;
     101end
     102
    50103if ~exist('ifmin','var') || isempty(ifmin)
    51104    ifmin=0;
     
    56109end
    57110
    58 %%  assemble the data into a matrix
    59 
    60 desc=cell (1,length(dresp));
    61 for i=1:length(dresp)
    62     ldata(i)=length(dresp(i).impfac);
    63 end
    64 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 end
    71 
    72111%%  sort the data, if necessary
    73112
    74113if (isort)
    75     ifmean=mean(data,1);
     114    ifmean=mean(ifr,1);
    76115    if (isort > 0)
    77116        [ifmean,index]=sort(ifmean,'descend');
     
    82121   
    83122    dvar=dvar(index);
    84     data=data(:,index);
     123    ifr =ifr (:,index);
    85124end
    86125
     
    90129    nif=length(dvar);
    91130    dvar(nif+1,1)=cellstr(sprintf('others < %f',ifmin));
    92     data(:,nif+1)=0.;
     131    ifr (:,nif+1)=0.;
    93132   
    94133    nif2=0;
    95134    dvar2=cell (size(dvar));
    96     data2=zeros(size(data));
     135    ifr2 =zeros(size(ifr ));
    97136   
    98137%  sum filtered rows and copy unfiltered rows
    99138
    100139    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);
    103142        else
    104143            nif2=nif2+1;
    105144            dvar2(nif2)  =dvar(i);
    106             data2(:,nif2)=data(:,i);
     145            ifr2 (:,nif2)=ifr (:,i);
    107146        end
    108147    end
     
    111150
    112151    dvar2(nif2+1)  =dvar(nif+1);
    113     data2(:,nif2+1)=data(:,nif+1);
     152    ifr2 (:,nif2+1)=ifr (:,nif+1);
    114153   
    115154%  copy back and truncate filtered rows
    116155
    117     clear dvar data
     156    clear dvar ifr
    118157    if (isort >= 0)
    119158        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);
    121160    else
    122161        dvar(1       )  =dvar2(  nif2+1);
    123162        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 data2
     163        ifr (:,1       )=ifr2 (:,  nif2+1);
     164        ifr (:,2:nif2+1)=ifr2 (:,1:nif2  );
     165    end
     166    clear nif nif2 dvar2 ifr2
    128167end
    129168
     
    134173
    135174if length(dresp) == 1
    136     data=[data; data];
    137 end
    138 
    139 hl1=bar(data,'stacked');
     175    ifr=[ifr; ifr];
     176end
     177
     178figure
     179hl1=bar(ifr,'stacked');
    140180
    141181ax1=gca;
    142 set(ax1,'ylim',[0 1.2])
    143182if length(dresp) == 1
    144183    set(ax1,'xlim',[0.5 1.5])
    145184end
    146 set(ax1,'xticklabel',desc)
     185
     186% set(ax1,'ylim',[0 1.2])
     187% ylim('auto')
     188% [ylims]=ylim;
     189[ylims]=[0 1.2];
     190if exist('ymin','var')
     191    ylims(1)=ymin;
     192end
     193if exist('ymax','var')
     194    ylims(2)=ymax;
     195end
     196ylim(ylims)
     197
     198set(ax1,'xtick',1:length(descr))
     199set(ax1,'xticklabel',descr)
     200if 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
     206end
    147207
    148208%  add the annotation
     
    150210title('Importance Factors')
    151211xlabel('Response')
     212if 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
     217end
    152218ylabel('Importance Factor Value')
    153219
  • issm/trunk/src/m/solutions/dakota/plot_normdist_bars.m

    r1013 r3092  
    22%  plot a stacked bar chart of the sample distributions.
    33%
    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)
    57%
    68%  where the required input is:
    79%    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)
    1216%
    1317%  the required fields of dresp are:
     
    1822%    mean          (double, mean of sample)
    1923%    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)
    2034%
    2135%  for each response in the input array, this function plots
     
    3549%  acknowledged. Any commercial use must be negotiated with
    3650%  the Office of Technology Transfer at the California Institute
    37 %  of Technology.  (NTR 47078)
     51%  of Technology.  (J. Schiermeier, NTR 47078)
    3852%
    3953%  This software may be subject to U.S. export control laws.
     
    4458%  to foreign countries or providing access to foreign persons."
    4559%
    46 function []=plot_normdist_bars(dresp,plev,lstr)
     60function []=plot_normdist_bars(varargin)
    4761
    4862if ~nargin
     
    5165end
    5266
    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
     71iarg=1;
     72if 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
     81else
     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
     104end
     105
     106%  parameters
     107
     108while (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;
     116end
     117
     118%%  calculate any missing information (noting that dresp is local)
    61119
    62120if ~isfield(dresp,'mean') || ~isfield(dresp,'stddev')
    63121    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
     124end
     125
     126%%  assemble the data into a matrix and calculate the increments
     127
     128if ~exist('prob','var') || isempty(prob)
     129    prob=[0.01 0.25 0.50 0.75 0.99];
     130end
     131
     132descr=cell (1,length(dresp));
     133data =zeros(length(dresp),length(prob));
    70134
    71135for i=1:length(dresp)
    72     desc(i)=cellstr(dresp(i).descriptor);
    73     data(i,:)=norminv(plev,dresp(i).mean,dresp(i).stddev);
    74 end
    75 
    76 for j=length(plev):-1:2
     136    descr(i)=cellstr(dresp(i).descriptor);
     137    data(i,:)=norminv(prob,dresp(i).mean,dresp(i).stddev);
     138end
     139
     140for j=length(prob):-1:2
    77141    data(:,j)=data(:,j)-data(:,j-1);
    78142end
     
    87151end
    88152
     153figure
    89154hl1=bar(data,'stacked');
    90155%  set barseries properties for lowest value
     
    97162    set(ax1,'xlim',[0.5 1.5])
    98163end
    99 set(ax1,'xtick',1:1:max(length(dresp),2));
    100 set(ax1,'xticklabel',desc)
     164
     165ylim('auto')
     166[ylims]=ylim;
     167if exist('ymin','var')
     168    ylims(1)=ymin;
     169end
     170if exist('ymax','var')
     171    ylims(2)=ymax;
     172end
     173ylim(ylims)
     174
     175set(ax1,'xtick',1:length(descr))
     176set(ax1,'xticklabel',descr)
     177if 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
     183end
    101184
    102185%  add the annotation
    103186
    104 title('Normal Distributions of Variables and/or Responses')
    105 xlabel('Variable or Response')
     187title('Normal Distributions of Responses')
     188xlabel('Response')
     189if 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
     194end
    106195ylabel('Value')
    107196
    108197if ~exist('lstr','var') || isempty(lstr)
    109     lstr=cell(1,length(plev));
    110     for i=1:length(plev)
    111         lstr(i)=cellstr(sprintf('%g%%',100*plev(i)));
     198    lstr=cell(1,length(prob));
     199    for i=1:length(prob)
     200        lstr(i)=cellstr(sprintf('%g%%',100*prob(i)));
    112201    end
    113202end
  • issm/trunk/src/m/solutions/dakota/plot_normplot.m

    r1013 r3092  
    22%  plot a normal probability plot of the responses.
    33%
    4 %  []=plot_normplot(dresp)
     4%  []=plot_normplot(dresp      ,params)
     5%  []=plot_normplot(dresp,descr,params)
     6%  []=plot_normplot(sampr,descr,params)
    57%
    68%  where the required input is:
    79%    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)
    816%
    917%  the required fields of dresp are:
    1018%    descriptor    (char, description)
    1119%    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)
    1227%
    1328%  for each response in the input array, this function plots
     
    2338%  acknowledged. Any commercial use must be negotiated with
    2439%  the Office of Technology Transfer at the California Institute
    25 %  of Technology.  (NTR 47078)
     40%  of Technology.  (J. Schiermeier, NTR 47078)
    2641%
    2742%  This software may be subject to U.S. export control laws.
     
    3247%  to foreign countries or providing access to foreign persons."
    3348%
    34 function []=plot_normplot(dresp)
     49function []=plot_normplot(varargin)
    3550
    3651if ~nargin
     
    3954end
    4055
    41 %%  assemble the data into a matrix
     56%%  process input data and assemble into matrices as needed
    4257
    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
    4859
    49 for i=1:length(dresp)
    50     desc(i)=cellstr(dresp(i).descriptor);
    51     data(1:ldata(i),i)=dresp(i).sample;
     60iarg=1;
     61if 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
     83else
     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
    5296end
    5397
     98for i=1:length(descr)
     99    if isempty(descr{i})
     100        descr(i)={['resp_' num2str(i)]};
     101    end
     102end
     103
     104%  parameters
     105
     106while (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;
     114end
     115   
    54116%%  draw the plot
    55117
    56118%  draw normal probability plot
    57119
    58 normplot(data)
     120figure
     121normplot(sampr)
    59122ax1=gca;
    60123
    61124%  add the annotation
    62125
    63 title('Normal Probability Plot of Variables and/or Responses')
    64 xlabel('Value')
    65 ylabel('Probability')
     126xlim('auto')
     127[xlims]=xlim;
     128if exist('xmin','var')
     129    xlims(1)=xmin;
     130end
     131if exist('xmax','var')
     132    xlims(2)=xmax;
     133end
     134xlim(xlims)
    66135
    67 hleg1=legend(ax1,desc,'Location','EastOutside',...
     136if (size(sampr,2) == 1)
     137    tlabc=descr{1};
     138else
     139    tlabc='Responses';
     140end
     141title(['Normal Probability Plot of ' tlabc],'Interpreter','none');
     142xlabel('Value'      ,'Interpreter','none');
     143ylabel('Probability','Interpreter','none');
     144
     145hleg1=legend(ax1,descr,'Location','EastOutside',...
    68146             'Orientation','vertical','Interpreter','none');
    69147
  • issm/trunk/src/m/solutions/dakota/plot_prob_bars.m

    r1013 r3092  
    22%  plot a stacked bar chart of the probabilities in the CDF.
    33%
    4 %  []=plot_prob_bars(dresp,lstr)
     4%  []=plot_prob_bars(dresp      ,params)
     5%  []=plot_prob_bars(dresp,descr,params)
    56%
    67%  where the required input is:
    78%    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)
    1112%
    1213%  the required fields of dresp are:
    1314%    descriptor    (char, description)
    1415%    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)
    1526%
    1627%  for each response in the input array, this function plots
     
    2839%  acknowledged. Any commercial use must be negotiated with
    2940%  the Office of Technology Transfer at the California Institute
    30 %  of Technology.  (NTR 47078)
     41%  of Technology.  (J. Schiermeier, NTR 47078)
    3142%
    3243%  This software may be subject to U.S. export control laws.
     
    3748%  to foreign countries or providing access to foreign persons."
    3849%
    39 function []=plot_prob_bars(dresp,lstr)
     50function []=plot_prob_bars(varargin)
    4051
    4152if ~nargin
     
    4657%%  assemble the data into a matrix and calculate the increments
    4758
    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));
    5359
    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
     64iarg=1;
     65if 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
    6190            end
    6291        end
    6392    end
     93else
     94    error(['''' inputname(iarg) ''' is not a structure.']);
    6495end
    6596
    6697%  convert to percentage
    6798
    68 data=data*100.;
     99cdfr=cdfr*100.;
     100
     101%  parameters
     102
     103while (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;
     111end
    69112
    70113%%  draw the stacked bar plot
     
    74117
    75118if length(dresp) == 1
    76     data=[data; data];
     119    cdfr=[cdfr; cdfr];
    77120end
    78121
    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')
     122figure
     123hl1=bar(cdfr,'stacked');
     124if 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
     136end
    86137
    87138ax1=gca;
    88 set(ax1,'ylim',[0 120])
    89139if length(dresp) == 1
    90140    set(ax1,'xlim',[0.5 1.5])
    91141end
    92 set(ax1,'xticklabel',desc)
     142
     143% set(ax1,'ylim',[0 120])
     144% ylim('auto')
     145% [ylims]=ylim;
     146[ylims]=[0 120];
     147if exist('ymin','var')
     148    ylims(1)=ymin;
     149end
     150if exist('ymax','var')
     151    ylims(2)=ymax;
     152end
     153ylim(ylims)
     154
     155set(ax1,'xtick',1:length(descr))
     156set(ax1,'xticklabel',descr)
     157if 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
     163end
    93164
    94165%  add the annotation
     
    96167title('Probabilities for Specified Response Levels (RIA)')
    97168xlabel('Response')
     169if 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
     174end
    98175ylabel('Percent Below Level')
    99176
    100177if ~exist('lstr','var') || isempty(lstr)
    101     lstr=cell(1,max(ldata));
    102     for i=1:max(ldata)
     178    lstr=cell(1,max(lcdfr));
     179    for i=1:max(lcdfr)
    103180        lstr(i)=cellstr(sprintf('%g',...
    104             dresp(find(ldata == max(ldata),1,'first')).cdf(i,1)));
     181            dresp(find(lcdfr == max(lcdfr),1,'first')).cdf(i,1)));
    105182    end
    106     if ~isempty(find(ldata < max(ldata)))
     183    if ~isempty(find(lcdfr < max(lcdfr)))
    107184        warning('Variable number of levels for responses.');
    108185    end
  • issm/trunk/src/m/solutions/dakota/plot_rlev_bars.m

    r1013 r3092  
    22%  plot a stacked bar chart of the response levels in the cdf.
    33%
    4 %  []=plot_rlev_bars(dresp,lstr)
     4%  []=plot_rlev_bars(dresp      ,params)
     5%  []=plot_rlev_bars(dresp,descr,params)
    56%
    67%  where the required input is:
    78%    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)
    1112%
    1213%  the required fields of dresp are:
    1314%    descriptor    (char, description)
    1415%    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)
    1525%
    1626%  for each response in the input array, this function plots
     
    2838%  acknowledged. Any commercial use must be negotiated with
    2939%  the Office of Technology Transfer at the California Institute
    30 %  of Technology.  (NTR 47078)
     40%  of Technology.  (J. Schiermeier, NTR 47078)
    3141%
    3242%  This software may be subject to U.S. export control laws.
     
    3747%  to foreign countries or providing access to foreign persons."
    3848%
    39 function []=plot_rlev_bars(dresp,lstr)
     49function []=plot_rlev_bars(varargin)
    4050
    4151if ~nargin
     
    4454end
    4555
    46 %%  assemble the data into a matrix and calculate the increments
     56%%  process input data and assemble into matrices and increments
    4757
    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
    5359
    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);
     60iarg=1;
     61if 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
    6186            end
    6287        end
    6388    end
     89else
     90    error(['''' inputname(iarg) ''' is not a structure.']);
     91end
     92
     93%  parameters
     94
     95while (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;
    64103end
    65104
     
    70109
    71110if length(dresp) == 1
    72     data=[data; data];
     111    cdfr=[cdfr; cdfr];
    73112end
    74113
    75 hl1=bar(data,'stacked');
     114figure
     115hl1=bar(cdfr,'stacked');
    76116%  set barseries properties for lowest value
    77117whitebg('white')
     
    83123    set(ax1,'xlim',[0.5 1.5])
    84124end
    85 set(ax1,'xticklabel',desc)
     125
     126ylim('auto')
     127[ylims]=ylim;
     128if exist('ymin','var')
     129    ylims(1)=ymin;
     130end
     131if exist('ymax','var')
     132    ylims(2)=ymax;
     133end
     134ylim(ylims)
     135
     136set(ax1,'xtick',1:length(descr))
     137set(ax1,'xticklabel',descr)
     138if 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
     144end
    86145
    87146%  add the annotation
    88147
    89148title('Response Levels for Specified Probabilities (PMA)')
    90 xlabel('Response')
     149xlabel('Response');
     150if 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
     155end
    91156ylabel('Response Level')
    92157
    93158if ~exist('lstr','var') || isempty(lstr)
    94     lstr=cell(1,max(ldata));
    95     for i=1:max(ldata)
     159    lstr=cell(1,max(lcdfr));
     160    for i=1:max(lcdfr)
    96161        lstr(i)=cellstr(sprintf('%g%%',...
    97             100*dresp(find(ldata == max(ldata),1,'first')).cdf(i,2)));
     162            100*dresp(find(lcdfr == max(lcdfr),1,'first')).cdf(i,2)));
    98163    end
    99     if ~isempty(find(ldata < max(ldata)))
     164    if ~isempty(find(lcdfr < max(lcdfr),1))
    100165        warning('Variable number of probabilities for responses.');
    101166    end
  • issm/trunk/src/m/solutions/dakota/plot_sampdist_bars.m

    r1013 r3092  
    22%  plot a stacked bar chart of the sample distributions.
    33%
    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)
    57%
    68%  where the required input is:
    79%    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)
    1116%
    1217%  the required fields of dresp are:
     
    2126%    max           (double, maximum of sample)
    2227%
     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%
    2337%  for each response in the input array, this function plots
    2438%  a stacked bar plot of the list of samples, where the bars
     
    3448%  acknowledged. Any commercial use must be negotiated with
    3549%  the Office of Technology Transfer at the California Institute
    36 %  of Technology.  (NTR 47078)
     50%  of Technology.  (J. Schiermeier, NTR 47078)
    3751%
    3852%  This software may be subject to U.S. export control laws.
     
    4357%  to foreign countries or providing access to foreign persons."
    4458%
    45 function []=plot_sampdist_bars(dresp,lstr)
     59function []=plot_sampdist_bars(varargin)
    4660
    4761if ~nargin
     
    5064end
    5165
    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
     70iarg=1;
     71if 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
     80else
     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
     103end
     104
     105%  parameters
     106
     107while (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;
     115end
     116
     117%%  calculate any missing information (noting that dresp is local)
    56118
    57119if ~isfield(dresp,'min')    || ~isfield(dresp,'quart1') || ...
     
    67129end
    68130
     131%%  assemble the data into a matrix and calculate the increments
     132
     133descr=cell (1,length(dresp));
     134data =zeros(length(dresp),5);
     135
    69136for i=1:length(dresp)
    70     desc(i)=cellstr(dresp(i).descriptor);
     137    descr(i)=cellstr(dresp(i).descriptor);
    71138    data(i,1)=dresp(i).min;
    72139    data(i,2)=dresp(i).quart1-dresp(i).min;
     
    85152end
    86153
     154figure
    87155hl1=bar(data,'stacked');
    88156%  set barseries properties for lowest value
     
    95163    set(ax1,'xlim',[0.5 1.5])
    96164end
    97 set(ax1,'xtick',1:1:max(length(dresp),2));
    98 set(ax1,'xticklabel',desc)
     165
     166ylim('auto')
     167[ylims]=ylim;
     168if exist('ymin','var')
     169    ylims(1)=ymin;
     170end
     171if exist('ymax','var')
     172    ylims(2)=ymax;
     173end
     174ylim(ylims)
     175
     176set(ax1,'xtick',1:length(descr))
     177set(ax1,'xticklabel',descr)
     178if 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
     184end
    99185
    100186%  add the annotation
    101187
    102 title('Sample Distributions of Variables and/or Responses')
    103 xlabel('Variable or Response')
     188title('Sample Distributions of Responses')
     189xlabel('Response')
     190if 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
     195end
    104196ylabel('Value')
    105197
Note: See TracChangeset for help on using the changeset viewer.