error in fitness function (gaoptimset) ??? despite convex function gaoptimset does not optimise 2010b
3 views (last 30 days)
Show older comments
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);
2 Comments
Accepted Answer
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
2 Comments
More Answers (1)
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!