fmincon produces different results on different PCs
4 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Matt J
on 15 Mar 2017
Edited: Matt J
on 15 Mar 2017
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 Comments
Steven Lord
on 15 Mar 2017
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 Comments
Matt J
on 15 Mar 2017
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.
See Also
Categories
Find more on Get Started with Optimization Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!