fmincon produces different results on different PCs

조회 수: 11 (최근 30일)
Evgeny Bespechansky
Evgeny Bespechansky 2017년 3월 15일
댓글: Matt J 2017년 3월 15일
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.

답변 (2개)

Matt J
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
Evgeny Bespechansky
Evgeny Bespechansky 2017년 3월 15일
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 2017년 3월 15일
편집: Matt J 2017년 3월 15일
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?

댓글을 달려면 로그인하십시오.


Steven Lord
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:
  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
Evgeny Bespechansky
Evgeny Bespechansky 2017년 3월 15일
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 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 CenterFile 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!

Translated by