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

1 次查看(过去 30 天)
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 个评论
Swarup
Swarup 2014-5-23
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
rho=999.702;
eta=1305.875E-6;
vi(i)=Q(i)/((rii^2)*pi);
...
...
end
q=size(Q,2)
for j=1:q %Rückskalieren auf m^3/h für plot
Q(j)=Q(j)*3600;
end
end

请先登录,再进行评论。

采纳的回答

Alan Weiss
Alan Weiss 2014-5-23
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 个评论
Matt J
Matt J 2014-5-23
编辑:Matt J 2014-5-23
For a smooth function, use an Optimization Toolbox solver such as fmincon.
Since it is a one-variable problem, you could even just use fminsearch or fminbnd by itself (not within ga).
Swarup
Swarup 2014-5-23
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 = []
end
Thanks guys. I have been scratching my head since monday!!

请先登录,再进行评论。

更多回答(1 个)

Swarup
Swarup 2014-5-23
Thanks for your suggestions Matt and Alan. Regards, Swarup

类别

Help CenterFile Exchange 中查找有关 Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by