~ubuntu-branches/ubuntu/raring/scilab/raring-proposed

« back to all changes in this revision

Viewing changes to modules/genetic_algorithms/help/en_US/algorithms/optim_ga.xml

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-08-30 14:42:38 UTC
  • mfrom: (1.4.7)
  • Revision ID: package-import@ubuntu.com-20120830144238-c1y2og7dbm7m9nig
Tags: 5.4.0-beta-3-1~exp1
* New upstream release
* Update the scirenderer dep
* Get ride of libjhdf5-java dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 *
13
13
 -->
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">
15
 
  <refnamediv>
16
 
    <refname>optim_ga</refname>
17
 
    <refpurpose>A flexible genetic algorithm</refpurpose>
18
 
  </refnamediv>
19
 
  <refsynopsisdiv>
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>
22
 
  </refsynopsisdiv>
23
 
  <refsection>
24
 
    <title>Arguments</title>
25
 
    <variablelist>
26
 
      <varlistentry>
27
 
        <term>ga_f</term>
28
 
        <listitem>
29
 
          <para>
30
 
            the function to be optimized. The prototype if y = f(x) or y =
31
 
            list(f,p1,p2,...).
32
 
          </para>
33
 
        </listitem>
34
 
      </varlistentry>
35
 
      <varlistentry>
36
 
        <term>pop_size</term>
37
 
        <listitem>
38
 
          <para>
39
 
            the size of the population of individuals (default value:
40
 
            100).
41
 
          </para>
42
 
        </listitem>
43
 
      </varlistentry>
44
 
      <varlistentry>
45
 
        <term>nb_generation</term>
46
 
        <listitem>
47
 
          <para>
48
 
            the number of generations (equivalent to the number of
49
 
            iterations in classical optimization) to be computed (default value:
50
 
            10).
51
 
          </para>
52
 
        </listitem>
53
 
      </varlistentry>
54
 
      <varlistentry>
55
 
        <term>p_mut</term>
56
 
        <listitem>
57
 
          <para>the mutation probability (default value: 0.1).</para>
58
 
        </listitem>
59
 
      </varlistentry>
60
 
      <varlistentry>
61
 
        <term>p_cross</term>
62
 
        <listitem>
63
 
          <para>the crossover probability (default value: 0.7).</para>
64
 
        </listitem>
65
 
      </varlistentry>
66
 
      <varlistentry>
67
 
        <term>Log</term>
68
 
        <listitem>
69
 
          <para>
70
 
            if %T, we will display to information message during the run
71
 
            of the genetic algorithm.
72
 
          </para>
73
 
        </listitem>
74
 
      </varlistentry>
75
 
      <varlistentry>
76
 
        <term>param</term>
77
 
        <listitem>
78
 
          <para>a list of parameters.</para>
79
 
          <itemizedlist>
80
 
            <listitem>
81
 
              <para>
82
 
                "codage_func": the function which will perform the coding
83
 
                and decoding of individuals (default function:
84
 
                coding_ga_identity).
85
 
              </para>
86
 
            </listitem>
87
 
            <listitem>
88
 
              <para>
89
 
                "init_func": the function which will perform the
90
 
                initialization of the population (default function:
91
 
                init_ga_default).
92
 
              </para>
93
 
            </listitem>
94
 
            <listitem>
95
 
              <para>
96
 
                "crossover_func": the function which will perform the
97
 
                crossover between two individuals (default function:
98
 
                crossover_ga_default).
99
 
              </para>
100
 
            </listitem>
101
 
            <listitem>
102
 
              <para>
103
 
                "mutation_func": the function which will perform the
104
 
                mutation of one individual (default function:
105
 
                mutation_ga_default).
106
 
              </para>
107
 
            </listitem>
108
 
            <listitem>
109
 
              <para>
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).
113
 
              </para>
114
 
            </listitem>
115
 
            <listitem>
116
 
              <para>
117
 
                "nb_couples": the number of couples which will be selected
118
 
                so as to perform the crossover and mutation (default value:
119
 
                100).
120
 
              </para>
121
 
            </listitem>
122
 
            <listitem>
123
 
              <para>
124
 
                "pressure": the value the efficiency of the worst
125
 
                individual (default value: 0.05).
126
 
              </para>
127
 
            </listitem>
128
 
          </itemizedlist>
129
 
        </listitem>
130
 
      </varlistentry>
131
 
      <varlistentry>
132
 
        <term>pop_opt</term>
133
 
        <listitem>
134
 
          <para>the population of optimal individuals.</para>
135
 
        </listitem>
136
 
      </varlistentry>
137
 
      <varlistentry>
138
 
        <term>fobj_pop_opt</term>
139
 
        <listitem>
140
 
          <para>
141
 
            the set of objective function values associated to pop_opt
142
 
            (optional).
143
 
          </para>
144
 
        </listitem>
145
 
      </varlistentry>
146
 
      <varlistentry>
147
 
        <term>pop_init</term>
148
 
        <listitem>
149
 
          <para>the initial population of individuals (optional).</para>
150
 
        </listitem>
151
 
      </varlistentry>
152
 
      <varlistentry>
153
 
        <term>fobj_pop_init</term>
154
 
        <listitem>
155
 
          <para>
156
 
            the set of objective function values associated to pop_init
157
 
            (optional).
158
 
          </para>
159
 
        </listitem>
160
 
      </varlistentry>
161
 
    </variablelist>
162
 
  </refsection>
163
 
  <refsection>
164
 
    <title>Description</title>
165
 
    <para>
166
 
      This function implements the classical genetic algorithm.
167
 
    </para>
168
 
    <para>
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.
178
 
    </para>
179
 
    <para>
180
 
      See in the Demonstrations for more examples for this function.
181
 
    </para>
182
 
  </refsection>
183
 
  <refsection>
184
 
    <title>Examples</title>
185
 
    <para>
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 
189
 
      [0,1]^3.
190
 
      The "dimension" field is passed to the function which computes the 
191
 
      initial population, which is <literal>init_ga_default</literal> 
192
 
      function by default.
193
 
      In the case where the "dimension" field is not customized,
194
 
      the default value is used, which is equal to 2.
195
 
    </para>
196
 
    <programlisting role="example"><![CDATA[ 
 
15
    <refnamediv>
 
16
        <refname>optim_ga</refname>
 
17
        <refpurpose>A flexible genetic algorithm</refpurpose>
 
18
    </refnamediv>
 
19
    <refsynopsisdiv>
 
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>
 
22
    </refsynopsisdiv>
 
23
    <refsection>
 
24
        <title>Arguments</title>
 
25
        <variablelist>
 
26
            <varlistentry>
 
27
                <term>ga_f</term>
 
28
                <listitem>
 
29
                    <para>
 
30
                        the function to be optimized. The prototype if y = f(x) or y =
 
31
                        list(f,p1,p2,...).
 
32
                    </para>
 
33
                </listitem>
 
34
            </varlistentry>
 
35
            <varlistentry>
 
36
                <term>pop_size</term>
 
37
                <listitem>
 
38
                    <para>
 
39
                        the size of the population of individuals (default value:
 
40
                        100).
 
41
                    </para>
 
42
                </listitem>
 
43
            </varlistentry>
 
44
            <varlistentry>
 
45
                <term>nb_generation</term>
 
46
                <listitem>
 
47
                    <para>
 
48
                        the number of generations (equivalent to the number of
 
49
                        iterations in classical optimization) to be computed (default value:
 
50
                        10).
 
51
                    </para>
 
52
                </listitem>
 
53
            </varlistentry>
 
54
            <varlistentry>
 
55
                <term>p_mut</term>
 
56
                <listitem>
 
57
                    <para>the mutation probability (default value: 0.1).</para>
 
58
                </listitem>
 
59
            </varlistentry>
 
60
            <varlistentry>
 
61
                <term>p_cross</term>
 
62
                <listitem>
 
63
                    <para>the crossover probability (default value: 0.7).</para>
 
64
                </listitem>
 
65
            </varlistentry>
 
66
            <varlistentry>
 
67
                <term>Log</term>
 
68
                <listitem>
 
69
                    <para>
 
70
                        if %T, we will display to information message during the run
 
71
                        of the genetic algorithm.
 
72
                    </para>
 
73
                </listitem>
 
74
            </varlistentry>
 
75
            <varlistentry>
 
76
                <term>param</term>
 
77
                <listitem>
 
78
                    <para>a list of parameters.</para>
 
79
                    <itemizedlist>
 
80
                        <listitem>
 
81
                            <para>
 
82
                                "codage_func": the function which will perform the coding
 
83
                                and decoding of individuals (default function:
 
84
                                coding_ga_identity).
 
85
                            </para>
 
86
                        </listitem>
 
87
                        <listitem>
 
88
                            <para>
 
89
                                "init_func": the function which will perform the
 
90
                                initialization of the population (default function:
 
91
                                init_ga_default).
 
92
                            </para>
 
93
                        </listitem>
 
94
                        <listitem>
 
95
                            <para>
 
96
                                "crossover_func": the function which will perform the
 
97
                                crossover between two individuals (default function:
 
98
                                crossover_ga_default).
 
99
                            </para>
 
100
                        </listitem>
 
101
                        <listitem>
 
102
                            <para>
 
103
                                "mutation_func": the function which will perform the
 
104
                                mutation of one individual (default function:
 
105
                                mutation_ga_default).
 
106
                            </para>
 
107
                        </listitem>
 
108
                        <listitem>
 
109
                            <para>
 
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).
 
113
                            </para>
 
114
                        </listitem>
 
115
                        <listitem>
 
116
                            <para>
 
117
                                "nb_couples": the number of couples which will be selected
 
118
                                so as to perform the crossover and mutation (default value:
 
119
                                100).
 
120
                            </para>
 
121
                        </listitem>
 
122
                        <listitem>
 
123
                            <para>
 
124
                                "pressure": the value the efficiency of the worst
 
125
                                individual (default value: 0.05).
 
126
                            </para>
 
127
                        </listitem>
 
128
                    </itemizedlist>
 
129
                </listitem>
 
130
            </varlistentry>
 
131
            <varlistentry>
 
132
                <term>pop_opt</term>
 
133
                <listitem>
 
134
                    <para>the population of optimal individuals.</para>
 
135
                </listitem>
 
136
            </varlistentry>
 
137
            <varlistentry>
 
138
                <term>fobj_pop_opt</term>
 
139
                <listitem>
 
140
                    <para>
 
141
                        the set of objective function values associated to pop_opt
 
142
                        (optional).
 
143
                    </para>
 
144
                </listitem>
 
145
            </varlistentry>
 
146
            <varlistentry>
 
147
                <term>pop_init</term>
 
148
                <listitem>
 
149
                    <para>the initial population of individuals (optional).</para>
 
150
                </listitem>
 
151
            </varlistentry>
 
152
            <varlistentry>
 
153
                <term>fobj_pop_init</term>
 
154
                <listitem>
 
155
                    <para>
 
156
                        the set of objective function values associated to pop_init
 
157
                        (optional).
 
158
                    </para>
 
159
                </listitem>
 
160
            </varlistentry>
 
161
        </variablelist>
 
162
    </refsection>
 
163
    <refsection>
 
164
        <title>Description</title>
 
165
        <para>
 
166
            This function implements the classical genetic algorithm.
 
167
        </para>
 
168
        <para>
 
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.
 
178
        </para>
 
179
        <para>
 
180
            See in the Demonstrations for more examples for this function.
 
181
        </para>
 
182
    </refsection>
 
183
    <refsection>
 
184
        <title>Examples</title>
 
185
        <para>
 
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 
 
189
            [0,1]^3.
 
190
            The "dimension" field is passed to the function which computes the 
 
191
            initial population, which is <literal>init_ga_default</literal> 
 
192
            function by default.
 
193
            In the case where the "dimension" field is not customized,
 
194
            the default value is used, which is equal to 2.
 
195
        </para>
 
196
        <programlisting role="example"><![CDATA[ 
197
197
function y=f(x)
198
198
  y = sum(x.^2)
199
199
endfunction
211
211
[pop_opt, fobj_pop_opt] = ..
212
212
  optim_ga(f, PopSize, NbGen, Proba_mut, Proba_cross, Log, ga_params);
213
213
 ]]></programlisting>
214
 
    <para>
215
 
      Once the algorithm done, we can analyze the results.
216
 
      In the following script, we compute some basic statistics about the
217
 
      optimum population and get the best and the worst points.
218
 
    </para>
219
 
    <programlisting role="example"><![CDATA[ 
 
214
        <para>
 
215
            Once the algorithm done, we can analyze the results.
 
216
            In the following script, we compute some basic statistics about the
 
217
            optimum population and get the best and the worst points.
 
218
        </para>
 
219
        <programlisting role="example"><![CDATA[ 
220
220
// Display basic statistics
221
221
// min, mean and max function values of the population.
222
222
disp([min(fobj_pop_opt) mean(fobj_pop_opt) max(fobj_pop_opt)])
227
227
[fmax ,k] = max(fobj_pop_opt)
228
228
xmax = pop_opt(k)
229
229
 ]]></programlisting>
230
 
    <para>
231
 
      In the following example, we customize all the options 
232
 
      in order to show all the features of the algorithm.
233
 
    </para>
234
 
    <programlisting role="example"><![CDATA[ 
 
230
        <para>
 
231
            In the following example, we customize all the options 
 
232
            in order to show all the features of the algorithm.
 
233
        </para>
 
234
        <programlisting role="example"><![CDATA[ 
235
235
function y=f(x)
236
236
  y = sum(x.^2)
237
237
endfunction
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>
269
 
  </refsection>
270
 
  <refsection>
271
 
    <title>Customizing the initial population</title>
272
 
    <para>
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
277
 
      init_ga_default).
278
 
      We could use any other type of population generator, including, 
279
 
      for example, a low discrepancy sequence such as the Halton or Sobol 
280
 
      sequence.
281
 
    </para>
282
 
    <programlisting role="example"><![CDATA[ 
 
269
    </refsection>
 
270
    <refsection>
 
271
        <title>Customizing the initial population</title>
 
272
        <para>
 
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
 
277
            init_ga_default).
 
278
            We could use any other type of population generator, including, 
 
279
            for example, a low discrepancy sequence such as the Halton or Sobol 
 
280
            sequence.
 
281
        </para>
 
282
        <programlisting role="example"><![CDATA[ 
283
283
function y=f(x)
284
284
  y = sum(x.^2)
285
285
endfunction
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>
325
 
  </refsection>
326
 
  <refsection>
327
 
    <title>Extra parameters for the function</title>
328
 
    <para>
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.
334
 
    </para>
335
 
    <para>
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.
340
 
    </para>
341
 
    <programlisting role="example"><![CDATA[ 
 
325
    </refsection>
 
326
    <refsection>
 
327
        <title>Extra parameters for the function</title>
 
328
        <para>
 
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.
 
334
        </para>
 
335
        <para>
 
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.
 
340
        </para>
 
341
        <programlisting role="example"><![CDATA[ 
342
342
function y = f ( x , a1 , a2 )
343
343
  y = a1*sum(x.^2) + a2
344
344
endfunction
363
363
[pop_opt, fobj_pop_opt] = ..
364
364
  optim_ga(myobjfun, PopSize, NbGen, Proba_mut, Proba_cross, Log, ga_params);
365
365
 ]]></programlisting>
366
 
  </refsection>
367
 
  <refsection role="see also">
368
 
    <title>See Also</title>
369
 
    <simplelist type="inline">
370
 
      <member>
371
 
        <link linkend="optim_moga"> optim_moga </link>
372
 
      </member>
373
 
      <member>
374
 
        <link linkend="optim_nsga"> optim_nsga </link>
375
 
      </member>
376
 
      <member>
377
 
        <link linkend="optim_nsga2"> optim_nsga2 </link>
378
 
      </member>
379
 
    </simplelist>
380
 
  </refsection>
381
 
  <refsection>
382
 
    <title>References</title>
383
 
    <itemizedlist>
384
 
      <listitem>
385
 
        <para>
386
 
          Michalewicz Zbigniew "Genetic Algorithms + Data Structures = Evolution Programs"
387
 
        </para>
388
 
      </listitem>
389
 
    </itemizedlist>
390
 
  </refsection>
 
366
    </refsection>
 
367
    <refsection role="see also">
 
368
        <title>See Also</title>
 
369
        <simplelist type="inline">
 
370
            <member>
 
371
                <link linkend="optim_moga"> optim_moga </link>
 
372
            </member>
 
373
            <member>
 
374
                <link linkend="optim_nsga"> optim_nsga </link>
 
375
            </member>
 
376
            <member>
 
377
                <link linkend="optim_nsga2"> optim_nsga2 </link>
 
378
            </member>
 
379
        </simplelist>
 
380
    </refsection>
 
381
    <refsection>
 
382
        <title>References</title>
 
383
        <itemizedlist>
 
384
            <listitem>
 
385
                <para>
 
386
                    Michalewicz Zbigniew "Genetic Algorithms + Data Structures = Evolution Programs"
 
387
                </para>
 
388
            </listitem>
 
389
        </itemizedlist>
 
390
    </refsection>
391
391
</refentry>