function  search_params = PLM_search_params(spec)

%PLM_SEARCH_PARAMS --  Parameters for PLM_Hebb2 parameter search.
%   
%  search_params = PLM_search_params
%  search_params = PLM_search_params(spec)
%
%  When supplied, SPEC is a "seed" structure that is filled in with
%  default values for the omitted slots. Existing values are preserved.
%  When providing explicit conversion templates, it is up to the caller
%  to ensure that P2V_TEMPL, V2P_TEMPL, and BOUNDS are consistent. It is
%  therefore a bad idea to supply any one of these three slots without
%  supplying the other two as well. (Any missing templates or bounds will
%  be filled in with defaults as defined in PLM_TEMPLATE.)
%
%  With one additional slot, MODEL_DATA, the search parameter structure is
%  suitable for passing as a second argument to PLM_PARAMSEARCH.
%
%  Example: search_params = PLM_search_params
%    lsfun_name: 'PLM_paramsearch'   % loss function M-file
%    sumsq_name: 'PLM_sumsqfit2'     % error = zPcon^2+zPinc^2+dpr^2
%    model_name: 'PLM_Zcongr2'       % model M-file
%        params: [1x1 struct]   % initial approximation (see PLM_PARAMS)
%     p2v_templ: {1xk cell}     % see PARAMS2VECTOR and PLM_TEMPLATE
%     v2p_templ: {1xk cell}     % see VECTOR2PARAMS and PLM_TEMPLATE
%        bounds: [2xk double]   % upper and lower bounds for each param
%         optns: [1x1 struct]   % optimiz. options: optimset('fmincon')
%       verbose: 0              % do not report X on every iteration
%
%  See also PARAMSEARCH, PLM_PARAMSEARCH, PLM_PARAMS, PLM_TEMPLATE.

%  Original coding by Alexander Petrov, Carnegie Mellon University.
%  $Revision: 1.3 $  $Date: 2005/06/23 20:00 $

if (nargin==0)                % default
  search_params = struct('lsfun_name','PLM_paramsearch') ;
end

%--- Fill-in missing slots
if (~isfield(search_params,'lsfun_name'))
  search_params.model_name = 'PLM_paramsearch' ;
end
if (~isfield(search_params,'sumsq_name'))
  search_params.sumsq_name = 'PLM_sumsqfit2' ;
end
if (~isfield(search_params,'model_name'))
  search_params.model_name = 'PLM_Zcongr2' ;   % was PLM_Zcongr1 for Hebb1
end
if (~isfield(search_params,'params'))
  search_params.params = PLM_params ;
end
[p2v_templ,v2p_templ,lb,ub] = PLM_template ;
if (~isfield(search_params,'p2v_templ'))
  search_params.p2v_templ = p2v_templ ;
end
if (~isfield(search_params,'v2p_templ'))
  search_params.v2p_templ = v2p_templ ;
end
if (~isfield(search_params,'bounds'))
  search_params.bounds = [lb ; ub] ;
end
if (~isfield(search_params,'optns'))
  optns = optimset('fmincon') ;   % start from defaults from FMINCON
  optns = optimset(optns,'LargeScale','off',...  % as no gradients avail
    'TolCon',1e-4,'TolFun',1e-1,'TolX',1e-2,...  % as PLM is expensive
    'DiffMinChange',1e-6,... 
    'MaxIter',40,'MaxFunEvals',120,'Display','iter') ;
  search_params.optns = optns ;
end
if (~isfield(search_params,'verbose'))
  search_params.verbose = 0 ;
end

%--- Return SEARCH_PARAMS
%%%%% End of file PLM_SEARCH_PARAMS.M
