GEATbx: Main page  Tutorial  Algorithms  M-functions  Parameter/Options  Example functions  www.geatbx.com

# 12 Special initialization options

Aside from the standard initialization (uniform at random) the user may initialize a number of individuals and provide the resulting population matrix as fourth input parameter to geamain2. An application-specific initialization gives the chance of incorporating application-specific knowledge. The number of individuals in the initial population can be anything from 1 to Inf, only the number of variables must be correct (the same as defined in System.ObjFunVarBounds). All adjustments are done in initpop automatically using the following options.

The preinitialized population is send to initpop. The following options control:

• how many of these preinitialized individuals are used unchanged (Special.InitPresetKeep),
• how many individuals are created uniform at random (Special.InitUniformCreate),
• how much further individuals are randomized around the preinitialized individuals (normal randomization). The number of normally randomized individuals is the remainder of the above two proportions and the size of the population.

The function initpop contains some examples (help initpop). The format of the variables (real, integer, binary, permutation variables - VariableFormat) is always considered.

### Special.InitPresetKeep

This option controls how many preinitialized individuals (percentage of population size) should be kept unchanged in the population. If less preinitialized individuals are provided, all these individuals are kept unchanged in initial population. If more individuals are provided, only the defined percentage is kept in the initial population (individuals are selected uniform at random).

• Default value: 0.5
• Type: scalar in [0, 1]
• The following variants are available:
• 0: keep none of the preinitialized individuals unchanged
• > 0: scalar (percentage of population size) how many individuals from the initial population to copy to population of the first generation
• example 0.2: keep not more than 20% of provided individuals in population
• Example - set percentage of unchanged preinitialized individuals to not more than 80%:
`GeaOpt = geaoptset(GeaOpt, 'Special.InitPresetKeep', 0.8);`

### Special.InitUniformCreate

This option controls how many individuals are created uniform at random (standard initialization, uniform at random in the domain of the variables - System.ObjFunVarBounds). The proportion of uniform individuals has an lower priority than the proportion of unchanged individuals (Special.InitPresetKeep). If the number of missing individuals is smaller than defined in Special.InitUniformCreate, only the remaining proportion is created uniform at random.

• Default value: 0.5
• Type: scalar in [0, 1]
• Example - set the percentage of uniformly created individuals to 40%:
`GeaOpt = geaoptset(GeaOpt, 'Special.InitUniformCreate', 0.4);`

### Special.InitPresetRand

This option controls how much preinitialized individuals are normally randomized. The number of normally randomized individuals is the remainder after keeping individuals unchanged (Special.InitPresetKeep) and creating individuals uniform at random (Special.InitUniformCreate).
The normally randomized individuals are randomized around preinitialized individuals. This method is called innoculation. The level of randomization is such, that 1.0 corresponds to the domain of the search space. Nevertheless, the variables of the randomized individuals may be outside the defined boundaries. Currently, the variables are not reset to the boundaries (this is a feature).

• Default value: 0.25
• Type: scalar in [0, 1]
• Example - set randomization of provided individuals to 0.5:
`GeaOpt = geaoptset(GeaOpt, 'Special.InitPresetRand', 0.5);`

The following two options (Special.InitDo and Special.InitFunction) are obsolete. You may initialize a number of individuals and provide the resulting population matrix as fourth input parameter to geamain2. This new way (version 3.x) is much more flexible. Nevertheless, for a limited time the use of an application-specific initialization function inside geamain2 is supported.

### Special.InitDo

This option switches initialization with an application-specific initialization function on or off.

• Default value: 0
• Type: integer in {0, 1}
• Two variants are available:
• 0: do not use a special initialization function
• 1: use a special initialization function
• Example - switch use of special initialization function on:
`GeaOpt = geaoptset(GeaOpt, 'Special.InitDo', 1);`
• Special feature: if Special.InitDo is larger than 10, a graphical representation of the initial population is plotted. This graphic may be used to test the special initialization. To use this feature, provide an initial population (fourth input parameter to geamain2 or by employing a special initialization function) and set Special.InitDo to 11 or higher. When the initial population is provided as fourth input parameter, Special.InitFunction should be set to an empty string.
• Example - provide some individuals for special initialization and visualize the full initial population:
```PopInit = [ 1 2 3 4 5; 10 9 8 7 6]; % Defines two initial individuals
GeaOpt = geaoptset(GeaOpt, 'Special.InitDo', 11, ...
'Special.InitFunction', '');
[x, GeaOptOut] = geamain2('objfun8', GeaOpt, VLUB, PopInit);```
• Option number in previous versions: 42 (2.x), 29 (1.x)

### Special.InitFunction

This option contains the function name of the application specific initialization function.

• Default value: ' '
• Type: string
• Example - set the function name of the special initialization function to 'initdopi':
`GeaOpt = geaoptset(GeaOpt, 'Special.InitFunction', 'initdopi');`
• The special initialization function ('initdopi') is called very similar to the objective function ('objdopi').
Call of objective function (Chrom contains current population, method, TSTART and TEND are additional parameters):
[ObjVal, t, x] = objdopi(Chrom, method, TSTART, TEND)

Call of special initialization function 'initdopi' for 'objdopi' from inside of geamain2:
NewPop = initdopi(Nind, VLUB, gen, varargin)

The variable Nind contains the number of individuals needed, VLUB the boundaries of the variables. In varargin all additional parameters are included (cell array with method, TSTART and TEND). The special initialization function may not produce as many individuals as needed. If the number doesn't match Nind, the standard initialization function initpop is called and produces the missing individuals or deletes some individuals according to the special initialization options described above.
• Option number in previous versions: global Variable GLOBAL_INITFUN (2.x), not available (1.x), the global variable GLOBAL_INITFUN is no longer necessary to define the name of the special initialization function.

### Special.CollectBest.Interval

This option controls if any and how much good/best individuals are collected during an optimization (see colbestind). This collection is separate from the saving of text results (Output.SaveBinDataInterval) or binary data (Output.SaveBinDataInterval). The collected individuals are compared for being not identical according to the criteria in Special.CollectBest.Compare. When an individual is selected, the objective value(s) and the variables of this individual are written into an internal matrix. The collected individuals can also be written into a text file (see Special.CollectBest.WriteFile and Special.CollectBest.FileName).

A value of 0 switches the collection of individuals off. A value of 1 collects individuals every generation. Higher values collect individuals only every defined generation.

• Default value: 0
• Type: integer in [0, Inf]
• Example - collect the best individuals in every 3rd generation:
`GeaOpt = geaoptset(GeaOpt, 'Special.CollectBest.Interval', 3);`
• Option number in previous versions: not available (2.x and 1.x)

### Special.CollectBest.Rate

This option defines the fraction of the whole population or the number of individuals to be collected as best individuals during a collection. Values smaller than 1 define a fraction of the population size. Values of 1 and larger define directly the number of individuals.

• Default value: 0.1 (10%)
• Type: scalar in [0, 1) or integer in [1 Inf]
• Example - set collection rate to 15% and collect every 2 generations:
```GeaOpt = geaoptset(GeaOpt, 'Special.CollectBest.Interval', 2
'Special.CollectBest.Rate', 0.15);```
• Example - set collection rate to 4 individuals and collect every generation:
```GeaOpt = geaoptset(GeaOpt, 'Special.CollectBest.Interval', 1
'Special.CollectBest.Rate', 4);```
• Option number in previous versions: not available (2.x and 1.x)

### Special.CollectBest.Compare

This option defines the comparison method for the good individuals. This ensures only distinctive individuals are collected. The individuals of the current generation are compared to each other and to the individuals already collected in previous generations. Two individuals can be compared for identity according to their variables values and/or their objective values (even multiple objective values). If the comparison yields the individuals are identical in all values, then this individual is not added to the collection.

• Default value: 0
• Type: integer in {0, 1, 2}
• Three variants are available:
• 0: check only for identical variable values
• 1: check for identical objective values and identical variable values
• 2: check only for identical objective values
• Example - compare the objective values and the variable values of the individuals before collection:
`GeaOpt = geaoptset(GeaOpt, 'Special.CollectBest.Compare', 1);`
• The least restrictive method is comparing variable values and objective values. Then an individual is even collected, when another individual produced the same objective value (objective value is identical, but not the variable values). The other way around, when one individual produces different objective values (disturbed objective function), then the two (identical according to their variable values) can still be added to the collection.
• Example: When different individuals according to their variable values are needed then compare just the variable values:
`GeaOpt = geaoptset(GeaOpt, 'Special.CollectBest.Compare', 0);`
• Example: When only one individual per found good objective value is needed, then comparing the objective values is best:
`GeaOpt = geaoptset(GeaOpt, 'Special.CollectBest.Compare', 2);`
• Option number in previous versions: not available (2.x and 1.x)

### Special.CollectBest.WriteFile

This option switches writing the collected individuals to a text file on. The name of the file is defined in Special.CollectBest.FileName.

• Default value: 0
• Type: integer in {0, 1}
• Two variants are available:
• 0: do not write the collected individuals to a text file
• 1: write the collected individuals to a text file
• Example - switch writing collected individuals to a text file on:
`GeaOpt = geaoptset(GeaOpt, 'Special.CollectBest.WriteFile', 1);`
• Option number in previous versions: not available (2.x and 1.x)

### Special.CollectBest.FileName

This option contains the file name to save the collected best individuals. An optional relative or absolute path may be added (employing Matlab conventions). If no path is defined, the current working directory is used.

• Default value: 'CollectBestInd'
• Type: string
• Example - set the file name for best individuals to 'ColInd.txt' and add the current date and time at the end of the file name (using straddtime):
```GeaOpt = geaoptset(GeaOpt, 'Special.CollectBest.FileName',
% filename: ColInd_2000_Aug_27_14-32.txt```
• Example of file with collected best individuals (objfun1, 5 variables, collect 4 individuals). The header shows the number of the objective and the variables. Each line contains one individual. The best individual of every collection phase comes first, the next best follow. Here, 4 individuals are added during each collection phase. The first 3 collections are shown:
```       1. objv                1. var        2. var        3. var        4. var        5. Var
65438               -189.83        97.117       -62.709       -90.832       -88.249
68964               -127.04       -92.959        -135.3        122.15       -104.67
81624               -7.2665       -37.553        80.748        253.08       -97.927
1.0767e+005                124.55        63.665        154.57        6.5249        253.32
21843               -122.04        69.944       -7.5338       -43.448        10.678
43095                -162.7        86.244       -40.631       -71.871       -48.664
54318               -154.47        73.266       -48.199       -106.82       -106.56
73896               -127.64        224.38       -77.343        19.578       -29.873
36771               -145.71        105.68          26.7        59.601       -10.325
50791               -148.92         104.4       -54.164        -80.84       -90.809
52756               -175.42        91.341       -50.982       -80.761       -67.224
60138               -184.06        94.804       -58.013       -86.799       -79.829```
• The utility function straddtime is part of the GEATbx. It is useful for extending a static file name with the current date and time when running the same optimization multiple times. The results of each run are separate.
• Option number in previous versions: not available (2.x and 1.x)

 GEATbx: Main page  Tutorial  Algorithms  M-functions  Parameter/Options  Example functions  www.geatbx.com

This document is part of version 3.8 of the GEATbx: Genetic and Evolutionary Algorithm Toolbox for use with Matlab - www.geatbx.com.
The Genetic and Evolutionary Algorithm Toolbox is not public domain.