fmincon produces different results on different PCs
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Matt J
el 15 de Mzo. de 2017
Editada: Matt J
el 15 de Mzo. de 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 comentarios
Matt J
el 15 de Mzo. de 2017
Editada: Matt J
el 15 de Mzo. de 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?
Steven Lord
el 15 de Mzo. de 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 comentarios
Matt J
el 15 de Mzo. de 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.
Ver también
Categorías
Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!