1

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.

  • No input for `GaFitness()`? – Adam Jun 25 '19 at 18:50
  • Well, I'm trying to figure out what my input needs to be, also my output. I assume it will be a chromosome which is a set of rules for a fuzzy controller. This is my Q&A about my problem: [link](https://stackoverflow.com/questions/56689104/ga-custom-integer-selection-with-roulette-wheel) –  Jun 25 '19 at 19:06
  • What's the function you want to optimize? `GaFitness()` takes a chromosome as input and returns a value, the higher values one get their chromosome selected for `RouletteWheelSelection` tournament – Adam Jun 25 '19 at 19:26
  • @adam.Yes, I want to optimize `GaFitness()`, more precisely Fuzzy control rules inside `GaFitness`. So, I assume input will be a set of rules (chromosome, exp.: [`1,2,3,1,1..]` and based on that input, return a result of xy variable that was impacted of new fuzzy settings. –  Jun 25 '19 at 20:49
  • 1
    Perhaps [this example](https://stackoverflow.com/a/42838593/3372061) could help you. – Dev-iL Jun 26 '19 at 10:16
  • @Dev-iL thanks, I will give it a try today or tomorrow. –  Jun 26 '19 at 14:14
  • @Dev-iL I looked at your answer that you linked and basically if I understood right, inputs are irrelevant, but the output must be as documented. In ˙GaFitness˙ input will be chromosome, and output result I want to minimize. Could you help me with other functions? (Mutation/Selection) Where can I look at what they need for input/output? Some example maybe? –  Jun 27 '19 at 20:38

0 Answers0