Documentation ¶
Overview ¶
Package gago has a convention for naming genetic operators. The name begins with a letter or a short sequence of letters to specify which kind of operator it is:
- `C`: crossover - `Mut`: mutator - `Mig`: migrator - `S`: selector
Then comes the second part of the name which indicates on what kind of genomes the operator works:
- `F`: `float64` - `S`: `string` - No letter means the operator works on any kind of genome, regardless of the underlying type.
Finally the name of the operator ends with a word to indicate what it does.
Index ¶
- Variables
- type CFProportionate
- type CFUniform
- type CPMX
- type CPoint
- type Crossover
- type Deme
- type FitnessFunction
- type FloatFunction
- type Genome
- type IFGaussian
- type IFUniform
- type ISUniform
- type ISUnique
- type Individual
- type Individuals
- type Initializer
- type MigShuffle
- type Migrator
- type MutFNormal
- type MutPermute
- type MutSplice
- type Mutator
- type Population
- type SElitism
- type STournament
- type Selector
- type StringFunction
Constants ¶
This section is empty.
Variables ¶
var Float = Population{ NbDemes: 2, NbIndividuals: 30, Initializer: IFUniform{ Lower: -10, Upper: 10, }, Selector: STournament{ NbParticipants: 3, }, Crossover: CFUniform{}, Mutators: []Mutator{ MutFNormal{ Rate: 0.1, Std: 1, }, }, Migrator: MigShuffle{}, }
Float problem configuration.
Functions ¶
This section is empty.
Types ¶
type CFProportionate ¶
type CFProportionate struct { // Should be any integer above or equal to two NbIndividuals int }
CFProportionate crossover combines any number of individuals. Each of the offspring's genes is a random combination of the selected individuals genes. Each individual is assigned a weight such that the sum of the weights is equal to 1, this is done by normalizing each weight by the sum of the generated weights. With this crossover method the CrossSize can be set to any positive integer, in other words any number of individuals can be combined to generate an offspring. Only works for floating point values.
type CFUniform ¶
type CFUniform struct{}
CFUniform crossover combines two individuals (the parents) into one (the offspring). Each parent's contribution to the Genome is determined by the value of a probability p. The offspring can inherit from it's mother's genes (p <= 0.33), from it's father's genes (0.33 < p <= 0.66) or from a random mix of both (0.66 < p <= 1). A coin is thrown for each gene. Only works for floating point values.
type CPMX ¶
type CPMX struct{}
CPMX (Partially Mapped Crossover) randomly picks a crossover point. The offspring is built by copying one of the parents and then copying the other parent's values up to the crossover point. Each gene that is replaced is permuted with the gene that is copied in the first parent's genome. Two offsprings are generated in such a way (because there are two parents). This crossover method ensures the offspring's genomes are composed of unique genes, which is particularly useful for permutation problems such as the Traveling Salesman Problem (TSP).
type CPoint ¶
type CPoint struct {
NbPoints int
}
CPoint selects identical random points on each parent's genome and exchanges mirroring segments. It generalizes one-point crossover and two-point crossover to n-point crossover. One of the generated offsprings is returned at random.
type Crossover ¶
type Crossover interface {
// contains filtered or unexported methods
}
Crossover mixes two or more individuals into a new individual called the offspring.
type Deme ¶
type Deme struct { // Individuals Individuals Individuals // contains filtered or unexported fields }
A Deme contains individuals. Individuals mate within a deme. Individuals can migrate from one deme to another.
type FitnessFunction ¶
type FitnessFunction interface {
// contains filtered or unexported methods
}
FitnessFunction wraps user defined functions in order to generalize other functions.
type FloatFunction ¶
FloatFunction is for functions with floating point slices as input.
type Genome ¶
type Genome []interface{}
A Genome contains the genes of an individual.
func (Genome) CastString ¶
CastString casts each gene to a string.
type IFGaussian ¶
type IFGaussian struct {
Mean, Std float64
}
IFGaussian generates random floating point values sampled from a normal distribution.
type IFUniform ¶
type IFUniform struct {
Lower, Upper float64
}
IFUniform generates random floating points x such that lower < x < upper.
type ISUniform ¶
type ISUniform struct {
Corpus []string
}
ISUniform generates random string slices based on a given corpus.
type ISUnique ¶
type ISUnique struct {
Corpus []string
}
ISUnique generates random string slices based on a given corpus, each element from the corpus is only represented once in each slice. The method starts by shuffling, it then assigns the elements of the corpus in increasing index order to an individual. Usually the length of the individual's genome should match the length of the corpus.
type Individual ¶
An Individual represents a potential solution to a problem. The individual's is defined by it's genome, which is a slice containing genes. Every gene is a floating point numbers. The fitness is the individual's phenotype and is represented by a floating point number.
func (*Individual) Evaluate ¶
func (indi *Individual) Evaluate(ff FitnessFunction)
Evaluate the fitness of an individual.
type Individuals ¶
type Individuals []Individual
Individuals type is necessary for sorting and selection purposes.
func (Individuals) Len ¶
func (indis Individuals) Len() int
func (Individuals) Less ¶
func (indis Individuals) Less(i, j int) bool
func (Individuals) Sort ¶
func (indis Individuals) Sort()
Sort the individuals of a deme in ascending order based on their fitness. The convention is that we always want to minimize a function. A function f(x) can be function maximized by minimizing -f(x) or 1/f(x).
func (Individuals) Swap ¶
func (indis Individuals) Swap(i, j int)
type Initializer ¶
type Initializer interface {
// contains filtered or unexported methods
}
The Initializer is here to create the first generation of individuals in a deme. It applies to an individual level and instantiates it's genome gene by gene.
type MigShuffle ¶
type MigShuffle struct{}
MigShuffle migration exchanges individuals between demes in a random fashion.
type Migrator ¶
type Migrator interface {
// contains filtered or unexported methods
}
Migrator applies crossover to the population level, as such it doesn't require an independent random number generator and can use the global one.
type MutFNormal ¶
MutFNormal mutation modifies a float gene if a coin toss is under a defined mutation rate. It does so for each gene. The new gene value is a random value sampled from a normal distribution centered on the gene's current value and with the intensity parameter as it's standard deviation. Only works for floating point values.
type MutPermute ¶
type MutPermute struct { // Mutation rate Rate float64 }
MutPermute permutes two genes.
type MutSplice ¶
type MutSplice struct { // Mutation rate Rate float64 }
MutSplice a genome and glue it back in another order.
type Mutator ¶
type Mutator interface {
// contains filtered or unexported methods
}
Mutator mutates an individual by modifying part of it's genome.
type Population ¶
type Population struct { // Number of demes NbDemes int // Number of individuals in each deme NbIndividuals int // Number of genes in each individual (imposed by the problem) NbGenes int // Demes Demes []Deme // Overall best individual (dummy initialization at the beginning) Best Individual // Fitness function to evaluate individuals (imposed by the problem) Ff FitnessFunction // Initial random boundaries Initializer Initializer // Selection method Selector Selector // Crossover method Crossover Crossover // Mutation methods Mutators []Mutator // Migration method Migrator Migrator }
A Population contains deme which themselves contain individuals.
func (*Population) Enhance ¶
func (pop *Population) Enhance()
Enhance each deme in the population. The deme level operations are done in parallel with a wait group. After all the deme operations have been run, the population level operations are run.
func (*Population) Initialize ¶
func (pop *Population) Initialize(variables int)
Initialize each deme in the population and assign an initial fitness to each individual in each deme.
type SElitism ¶
type SElitism struct{}
SElitism selection returns the best individuals in the population.
type STournament ¶
type STournament struct {
NbParticipants int
}
STournament selection chooses an individual through tournament selection. The tournament is composed of randomly chosen individuals. The winner of the tournament is the individual with the lowest fitness.
type Selector ¶
type Selector interface {
// contains filtered or unexported methods
}
Selector chooses a sample of individual from a larger of individuals.
type StringFunction ¶
StringFunction is for function with string slices as input.