fmincon produces different results on different PCs
7 次查看(过去 30 天)
显示 更早的评论
We use an fmincon() function that with the same inputs generates different results on different PCs. What could be the reason? Is there a way to fix it? Can it be that the result depends on OS used? One PC runs Win8.1, and another Win10.
0 个评论
回答(2 个)
Matt J
2017-3-15
编辑:Matt J
2017-3-15
Different versions of fmincon from different releases of MATLAB could take different iterative paths and produce different results. Also, the problem itself could be unstable such as when a continuum of non-unique solutions exists. An example is with the objective function,
f(x,y)=(x-y)^2
where the whole line x=y is a solution. When this occurs, differences in hardware architecture, rounding, etc... can lead to different solutions. You should check whether the minimized objective function value is the same on both machines, even if the minimizing point is not.
2 个评论
Steven Lord
2017-3-15
It's impossible to answer this question definitively without seeing a sample of code, but there are a number of possible reasons. Three of those possible reasons:
- Your objective function uses rand, randn, randi, or a function that internally uses one of those random number generators. You could try setting the random number generator state using rng before calling fmincon to try to eliminate this, though if the function that's using random numbers itself calls rng (particularly rng shuffle) you can't really stop that.
- You're running different releases of MATLAB and Optimization Toolbox, and a change in the code of fmincon or a function called by the optimization process in the later of those releases (to fix a bug or add new functionality) is causing a different result.
- Somewhat related to reason 2, you're calling a function that has multiple possible correct answers and a different correct answer is being returned on the two machines, or the correct answers are being returned in a different order and your code depended on the answers being returned in a specific order. For one example of this, see this Answers post from last year.
2 个评论
Matt J
2017-3-15
4. The part of the code that was written by you is not the same on both machines. I.e., you copied it incorrectly or there is a version of the file with the same name higher up on your path. Use 'which -all' to check.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!