GODPAPER | All Packages | All Classes | Index | Frames No Frames |
GeneticEngine

Package | com.suckatmath.machinelearning.genetic.core
Class | public class GeneticEngine
Inheritance | GeneticEngine Object
Implements | EvolvableComparator

performs actual genetic algorithms

Public Properties

| Property | Defined By
--- | --- | ---
|  | numNewPerGeneration : int = 1 Number of new random genomes per generation. | GeneticEngine

Public Methods

| Method | Defined By
--- | --- | ---
|  | GeneticEngine(f:EvolvableFactory, mutate:Boolean = true, crossover:Boolean = true, npg:int = 1, mprob:Number = 0.5, cparents:int = 2, ccross:int = 1) new engine constructor | GeneticEngine
|  | compareFitness(a:Evolvable, b:Evolvable):int Used both in ROULETTE and as default EvolvableComparator function for TOURNAMENT selection | GeneticEngine
|  | getAvgPopFitness():Number return the average fitness of the population. | GeneticEngine
|  | getPopulation():Array gets population. | GeneticEngine
|  | nextGeneration():void main work method. | GeneticEngine
|  | randomPopulation(psize:int):void generate a new population of psize. | GeneticEngine
|  | setCarryOverNum(n:int):void how many of the fittest of previous generation to put in new pop. | GeneticEngine
|  | setCrossoverNumParents(n:int):void set how many parents to use for crossover - should be <= number of crossover points +1 | GeneticEngine
|  | setCrossoverNumPoints(n:int):void set number of crossover points | GeneticEngine
|  | setFactory(fac:EvolvableFactory):void set EvolvableFactory to use to create new Evolvables | GeneticEngine
|  | setMutateProbability(n:Number):void set probability of mutation in generating new individuals | GeneticEngine
|  | setNumNewPerGeneration(n:int):void set number of new random individuals per generation. | GeneticEngine
|  | setPopulation(pop:Array):void set population to array of Evolvables | GeneticEngine
|  | setSelectionMode(s:int):void set selectionMode to ROULETTE or TOURNAMENT | GeneticEngine
|  | setTournamentComparator(e:EvolvableComparator):void set EvolvableCOmparator to use during TOURNAMENT selection | GeneticEngine
|  | useCrossover(c:Boolean):void set whether to use crossover in generating new individuals | GeneticEngine
|  | useMutate(m:Boolean):void set whether to use mutation in generating new individuals | GeneticEngine

Public Constants

| Constant | Defined By
--- | --- | ---
|  | ROULETTE : int = 1 [static] constant for ROULETTE selection : proportional selection. | GeneticEngine
|  | TOURNAMENT : int = 2 [static] constant for TOURNAMENT selection | GeneticEngine

Property Detail

numNewPerGeneration | property

`public var numNewPerGeneration:int = 1`

Number of new random genomes per generation.

Constructor Detail

GeneticEngine | () | Constructor

`public function GeneticEngine(f:EvolvableFactory, mutate:Boolean = true, crossover:Boolean = true, npg:int = 1, mprob:Number = 0.5, cparents:int = 2, ccross:int = 1)`

new engine constructor

Parameters

| `f:EvolvableFactory` — EvolvableFactory to generate new Evolvables from Genomes
| `mutate:Boolean` (default = `true`)`` — Boolean whether to use mutation
| `crossover:Boolean` (default = `true`)`` — Boolean whether to use crossover
| `npg:int` (default = `1`)`` — int number of new random individuals per generation
| `mprob:Number` (default = `0.5`)`` — Number probablity of mutation
| `cparents:int` (default = `2`)`` — int Number of parents to use for crossover
| `ccross:int` (default = `1`)`` — int Number of points to cross over in crossover operation

Method Detail

compareFitness | () | method

`public function compareFitness(a:Evolvable, b:Evolvable):int`

Used both in ROULETTE and as default EvolvableComparator function for TOURNAMENT selection

Parameters

| `a:Evolvable`
| `b:Evolvable`

Returns

| `int` —

getAvgPopFitness | () | method |

`public function getAvgPopFitness():Number`

return the average fitness of the population. This may be an EXPENSIVE operation if getFitness is expensive

Returns

| `Number` —

getPopulation | () | method |

`public function getPopulation():Array`

gets population.

Returns

| `Array` —

nextGeneration | () | method |

`public function nextGeneration():void`

main work method. Calls to this will change the population array.

randomPopulation | () | method |

`public function randomPopulation(psize:int):void`

generate a new population of psize. OR if population is already an existing array, replace it with an array of the same size which is full of random individuals

Parameters

| `psize:int` — int

setCarryOverNum | () | method |

`public function setCarryOverNum(n:int):void`

how many of the fittest of previous generation to put in new pop. Not used in TOURNAMENT selection

Parameters

| `n:int`

setCrossoverNumParents | () | method |

`public function setCrossoverNumParents(n:int):void`

Parameters

| `n:int`

setCrossoverNumPoints | () | method |

`public function setCrossoverNumPoints(n:int):void`

set number of crossover points

Parameters

| `n:int`

setFactory | () | method |

`public function setFactory(fac:EvolvableFactory):void`

set EvolvableFactory to use to create new Evolvables

Parameters

| `fac:EvolvableFactory`

setMutateProbability | () | method |

`public function setMutateProbability(n:Number):void`

set probability of mutation in generating new individuals

Parameters

| `n:Number`

setNumNewPerGeneration | () | method |

`public function setNumNewPerGeneration(n:int):void`

set number of new random individuals per generation. 1 or 0 usually.

Parameters

| `n:int`

setPopulation | () | method |

`public function setPopulation(pop:Array):void`

set population to array of Evolvables

Parameters

| `pop:Array`

setSelectionMode | () | method |

`public function setSelectionMode(s:int):void`

set selectionMode to ROULETTE or TOURNAMENT

Parameters

| `s:int`

setTournamentComparator | () | method |

`public function setTournamentComparator(e:EvolvableComparator):void`

set EvolvableCOmparator to use during TOURNAMENT selection

Parameters

| `e:EvolvableComparator`

useCrossover | () | method |

`public function useCrossover(c:Boolean):void`

set whether to use crossover in generating new individuals

Parameters

| `c:Boolean`

useMutate | () | method |

`public function useMutate(m:Boolean):void`

set whether to use mutation in generating new individuals

Parameters

| `m:Boolean`

Constant Detail

ROULETTE | Constant

`public static const ROULETTE:int = 1`

constant for ROULETTE selection : proportional selection. This is the default selection mode

TOURNAMENT | Constant |

`public static const TOURNAMENT:int = 2`

constant for TOURNAMENT selection

Thu Jan 16 2014, 01:11 PM +08:00