fmincon produces different results on different PCs

4 views (last 30 days)
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.

Answers (2)

Matt J
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
Evgeny Bespechansky
Evgeny Bespechansky on 15 Mar 2017
Thank you for your answer. Both PCs run the same version of Matlab, so I guess it's not the case. Furthermore, each execution on each machine produces a stable result. but they are constantly different between the machines. So, I assume the problem is between machines, and not in poorly stated optimization problem.
Matt J
Matt J on 15 Mar 2017
Edited: Matt J on 15 Mar 2017
But as I also said, different hardware architectures can give you different results if the solution is not unique. Are there any differences in CPUs/GPUs on the two machines? And did you compare the final objective function values, as I suggested?

Sign in to comment.


Steven Lord
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:
  1. 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.
  2. 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.
  3. 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
Evgeny Bespechansky
Evgeny Bespechansky on 15 Mar 2017
Thank you for your reply. We don't use any randomization in the optimized problem, at least for my best knowledge. Can it be that some internal process uses randomization? Anyway, each time the code runs on each PC, the result is the same. It's the difference between result on different PCs that is a problem.
Also, we use the same version of Matlab on both PCs.
Matt J
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.

Sign in to comment.

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!