필터 지우기
필터 지우기

Getting differnet results with fmincon in different runs

조회 수: 4 (최근 30일)
Ali Aghaeifar
Ali Aghaeifar 2019년 6월 1일
편집: Matt J 2019년 6월 5일
I use following code to find proper X which minimize myFun
problem.x0 = zeros(3,20);
problem.ub = 10*ones(3,20);
problem.lb = -problem.ub;
problem.objective = @(x) myFun(x);
problem.solver = 'fmincon';
problem.options = optimoptions(@fmincon, 'Algorithm', 'sqp', 'MaxFunEvals', 1e6, 'MaxIter', 1e5);
xFinal = fmincon(problem);
The cost function, myFun, is not convex and the gradient is not specified as well, so, there no no garantee to yeild global minimum (no problem so far).
My probem is that number of iterations is different if I run this code in different computers, and I get different X as local minimum. Start value, constraints, ... all are same. MATLAB version is also same.
Any idea why I cannot get same results in different PCs?
Thanks.
--------
p.s.
Tried to add
rng(1,'twister')
at the beggining, but didn't solve the issue.
after iteration No. 0, I get different f(x) or Fval. Iiteration No. 0 is same for all runs.
F-count is not same after first iteration as well (for the runs in different computers).
  댓글 수: 1
Ali Aghaeifar
Ali Aghaeifar 2019년 6월 3일
Update:
Not sure, but seems the problem returns back to OS. I got same results when I ran on two PCs with windows 10. However, different OS yeild different results (tested with Windows 7, 10 and ubuntu 14)

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

답변 (1개)

Matt J
Matt J 2019년 6월 3일
편집: Matt J 2019년 6월 3일
Does myFun have any randomization commands in it? It shouldn't.
Otherwise, it is possible that you have a continuum of solutions, similar to how has a global minimum for all x=y. In such cases, the result will be numerically unstable, and different machines with different processors can give very different results.
It is also conceivable that one machine is converging to a saddle point, remaining in regions with positive curvature. The other machine, which does the numerical calculations slightly differently, lands in the region of negative curvature and manages to get greater descent.
  댓글 수: 2
Ali Aghaeifar
Ali Aghaeifar 2019년 6월 3일
Thanks for your reply.
No, there are no randomization commands.
Then it's bad news for portablity of programs if different processors can give different results. However, I'm in doublt this can be the main reason. All the function evaluations for the zeroth iteration yeild same results in different computers (e.g. F-count is 25 for the zeroth iteration and function evalution of all 25 times are also same).
I also don't have continuum of solutions, beacause evalution of objective function with different solutions gives different results.
I just saw two more questions with a similar problem of mine:
Matt J
Matt J 2019년 6월 4일
편집: Matt J 2019년 6월 5일
Then it's bad news for portablity of programs if different processors can give different results.
No, it's not a broad issue of portability. Different processors can give significantly different results only for optimization problems with certain unstable properties, such as those I described in the thread you referenced.
The first thing I would verify is whether both of the solutions you are getting are stable solutions. One way to do this is to add small random noise to the solution and re-run the optimization using this noisy point as your initial x0. If the optimization returns to the solution, it is probably stable.

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

카테고리

Help CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by