Genetic Algorithm Options

Optimization Tool vs. Command Line

There are two ways to specify options for the genetic algorithm, depending on whether you are using the Optimization Tool or calling the functions ga or at the command line:

In this section, each option is listed in two ways:

For example:

Plot Options

Plot options enable you to plot data from the genetic algorithm while it is running. When you select plot functions and run the genetic algorithm, a plot window displays the plots on separate axes. Click on any subplot to view a larger version of the plot in a separate figure window. You can stop the algorithm at any time by clicking the Stop button on the plot window.

Plot interval (PlotInterval) specifies the number of generations between consecutive calls to the plot function.

You can select any of the following plot functions in the Plot functions pane:

To display a plot when calling ga from the command line, set the PlotFcns field of options to be a function handle to the plot function. For example, to display the best fitness plot, set options as follows

options = gaoptimset('PlotFcns', @gaplotbestf);

To display multiple plots, use the syntax

options =gaoptimset('PlotFcns', {@plotfun1, @plotfun2, ...});

where @plotfun1, @plotfun2, and so on are function handles to the plot functions.

Structure of the Plot Functions

The first line of a plot function has the form

function state = plotfun(options, state, flag)

The input arguments to the function are

Passing Extra Parameters in the Optimization Toolbox™ User's Guide explains how to provide additional parameters to the function.

The State Structure

The state structure, which is an input argument to plot, mutation, and output functions, contains the following fields:

Population Options

Population options enable you to specify the parameters of the population that the genetic algorithm uses.

Population type (PopulationType) specifies the data type of the input to the fitness function. You can set Population type to be one of the following:

Population size (PopulationSize) specifies how many individuals there are in each generation. With a large population size, the genetic algorithm searches the solution space more thoroughly, thereby reducing the chance that the algorithm will return a local minimum that is not a global minimum. However, a large population size also causes the algorithm to run more slowly.

If you set Population size to a vector, the genetic algorithm creates multiple subpopulations, the number of which is the length of the vector. The size of each subpopulation is the corresponding entry of the vector.

Creation function (CreationFcn) specifies the function that creates the initial population for ga. You can choose from the following functions:

Initial population (InitialPopulation) specifies an initial population for the genetic algorithm. The default value is [], in which case ga uses the default Creation function to create an initial population. If you enter a nonempty array in the Initial population field, the array must have no more than Population size rows, and exactly Number of variables columns. In this case, the genetic algorithm calls a Creation function to generate the remaining individuals, if required.

Initial scores (InitialScores) specifies initial scores for the initial population. The initial scores can also be partial.

Initial range (PopInitRange) specifies the range of the vectors in the initial population that is generated by a creation function. You can set Initial range to be a matrix with two rows and Number of variables columns, each column of which has the form [lb; ub], where lb is the lower bound and ub is the upper bound for the entries in that coordinate. If you specify Initial range to be a 2-by-1 vector, each entry is expanded to a constant row of length Number of variables.

See Example — Setting the Initial Range for an example.

Fitness Scaling Options

Fitness scaling converts the raw fitness scores that are returned by the fitness function to values in a range that is suitable for the selection function. You can specify options for fitness scaling in the Fitness scaling pane.

Scaling function (FitnessScalingFcn) specifies the function that performs the scaling. The options are

See Fitness Scaling for more information.

Selection Options

Selection options specify how the genetic algorithm chooses parents for the next generation. You can specify the function the algorithm uses in the Selection function (SelectionFcn) field in the Selection options pane. The options are

See Selection for more information.

Reproduction Options

Reproduction options specify how the genetic algorithm creates children for the next generation.

Elite count (EliteCount) specifies the number of individuals that are guaranteed to survive to the next generation. Set Elite count to be a positive integer less than or equal to the population size. The default value is 2.

Crossover fraction (CrossoverFraction) specifies the fraction of the next generation, other than elite children, that are produced by crossover. Set Crossover fraction to be a fraction between 0 and 1, either by entering the fraction in the text box or moving the slider. The default value is 0.8.

See Setting the Crossover Fraction for an example.

Mutation Options

Mutation options specify how the genetic algorithm makes small random changes in the individuals in the population to create mutation children. Mutation provides genetic diversity and enable the genetic algorithm to search a broader space. You can specify the mutation function in the Mutation function (MutationFcn) field in the Mutation options pane. You can choose from the following functions:

Crossover Options

Crossover options specify how the genetic algorithm combines two individuals, or parents, to form a crossover child for the next generation.

Crossover function (CrossoverFcn) specifies the function that performs the crossover. You can choose from the following functions:

Migration Options

Migration options specify how individuals move between subpopulations. Migration occurs if you set Population size to be a vector of length greater than 1. When migration occurs, the best individuals from one subpopulation replace the worst individuals in another subpopulation. Individuals that migrate from one subpopulation to another are copied. They are not removed from the source subpopulation.

You can control how migration occurs by the following three fields in the Migration options pane:

Algorithm Settings

Algorithm settings define algorithmic specific parameters.

Parameters that can be specified for a nonlinear constraint algorithm include

Multiobjective Options

Multiobjective options define parameters characteristic of the multiobjective genetic algorithm. You can specify the following parameters:

Hybrid Function Options

A hybrid function is another minimization function that runs after the genetic algorithm terminates. You can specify a hybrid function in Hybrid function (HybridFcn) options. The choices are

You can set a separate options structure for the hybrid function. Use psoptimset or optimset to create the structure, depending on whether the hybrid function is patternsearch or not:

hybridopts = optimset('display','iter','LargeScale','off');

Include the hybrid options in the Genetic Algorithm options structure as follows:

options = gaoptimset(options,'HybridFcn',{@fminunc,hybridopts}); 

hybridopts must exist before you set options.

See Using a Hybrid Function for an example.

Stopping Criteria Options

Stopping criteria determine what causes the algorithm to terminate. You can specify the following options:

See Setting the Maximum Number of Generations for an example.

Output Function Options

Output functions are functions that the genetic algorithm calls at each generation. The following options are available:

History to new window (@gaoutputgen) displays the history of points computed by the algorithm in a new window at each multiple of Interval iterations.

Custom enables you to write your own output function. To specify the output function using the Optimization Tool,

If you are using ga, set

options = gaoptimset('OutputFcn',@myfun);

To see a template that you can use to write your own output functions, enter

edit gaoutputfcntemplate

at the MATLAB command line.

Structure of the Output Function

The output function has the following calling syntax.

[state,options,optchanged] = myfun(options,state,flag,interval)

The function has the following input arguments:

Passing Extra Parameters in the Optimization Toolbox User's Guide explains how to provide additional parameters to the function.

The output function returns the following arguments to ga:

Display to Command Window Options

Level of display ('Display') specifies how much information is displayed at the command line while the genetic algorithm is running. The available options are

Both Iterative and Diagnose display the following information:

When a nonlinear constraint function has been specified, Iterative and Diagnose will not display the Mean f(x), but will additionally display:

The default value of Level of display is

Vectorize Option

The vectorize option specifies whether the computation of the fitness function is vectorized. Set Set Objective function is vectorized to On to indicate that the fitness function is vectorized. When Objective function is vectorized is Off, the algorithm calls the fitness function on one individual at a time as it loops through the population.

See Vectorizing the Fitness Function for an example.

Parallel Option

Specifies whether ga or gamultiobj evaluates populations in parallel, using multiple processes or processors, or evaluates them serially. Set UseParallel to 'always' to evaluate in parallel. Set UseParallel to 'never' to evaluate serially.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS