问题
It is hard for me to find Documentation on how to write signatures of my custom selection, mutation, crossover functions for Genetic Algorithm.
I can't figure out how ga() functions works. (I know this exists: link ), but how these functions communicate, what they are expecting for inputs and for outputs?
Q&A, More about my problem: link
This are my GA options:
options = gaoptimset(...
'PopulationSize', 10, ...
'Generations', 50, ...
'CrossoverFcn', {'crossoverscattered'}, ...
'MutationFcn', { @Mutation, 0.01 }, ...
'SelectionFcn', { @RouletteWheelSelection }, ...
'UseParallel', true, ...
'Display', 'iter' ...
);
My GA function:
lb = 1; % Lower bound on x
ub = 3; % Upper bound on x
nvars = 1;
x = ga(@GaFitness,nvars,[],[],[],[],lb,ub,[],[],options);
My GaFitness Fcn signature (for now):
function result = GaFitness()
My Mutation function signature:
function chromosome = Mutation( chromosome )
My Selection function signature:
function selected_chromosome = RouletteWheelSelection( population )
If you need more info about my problem or more code, pls let me know.
This is Error I'm getting:
Error using GaFitness
Too many input arguments.
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in galincon (line 17)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 374)
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
Using Matlab 2016b.
来源:https://stackoverflow.com/questions/56759269/how-to-write-signature-of-custom-ga-functions-selection-mutation-crossover