Global optimization using genetic algorithm

I use ff2n function to generate the input for my function. For the example of ff2n(4), some sample input rows are:
1 0 1 0
1 1 0 0
0 0 1 1
...
...
Based on the input from ff2n(4), a total of 16 scalar values will be generated for my function. If I sorted the 16 scalar values generated, I will be able to find the minimum value.
Can I use GA to find the minimum value for my function based on the following commands?
>> [x fval exitflag] = ga(@my_fun, 2)
My input values are fixed, which are 0 and 1. Can I consider the total number of variables as 2? Is it possible for me to get the following sample output:
x = 1 1 0 0
fval = 0.12345
exitflag = 1
If this GA command is inapplicable, please give me some suggestions how can I use GA to solve my problem.
Alternatively, in order to get the x and fval values, can I use the optimization toolbox by choosing GA solver, enter my fitness function, put 2 as number of variables and run it?

Answers (1)

You might do well to read the documentation on ga with integer constraints. If I understand you, for this case you have n = 4 dimensions, not 2, because there are 4 design variables. Each design variable is binary, so is integer valued with a lower bound of 0 and an upper bound of 1.
Alan Weiss
MATLAB mathematical toolbox documentation

4 Comments

May I clarify, my input values are real numbers. For example, based on ff2n(4), I replace 0 and 1 with 3.98765 (variable x) and 4.98765 (variable y). So the sample input rows are:
4.98765 3.98765 4.98765 3.98765;
4.98765 4.98765 3.98765 3.98765;
3.98765 3.98765 4.98765 4.98765;
...;
...
1) There are only 2 input variables used for each row but with different combinations, so is it confirm n = 4 dimension (i.e number of variables = 4)?
2) Each row of the input will produce a scalar value for my fitness function. So the GA crossover operator will perform the re-combination for x (3.98765) and y (4.98765). How do I produce the codes for this crossover in my function? For example, based on the roulette wheel selection, each generation will produce a value for my fitness function and the GA will stop when the minimum value for my fitness function is found. Again, how to do the coding for this information? Basically, how are the MATLAB coding like for chromosome, crossover, selection and all the necessary codes for GA?
3 For my problem here, mutation is inapplicable, because I don’t want to mutate (alter) my x (3.98765) and y (4.98765) values (only crossover for each row to re-combine x and y values). So, if I use GA command line, how to disable the mutation operator? Similarly, to use toolbox with GA solver, how to disable the mutation operator? In another way, how to specify that I need only crossover without mutation? Without involving mutation, is it call evolutionary algorithm or can I still call it as Genetic Algorithm.
4) My input values are fixed real numbers (i.e. x = 3.98765 and y = 4.98765), so is setting of lower and upper bounds critical?
Basically my 0 < x < 5 and 0 < y < 5. If I use the toolbox, how to set the bounds as vectors for the followings?
lb = zeros(N,1);
ub = 5*ones(N,1);
Here N is the number of dimensions.
Perhaps this example will show you how to use integer ga to solve your problem.
Your population looks 4-dimensional to me, with each component given as one of two different values. This can be mapped to integer (binary) variables, as in the example. To get those two values, set the x components as integers with lower bounds of 0 and upper bounds of 1, and map
y = x0 + (x1 - x0)*x
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
where x0 is your lower number 3.98765 and x1 is your upper number 4.98765.
Sata
Sata on 1 Nov 2012
Edited: Sata on 5 Nov 2012
Hi Alan,
1) I agreed with you that this is a problem of 4-dimensional with each component given as one of the two different values. What is the different to use my actual real numbers for variable x (3.98765) and y (4.98765) instead of using binary numbers of 0 and 1 to map?
2) Basically my 0 < x < 5 and 0 < y < 5, if we map it with binary number with lb = 0 and ub = 1, does it match?
3) Sorry, can you explain further about the mapping example you mentioned earlier:
y = x0 + (x1 - x0)*x
y = 3.98765 + (4.98765 - 3.98765)*x --> what information can I get?
4) Can somebody answer my previous (Q3) regarding mutation operator? i.e. what do I do if mutation is inapplicable in my problem..

Sign in to comment.

Asked:

on 23 Oct 2012

Community Treasure Hunt

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

Start Hunting!