Borrar filtros
Borrar filtros

Global optimization for Rastrigin's function

5 visualizaciones (últimos 30 días)
Sata
Sata el 29 de Oct. de 2012
The code for Rastrigin function, rastriginsfcn.m are as follows:
function scores = rastriginsfcn(pop)
% pop = max(-5.12,min(5.12,pop));
scores = 10.0 * size(pop,2) + sum(pop .^2 - 10.0 * cos(2 * pi .* pop),2);
The following are the codes to optimize the rastrigin’s function:
rf2 = @(x)rastriginsfcn(x/10);
x0 = [20,30]; % start point away from the minimum
initpop = 10*randn(20,2) + repmat([10 30],20,1);
opts = gaoptimset('InitialPopulation',initpop);
[xga fga flga oga] = ga(rf2,2,[],[],[],[],[],[],[],opts);
1) When I run the above codes, I only got the following optimization terminated information without the output for xga fga flga oga,
why?
Optimization terminated: average change in the fitness value less than options.TolFun.
2) If I use the toolbox with GA solver, how to include the following information into rastriginsfcn.m?
- how to include “x0 = [20,30];
% start point away from the minimum”?
- how to include random numbers to be generated as intial population
“initpop = 10*randn(20,2) + repmat([10 30],20,1);”
3) To create a fitness function for GA, are there any functions for me to specify my chromosome?
4) Where can I find more examples of GA fitness function besides Rastrigin's function?
5) When should I use the toolbox with GA solver and when should I use the command line? Which one is easier? Can I perform exactly the same tasks in command line and by using toolbox? For the same problem, do I need to create 2 different fitness functions? One for command line and one for toolbox? Is it possible for me to run the fitness function which I use in command line to directly use it in toolbox without any amendments?

Respuestas (1)

Alan Weiss
Alan Weiss el 29 de Oct. de 2012
I think you would do yourself a favor to read the documentation, and try to work the examples. But to answer your questions:
1. Leave off the semicolon to see the output:
[xga fga flga oga] = ga(rf2,2,[],[],[],[],[],[],[],opts) % no semicolon at end
2. You give the answer to the question yourself. I do not understand what you do not understand.
5. You can solve all problems either way, command line or GUI, they are entirely equivalent. But yout will probably do better NOT to use GA at all, but instead to use PATTERNSEARCH, which is a faster, more robust, and easier-to-tune solver.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by