genome

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package genome provides the basis for a single GEP genome. A genome consists of one or more genes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Genome

type Genome struct {
	Genes    []*gene.Gene
	LinkFunc string
	Score    float64

	SymbolMap map[string]int // do not use directly.  Use SymbolCount() instead.
}

Genome contains the genes that make up the genome. It also provides the linking function and the score that results from evaluating the genome against the fitness function.

func New

func New(genes []*gene.Gene, linkFunc string) *Genome

New creates a new genome from the given genes and linking function.

func (*Genome) Dup

func (g *Genome) Dup() *Genome

Dup duplicates the genome into the provided destination genome.

func (*Genome) EvalBool

func (g *Genome) EvalBool(in []bool) bool

EvalBool evaluates the genome as a boolean expression and returns the result. in represents the boolean inputs available to the genome. fm is the map of available boolean functions to the genome.

func (*Genome) EvalInt added in v2.1.0

func (g *Genome) EvalInt(in []int) int

EvalInt evaluates the genome as an integer expression and returns the result. in represents the int inputs available to the genome.

func (*Genome) EvalIntTuple added in v2.1.0

func (g *Genome) EvalIntTuple(in, out []int)

EvalIntTuple evaluates the genome by evaluating each gene and assigning its output to each element of the tuple.

func (*Genome) EvalMath

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

EvalMath evaluates the genome as a floating-point expression and returns the result. in represents the float64 inputs available to the genome.

func (*Genome) Evaluate

func (g *Genome) Evaluate(stepsSinceReset int, obs gym.Obs, action interface{}) error

Evaluate runs the model with the observation and populates the provided action based on the link function.

func (*Genome) EvaluateWithScore added in v2.1.0

func (g *Genome) EvaluateWithScore(sf ScoringFunc, c chan<- *Genome)

EvaluateWithScore scores a genome and sends the result to a channel.

func (*Genome) Mutate

func (g *Genome) Mutate(numMutations int)

Mutate mutates a genome by performing numMutations random symbol exchanges within the genome.

func (Genome) String

func (g Genome) String() string

String returns the Karva representation of the genome.

func (*Genome) SymbolCount

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

SymbolCount returns the count of the number of times the symbol is actually used in the Genome. 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 Genome.

func (*Genome) Write

func (g *Genome) Write(w io.Writer, grammar *grammars.Grammar)

type ScoringFunc

type ScoringFunc func(g *Genome) float64

ScoringFunc is the function that is used to evaluate the fitness of the model. Typically, a return value of 0 means that the function is nowhere close to being a valid solution and a return value of 1000 (or higher) means a perfect solution.

Jump to

Keyboard shortcuts

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