FUNCTION REFERENCE
ga
Find a global minimum with a genetic algorithm.
Find a global minimum with a genetic algorithm.
Syntax
[x, fval, exitflag, output, population, scores] = ga(fun, nvars, A, b, Aeq, beq, lb, ub, nonlcon, options)fun receives a 1-by-nvars row. Arguments after nvars can be omitted or given
as []. A stochastic method: results depend on the random state; rng(seed)
before the call makes a run repeatable (ga draws from the rand/randn stream).
Algorithm: real-coded genetic algorithm (Goldberg 1989; Deb 2000):
binary tournament selection, 5% elite (EliteCount), CrossoverFraction 0.8 of
the other children by crossover (scattered or arithmetic with equal chance;
always arithmetic with linear constraints), the rest by Gaussian mutation whose scale (the initial
range) shrinks linearly to 0 at MaxGenerations. The initial population is
uniform within the bounds, or within a range of width 20 where a bound is
infinite. Children are repaired onto the bounds and linear constraints by
cyclic projections; nonlcon violations use Deb's feasibility rules (a feasible
point beats an infeasible one, infeasible points rank by violation).
PopulationSize 50 (nvars <= 5) else 200; MaxGenerations 100*nvars (MaxIterations
is accepted as a synonym); MaxStallGenerations 50: stop with exitflag 1 when
the average change of the best fitness over that window is below
FunctionTolerance (1e-6). Exitflag 0: generation or evaluation budget; -2: no
feasible point. output has problemtype, generations, funccount, message and
maxconstraint. Differences from MATLAB: populations and results differ for the
same seed (different internals); no intcon, hybrid or plot functions.
Example
rng(1); [x,f]=ga(@(x)(x(1)-1)^2+(x(2)-2)^2,2,[],[],[],[],[-5 -5],[5 5])These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.