MATLAB Answers

error in fitness function (gaoptimset) ??? despite convex function gaoptimset does not optimise 2010b

2 views (last 30 days)
Swarup on 22 May 2014
Answered: Swarup on 23 May 2014
I have a single variable objective function. This variable goes into my for loop.
irrespective of what lower and upper bonds I assign; initial range i give and with vectorize option 'on'.
does not optimize. I get following values
x: 100.000000.
fval: 8231923.58.
My objective function does have a convex behavior. this plot was generated by manually setting the forloop upto 10000
And went I set the options = gaoptimset(options,'Vectorized', 'off');
??? Subscripted assignment dimension mismatch.
Error in ==> fcnvectorizer at 14
y(i,:) = feval(fun,(pop(i,:)));
numberOfVariables = 1; % always 1
PopulationSize_input = 100; % can vary between 20 to 100
%%Bounds on our flowrate
lb =100; %100;
ub = 1000; %0.00050
%%---- parametarising Genetic algorithm-----------%%
options = gaoptimset;
% Modify options setting
%options = gaoptimset(options,'PopInitRange' ,[0 ; 0.00050]);
options = gaoptimset(options,'PopInitRange' ,[lb ; ub]);
options = gaoptimset(options,'MutationFcn' ,@mutationadaptfeasible);
options = gaoptimset(options,'CrossoverFcn' ,@crossoverarithmetic);
options = gaoptimset(options,'PopulationSize', PopulationSize_input);
options = gaoptimset(options,'Display', 'off');
options = gaoptimset(options,'PlotFcns', { @gaplotbestf @gaplotbestindiv @gaplotrange @gaplotselection });
options = gaoptimset(options,'Vectorized', 'off');
options = gaoptimset(options,'UseParallel', 'never');
%options = gaoptimset(options,'HybridFcn' ,@fminsearch);
%options = gaoptimset('OutputFcns', @gaoutputgen);
%options = gaoptimset(options,'OutputFcns' ,{ @gaplotbestf @gaplotbestindiv @gaplotrange @gaplotselection });
FitFcnn = @(f) HydraulicCOAX(f);
[x, fval] = ga(FitFcnn,numberOfVariables,[],[],[],[],lb,ub,[],options);
fprintf('The flow rate: %6.6f.\n',x);
fprintf('The Qeng: %6.2f.\n',fval);
Swarup on 23 May 2014
Hi Matt,
1) I tried using fminsearch as options = gaoptimset(options,'HybridFcn' ,@fminsearch);
??? Undefined function or variable "Q".
Error in ==> HydraulicCOAXfmin at 54 q=size(Q,2);
Error in ==> @(f)HydraulicCOAXfmin(f)
Error in ==> validate>@(x)fitness(x,FitnessFcnArgs{:}) at 136 fitness = @(x) fitness(x,FitnessFcnArgs{:});
and fminsearch
Optimization running. Error running optimization. Subscripted assignment dimension mismatch.
Is it because the for loop in my objective function takes integer values??
and the f (which come from PopulationSize =100) are not integers.
function [Peng] = HydraulicCOAXfmin(f)
for i=1:f
Q(i)= f/10/3600
for j=1:q %Rückskalieren auf m^3/h für plot

Sign in to comment.

Accepted Answer

Alan Weiss
Alan Weiss on 23 May 2014
I don't know why you think that the solver failed. From your graph, the minimum value of your objective function occurs at the point x = 0, and rises in a convex fashion as x increases. So you give a lower bound of 100 and an upper bound of 1000, and of course you find that the best point in this range is at x = 100.
It looks to me as if the solver is doing its job.
However, I am not at all sure why you are using ga on this type of function. For a smooth function, use an Optimization Toolbox solver such as fmincon.
Alan Weiss
MATLAB mathematical toolbox documentation
Swarup on 23 May 2014
Hi Matt and Alan,
Thanks, I agree, but a small argument. My single variable problem a convex shape (local minima), why dosent, GA find this mimina?
Now I am tangled a bit in my own problem, I would have to assign constraints for fminsearch and fminbnd..
[c ceq] =fltrcn(f)
c = ??
ceq = []
Thanks guys. I have been scratching my head since monday!!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!