2013-12-06 18:34:32 +01:00
|
|
|
function osr_res = osr1(i_params,i_var,weights)
|
2013-07-28 12:38:15 +02:00
|
|
|
% Compute the Optimal Simple Rules
|
|
|
|
% INPUTS
|
|
|
|
% i_params vector index of optimizing parameters in M_.params
|
|
|
|
% i_var vector variables indices
|
|
|
|
% weights vector weights in the OSRs
|
|
|
|
%
|
|
|
|
% Copyright (C) 2005-2013 Dynare Team
|
2008-08-01 20:53:30 +02:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
|
|
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
global M_ oo_ options_ it_
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
klen = M_.maximum_lag + M_.maximum_lead + 1;
|
|
|
|
iyv = M_.lead_lag_incidence';
|
|
|
|
iyv = iyv(:);
|
|
|
|
iyr0 = find(iyv) ;
|
|
|
|
it_ = M_.maximum_lag + 1 ;
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
if M_.exo_nbr == 0
|
2005-02-18 20:54:39 +01:00
|
|
|
oo_.exo_steady_state = [] ;
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
if ~ M_.lead_lag_incidence(M_.maximum_lag+1,:) > 0
|
2010-08-30 14:15:17 +02:00
|
|
|
error ('OSR: Error in model specification: some variables don''t appear as current') ;
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
if M_.maximum_lead == 0
|
2010-08-30 14:15:17 +02:00
|
|
|
error ('Backward or static model: no point in using OSR') ;
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
exe =zeros(M_.exo_nbr,1);
|
|
|
|
|
2012-06-29 12:32:54 +02:00
|
|
|
oo_.dr = set_state_space(oo_.dr,M_,options_);
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2006-09-21 17:48:01 +02:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
np = size(i_params,1);
|
|
|
|
t0 = M_.params(i_params);
|
2011-12-18 17:33:08 +01:00
|
|
|
inv_order_var = oo_.dr.inv_order_var;
|
2006-09-21 17:48:01 +02:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
H0 = 1e-4*eye(np);
|
2013-06-24 22:52:10 +02:00
|
|
|
crit=options_.osr.tolf;
|
|
|
|
nit=options_.osr.maxit;
|
|
|
|
verbose=options_.osr.verbose;
|
2006-09-21 17:48:01 +02:00
|
|
|
|
2013-07-28 12:38:15 +02:00
|
|
|
%% do initial checks
|
|
|
|
[loss,vx,info,exit_flag]=osr_obj(t0,i_params,inv_order_var(i_var),weights(i_var,i_var));
|
|
|
|
if info~=0
|
|
|
|
print_info(info, options_.noprint, options_);
|
|
|
|
else
|
|
|
|
fprintf('\nOSR: Initial value of the objective function: %g \n\n',loss);
|
|
|
|
end
|
|
|
|
|
|
|
|
%%do actual optimization
|
2010-07-28 15:26:56 +02:00
|
|
|
[f,p]=csminwel1('osr_obj',t0,H0,[],crit,nit,options_.gradient_method,options_.gradient_epsilon,i_params,...
|
2011-02-04 17:17:48 +01:00
|
|
|
inv_order_var(i_var),weights(i_var,i_var));
|
2013-12-06 18:34:32 +01:00
|
|
|
osr_res.objective_function = f;
|
|
|
|
for i=1:length(i_params)
|
|
|
|
osr_res.optim_params.(deblank(M_.param_names(i_params(i),:))) = p(i);
|
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
|
|
|
|
% options = optimset('fminunc');
|
2006-09-21 17:48:01 +02:00
|
|
|
% options = optimset('display','iter');
|
|
|
|
% [p,f]=fminunc(@osr_obj,t0,options,i_params,...
|
2010-01-05 11:46:10 +01:00
|
|
|
% inv_order_var(i_var),weights(i_var,i_var));
|
2006-07-31 17:45:12 +02:00
|
|
|
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2009-12-16 18:17:34 +01:00
|
|
|
disp('OPTIMAL VALUE OF THE PARAMETERS:')
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2009-12-16 18:17:34 +01:00
|
|
|
for i=1:np
|
2006-07-31 17:45:12 +02:00
|
|
|
disp(sprintf('%16s %16.6g\n',M_.param_names(i_params(i),:),p(i)))
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
disp(sprintf('Objective function : %16.6g\n',f));
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2011-09-17 12:33:07 +02:00
|
|
|
[oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
% 05/10/03 MJ modified to work with osr.m and give full report
|