{"action":"created","issue":{"url":"https://api.github.com/repos/DynareTeam/dynare/issues/1067","labels_url":"https://api.github.com/repos/DynareTeam/dynare/issues/1067/labels{/name}","comments_url":"https://api.github.com/repos/DynareTeam/dynare/issues/1067/comments","events_url":"https://api.github.com/repos/DynareTeam/dynare/issues/1067/events","html_url":"https://github.com/DynareTeam/dynare/issues/1067","id":109822949,"number":1067,"title":"Fix trust region exit criterion","user":{"login":"JohannesPfeifer","id":3679304,"avatar_url":"https://avatars.githubusercontent.com/u/3679304?v=3","gravatar_id":"","url":"https://api.github.com/users/JohannesPfeifer","html_url":"https://github.com/JohannesPfeifer","followers_url":"https://api.github.com/users/JohannesPfeifer/followers","following_url":"https://api.github.com/users/JohannesPfeifer/following{/other_user}","gists_url":"https://api.github.com/users/JohannesPfeifer/gists{/gist_id}","starred_url":"https://api.github.com/users/JohannesPfeifer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohannesPfeifer/subscriptions","organizations_url":"https://api.github.com/users/JohannesPfeifer/orgs","repos_url":"https://api.github.com/users/JohannesPfeifer/repos","events_url":"https://api.github.com/users/JohannesPfeifer/events{/privacy}","received_events_url":"https://api.github.com/users/JohannesPfeifer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-05T15:30:50Z","updated_at":"2015-10-06T08:30:09Z","closed_at":null,"body":"In  ```trust_region.m``` we have a problem with trying to encode three pieces of information in a binary variable ```check```\r\n\r\nThe problem is error code -3 (Trust region became uselessly small). c01352ea3bfd6dd29074a2e0867afc5a1763f79d tried to prevent the solver from accepting error code -3 as a solved steady state. But this breaks the loop in ```dynare_solve.m```:\r\n\r\n```\r\n    for i=length(r)-1:-1:1\r\n        if options.debug\r\n            disp(['DYNARE_SOLVE (solve_algo=2|4): solving block ' num2str(i) ', of size ' num2str(r(i+1)-r(i)) ]);\r\n        end\r\n        [x,info]=solver(func,x,j1(r(i):r(i+1)-1),j2(r(i):r(i+1)-1),jacobian_flag, ...\r\n                        options.gstep, ...\r\n                        tolf,options.solve_tolx, ...\r\n                        options.steady.maxit,options.debug,varargin{:});\r\n        if info\r\n            return\r\n        end\r\n    end\r\n```\r\nwhich relies on being able to continue with the loop when the code internally was -3 (as ~(-3)=0), i.e. we discard the information that -3 is a problem. But further below we have the final check\r\n```\r\n    if max(abs(fvec)) > tolf\r\n        [x,info]=solver(func,x,1:nn,1:nn,jacobian_flag, ...\r\n                        options.gstep, tolf,options.solve_tolx, ...\r\n                        options.steady.maxit,options.debug,varargin{:});\r\n    end\r\n```\r\nHere, we would need to know whether a 0 in info comes from info = ~(1) (everything fine) vs. info=~(-3) (still a problem after the last iteration). \r\n\r\nMy proposed solution would be to augment both ```trust_region.m``` and ```solve1.m``` with a third output argument ```exitflag``` that encodes the full integer error code. That way we would only need to check for this argument in the final check of ```dynare_solve.m```"},"comment":{"url":"https://api.github.com/repos/DynareTeam/dynare/issues/comments/145781972","html_url":"https://github.com/DynareTeam/dynare/issues/1067#issuecomment-145781972","issue_url":"https://api.github.com/repos/DynareTeam/dynare/issues/1067","id":145781972,"user":{"login":"MichelJuillard","id":584236,"avatar_url":"https://avatars.githubusercontent.com/u/584236?v=3","gravatar_id":"","url":"https://api.github.com/users/MichelJuillard","html_url":"https://github.com/MichelJuillard","followers_url":"https://api.github.com/users/MichelJuillard/followers","following_url":"https://api.github.com/users/MichelJuillard/following{/other_user}","gists_url":"https://api.github.com/users/MichelJuillard/gists{/gist_id}","starred_url":"https://api.github.com/users/MichelJuillard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MichelJuillard/subscriptions","organizations_url":"https://api.github.com/users/MichelJuillard/orgs","repos_url":"https://api.github.com/users/MichelJuillard/repos","events_url":"https://api.github.com/users/MichelJuillard/events{/privacy}","received_events_url":"https://api.github.com/users/MichelJuillard/received_events","type":"User","site_admin":false},"created_at":"2015-10-06T08:30:09Z","updated_at":"2015-10-06T08:30:09Z","body":"I think that your first idea was the right one. If I understand correctly info can take three value at the end of the main loop\r\ninfo = 0 : maxiter has been reached\r\ninfo = -3: trust region too small\r\ninfo = 1: success\r\n\r\nThe two first values indicate a problem and the procedure should stop and report failure\r\n\r\nHowever, I think there was a problem in your first patch because when info == 1, check was returned undetermined instead of equal to 0\r\n"}}