fmincon options: How can i prevent the optimization to make big steps of X, to search for a possible global optimum, when she solver found a possible lokal minimum?

5 views (last 30 days)
Hey guys, (excuse my englisch, i'm not a native speaker) im using fmincon to optimize a tendon driven robot. The value i optimize right now is the tendon-force X = tau(in my code). And the function that is optimized passes back the distance of the robot-tip to a point in 3D space. Can't give more information on that.
My function worked fine until i used nonlcon. The distance was optimized to less than a milimeter. With nonlcon the distance is 12mm or more. Often the function finds a lokal minimum, that is not near the gobal minimum. But then X = tau is increased to much and another function (TM_IVP_2) malfunctions.
tipError =
0.0449
tipError =
0.0449
tipError =
0.0449
tipError =
0.0450
Warning: No solution for BVP found, exitflag=0
> In TM_IVP_2 (line 106)
In Test_Code_fmincon_voxel/optimFct (line 8)
In sqpInterface
In fmincon (line 808)
In Test_Code_fmincon_voxel (line 64)
In Test_Code_Start_noloop_voxel (line 97)
tipError =
0.1254
Warning: No solution for BVP found, exitflag=0
> In TM_IVP_2 (line 106)
In Test_Code_fmincon_voxel/Test_Code_Collision (line 26)
In sqpInterface
In fmincon (line 808)
In Test_Code_fmincon_voxel (line 64)
In Test_Code_Start_noloop_voxel (line 97)
Warning: No solution for BVP found, exitflag=0
> In TM_IVP_2 (line 106)
In Test_Code_fmincon_voxel/optimFct (line 8)
In sqpInterface
In fmincon (line 808)
In Test_Code_fmincon_voxel (line 64)
In Test_Code_Start_noloop_voxel (line 97)
tipError =
0.1289
Warning: No solution for BVP found, exitflag=0
> In TM_IVP_2 (line 106)
In Test_Code_fmincon_voxel/Test_Code_Collision (line 26)
In sqpInterface
In fmincon (line 808)
In Test_Code_fmincon_voxel (line 64)
In Test_Code_Start_noloop_voxel (line 97)
tipError =
0.1196
tipError =
0.1217
tipError =
0.1350
tipError =
0.1220
tipError =
0.1117
tipError =
0.0976
tipError =
0.0776
tipError =
0.0629
tipError =
0.0541
What i want to know is:
  • Am i using nonlcon wrong? I need it to constrain the 3D space, because there are objects the robot should not pass.
  • Is there a way to stop the optimization to search for a global minimum, when a possible local minimum is found?
function [ tau , Optimization, exflag, output ] = Test_Code_fmincon_voxel(indexKid, u_init_guess, tau_start, param, l, F, Voxel)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
Optimization = 0;
% tau = tau_start;
function tipError = optimFct(tau)
Optimization = Optimization +1;
[y] = TM_IVP_2(u_init_guess,tau,l,F,param);
indexRobo = Test_Code_Voxelize_Points(y(end,1:3), Voxel); % pass row vector
tipError = norm(Test_Code_Coordinate_Voxel(indexKid, Voxel)-y(end,1:3))
% memory
% drawnow
end
%%Constraints
function [c, ceq] = Test_Code_Collision(tau)
ceq = [];
[y] = TM_IVP_2(u_init_guess,tau,l,F,param); % calculates Robot structure
indexRobo = Test_Code_Voxelize_Points(y(1:end,1:3), Voxel); % pass row vector
c = 0;
for i=1:length(indexRobo(1:end,1))
if Voxel.volume(indexRobo(i,1),indexRobo(i,2),indexRobo(i,3)) == 2
c = 1;
break
else
c = -1;
end
end
end
nonlcon = @Test_Code_Collision;
options = optimoptions('fmincon');
options.Display = 'final-detailed';%'off','iter','notify','notify-detailed','final','final-detailed',iter-detailed'
options.Algorithm='sqp';
options.TolX = 1e-4;
options.Diagnostics = 'off';
% options.UseParallel = 'always';
% my options
% options.PlotFcns = @optimplotstepsize;
options.TolFun = 1e-6;
options.MaxIterations = 500;
options.FiniteDifferenceStepSize = 1e-2;
options.OptimalityTolerance = 1e-20;
options.ConstraintTolerance = 1e-8;
% options.DiffMaxChange = 5e-2;
ub = Inf*ones(3,2);
% ub = [5,5;5,5;5,5];
% lb = zeros(3,2);
lb = -Inf*ones(3,2);
[tau, val, exflag, output] = fmincon(@optimFct,tau_start,[],[],[],[],lb,ub,nonlcon,options);
end
TM_IVP_2 calculates the robot structure. I have to use FiniteDifferenceStepSize, otherwise the optimization does not increase X = tau in a significant way.
If you need more information, let me know. Glad for all help.
(how can i produce a textparagraph, like one after "Hey guys,". cant figure it out :D )
Greetings Vince

Answers (1)

Matt J
Matt J on 20 Aug 2017
Edited: Matt J on 20 Aug 2017
Am i using nonlcon wrong?
At the very least, you appear to be ignoring smoothness/differentiabilty requirements on the objective function and constraints. In particular your constraint is discrete (taking only values of 1 and -1) and therefore cannot be differentiable. Similarly, your objective function looks at norm(z) which is non-differentiable at z=0 instead of norm(z)^2.
Is there a way to stop the optimization to search for a global minimum, when a possible local minimum is found?
fmincon always stops when a possible local minimum is found. fmincon has no way of distinguishing between local and global minima.
  12 Comments
Matt J
Matt J on 22 Aug 2017
Edited: Matt J on 22 Aug 2017
So, now i tried out something new. I check the distance of a Voxel of the Robot to all Voxel of the object.
Voxelizing the robot seems like a bad idea, because it is a discrete function of your optimization variables, x. This again creates differentiability problems and forces you to use very large finite difference step sizes.
Could you not draw a simpler bounding surface around the object you are trying to avoid? A sphere, for example, or a set of planes? The distance of the robot tip to the surface would be easier to express analytically/differentiably.
Consider also that you are not looking for an exact solution anyway - just something you will later refine with global optimization.
Vincent Hielscher
Vincent Hielscher on 24 Aug 2017
Strange i checked for answers each day. But today it's the 1. time i see it.
Anyway...i'll invest some time on thinking about the way i set my boundings. Yeah i know, i don't get the exact solution with optimization.
Thanks a lot for your help Matt! Greetings Vince

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!