Reputation: 464
I have a GA with a vectorized fitness function, which works as expected:
objFunc = @(N) -fitfun(N, foo, NUM);
[ N, ~, ~, ~, ~, ~ ] = ga(objFunc, 3 * NUM, [], [], [], [], ...
[], [], [], options);
When bounds are introduced, it doesn't anymore:
UB = Inf(1, 3 * NUM);
LB = -UB;
for i = 3 : 3 : 3 * NUM
LB(i) = 3000;
UB(i) = 9000;
end
objFunc = @(N) -fitfun(N, foo, NUM);
[ N, ~, ~, ~, ~, ~ ] = ga(objFunc, 3 * NUM, [], [], [], [], ...
LB, UB, [], options);
Corresponding stack trace:
> Error using delaunayTriangulation/convexHull
The triangulation is empty.
> Error in fitfun (line 66)
[ facets, volume(i) ] = convexHull(DT);
> Error in run_fitfun>@(N)-fitfun(N,foo,NUM) (line 127)
objFunc = @(N) -fitfun(N, foo, NUM);
> Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
> Error in makeState (line 64)
Score = FitnessFcn(state.Population(initScoreProvided+1:end,:));
> Error in galincon (line 17)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
> Error in ga (line 359)
[x,fval,exitFlag,output,population,scores] =
galincon(FitnessFcn,nvars, ...
> Error in run_fitfun (line 140)
[ N, ~, ~, ~, ~, ~ ] = ga(objFunc, 3 * NUM, [], [], [], [], ...
> Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot
continue.
To be clear, I have set 'MutationFcn', @mutationadaptfeasible
, and have also tried it with 'Vectorized', 'off'
.
EDIT:
As it turns out, I have 'PopInitRange', [ 5000; 7000 ]
set in the options, but the first (zeroeth?) generation of the GA shows that the incoming vector has LB (3000) set for every third variable, causing the delaunayTriangulation
to be obviously empty.
N2 = reshape(N(i,:), 3, NUM).'
N2 =
1.0e+03 *
-0.0009 -0.0007 3.0000
0.0007 -0.0002 3.0000
-0.0005 0.0019 3.0000
0.0002 0.0005 3.0000
0.0021 -0.0009 3.0000
0.0009 0.0015 3.0000
-0.0007 -0.0005 3.0000
-0.0008 -0.0013 3.0000
-0.0004 0.0020 3.0000
-0.0001 0.0003 3.0000
0.0011 0.0010 3.0000
0.0015 0.0010 3.0000
0.0009 0.0013 3.0000
-0.0008 -0.0010 3.0000
-0.0005 0.0010 3.0000
-0.0002 0.0020 3.0000
-0.0003 -0.0001 3.0000
0.0002 0.0015 3.0000
-0.0008 0.0010 3.0000
-0.0007 0.0017 3.0000
0.0005 0.0018 3.0000
-0.0002 -0.0003 3.0000
-0.0006 0.0010 3.0000
-0.0000 0.0008 3.0000
-0.0006 -0.0012 3.0000
This seems like a case of the GA not respecting the initial population seeding range, even though it is clearly within the specified bounds. What could be a way around this?
Upvotes: 0
Views: 2982
Reputation: 1320
My first guess would be to set CreationFcn
to for instance @gacreationuniform
, but this does not work: the ga implementation still exhibits the default behavior and evaluates a vector of which the entries are equal to the lower bound values (if these lower bounds are finite).
A solution that does force a different first vector is providing this vector in the InitialPopulation
field of the options. (Note: make sure that your inital vector does satisfy the bounds and constraints, otherwise, ga
will still use his approach of evaluating the lower bound)
I hope that solves your problem.
By the way, you could include a constraint that checks if the triangulation will work (use a nonlcon
constraint function for that).
Upvotes: 1