~ubuntu-branches/ubuntu/maverick/commons-math/maverick

« back to all changes in this revision

Viewing changes to src/site/xdoc/userguide/genetics.xml

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2009-08-22 01:13:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090822011325-hi4peq1ua5weguwn
Tags: 2.0-1
* New upstream release.
* Set Maintainer field to Debian Java Team
* Add myself as Uploaders
* Switch to Quilt patch system:
  - Refresh all patchs
  - Remove B-D on dpatch, Add B-D on quilt
  - Include patchsys-quilt.mk in debian/rules
* Bump Standards-Version to 3.8.3:
  - Add a README.source to describe patch system
* Maven POMs:
  - Add a Build-Depends-Indep dependency on maven-repo-helper
  - Use mh_installpom and mh_installjar to install the POM and the jar to the
    Maven repository
* Use default-jdk/jre:
  - Depends on java5-runtime-headless
  - Build-Depends on default-jdk
  - Use /usr/lib/jvm/default-java as JAVA_HOME
* Move api documentation to /usr/share/doc/libcommons-math-java/api
* Build-Depends on junit4 instead of junit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0"?>
 
2
 
 
3
<!--
 
4
    Licensed to the Apache Software Foundation (ASF) under one or more
 
5
    contributor license agreements.  See the NOTICE file distributed with
 
6
    this work for additional information regarding copyright ownership.
 
7
    The ASF licenses this file to You under the Apache License, Version 2.0
 
8
    (the "License"); you may not use this file except in compliance with
 
9
    the License.  You may obtain a copy of the License at
 
10
   
 
11
         http://www.apache.org/licenses/LICENSE-2.0
 
12
   
 
13
    Unless required by applicable law or agreed to in writing, software
 
14
    distributed under the License is distributed on an "AS IS" BASIS,
 
15
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
16
    See the License for the specific language governing permissions and
 
17
    limitations under the License.
 
18
  -->
 
19
  
 
20
<?xml-stylesheet type="text/xsl" href="./xdoc.xsl"?>
 
21
<!-- $Revision: 799857 $ $Date: 2009-08-01 09:07:12 -0400 (Sat, 01 Aug 2009) $ -->
 
22
<document url="genetics.html">
 
23
  <properties>
 
24
    <title>The Commons Math User Guide - Genetic Algorithms</title>
 
25
  </properties>
 
26
  <body>
 
27
    <section name="14 Genetic Algorithms">
 
28
      <subsection name="14.1 Overview" href="overview">
 
29
        <p>
 
30
          The genetics package provides a framework and implementations for 
 
31
          genetic algorithms.
 
32
        </p>
 
33
      </subsection>
 
34
      <subsection name="14.2 GA Framework">
 
35
      <p>
 
36
      <a href="../apidocs/org/apache/commons/math/genetics/GeneticAlgorithm.html">
 
37
          org.apache.commons.math.genetic.GeneticAlgorithm</a> provides an
 
38
          execution framework for Genetic Algorithms (GA).  
 
39
          <a href="../apidocs/org/apache/commons/math/genetics/Population.html">Populations,</a> consisting
 
40
          of <a href="../apidocs/org/apache/commons/math/genetics/Chromosome.html">
 
41
          Chromosomes</a> are evolved by the <code>GeneticAlgorithm</code> until a 
 
42
          <a href="../apidocs/org/apache/commons/math/genetics/StoppingCondition.html">StoppingCondition</a>
 
43
          is reached. Evolution is determined by
 
44
          <a href="../apidocs/org/apache/commons/math/genetics/SelectionPolicy.html">SelectionPolicies</a>,
 
45
          <a href="../apidocs/org/apache/commons/math/genetics/MutationPolicy.html"> MutationPolicies</a>
 
46
          and <a href="../apidocs/org/apache/commons/math/genetics/Fitness.html">Fitness</a>.
 
47
      </p>
 
48
      <p>
 
49
          The GA itself is implemented by the <code>evolve</code> method of the <code>GeneticAlgorithm</code> class,
 
50
          which looks like this:
 
51
          <source>
 
52
public Population evolve(Population initial, StoppingCondition condition) {
 
53
    Population current = initial;
 
54
    while (!condition.isSatisfied(current)) {
 
55
        current = nextGeneration(current);
 
56
    }
 
57
    return current;
 
58
}
 
59
          </source>
 
60
          The <code>nextGeneration</code> method implements the following algorithm:
 
61
          <ol>
 
62
          <li>Get nextGeneration population to fill from <code>current</code>
 
63
             generation, using its nextGeneration method</li>
 
64
          <li>Loop until new generation is filled:</li>
 
65
          <ul><li>Apply configured <code>SelectionPolicy</code> to select a pair of parents
 
66
                 from <code>current</code></li>
 
67
             <li>With probability = 
 
68
                 <a href="../apidocs/org/apache/commons/math/genetics/GeneticAlgorithm.html#getCrossoverRate()">
 
69
                 getCrossoverRate()</a>, apply configured <code>CrossoverPolicy</code> to parents</li>
 
70
             <li>With probability = 
 
71
                 <a href="../apidocs/org/apache/commons/math/genetics/GeneticAlgorithm.html#getMutationRate()">
 
72
                 getMutationRate()</a>,
 
73
                 apply configured <code>MutationPolicy</code> to each of the offspring</li>
 
74
             <li>Add offspring individually to nextGeneration,
 
75
                 space permitting</li>
 
76
          </ul>
 
77
          <li>Return nextGeneration</li>
 
78
         </ol>  
 
79
      </p>
 
80
      </subsection>
 
81
      <subsection name="14.3 Implementation">
 
82
      <p>
 
83
      Here is an example GA execution:
 
84
      <source>
 
85
// initialize a new genetic algorithm
 
86
GeneticAlgorithm ga = new GeneticAlgorithm(
 
87
    new OnePointCrossover&lt;Integer&gt;(),
 
88
    1,
 
89
    new RandomKeyMutation(),
 
90
    0.10,
 
91
    new TournamentSelection(TOURNAMENT_ARITY)
 
92
);
 
93
        
 
94
// initial population
 
95
Population initial = getInitialPopulation();
 
96
        
 
97
// stopping condition
 
98
StoppingCondition stopCond = new FixedGenerationCount(NUM_GENERATIONS);
 
99
        
 
100
// run the algorithm
 
101
Population finalPopulation = ga.evolve(initial, stopCond);
 
102
        
 
103
// best chromosome from the final population
 
104
Chromosome bestFinal = finalPopulation.getFittestChromosome();
 
105
        </source>
 
106
        The arguments to the <code>GeneticAlgorithm</code> constructor above are: <br/>
 
107
        <table>
 
108
        <tr><th>Parameter</th><th>value in example</th><th>meaning</th></tr>
 
109
        <tr><td>crossoverPolicy</td>
 
110
        <td><a href="../apidocs/org/apache/commons/math/genetics/OnePointCrossover.html">OnePointCrossover</a></td>
 
111
        <td>A random crossover point is selected and the first part from each parent is copied to the corresponding
 
112
        child, and the second parts are copied crosswise.</td></tr>
 
113
        <tr><td>crossoverRate</td>
 
114
        <td>1</td>
 
115
        <td>Always apply crossover</td></tr>
 
116
        <tr><td>mutationPolicy</td>
 
117
        <td><a href="../apidocs/org/apache/commons/math/genetics/RandomKeyMutation.html">RandomKeyMutation</a></td>
 
118
        <td>Changes a randomly chosen element of the array representation to a random value uniformly distributed in [0,1].</td></tr>
 
119
        <tr><td>mutationRate</td>
 
120
        <td>.1</td>
 
121
        <td>Apply mutation with probability 0.1 - that is, 10% of the time.</td></tr>
 
122
        <tr><td>selectionPolicy</td>
 
123
        <td><a href="../apidocs/org/apache/commons/math/genetics/TournamentSelection.html">TournamentSelection</a></td>
 
124
        <td>Each of the two selected chromosomes is selected based on an n-ary tournament -- this is done by drawing
 
125
        n random chromosomes without replacement from the population, and then selecting the fittest chromosome among them.</td></tr>
 
126
        </table><br/>
 
127
        The algorithm starts with an <code>initial</code> population of <code>Chromosomes.</code> and executes until 
 
128
        the specified <a href="../apidocs/org/apache/commons/math/genetics/StoppingCondition.html">StoppingCondition</a>
 
129
        is reached.  In the example above, a
 
130
        <a href="../apidocs/org/apache/commons/math/genetics/FixedGenerationCount.html">FixedGenerationCount</a>
 
131
        stopping condition is used, which means the algorithm proceeds through a fixed number of generations.
 
132
      </p>
 
133
      </subsection>
 
134
    </section>
 
135
  </body>
 
136
</document>