Genetic Algorithm Options 您所在的位置:网站首页 matlab遗传算法ga函数options介绍 Genetic Algorithm Options

Genetic Algorithm Options

2023-08-13 03:56| 来源: 网络整理| 查看: 265

Genetic Algorithm OptionsOptions for Genetic Algorithm

Set options for ga by using optimoptions.

options = optimoptions('ga','Option1','value1','Option2','value2');

Some options are listed in italics. These options do not appear in the listing that optimoptions returns. To see why 'optimoptions hides these option values, see Options that optimoptions Hides.

Ensure that you pass options to the solver. Otherwise, patternsearch uses the default option values.

[x,fval] = ga(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)Plot Options

PlotFcn specifies the plot function or functions called at each iteration by ga or gamultiobj. Set the PlotFcn option to be a built-in plot function name or a handle to the plot function. You can stop the algorithm at any time by clicking the Stop button on the plot window. For example, to display the best function value, set options as follows:

options = optimoptions('ga','PlotFcn','gaplotbestf');

To display multiple plots, use a cell array of built-in plot function names or a cell array of function handles:

options = optimoptions('patternsearch',... 'PlotFcn', {@plotfun1, @plotfun2, ...});

where @plotfun1, @plotfun2, and so on are function handles to the plot functions. If you specify more than one plot function, all plots appear as subplots in the same window. Right-click any subplot to obtain a larger version in a separate figure window.

Available plot functions for ga or for gamultiobj:

'gaplotscorediversity' plots a histogram of the scores at each generation.

'gaplotstopping' plots stopping criteria levels.

'gaplotgenealogy' plots the genealogy of individuals. Lines from one generation to the next are color-coded as follows:

Red lines indicate mutation children.

Blue lines indicate crossover children.

Black lines indicate elite individuals.

'gaplotscores' plots the scores of the individuals at each generation.

'gaplotdistance' plots the average distance between individuals at each generation.

'gaplotselection' plots a histogram of the parents.

'gaplotmaxconstr' plots the maximum nonlinear constraint violation at each generation. For ga, available only when the NonlinearConstraintAlgorithm option is 'auglag' (default for non-integer problems). Therefore, not available for integer-constrained problems, as they use the 'penalty' nonlinear constraint algorithm.

You can also create and use your own plot function. Structure of the Plot Functions describes the structure of a custom plot function. Pass any custom function as a function handle.

The following plot functions are available for ga only:

'gaplotbestf' plots the best score value and mean score versus generation.

'gaplotbestindiv' plots the vector entries of the individual with the best fitness function value in each generation.

'gaplotexpectation' plots the expected number of children versus the raw scores at each generation.

'gaplotrange' plots the minimum, maximum, and mean score values in each generation.

The following plot functions are available for gamultiobj only:

'gaplotpareto' plots the Pareto front for the first two or three objective functions.

'gaplotparetodistance' plots a bar chart of the distance of each individual from its neighbors.

'gaplotrankhist' plots a histogram of the ranks of the individuals. Individuals of rank 1 are on the Pareto frontier. Individuals of rank 2 are lower than at least one rank 1 individual, but are not lower than any individuals from other ranks, etc.

'gaplotspread' plots the average spread as a function of iteration number.

Structure of the Plot Functions

The first line of a plot function has this form:

function state = plotfun(options,state,flag)

The input arguments to the function are

options — Structure containing all the current options settings.

state — Structure containing information about the current generation. The State Structure describes the fields of state.

flag — Description of the stage the algorithm is currently in. For details, see Output Function Options.

Passing Extra Parameters explains how to provide additional parameters to the function.

The output argument state is a state structure as well. Pass the input argument, modified if you like; see Changing the State Structure. To stop the iterations, set state.StopFlag to a nonempty character vector, such as 'y'.

The State Structure

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

Generation — Current generation number.

StartTime — Time when genetic algorithm started, returned by tic.

StopFlag — Reason for stopping, a character vector.

LastImprovement — Generation at which the last improvement in fitness value occurred.

LastImprovementTime — Time at which last improvement occurred.

Best — Vector containing the best score in each generation.

how — The 'augLag' nonlinear constraint algorithm reports one of the following actions: 'Infeasible point', 'Update multipliers', or 'Increase penalty'; see Augmented Lagrangian Genetic Algorithm.

FunEval — Cumulative number of function evaluations.

Expectation — Expectation for selection of individuals.

Selection — Indices of individuals selected for elite, crossover, and mutation.

Population — Population in the current generation.

Score — Scores of the current population.

NonlinIneq — Nonlinear inequality constraints at current point, present only when a nonlinear constraint function is specified, there are no integer variables, flag is not 'interrupt', and NonlinearConstraintAlgorithm is 'auglag'.

NonlinEq — Nonlinear equality constraints at current point, present only when a nonlinear constraint function is specified, there are no integer variables, flag is not 'interrupt', and NonlinearConstraintAlgorithm is 'auglag'.

EvalElites — Logical value indicating whether ga evaluates the fitness function of elite individuals. Initially, this value is true. In the first generation, if the elite individuals evaluate to their previous values (which indicates that the fitness function is deterministic), then this value becomes false by default for subsequent iterations. When EvalElites is false, ga does not reevaluate the fitness function of elite individuals. You can override this behavior in a custom plot function or custom output function by changing the output state.EvalElites.

HaveDuplicates — Logical value indicating whether ga adds duplicate individuals for the initial population. ga uses a small relative tolerance to determine whether an individual is duplicated or unique. If HaveDuplicates is true, then ga locates the unique individuals and evaluates the fitness function only once for each unique individual. ga copies the fitness and constraint function values to duplicate individuals. ga repeats the test in each generation until all individuals are unique. The test takes order n*m*log(m) operations, where m is the population size and n is nvars. To override this test in a custom plot function or custom output function, set the output state.HaveDuplicates to false.

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

Population — Population in the current generation

Score — Scores of the current population, a Population-by-nObjectives matrix, where nObjectives is the number of objectives

Generation — Current generation number

StartTime — Time when genetic algorithm started, returned by tic

StopFlag — Reason for stopping, a character vector

FunEval — Cumulative number of function evaluations

Selection — Indices of individuals selected for elite, crossover, and mutation

Rank — Vector of the ranks of members in the population

Distance — Vector of distances of each member of the population to the nearest neighboring member

AverageDistance — Standard deviation (not average) of Distance

Spread — Vector where the entries are the spread in each generation

mIneq — Number of nonlinear inequality constraints

mEq — Number of nonlinear equality constraints

mAll — Total number of nonlinear constraints, mAll = mIneq + mEq

C — Nonlinear inequality constraints at current point, a PopulationSize-by-mIneq matrix

Ceq — Nonlinear equality constraints at current point, a PopulationSize-by-mEq matrix

isFeas — Feasibility of population, a logical vector with PopulationSize elements

maxLinInfeas — Maximum infeasibility with respect to linear constraints for the population

Population Options

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

PopulationType specifies the type of input to the fitness function. Types and their restrictions are:

'doubleVector' — Use this option if the individuals in the population have type double. Also, the recommended data type for mixed integer programming is 'doubleVector', using the technique in Mixed Integer ga Optimization. 'doubleVector' is the default data type.

'bitstring' — You can use this option if the individuals in the population have components that are 0 or 1.

Caution

The individuals in a Bit string population are vectors of type double, not strings or characters.

For CreationFcn and MutationFcn, use 'gacreationuniform' and 'mutationuniform' or handles to custom functions. For CrossoverFcn, use 'crossoverscattered', 'crossoversinglepoint', 'crossovertwopoint', or a handle to a custom function.

The 'bitstring' data type can be awkward to use. ga ignores all constraints, including bounds, linear constraints, and nonlinear constraints. You cannot use a HybridFcn. To use binary variables most easily in ga, see Mixed Integer ga Optimization.

'custom' — Indicates a custom population type. In this case, you must also use a custom CrossoverFcn and MutationFcn. You must provide either a custom creation function or an InitialPopulationMatrix. You cannot use a HybridFcn, and ga ignores all constraints, including bounds, linear constraints, and nonlinear constraints.

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 returns a local minimum that is not a global minimum. However, a large population size also causes the algorithm to run more slowly. The default is '50 when numberOfVariables



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有