spgSetParms

PURPOSE ^

SPGSETPARMS Set options for SPGL1

SYNOPSIS ^

function options = spgSetParms(varargin)

DESCRIPTION ^

SPGSETPARMS  Set options for SPGL1

   options = spgSetParms('param1',val1,'param2',val2,...) creates an
   options structure in which the named parameters have the specified
   values.  Unspecified parameters are empty and their default
   values are used.
   
   spgSetParms with no input arguments and no output arguments
   displays all parameter names and their possible values.

   options = spgSetParms (with no input arguments) creates an options
   structure where all the fields are empty.

   spgSetParms.m
   $Id: spgSetParms.m 1093 2008-09-23 04:23:26Z ewout78 $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function options = spgSetParms(varargin)
0002 %SPGSETPARMS  Set options for SPGL1
0003 %
0004 %   options = spgSetParms('param1',val1,'param2',val2,...) creates an
0005 %   options structure in which the named parameters have the specified
0006 %   values.  Unspecified parameters are empty and their default
0007 %   values are used.
0008 %
0009 %   spgSetParms with no input arguments and no output arguments
0010 %   displays all parameter names and their possible values.
0011 %
0012 %   options = spgSetParms (with no input arguments) creates an options
0013 %   structure where all the fields are empty.
0014 %
0015 %   spgSetParms.m
0016 %   $Id: spgSetParms.m 1093 2008-09-23 04:23:26Z ewout78 $
0017 
0018 % Print out possible values of properties.
0019 if nargin == 0 && nargout == 0
0020    fprintf(' Default parameters for l1Set.m:\n');
0021    fprintf('        fid : [ positive integer        |     1 ]\n');
0022    fprintf('  verbosity : [ integer: 1, 2, or 3     |     3 ]\n');
0023    fprintf(' iterations : [ positive integer        |  10*m ]\n');
0024    fprintf('  nPrevVals : [ positive integer        |    10 ]\n');
0025    fprintf('      bpTol : [ positive scalar         | 1e-06 ]\n');
0026    fprintf('     optTol : [ positive scalar         | 1e-04 ]\n');
0027    fprintf('     decTol : [ positive scalar         | 1e-04 ]\n');   
0028    fprintf('    stepMin : [ positive scalar         | 1e-16 ]\n');
0029    fprintf('    stepMax : [ positive scalar         | 1e+05 ]\n');
0030    fprintf(' rootMethod : [ 1=linear, 2=quadratic   |     2 ]\n');
0031    fprintf('activeSetIt : [ positive integer        |   Inf ]\n');
0032    fprintf('subspaceMin : [ 0=no, 1=yes             |     0 ]\n');
0033    fprintf('  iscomplex : [ 0=no, 1=yes, NaN=auto   |   NaN ]\n');
0034    fprintf('  maxMatvec : [ positive integer        |   Inf ]\n');
0035    fprintf('    weights : [ vector                  |     1 ]\n');
0036    fprintf('    project : [ projection function     |    @()]\n');
0037    fprintf('primal_norm : [ primal norm eval fun    |    @()]\n');
0038    fprintf('  dual_norm : [ dual norm eval fun      |    @()]\n');
0039    fprintf('\n');
0040    return;
0041 end
0042 
0043 Names = [
0044     'fid               '
0045     'verbosity         '
0046     'iterations        '
0047     'nPrevVals         '
0048     'bpTol             '
0049     'optTol            '
0050     'decTol            '
0051     'stepMin           '
0052     'stepMax           '
0053     'rootMethod        '
0054     'activeSetIt       '
0055     'subspaceMin       '
0056     'iscomplex         '
0057     'maxMatvec         '
0058     'weights           '
0059     'project           '
0060     'primal_norm       '
0061     'dual_norm         '
0062     ];
0063 [m,n] = size(Names);
0064 names = lower(Names);
0065 
0066 % Combine all leading options structures o1, o2, ... in l1Set(o1,o2,...).
0067 options = [];
0068 for j = 1:m
0069    eval(['options.' Names(j,:) '= [];']);
0070 end
0071 i = 1;
0072 while i <= nargin
0073    arg = varargin{i};
0074    if ischar(arg), break; end
0075    if ~isempty(arg)                      % [] is a valid options argument
0076        if ~isa(arg,'struct')
0077           error(sprintf(['Expected argument %d to be a string parameter name ' ...
0078                'or an options structure\ncreated with OPTIMSET.'], i));
0079       end
0080       for j = 1:m
0081           if any(strcmp(fieldnames(arg),deblank(Names(j,:))))
0082              eval(['val = arg.' Names(j,:) ';']);
0083           else
0084              val = [];
0085           end
0086           if ~isempty(val)
0087              eval(['options.' Names(j,:) '= val;']);
0088          end
0089       end
0090    end
0091    i = i + 1;
0092 end
0093 
0094 % A finite state machine to parse name-value pairs.
0095 if rem(nargin-i+1,2) ~= 0
0096    error('Arguments must occur in name-value pairs.');
0097 end
0098 expectval = 0;                          % start expecting a name, not a value
0099 while i <= nargin
0100    arg = varargin{i};
0101    
0102    if ~expectval
0103       if ~ischar(arg)
0104          error(sprintf('Expected argument %d to be a string parameter name.', i));
0105       end
0106       
0107       lowArg = lower(arg);
0108       j = strmatch(lowArg,names);
0109       if isempty(j)                       % if no matches
0110          error(sprintf('Unrecognized parameter name ''%s''.', arg));
0111       elseif length(j) > 1                % if more than one match
0112          % Check for any exact matches (in case any names are subsets of others)
0113          k = strmatch(lowArg,names,'exact');
0114          if length(k) == 1
0115             j = k;
0116          else
0117             msg = sprintf('Ambiguous parameter name ''%s'' ', arg);
0118             msg = [msg '(' deblank(Names(j(1),:))];
0119             for k = j(2:length(j))'
0120                msg = [msg ', ' deblank(Names(k,:))];
0121             end
0122             msg = sprintf('%s).', msg);
0123             error(msg);
0124          end
0125       end
0126       expectval = 1;                      % we expect a value next
0127       
0128    else
0129       eval(['options.' Names(j,:) '= arg;']);
0130       expectval = 0;
0131       
0132    end
0133    i = i + 1;
0134 end
0135 
0136 if expectval
0137    error(sprintf('Expected value for parameter ''%s''.', arg));
0138 end
0139

Generated on Mon 10-Jun-2013 23:03:23 by m2html © 2005