Different result on fmincon - same machine, Linux OS

Hi everyone,
I am running same code again and again, I didn't change anything, but the result is different after each run. My program is essentially solving an optimization using fmincon, and I think this solver should be deterministic. It's possible to have different results if we run on different machine because of different MKL. However, in my case, it's running on same machine and same code. Can anyone think of some reason that can cause this?
One reason I can think of is the problem is ill-posed? I did observe that when the program exit with flag 2 due to small step size, the "First order optimality" is large, usually 10^3~10^5.
Any thoughts are appreciated!

Answers (1)

There are many things in code that you THINK should be deterministic, but are in fact not. Many functions you might call can end up using a random component, perhaps for starting values, etc.
Being ill-posed is not at all a reason for code to be non-deterministic.
Without seeing your code, nobody can do any more than make idle speculation. So if you will not show the code, all I can suggest is to look CAREFULLY at every function called. Read the documentation. In some place, you have a function that has some random component. One thing you can do is to set the system random seed in front. Then rerun the code, forcing the same random seed each time. My conjecture is this will return the process to being consistent.

Tags

Asked:

on 26 Jan 2018

Answered:

on 27 Jan 2018

Community Treasure Hunt

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

Start Hunting!