gene

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2018 License: Apache-2.0 Imports: 8 Imported by: 9

Documentation

Overview

Package gene provides the basis for a single gene in GEP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckEqual

func CheckEqual(g1 *Gene, g2 *Gene) error

CheckEqual is used for testing purposes only (exported to use in genome_test.go).

Types

type FuncWeight

type FuncWeight struct {
	Symbol string
	Weight int
}

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 New

func New(x string) *Gene

New creates a new gene based on the Karva string representation.

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) Dup

func (g *Gene) Dup() *Gene

Dup duplicates the gene into the provided destination gene.

func (*Gene) EvalBool

func (g *Gene) EvalBool(in []bool, nodes functions.FuncMap) bool

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

func (g *Gene) EvalMath(in []float64) float64

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

func (g *Gene) Expression(grammar *grammars.Grammar, helpers grammars.HelperMap) (string, error)

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) String

func (g Gene) String() string

String returns the Karva representation of the gene.

func (*Gene) SymbolCount

func (g *Gene) SymbolCount(sym string) int

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL