1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| Genetic Algorithm and Direct Search Toolbox ga
Find the minimum of a function using the genetic algorithm
Syntax
x = ga(fitnessfun, nvars)
x = ga(fitnessfun, nvars, options)
x = ga(problem)
[x, fval] = ga(...)
[x, fval, reason] = ga(...)
[x, fval, reason, output] = ga(...)
[x, fval, reason, output, population] = ga(...)
[x, fval, reason, output, population, scores] = ga(...)
Description
ga implements the genetic algorithm at the command line to minimize an objective function.
x = ga(fitnessfun, nvars) applies the genetic algorithm to an optimization problem, where fitnessfun is the objective function to minimize and nvars is the length of the solution vector x, the best individual found.
x = ga(fitnessfun, nvars, options) applies the genetic algorithm to an optimization problem, using the parameters in the options structure.
x = ga(problem) finds the minimum for problem, a structure that has three fields: fitnessfcn -- Fitness function nvars -- Number of independent variables for the fitness function options -- Options structure created with gaoptimset
[x, fval] = ga(...) returns fval, the value of the fitness function at x.
[x, fval, reason] = ga(...) returns reason, a string containing the reason the algorithm stops.
[x, fval, reason, output] = ga(...) returns output, a structure that contains output from each generation and other information about the performance of the algorithm. The output structure contains the following fields: randstate -- The state of rand, the MATLAB random number generator, just before the algorithm started. randnstate -- The state of randn the MATLAB normal random number generator, just before the algorithm started. You can use the values of randstate and randnstate to reproduce the output of ga. See Reproducing Your Results. generations -- The number of generations computed funccount -- The number of evaluations of the fitness function message -- The reason the algorithm terminated. This message is the same as the output argument reason.
[x, fval, reason, output, population] = ga(...) returns matrix population, whose rows are the final population.
[x, fval, reason, output, population, scores] = ga(...) returns scores, the scores of the final population.
Note For problems that use the population type Double Vector (the default), ga does not accepts functions whose inputs are of type complex. To solve problems involving complex data, write your functions so that they accept real vectors, by separating the real and imaginary parts.
Example
[x fval, reason] = ga(@rastriginsFcn, 10)
x =
Columns 1 through 7
0.9977 0.9598 0.0085 0.0097 -0.0274 -0.0173 0.9650
Columns 8 through 10
-0.0021 -0.0210 0.0065
fval =
3.7456
reason =
generations
Reference
[1] Goldberg, David E., Genetic Algorithms in Search, Optimzation & Machine Learning, Addison-Wesley, 1989.
See Also
gaoptimset, gatool |
Partager