| Genetic Algorithm and Direct Search Toolbox | ![]() |
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.
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
See Also
| Alphabetical List of Functions | gaoptimget | ![]() |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |