14
14
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="optim_ga" xml:lang="en">
16
<refname>optim_ga</refname>
17
<refpurpose>A flexible genetic algorithm</refpurpose>
20
<title>Calling Sequence</title>
21
<synopsis>[pop_opt,fobj_pop_opt,pop_init,fobj_pop_init] = optim_ga(ga_f,pop_size,nb_generation,p_mut,p_cross,Log,param)</synopsis>
24
<title>Arguments</title>
30
the function to be optimized. The prototype if y = f(x) or y =
39
the size of the population of individuals (default value:
45
<term>nb_generation</term>
48
the number of generations (equivalent to the number of
49
iterations in classical optimization) to be computed (default value:
57
<para>the mutation probability (default value: 0.1).</para>
63
<para>the crossover probability (default value: 0.7).</para>
70
if %T, we will display to information message during the run
71
of the genetic algorithm.
78
<para>a list of parameters.</para>
82
"codage_func": the function which will perform the coding
83
and decoding of individuals (default function:
89
"init_func": the function which will perform the
90
initialization of the population (default function:
96
"crossover_func": the function which will perform the
97
crossover between two individuals (default function:
98
crossover_ga_default).
103
"mutation_func": the function which will perform the
104
mutation of one individual (default function:
105
mutation_ga_default).
110
"selection_func": the function whcih will perform the
111
selection of individuals at the end of a generation (default
112
function: selection_ga_elitist).
117
"nb_couples": the number of couples which will be selected
118
so as to perform the crossover and mutation (default value:
124
"pressure": the value the efficiency of the worst
125
individual (default value: 0.05).
134
<para>the population of optimal individuals.</para>
138
<term>fobj_pop_opt</term>
141
the set of objective function values associated to pop_opt
147
<term>pop_init</term>
149
<para>the initial population of individuals (optional).</para>
153
<term>fobj_pop_init</term>
156
the set of objective function values associated to pop_init
164
<title>Description</title>
166
This function implements the classical genetic algorithm.
169
A great flexibility is authorized in customizing the behaviour of the
170
<literal>optim_ga</literal> function.
171
This flexibility is provided by the various functions which
172
can be set in the <literal>param</literal> variable.
173
In order to analyze the header of these functions (i.e.
174
the input and output arguments), we may read the help page
175
corresponding to the default function.
176
For example, in order to understand what are the input and output arguments of the
177
"codage_func" function, we may read the page of the <literal>coding_identity</literal> function.
180
See in the Demonstrations for more examples for this function.
184
<title>Examples</title>
186
The following session presents the simplest possible example.
187
We minimize a quadratic function in dimension 3.
188
By default, all the parameters are taken in the interval
190
The "dimension" field is passed to the function which computes the
191
initial population, which is <literal>init_ga_default</literal>
193
In the case where the "dimension" field is not customized,
194
the default value is used, which is equal to 2.
196
<programlisting role="example"><![CDATA[
16
<refname>optim_ga</refname>
17
<refpurpose>A flexible genetic algorithm</refpurpose>
20
<title>Calling Sequence</title>
21
<synopsis>[pop_opt,fobj_pop_opt,pop_init,fobj_pop_init] = optim_ga(ga_f,pop_size,nb_generation,p_mut,p_cross,Log,param)</synopsis>
24
<title>Arguments</title>
30
the function to be optimized. The prototype if y = f(x) or y =
39
the size of the population of individuals (default value:
45
<term>nb_generation</term>
48
the number of generations (equivalent to the number of
49
iterations in classical optimization) to be computed (default value:
57
<para>the mutation probability (default value: 0.1).</para>
63
<para>the crossover probability (default value: 0.7).</para>
70
if %T, we will display to information message during the run
71
of the genetic algorithm.
78
<para>a list of parameters.</para>
82
"codage_func": the function which will perform the coding
83
and decoding of individuals (default function:
89
"init_func": the function which will perform the
90
initialization of the population (default function:
96
"crossover_func": the function which will perform the
97
crossover between two individuals (default function:
98
crossover_ga_default).
103
"mutation_func": the function which will perform the
104
mutation of one individual (default function:
105
mutation_ga_default).
110
"selection_func": the function whcih will perform the
111
selection of individuals at the end of a generation (default
112
function: selection_ga_elitist).
117
"nb_couples": the number of couples which will be selected
118
so as to perform the crossover and mutation (default value:
124
"pressure": the value the efficiency of the worst
125
individual (default value: 0.05).
134
<para>the population of optimal individuals.</para>
138
<term>fobj_pop_opt</term>
141
the set of objective function values associated to pop_opt
147
<term>pop_init</term>
149
<para>the initial population of individuals (optional).</para>
153
<term>fobj_pop_init</term>
156
the set of objective function values associated to pop_init
164
<title>Description</title>
166
This function implements the classical genetic algorithm.
169
A great flexibility is authorized in customizing the behaviour of the
170
<literal>optim_ga</literal> function.
171
This flexibility is provided by the various functions which
172
can be set in the <literal>param</literal> variable.
173
In order to analyze the header of these functions (i.e.
174
the input and output arguments), we may read the help page
175
corresponding to the default function.
176
For example, in order to understand what are the input and output arguments of the
177
"codage_func" function, we may read the page of the <literal>coding_identity</literal> function.
180
See in the Demonstrations for more examples for this function.
184
<title>Examples</title>
186
The following session presents the simplest possible example.
187
We minimize a quadratic function in dimension 3.
188
By default, all the parameters are taken in the interval
190
The "dimension" field is passed to the function which computes the
191
initial population, which is <literal>init_ga_default</literal>
193
In the case where the "dimension" field is not customized,
194
the default value is used, which is equal to 2.
196
<programlisting role="example"><![CDATA[
266
266
[pop_opt, fobj_pop_opt, pop_init, fobj_pop_init] = ..
267
267
optim_ga(f, PopSize, NbGen, Proba_mut, Proba_cross, Log, ga_params);
268
268
]]></programlisting>
271
<title>Customizing the initial population</title>
273
In the following example, we customize the init function,
274
which computes the initial population.
275
In the <literal>myinitga</literal> function, we use the grand function
276
(instead of the default rand used in
278
We could use any other type of population generator, including,
279
for example, a low discrepancy sequence such as the Halton or Sobol
282
<programlisting role="example"><![CDATA[
271
<title>Customizing the initial population</title>
273
In the following example, we customize the init function,
274
which computes the initial population.
275
In the <literal>myinitga</literal> function, we use the grand function
276
(instead of the default rand used in
278
We could use any other type of population generator, including,
279
for example, a low discrepancy sequence such as the Halton or Sobol
282
<programlisting role="example"><![CDATA[
322
322
[pop_opt, fobj_pop_opt, pop_init, fobj_pop_init] = ..
323
323
optim_ga(f, PopSize, NbGen, Proba_mut, Proba_cross, Log, ga_params);
324
324
]]></programlisting>
327
<title>Extra parameters for the function</title>
329
In some cases, the objective function needs additionnal parameters
330
in order to be evaluated.
331
In this case, we can pass a list to the <literal>optim_ga</literal>
332
function, where the first element of the list is the function and the
333
remaining elements are the extra parameters.
336
This is done in the following script, where the function <literal>f</literal>
337
needs the two extra parameters <literal>a1</literal> and <literal>a2</literal>.
338
This is why we define the list <literal>myobjfun</literal> and
339
pass it to the <literal>optim_ga</literal> solver.
341
<programlisting role="example"><![CDATA[
327
<title>Extra parameters for the function</title>
329
In some cases, the objective function needs additionnal parameters
330
in order to be evaluated.
331
In this case, we can pass a list to the <literal>optim_ga</literal>
332
function, where the first element of the list is the function and the
333
remaining elements are the extra parameters.
336
This is done in the following script, where the function <literal>f</literal>
337
needs the two extra parameters <literal>a1</literal> and <literal>a2</literal>.
338
This is why we define the list <literal>myobjfun</literal> and
339
pass it to the <literal>optim_ga</literal> solver.
341
<programlisting role="example"><![CDATA[
342
342
function y = f ( x , a1 , a2 )
343
343
y = a1*sum(x.^2) + a2