MATLAB/NOMAD for global optima?

24 views (last 30 days)
basak ozturk
basak ozturk on 17 Apr 2020
Commented: Walter Roberson on 15 Sep 2022
Here comes my nonsmooth nonconvex MINLP, in fact this is a maximization problem. MATLAB/NOMAD from opti toolbox does not find the global optima? Do you have any idea why?
tnank you very much, basak
clc
fun=@(x)((((x(4)*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-185)/(190-185))+...
((1-x(4))*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-195)/(190-195)))*...
(x(5)*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-185)/(190-185))+...
(1-x(5))*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-195)/(190-195)))*...
(x(6)*((140.2333+ 5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-170)/(185-170))+...
(1-x(6))*((140.2333+ 5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-195)/(185-195))))^(1/3))
x0 = [1.0000 0.8629 0.5863 0 0 0]';
lb = [-1;-1;-1;0;0;0];
ub = [1;1;1;1;1;1];
xtype='CCCBBB';
opts=optiset('solver','nomad','display','iter','solverOpts',nomadset('direction_type','lt 2n'))
Opt=opti('fun',fun,'bounds',lb,ub,'xtype',xtype,'options',opts)
[x,fval,exitflag,info] = solve(Opt,x0)
  2 Comments
Walter Roberson
Walter Roberson on 15 Sep 2022
Edited: Walter Roberson on 15 Sep 2022
NOMAD appears to refer to the third party toolbox, one source of which is at https://github.com/jonathancurrie/OPTI
Note that third party toolboxes are not created by Mathworks, and volunteers here might not be familiar with them.
basak ozturk
basak ozturk on 15 Sep 2022
I am a mathematician who uses MATLAb because of its gui, I am not a software engineer, hence github sources becomes practically out of scope, thank you

Sign in to comment.

Answers (2)

Abdolkarim Mohammadi
Abdolkarim Mohammadi on 20 Jul 2020
Your problem is a bound-constrained problem with five decision variables. I think many solvers in the Global Optimization toolbox like GA and surrogate optimization can handle such problems efficiently.
  4 Comments
basak ozturk
basak ozturk on 15 Sep 2022
Thank you very much, I would be very happy if we answer the questions, surragate optimization is a new tool and I definitely would concentrate on it when it becomes a classic
Walter Roberson
Walter Roberson on 15 Sep 2022
NOMAD is third party code. The volunteers generally do not know anything about it.
I see that the third-party toolbox historically had a user forum. However, that appears to be closed now, as the toolbox is no longer being developed.

Sign in to comment.


Walter Roberson
Walter Roberson on 15 Sep 2022
Your function can return complex values. The ^(1/3) generates a complex result when the base expression is negative.
format long g
fun=@(x)((((x(4)*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-185)/(190-185))+...
((1-x(4))*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-195)/(190-195)))*...
(x(5)*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-185)/(190-185))+...
(1-x(5))*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-195)/(190-195)))*...
(x(6)*((140.2333+ 5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-170)/(185-170))+...
(1-x(6))*((140.2333+ 5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-195)/(185-195))))^(1/3))
fun = function_handle with value:
@(x)((((x(4)*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-185)/(190-185))+((1-x(4))*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-195)/(190-195)))*(x(5)*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-185)/(190-185))+(1-x(5))*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-195)/(190-195)))*(x(6)*((140.2333+5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-170)/(185-170))+(1-x(6))*((140.2333+5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-195)/(185-195))))^(1/3))
x0 = [1.0000 0.8629 0.5863 0 0 0]';
lb = [-1;-1;-1;0;0;0];
ub = [1;1;1;1;1;1];
ga_opts = optimoptions('ga', 'HybridFcn', 'fmincon')
ga_opts =
ga options: Set properties: HybridFcn: 'fmincon' Default properties: ConstraintTolerance: 0.001 CreationFcn: [] CrossoverFcn: [] CrossoverFraction: 0.8 Display: 'final' EliteCount: '0.05*PopulationSize' FitnessLimit: -Inf FitnessScalingFcn: @fitscalingrank FunctionTolerance: 1e-06 InitialPopulationMatrix: [] InitialPopulationRange: [] InitialScoresMatrix: [] MaxGenerations: '100*numberOfVariables' MaxStallGenerations: 50 MaxStallTime: Inf MaxTime: Inf MutationFcn: [] NonlinearConstraintAlgorithm: 'auglag' OutputFcn: [] PlotFcn: [] PopulationSize: '50 when numberOfVariables <= 5, else 200' PopulationType: 'doubleVector' SelectionFcn: [] UseParallel: 0 UseVectorized: 0
[ga_x, ga_fval, ga_exitflag, ga_info] = ga(fun, length(x0), [], [], [], [], lb, ub, [], ga_opts)
Optimization terminated: average change in the fitness value less than options.FunctionTolerance.
Error using optimfcnchk/checkfun
Supplied function '@(x)FitnessFcn(x,options.FitnessFcnArgs{:})' returned a complex value when evaluated;
FMINCON cannot continue.

Error in finDiffEvalAndChkErr

Error in finitedifferences

Error in computeFinDiffGradAndJac

Error in barrier

Error in fmincon (line 886)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...

Error in callHybrid (line 61)
[x,fval,eflag,output] = fmincon(FitnessHybridFcn,x0,Aineq,bineq,Aeq,beq,lb,ub,nonlcon,HybridFcnArgs{:});

Error in galincon/callHybridFunction (line 163)
callHybrid(hfunc,FitnessHybridFcn,x,options.HybridFcnArgs,Aineq,bineq,Aeq,beq,lb,ub,ConstrHybridFcn);

Error in galincon (line 129)
[x,fval, output.hybridflag] = callHybridFunction;

Error in ga (line 416)
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
[fmc_x, fmc_fval, fmc_exitflag, fmc_info] = fmincon(fun, x0, [], [], [], [], lb, ub, [], [])
  5 Comments
Walter Roberson
Walter Roberson on 15 Sep 2022
You can see from the below that if you permit continuous variables, then there are positions well within the bounds (not just right at the bounds) that produce complex results from the function. In my tests, roughly 45.3 % of all random configurations in-bounds produce complex results.
format long g
lb = [-1;-1;-1;0;0;0];
ub = [1;1;1;1;1;1];
N = 100;
M = length(lb);
trials = rand(M, N) .* (ub - lb) + lb;
fun=@(x)((((x(4)*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-185)/(190-185))+...
((1-x(4))*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-195)/(190-195)))*...
(x(5)*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-185)/(190-185))+...
(1-x(5))*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-195)/(190-195)))*...
(x(6)*((140.2333+ 5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-170)/(185-170))+...
(1-x(6))*((140.2333+ 5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-195)/(185-195))))^(1/3))
fun = function_handle with value:
@(x)((((x(4)*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-185)/(190-185))+((1-x(4))*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-195)/(190-195)))*(x(5)*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-185)/(190-185))+(1-x(5))*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-195)/(190-195)))*(x(6)*((140.2333+5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-170)/(185-170))+(1-x(6))*((140.2333+5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-195)/(185-195))))^(1/3))
results = zeros(1, N);
for K = 1 : N
results(K) = fun(trials(:,K));
end
mask = imag(results) ~= 0;
tp = trials(:,mask).';
x1 = tp(:,1); x2 = tp(:,2); x3 = tp(:,3); x4 = tp(:,4); x5 = tp(:,5); x6 = tp(:,6);
fval = results(mask);
fval_real = real(fval(:)); fval_imag = imag(fval(:));
T = table(fval_real, fval_imag, x1, x2, x3, x4, x5, x6);
if height(T) == 0
fprintf('Excellent, %d trials produced no complex results!\n', N);
else
fprintf('Opps, %d trials produced %d complex results!\n', N, height(T));
T
end
Opps, 100 trials produced 48 complex results!
T = 48×8 table
fval_real fval_imag x1 x2 x3 x4 x5 x6 _________________ _________________ __________________ __________________ __________________ __________________ _________________ __________________ 0.302036267914207 0.523142161755892 0.855313778814469 0.167890364370559 0.0722028543147295 0.773636892775948 0.748790637365133 0.854477000319776 0.692218663072773 1.19895789438944 -0.127728919215863 0.446704147486387 0.89215122469133 0.55399930615609 0.84959267633737 0.130278628196272 1.47901888917058 2.56173586139753 -0.846266323190261 0.359603615851935 -0.837466766233311 0.816154971675825 0.997270145172786 0.118301564702515 1.93873384508983 3.35798552204895 -0.52851829722236 -0.165609523897328 -0.247584322035819 0.981078408094133 0.935259559058378 0.988714463088133 2.98701427061245 5.17366047963406 0.742228322148513 -0.601178031646714 -0.457535097626576 0.230150076364672 0.867498124458657 0.176543685453211 1.01066193871383 1.75051782712842 -0.926501607159432 0.981109366147993 -0.585150676993805 0.467285660681846 0.697523023659257 0.0310193291640264 1.9926964985532 3.45145157955874 0.721081459950179 -0.823430131174107 0.285245074613108 0.909312596962406 0.842095142509196 0.97458936025113 2.35519833860522 4.07932318436605 0.656375255614923 -0.807051456913801 -0.755082562064693 0.262775457151212 0.946356055134857 0.550240301407202 1.26525127466414 2.19147949205958 -0.672576092089491 -0.584268041932339 0.632762234384127 0.589726591783466 0.998031020753582 0.0409425876625146 1.07933008780239 1.86945455021151 0.850412009173303 -0.277293521650321 -0.899023656825273 0.397590493694744 0.585689720864097 0.213107752684854 1.96197542672752 3.39824112229369 -0.652323322641124 -0.933325765084956 0.360206217988309 0.218356813737419 0.821102016732672 0.505683211972857 1.09188172385272 1.8911946215688 -0.299030526140808 0.735402756680416 -0.996004317623713 0.968077990873665 0.646739059040298 0.0786006489183513 2.61989576202502 4.53779257036171 -0.292347117069892 -0.526828500143656 -0.849161461114467 0.929864435897615 0.935262613586016 0.904328205780685 2.76324420891784 4.78607936356616 -0.687546163744532 -0.625164102281192 -0.33742676532606 0.0694593496238728 0.164381555058081 0.916729011788188 0.538851774640784 0.933318651426492 -0.828445883690186 0.779047799800357 -0.634560984566284 0.0799828530965894 0.531022688412337 0.295810685714847 0.370719751499232 0.642105444965979 0.778552376779659 0.605276118857012 -0.409681794006963 0.740212211899616 0.748395409921125 0.664631819919668
Walter Roberson
Walter Roberson on 15 Sep 2022
If you interpret the lb = 0 ub = 1 as being the locations of binary variables, and assume the -1 to 1 locations are continuous, then half of the random configurations lead to complex results.
format long g
lb = [-1;-1;-1;0;0;0];
ub = [1;1;1;1;1;1];
N = 1000;
M = length(lb);
trials = rand(M, N) .* (ub - lb) + lb;
trials(4:6, :) = randi([0 1], 3, N);
fun=@(x)((((x(4)*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-185)/(190-185))+...
((1-x(4))*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-195)/(190-195)))*...
(x(5)*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-185)/(190-185))+...
(1-x(5))*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-195)/(190-195)))*...
(x(6)*((140.2333+ 5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-170)/(185-170))+...
(1-x(6))*((140.2333+ 5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-195)/(185-195))))^(1/3))
fun = function_handle with value:
@(x)((((x(4)*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-185)/(190-185))+((1-x(4))*(174.9333+23.3750*x(2)+3.6250*x(3)-19.0000*x(2)*x(3)-195)/(190-195)))*(x(5)*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-185)/(190-185))+(1-x(5))*((154.8571+8.5000*x(1)+30.6250*x(2)+7.8750*x(3)-12.8571*x(1)^2+11.2500*x(1)*x(2)-195)/(190-195)))*(x(6)*((140.2333+5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-170)/(185-170))+(1-x(6))*((140.2333+5.3437*x(1)+18.2500*x(2)+19.5938*x(3)-195)/(185-195))))^(1/3))
results = zeros(1, N);
for K = 1 : N
results(K) = fun(trials(:,K));
end
mask = imag(results) ~= 0;
tp = trials(:,mask).';
x1 = tp(:,1); x2 = tp(:,2); x3 = tp(:,3); x4 = tp(:,4); x5 = tp(:,5); x6 = tp(:,6);
fval = results(mask);
fval_real = real(fval(:)); fval_imag = imag(fval(:));
T = table(fval_real, fval_imag, x1, x2, x3, x4, x5, x6);
if height(T) == 0
fprintf('Excellent, %d trials produced no complex results!\n', N);
else
fprintf('Opps, %d trials produced %d complex results!\n', N, height(T));
T
end
Opps, 1000 trials produced 499 complex results!
T = 499×8 table
fval_real fval_imag x1 x2 x3 x4 x5 x6 _________________ ________________ ___________________ __________________ __________________ __ __ __ 0.765174135811443 1.32532047986303 -0.627620563025766 0.713613270253988 -0.177459935981493 0 0 1 1.26385834049921 2.18906685931431 0.988053679562041 0.448849483369191 -0.968492181331381 1 0 1 1.54116641560331 2.66937853474375 0.0384926002740478 0.383317513499709 0.410954890582803 0 1 0 2.09028656313053 3.62048252972061 -0.754458217427597 -0.570283573899732 0.539703303215139 1 1 1 1.24452585998435 2.15558202082624 -0.923287437838263 0.194904492171103 0.332043662367417 1 1 1 1.48391019468221 2.57020785105902 0.744910334393307 0.0192149467987215 0.523744810222613 0 0 1 1.93047141268254 3.34367456932542 -0.206862798379165 -0.395886710834123 0.802344396662161 0 0 1 3.3227904702965 5.75524191745922 0.192426680560663 -0.903049473500569 0.765153552797197 0 1 0 2.06436948987523 3.57559284205894 -0.17419580241817 0.967258097554198 -0.859584603396955 0 0 0 2.26499593568055 3.92308803953572 0.377452942354955 -0.832288862539742 0.883172432788291 0 0 1 4.04268026603771 7.00212761953339 -0.340830379823908 -0.875518756058784 0.267215839543906 0 1 0 1.63217213867249 2.8270050708791 0.412029568246556 0.794782749154116 -0.925573891137459 1 1 0 5.62736559718543 9.74688312709033 -0.6661651489624 -0.847055069507603 -0.88853980262778 0 1 0 1.26087517686777 2.18389986833737 -0.877452310421777 0.5367768798219 0.0327113404834443 1 1 0 3.41773575432019 5.9196919733273 -0.173206949030919 -0.715038942268025 0.318751010348369 1 0 0 3.76902585182056 6.52814427039378 -0.0954255833206981 -0.839929714651277 -0.303185036333343 0 0 1

Sign in to comment.

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!