Fixed bugs highlighted by Junior, occurring when some constraint is violated when computing gradients.
git-svn-id: https://www.dynare.org/svn/dynare/trunk@2857 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
0ed63ac01a
commit
d2b3beb3e7
|
@ -165,7 +165,11 @@ while i<n,
|
||||||
% end
|
% end
|
||||||
% end
|
% end
|
||||||
f1(:,i)=fx;
|
f1(:,i)=fx;
|
||||||
|
if any(isnan(ffx)),
|
||||||
|
ff1=ones(size(ff0)).*fx/length(ff0);
|
||||||
|
else
|
||||||
ff1=ffx;
|
ff1=ffx;
|
||||||
|
end
|
||||||
if hflag, % two point based derivatives
|
if hflag, % two point based derivatives
|
||||||
xh1(i)=x(i)-h1(i);
|
xh1(i)=x(i)-h1(i);
|
||||||
% c=mr_nlincon(xh1,varargin{:});
|
% c=mr_nlincon(xh1,varargin{:});
|
||||||
|
@ -178,7 +182,11 @@ while i<n,
|
||||||
% end
|
% end
|
||||||
[fx, ffx]=feval(func,xh1,varargin{:});
|
[fx, ffx]=feval(func,xh1,varargin{:});
|
||||||
f_1(:,i)=fx;
|
f_1(:,i)=fx;
|
||||||
|
if any(isnan(ffx)),
|
||||||
|
ff_1=ones(size(ff0)).*fx/length(ff0);
|
||||||
|
else
|
||||||
ff_1=ffx;
|
ff_1=ffx;
|
||||||
|
end
|
||||||
% if ic,
|
% if ic,
|
||||||
% xh1(i)=x(i)+h1(i);
|
% xh1(i)=x(i)+h1(i);
|
||||||
% [f1(:,i), ff1]=feval(func,xh1,varargin{:});
|
% [f1(:,i), ff1]=feval(func,xh1,varargin{:});
|
||||||
|
@ -307,7 +315,7 @@ if hflag<2,
|
||||||
hessian_mat=hh_mat0(:);
|
hessian_mat=hh_mat0(:);
|
||||||
end
|
end
|
||||||
|
|
||||||
if isnan(hessian_mat),
|
if any(isnan(hessian_mat)),
|
||||||
hh_mat0=eye(length(hh_mat0));
|
hh_mat0=eye(length(hh_mat0));
|
||||||
ihh=hh_mat0;
|
ihh=hh_mat0;
|
||||||
hessian_mat=hh_mat0(:);
|
hessian_mat=hh_mat0(:);
|
||||||
|
|
Loading…
Reference in New Issue