function  [template,lb,ub] = sample_template(direction)

% SAMPLE_TEMPLATE -- Sample templates for VECTOR2PARAMS and PARAMS2VECTOR.
%   
%  TEMPLATE = SAMPLE_TEMPLATE('params2vector')
%  TEMPLATE = SAMPLE_TEMPLATE('vector2params')
%  [TEMPLATE,LOWBOUND,UPBOUND] = SAMPLE_TEMPLATE(DIRECTION)
%
%  This function produces sample templates specifying conversions b/n
%  PARAMS structures and vectors. These templates are passed to
%  functions PARAMS2VECTOR and VECTOR2PARAMS. Define your own function
%  that makes templates appropriate for your model.
%
%  DIRECTION must be one of the following four strings:
%   'params2vector'  or  'p2v'
%   'vector2params'  or  'v2p'
%
%  Note that not all fields of the PARAMS structure need to be converted;
%  only the ones that you want to optimize. See LOGL and FMINBND.
%
%  See also PARAMS2VECTOR, VECTOR2PARAMS, LOGL, FMINCON.

% Original coding by Alex Petrov, Ohio State University
% $Revision: 1.0 $  $Date: 2000/06/07 16:10 $
%
% Part of the utils toolbox version 1.1 for MATLAB version 5 and up.
% http://alexpetrov.com/softw/utils/
% Copyright (c) Alexander Petrov 1999-2006, http://alexpetrov.com
% Please read the LICENSE and NO WARRANTY statement in ../utils_license.m

% Suppose your model has four parameters: ALPHA, BETA, GAMMA, DELTA.
% They are bundled in a PARAMS structure.  You want to keep optimize
% ALPHA and BETA while keeping DELTA fixed. GAMMA can be calculated
% from BETA and DELTA. Thus, your optimization is in two dimensions
% and hence the conversion templates have two fields.
% Typical values for ALPHA are around 100 and for BETA around 0.5.
% The templates specify that the first element of the vector is ALPHA/100
% and the second element is BETA. (You divide ALPHA by 100 to make its
% variance commensurable with that of BETA. This helps the optimization.)

template = cell(1,2) ;

switch lower(direction)
case {'p2v', 'params2vector'}
  template{1} = 'VAL = PARAMS.alpha / 100 ;' ;
  template{2} = 'VAL = PARAMS.beta ;' ;
case {'v2p', 'vector2params'}
  template{1} = 'PARAMS.alpha = VAL * 100 ;' ;
  template{2} = 'PARAMS.beta = VAL ; PARAMS.gamma = VAL + PARAMS.delta' ;
otherwise
  error('DIRECTION must be ''params2vector'', ''p2v'', ''vector2params'', or ''v2p''.') ;
end

lb = [0.5  0.2] ;   % ALPHA_min =  50, BETA_min = 0.2
ub = [1.5  2.0] ;   % ALPHA_max = 150, BETA_max = 2.0

%% Return TEMPLATE and, possibly, LB and UB.
%%%%% End of file SAMPLE_TEMPLATE.M
