Home > classes > @ssm > modifparams.m

modifparams

PURPOSE ^

modifparams enables to options(i_options)y and substitute parameters

SYNOPSIS ^

function varargout = modifparams(varargin)

DESCRIPTION ^

 modifparams enables to options(i_options)y and substitute parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: modifparams enables to options(i_options)y and substitute parameters

 CALL: varargout = modfiparams(varargin)
 [sys_out] = modfiparams(sys, options)

 INPUTS:
 sys -      (array of) ssm objects
 options -   plist of options:
    'KEEP_PARAM' cell array of parameter to keep in the symbollic expression
    'KEEP_PARAM_ORDER' array of 1 / 0 depending whether parameter are kept
     or not
    'SET_PARAM_NAMES' Cell array of parameter names for numerical
     substitutions with user defined values
    'SET_PARAM_VALUES' Array of parameter means for numerical substitutions
    'SET_PARAM_SIGMAS' Array of parameter standard deviation for numerical
     substitutions 
    'SET_PARAM_VALUES_ORDER' Array of 1 / 0 depending whether parameter
     means are effectively substituted or not
    'SET_PARAM_SIGMAS_ORDER' Array of 1 / 0 depending whether parameter
     means are effectively substituted or not
    'SYMBOLIC_OUTPUT_ALLOWED' if 0 checks output tensors are double and
     not symbollic arrays

 OUTPUTS:
           The output array are of size Nsys*Noptions
 sys_out -  (array of) ssm objects with substitutions / modifications done
           (case when more output than inputs)
 sys     -  (array of) ssm objects with substitutions / modifications done
           (case when the number of inputs and outputs is the same (numel
           options =1))

 M-FILE INFO: Get information about this methods by calling
              >> ssm.getInfo('modifparams')

              Get information about a specified set-plist by calling:
              >> ssm.getInfo('modifparams', 'Default')

 HISTORY:  17-04-2008 A Grynagier
 01-04-2008 A Grynagier
 26-02-2008 A Grynagier
 29-01-2008 A Grynagier
 Creation

 TODO : Modify for multiple outputs
 detect case when parameter is Set twice in a list
 inplement error message if keep is not empty and no symbollic output is
 allowed
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % modifparams enables to options(i_options)y and substitute parameters
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: modifparams enables to options(i_options)y and substitute parameters
0005 %
0006 % CALL: varargout = modfiparams(varargin)
0007 % [sys_out] = modfiparams(sys, options)
0008 %
0009 % INPUTS:
0010 % sys -      (array of) ssm objects
0011 % options -   plist of options:
0012 %    'KEEP_PARAM' cell array of parameter to keep in the symbollic expression
0013 %    'KEEP_PARAM_ORDER' array of 1 / 0 depending whether parameter are kept
0014 %     or not
0015 %    'SET_PARAM_NAMES' Cell array of parameter names for numerical
0016 %     substitutions with user defined values
0017 %    'SET_PARAM_VALUES' Array of parameter means for numerical substitutions
0018 %    'SET_PARAM_SIGMAS' Array of parameter standard deviation for numerical
0019 %     substitutions
0020 %    'SET_PARAM_VALUES_ORDER' Array of 1 / 0 depending whether parameter
0021 %     means are effectively substituted or not
0022 %    'SET_PARAM_SIGMAS_ORDER' Array of 1 / 0 depending whether parameter
0023 %     means are effectively substituted or not
0024 %    'SYMBOLIC_OUTPUT_ALLOWED' if 0 checks output tensors are double and
0025 %     not symbollic arrays
0026 %
0027 % OUTPUTS:
0028 %           The output array are of size Nsys*Noptions
0029 % sys_out -  (array of) ssm objects with substitutions / modifications done
0030 %           (case when more output than inputs)
0031 % sys     -  (array of) ssm objects with substitutions / modifications done
0032 %           (case when the number of inputs and outputs is the same (numel
0033 %           options =1))
0034 %
0035 % M-FILE INFO: Get information about this methods by calling
0036 %              >> ssm.getInfo('modifparams')
0037 %
0038 %              Get information about a specified set-plist by calling:
0039 %              >> ssm.getInfo('modifparams', 'Default')
0040 %
0041 % HISTORY:  17-04-2008 A Grynagier
0042 % 01-04-2008 A Grynagier
0043 % 26-02-2008 A Grynagier
0044 % 29-01-2008 A Grynagier
0045 % Creation
0046 %
0047 % TODO : Modify for multiple outputs
0048 % detect case when parameter is Set twice in a list
0049 % inplement error message if keep is not empty and no symbollic output is
0050 % allowed
0051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0052 
0053 function varargout = modifparams(varargin)
0054 
0055   %% starting initial checks
0056   utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]);
0057 
0058   % Check if this is a call for parameters
0059   if utils.helper.isinfocall(varargin{:})
0060     varargout{1} = getInfo(varargin{3});
0061     return
0062   end
0063 
0064   % checking number of inputs work data
0065   if ~nargin==2, error('wrong number of inputs!'), end
0066 
0067   if ~isequal(class(varargin{1}),'ssm'), error(['argument is not a ssm but a ', class(varargin{1})]),end
0068   if ~isequal(class(varargin{2}),'plist'), error(['argument is not a plist but a ', class(varargin{2})]),end
0069 
0070   sys = varargin{1};
0071   options = varargin{2};
0072   Nsys     = length(sys);
0073   Noptions = length(options);
0074   %% begin function body
0075 
0076 
0077   %% building output depending on options
0078   if Noptions==1
0079     sys_out(:,1) = reshape(sys,Nsys,1);
0080   else
0081     for j=1:Noptions
0082       sys_out(:,j)=copy(reshape(sys,Nsys,1),true);
0083     end
0084   end
0085 
0086 
0087   for i_sys = 1:Nsys
0088     for i_options = 1 :Noptions
0089       options(i_options) = combine(options(i_options), getDefaultPlist('Default'));
0090       %% Retriveing option fields for operations
0091       KeepParamNamesIni = find(options(i_options),'KEEP_PARAM_NAMES') ;
0092       KeepParamOrder = find(options(i_options),'KEEP_PARAM_ORDER') ;
0093       SetParamNamesIni = find(options(i_options),'SET_PARAM_NAMES') ;
0094       SetParamValuesIni = find(options(i_options),'SET_PARAM_VALUES') ;
0095       SetParamSigmasIni = find(options(i_options),'SET_PARAM_SIGMAS') ;
0096       SetParamValuesOrder = find(options(i_options),'SET_PARAM_VALUES_ORDER') ;
0097       SetParamSigmasOrder = find(options(i_options),'SET_PARAM_SIGMAS_ORDER') ;
0098       SymbolicOutputAllowed = find(options(i_options),'SYMBOLIC_OUTPUT_ALLOWED') ;
0099       %% Retrieving system data
0100       if length(i_options)>1
0101         sys_out(i_sys, i_options) = sys(i_sys);
0102       end
0103 
0104       %% building updated list for KeepParam...
0105       if isequal(KeepParamOrder,'NONE') || SymbolicOutputAllowed==0
0106         KeepParamNames = {};
0107       elseif isequal(KeepParamOrder,'LIST')
0108         KeepParamNames = KeepParamNamesIni;
0109       elseif isequal(KeepParamOrder,'ALL')
0110         KeepParamNames = sys(i_sys).paramnames;
0111       else
0112         KeepParamNames = {};
0113         j=1;
0114         for i=1:length(KeepParamNamesIni)
0115           if KeepParamOrder(i)
0116             KeepParamNames{j} = KeepParamNamesIni{i}; %#ok<AGROW>
0117             j = j+1;
0118           end
0119         end
0120       end
0121       nKeep = length(KeepParamNames);
0122 
0123       %% building updated list for SetParamValues
0124       if (isequal(SetParamValuesOrder,'LIST'))
0125         SetParamValuesNames = SetParamNamesIni;
0126         SetParamValuesOrder = ones(length(SetParamNamesIni),1);
0127         SetParamValues = SetParamValuesIni;
0128       elseif (isequal(SetParamValuesOrder,'NONE'))
0129         SetParamValuesNames = {};
0130         SetParamValuesOrder = [];
0131         SetParamValues = [];
0132       else
0133         SetParamValuesNames = SetParamNamesIni;
0134         SetParamValues = SetParamValuesIni;
0135       end
0136       nValues = length(SetParamValues);
0137 
0138       %% building updated list for SetParamSigmas
0139       if (isequal(SetParamSigmasOrder,'LIST'))
0140         SetParamSigmasNames = SetParamNamesIni;
0141         SetParamSigmasOrder = ones(length(SetParamNamesIni),1);
0142         SetParamSigmas = SetParamSigmasIni;
0143       elseif (isequal(SetParamSigmasOrder,'NONE'))
0144         SetParamSigmasNames = {};
0145         SetParamSigmasOrder = [];
0146         SetParamSigmas = [];
0147       else
0148         SetParamSigmasNames = SetParamNamesIni;
0149         SetParamSigmas = SetParamSigmasIni;
0150       end
0151       nSigmas = length(SetParamSigmas);
0152 
0153       %% building param position tables
0154       posValues = zeros(nValues,1);
0155       posKeep = zeros(nKeep,1);
0156       posSigmas = zeros(nSigmas,1);
0157       for i=1:sys(i_sys).Nparams
0158         for j=1:nKeep
0159           if isequal(sys(i_sys).paramnames{i},KeepParamNames{j})
0160             posKeep(j) = i;
0161           end
0162         end
0163         for j=1:nValues
0164           if isequal(sys(i_sys).paramnames{i},SetParamValuesNames{j})
0165             posValues(j) = i;
0166           end
0167         end
0168         for j=1:nSigmas
0169           if isequal(sys(i_sys).paramnames{i},SetParamSigmasNames{j})
0170             posSigmas(j) = i;
0171           end
0172         end
0173       end
0174 
0175       %% looking for non exisiting but modified parameter names
0176       if not(nKeep==sum(posKeep>0))
0177         msg = 'error with keep parameter list because one does not exist in system.';
0178         error(msg);
0179       elseif not(nValues==sum(posValues>0))
0180         msg = 'error with SetValues parameter list because one does not exist in system.';
0181         error(msg);
0182       elseif not(nSigmas==sum(posSigmas>0))
0183         msg = 'error with SetSigma list because one does not exist in system.';
0184         error(msg);
0185       end
0186 
0187       %% modifying parameter tables in sys(i_sys) (Setparam list)
0188       for i=1:nValues
0189         if SetParamValuesOrder(i)
0190           sys(i_sys).paramvalues(posValues(i)) = SetParamValues(i);
0191         end
0192       end
0193       for i=1:nSigmas
0194         if SetParamSigmasOrder(i)
0195           sys(i_sys).paramsigmas(posSigmas(i)) = SetParamSigmas(i);
0196         end
0197       end
0198 
0199       %% Numerical value for symbolic variables
0200       for i=1:sys(i_sys).Nparams
0201         if sum(ismember(posKeep, i))==0
0202           cmd1 = ['sym(''', sys(i_sys).paramnames{i}, ''');'];
0203           cmd2 = [sys(i_sys).paramnames{i}, '= sys(i_sys).paramvalues(', num2str(i), ');'];
0204           eval(cmd1);
0205           eval(cmd2);
0206         else
0207           cmd1 = [sys(i_sys).paramnames{i}, '=sym(''', sys(i_sys).paramnames{i}, ''');'];
0208           eval(cmd1);
0209         end
0210       end
0211       
0212       %% keeping only params in 'keep param names'
0213       sys_out(i_sys,i_options).paramnames  = sys_out(i_sys,i_options).paramnames(posKeep);
0214       sys_out(i_sys,i_options).paramvalues = sys_out(i_sys,i_options).paramvalues(posKeep);
0215       sys_out(i_sys,i_options).paramsigmas = sys_out(i_sys,i_options).paramsigmas(posKeep);
0216 
0217       %% evaluation of A, B, C, D matrices
0218       for i_ss=1:sys_out(i_sys,i_options).Nss
0219         for j_ss =1:sys_out(i_sys,i_options).Nss
0220           %Mass Matrix
0221           if ~isempty(sys_out(i_sys,i_options).mmats{i_ss, j_ss})
0222             if ~isnumeric(sys_out(i_sys,i_options).mmats{i_ss, j_ss})
0223               sys_out(i_sys,i_options).mmats{i_ss, j_ss} = ...
0224                 eval(sym(sys_out(i_sys,i_options).mmats{i_ss, j_ss}));
0225             end
0226           end
0227           %A Matrix
0228           if ~isempty(sys_out(i_sys,i_options).amats{i_ss, j_ss})
0229             if ~isnumeric(sys_out(i_sys,i_options).amats{i_ss, j_ss})
0230               sys_out(i_sys,i_options).amats{i_ss, j_ss} = ...
0231                 eval(sym(sys_out(i_sys,i_options).amats{i_ss, j_ss}));
0232             end
0233           end
0234         end
0235       end
0236       for i_ss=1:sys_out(i_sys,i_options).Nss
0237         for j_in =1:sys_out(i_sys,i_options).Ninputs
0238           %B Matrix
0239           if ~isempty(sys_out(i_sys,i_options).bmats{i_ss, j_in})
0240             if ~isnumeric(sys_out(i_sys,i_options).bmats{i_ss, j_in})
0241               sys_out(i_sys,i_options).bmats{i_ss, j_in} = ...
0242                 eval(sym(sys_out(i_sys,i_options).bmats{i_ss, j_in}));
0243             end
0244           end
0245         end
0246       end
0247       for i_out=1:sys_out(i_sys,i_options).Noutputs
0248         for j_ss =1:sys_out(i_sys,i_options).Nss
0249           %C Matrix
0250           if ~isempty(sys_out(i_sys,i_options).cmats{i_out, j_ss})
0251             if ~isnumeric(sys_out(i_sys,i_options).cmats{i_out, j_ss})
0252               sys_out(i_sys,i_options).cmats{i_out, j_ss} = ...
0253                 eval(sym(sys_out(i_sys,i_options).cmats{i_out, j_ss}));
0254             end
0255           end
0256         end
0257       end
0258       for i_out=1:sys_out(i_sys,i_options).Noutputs
0259         for j_in =1:sys_out(i_sys,i_options).Ninputs
0260           %D Matrix
0261           if ~isempty(sys_out(i_sys,i_options).dmats{i_out, j_in})
0262             if ~isnumeric(sys_out(i_sys,i_options).dmats{i_out, j_in})
0263               sys_out(i_sys,i_options).dmats{i_out, j_in} = ...
0264                 eval(sym(sys_out(i_sys,i_options).dmats{i_out, j_in}));
0265             end
0266           end
0267         end
0268       end
0269       sys_out(i_sys,i_options) = validate(sys_out(i_sys,i_options));
0270       sys_out(i_sys,i_options).addHistory(ssm.getInfo(mfilename), options(i_options) , {''}, sys_out(i_sys,i_options).hist );
0271     end
0272   end
0273   varargout = {sys_out};
0274 end
0275 
0276 
0277 function ii = getInfo(varargin)
0278   if nargin == 1 && strcmpi(varargin{1}, 'None')
0279     sets = {};
0280     pls   = [];
0281   elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1})
0282     sets{1} = varargin{1};
0283     pls = getDefaultPlist(sets{1});
0284   else
0285     sets = {'Default'};
0286     pls = [];
0287     for kk=1:numel(sets)
0288       pls = [pls getDefaultPlist(sets{kk})];
0289     end
0290   end
0291   % Build info object
0292   ii = minfo(mfilename, 'ssm', '', 'STATESPACE', '$Id: resp.m,v 1.17 2008/07/22 10:22:38 ingo Exp $', sets, pls);
0293 end
0294 
0295 function plo = getDefaultPlist(set)
0296   switch set
0297     case 'Default'
0298       plo = plist( 'KEEP_PARAM_NAMES', {}, 'KEEP_PARAM_ORDER', 'LIST',...
0299         'SET_PARAM_NAMES', {}, 'SET_PARAM_VALUES', [], 'SET_PARAM_SIGMAS', [],...
0300         'SET_PARAM_VALUES_ORDER', 'LIST', 'SET_PARAM_SIGMAS_ORDER', 'NONE', 'SYMBOLIC_OUTPUT_ALLOWED', 1);
0301     otherwise
0302       error('### Unknown parameter set [%s].', set);
0303   end
0304 end

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003