Documentation ¶
Overview ¶
Package gene provides the basis for a single gene in GEP.
Index ¶
- func CheckEqual(g1 *Gene, g2 *Gene) error
- type FuncWeight
- type Gene
- func (g *Gene) Dup() *Gene
- func (g *Gene) EvalBool(in []bool, nodes functions.FuncMap) bool
- func (g *Gene) EvalMath(in []float64) float64
- func (g *Gene) Expression(grammar *grammars.Grammar, helpers grammars.HelperMap) (string, error)
- func (g *Gene) Mutate()
- func (g Gene) String() string
- func (g *Gene) SymbolCount(sym string) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckEqual ¶
CheckEqual is used for testing purposes only (exported to use in genome_test.go).
Types ¶
type FuncWeight ¶
FuncWeight contains the symbol name and its weight to be used during a run of the GEP algorithm. A symbol with weight 5, for example, will be five times more likely to be used than a symbol with weight 1.
type Gene ¶
type Gene struct { // Symbols is the slice of strings being used in this gene's expression. Symbols []string // Constants is the slice of floats available for use by this gene. Constants []float64 SymbolMap map[string]int // do not use directly. Use SymbolCount() instead. // contains filtered or unexported fields }
Gene contains all the information needed to represent a single gene in a GEP expression.
func RandomNew ¶
func RandomNew(headSize, tailSize, numTerminals, numConstants int, functions []FuncWeight) *Gene
RandomNew generates a new, random gene for further manipulation by the GEP algorithm. The headSize, tailSize, numTerminals, and numConstants determine the respective properties of the gene, and functions provide the available functions and their respective weights to be used in the creation of the gene.
func (*Gene) EvalBool ¶
EvalBool evaluates the gene as a boolean expression and returns the result. "in" represents the boolean inputs available to the gene. "nodes" is the map of available boolean functions to the gene.
func (*Gene) EvalMath ¶
EvalMath evaluates the gene as a floating-point expression and returns the result. in represents the float64 inputs available to the gene.
func (*Gene) Expression ¶
Expression builds up the expression tree and returns the resulting string. While building, it keeps track of any helper functions that are needed.
func (*Gene) Mutate ¶
func (g *Gene) Mutate()
Mutate mutates a gene by performing a single random symbol exchange within the gene.
func (*Gene) SymbolCount ¶
SymbolCount returns the count of the number of times the symbol is actually used in the Gene. Note that this count is typically different from the number of times the symbol appears in the Karva expression. This can be a handy metric to assist in the fitness evaluation of a Gene. Note also that this currently only works for Math expressions. Hopefully this restriction will be lifted in the future. A workaround for using it with other types is to evaluate the Gene, and then g.symbolCount will already be populated.