How to resolve the fminunc problem
2 次查看(过去 30 天)
显示 更早的评论
Hey everybody, I am runing the post maximization of a financial friction model but each time I run it I have the following errors:
Error in ==> post_minus at 3
x = trans2(xtrans);
??? Error using ==> feval
Output argument "min_post" (and maybe others) not assigned during call to "F:\new
folders\67bis\Restricted Models (Table 3)\Fin Frictions Mod\Post
Maximization\post_minus.m>post_minus".
Error in ==> lineSearch>bracketingPhase at 103
f_alpha =
feval(funfcn{3},reshape(xInitial(:)+alpha*dir(:),sizes.xRows,sizes.xCols),varargin{:});
Error in ==> lineSearch at 48
[a,b,f_a,fPrime_a,f_b,fPrime_b,alpha,f_alpha,grad,exitflagBrckt,funcCountBrckt] = ...
Error in ==> fminusub at 208
[alpha,f,grad,exitflagLnSrch,funcCountLnSrch] = ...
Error in ==> fminunc at 367
[x,FVAL,GRAD,HESSIAN,EXITFLAG,OUTPUT] = fminusub(funfcn,x, ...
Error in ==> max_run_loop at 72
[xtrans,fval,exitflag,output,grad,hessian]...
You can find the code following this link https://www.mathworks.com/matlabcentral/fileexchange/63625-the-financial-friction-post-maximization-code-of-chang-and-fernandez--2013-
When I run this code with the original data of the author it works and even with another set of variable, but using this data I didn't succeed to obtain the posterior mode and the inverse of the Hessian matrix to finish the estimation procedure (the original code can be found in the homepage of Andrés Fernandez).
Please hepl me
Thanks in advance
Houda
3 个评论
采纳的回答
Walter Roberson
2017-7-5
The code in post_minus includes the line
if logprior(1) == NaN
It is not possible to use "==" to compare to NaN . NaN == NaN is false. NaN has the strange property of being the only value for which x ~= x . The test should be
if isnan(logprior(1))
and likewise further down for elseif logdata(1) == NaN
Further down the code has
if ind == 1 % ind. is a flag signaling the inexistence of solution
return;
end
It does this without having assigned a value to min_post. It should probably be
if ind == 1 % ind. is a flag signaling the inexistence of solution
min_post = 0;
return;
end
This is probably what you are encountering, that it is detecting that there is no feasible solution.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!