Cannot replicate results of nonlinear optimization w/ nonlinear constraints from replication files
Mostrar comentarios más antiguos
I cannot seem to replicate simulation results generated by my MATLAB code despite using same code, functions, starting values, random number generator, etc. Since I am literally using the same code/conditions used to generate the code the first time, I have omitted the code itself.
General description of code used: I simulate N nonlinear optimization problems with nonlinear constraints using fmincon, parallelized over my machine’s cores. I iterate over these simulations until a fixed point is reached. I am using fmincon’s SQP solver with centralized finite differences and have provided the analytical gradients for both my objective and constraint functions. Generally, CheckGradients does not fail – will get one failed for a large number of passed CheckGradients, presumably due to some scaling issue for a particular simulation.
Description of problem: I ran five experiments in the latter months of 2021: 3 in September on MATLAB 2018A, and 2 in December on MATLAB 2021B. All five experiments generated results that were generally consistent with one another.
In January 2022, I attempted to replicate all three of the September experiments using code archived in October for the express purpose of replicating the September results (there were no changes to the code between September and October); in particular, when I attempt to simply re-run the last iteration of the fixed-point algorithm – i.e., the iteration in which the code should terminate – the code does not terminate. In fact, in examining the “replicate” simulations, I see results that are very, very different than my original results.
Final context: I believe I installed the following updates in between the last time my code was generating consistent results and the point at which things started going haywire:
- Feature update to Windows 10, version 21H2
- Cumulative Update for .NET Framework 3.5 and 4.8 for Windows 10 Version 20H2 for x64 (KB5008876)
- Update for Windows 10 Version 21H2 for x64-based systems (KB5008212)
Again – I am using the same code files, same environments, same starting environments, etc. Can someone shed some light as to why I am encountering this phenomenon?
Respuestas (1)
when I attempt to simply re-run the last iteration of the fixed-point algorithm
You wouldn't be able to re-run the last iteration unless you had the second to last iteration as a start point. If you mean you used the October 2021 output of fmincon as the initial guess, then,
(1) Whether the iterations would continue depends on which stopping criteria caused the October 2021 runs to stop. If you simply reached the MaxIteration limit, then convergence never happenened and there is no reason the iterations should not continue when resumed.
(2) Some stopping criteria are defined relative to the norm of the gradient at the initial point, see
Since you are now launching fmincon at a different point, those stopping rules would be affected.
(3) The SQP algorithm uses quasi-newton methods to estimate the Hessian of the Lagrangian, which means the Hessian is iteratively updated from some starting guess. I don't think you have any way of resuming the Hessian updates from where they left off in October.
(4) You may have multiple solutions. What is the first order optimality measure at the new and old solutions? How different are the objective values at the two solutions?
(5) You say the new solutions are very different, but we don't know how you are evaluating that. Even if the differences are on the order of 10^15, we can't know whether to consider that a large number. If the gradients in the neighborhood of the October solution are also O(10^15), it makes sense to view that as a small change.
7 comentarios
Nick Rowe
el 4 de Feb. de 2022
The outer while loop is not something we can help you with. It's a home-brewed algorithm devised by you and only you have anyway of predicting its behavior. We also have no way of testing your claim that you are initializing the loop step consistent with October 2021. If you aren't (even if you think you are) that would explain why the results are different now.
The question we can explore with you is whether fmincon is doing its job. Is it giving you exitflag=1? Is it giving you a small optimality measure at convergence? Is the new solution feasible and giving a lower objective value than the previous solution? If yes to all of the above, what reason is there to doubt that the optimization steps are failing to produce valid output?
The only thing I can think of is that the parallel deployment could be different. If you have different non-Matlab process going on in the background since October, Matlab may not be able to subscribe the exact same cores to each worker. Therefore, the operations inside your objective function may not be multithreaded the same way, leading to differences in floating point errors. However, if the solutions ot the optimization problems are unique and well-conditioned, as you say they are, the difference shouldn't be very big.
One very important thing to note, however, is that if the new fvals are susbtantially better than the old ones, it means that your original optimization never succeeded, assuming the objective function and constraints indeed haven't changed. That means your original code had a bug in it, because the exitflag and conditions for convergence weren't as well-checked as you say they should be. A further possibility therefore is that you later fixed the bug, but neglected to rerun the computation before you archived the code in October.
Therefore, the operations inside your objective function may not be multithreaded the same way, leading to differences in floating point errors. However, if the solutions ot the optimization problems are unique and well-conditioned, as you say they are, the difference shouldn't be very big.
Unless, perhaps, the October solutions were saddle points of the objective function. Saddle points are unstable, so small floating point differences could tip the iterations in the direction of a substantially different minimum, like in the simplified problem below:
fun=@(x) x(1)^2-x(2)^2;
lb=[-1;-1]; ub=-lb;
optimoptions('fmincon','Algorithm','sqp');
[x,fval,exitflag,output]=fmincon(fun,[1e-8,1e-8],[],[],[],[],lb,ub), %unstable
[x,fval,exitflag,output]=fmincon(fun,[1e-8,1e-6],[],[],[],[],lb,ub), %stable
Nick Rowe
el 5 de Feb. de 2022
Matt J
el 5 de Feb. de 2022
You are quite welcome.
Categorías
Más información sobre Solver Outputs and Iterative Display en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!