FMINCON performing Differently in Mac vs Windows
7 次查看(过去 30 天)
显示 更早的评论
I am running an optimization code using fmincon, and using parallel computing. It happens to give me different outputs when run on Mac vs Windows, any idea what can be fixed?
4 个评论
John D'Errico
2024-5-29
Lol. "This is an unacceptable solution." I can rant and rave, stomp my feet all I want, and there are things in the world I cannot change, despite my most strident demands.
If you insist on exactly the same results always, down to the least significant bit, then never change release. Never use a different computer. That MIGHT be sufficient. Even things like the number of processors or the amount of RAM you have may cause issues, since that may influence how a computation gets parallelized.
Instead, you should learn about floating point computations, why they are impacted by the exact sequence of operations performed, and why computations done in parallel can change the results you see. You should learn about the need for tolerances on any result. Never compare two floating point results for exact equality, as even the simplest result need not yield what you know to be mathematically true.
0.1 + 0.2 - 0.3 == 0.2 - 0.3 + 0.1
Of course, you don't say if the difference in results is down in the least significant bits, or if it is larger. But even then, the magnitude of the difference may simply be explained by an ill-conditioned system amplifying tiny errors in the least significant bits.
Matt J
2024-5-29
移动:Matt J
2024-5-29
It happens to give me different outputs when run on Mac vs Windows, any idea what can be fixed?
Do both solutions give similar objective function values, fval? If so, it is a sign that you may have a non-unique space of solutions. You will need to regularize the problem in some way, to remove the ambiguity in the solution. We might be able to give advice on that, but not without seeing a mathematical description of the problem.
回答(1 个)
Ganesh
2024-5-29
As @Torsten has pointed out, it is not unusual for such behaviour. The function "fmincon()" can behave differently on different machines due to slight difference in the underlying mathematical functions. Moreover, as you have parallelized the process, the overall result would get compounded and be different too.
However, you can be assured that the underlying algorithm used for both the processes remain the same.
To answer your question, if you intend to achieve the same result on both your machines, you will have to understand the underlying math and give varying "Initial Guesses" accordingly.
Kindly refer to the following MATLAB Answer, and follow through the entire answer for better understanding.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Direct Search 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!