Home > matlab > mr_gstep.m

mr_gstep

PURPOSE ^

function [f0, x, ig] = mr_gstep(h1,x,func0,htol0,varargin)

SYNOPSIS ^

function [f0, x, ig] = mr_gstep(h1,x,func0,htol0,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults)

DESCRIPTION ^

 function [f0, x, ig] = mr_gstep(h1,x,func0,htol0,varargin)

 Gibbs type step in optimisation

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [f0, x, ig] = mr_gstep(h1,x,func0,htol0,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults)
0002 % function [f0, x, ig] = mr_gstep(h1,x,func0,htol0,varargin)
0003 %
0004 % Gibbs type step in optimisation
0005 
0006 % Copyright (C) 2006-2011 Dynare Team
0007 %
0008 % This file is part of Dynare.
0009 %
0010 % Dynare is free software: you can redistribute it and/or modify
0011 % it under the terms of the GNU General Public License as published by
0012 % the Free Software Foundation, either version 3 of the License, or
0013 % (at your option) any later version.
0014 %
0015 % Dynare is distributed in the hope that it will be useful,
0016 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0017 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018 % GNU General Public License for more details.
0019 %
0020 % You should have received a copy of the GNU General Public License
0021 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0022 
0023 n=size(x,1);
0024 
0025 if isempty(htol0)
0026     htol = 1.e-6;
0027 else
0028     htol = htol0;
0029 end
0030 f0=feval(func0,x,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
0031 
0032 xh1=x;
0033 f1=zeros(size(f0,1),n);
0034 f_1=f1;
0035 
0036 i=0;
0037 ig=zeros(n,1);
0038 while i<n
0039     i=i+1;
0040     h10=h1(i);
0041     hcheck=0;
0042     dx=[];
0043     xh1(i)=x(i)+h1(i);
0044     fx = feval(func0,xh1,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
0045     f1(:,i)=fx;
0046     xh1(i)=x(i)-h1(i);
0047     fx = feval(func0,xh1,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
0048     f_1(:,i)=fx;
0049     if hcheck && htol<1
0050         htol=min(1,max(min(abs(dx))*2,htol*10));
0051         h1(i)=h10;
0052         xh1(i)=x(i);
0053         i=i-1;
0054     else
0055         gg=zeros(size(x));
0056         hh=gg;
0057         gg(i)=(f1(i)'-f_1(i)')./(2.*h1(i));
0058         hh(i) = 1/max(1.e-9,abs( (f1(i)+f_1(i)-2*f0)./(h1(i)*h1(i)) ));
0059         if gg(i)*(hh(i)*gg(i))/2 > htol
0060             [f0 x fc retcode] = csminit1(func0,x,f0,gg,0,diag(hh),DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
0061             ig(i)=1;
0062             fprintf(['Done for param %s = %8.4f\n'],BayesInfo.name{i},x(i))
0063         end
0064         xh1=x;
0065     end
0066     save gstep.mat x h1 f0
0067 end
0068 
0069 save gstep.mat x h1 f0
0070

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005