Version: v2.1.0 Latest Latest

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

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



Package model provides the complete representation of the model for a given GEP problem.



This section is empty.


This section is empty.


This section is empty.


type Generation

type Generation struct {
	Genomes     []*genome.Genome
	Funcs       []gene.FuncWeight
	ScoringFunc genome.ScoringFunc

Generation represents one complete generation of the model.

func New

func New(fs []gene.FuncWeight, funcType functions.FuncType, numGenomes, headSize, numGenesPerGenome, numTerminals, numConstants int, linkFunc string, sf genome.ScoringFunc) *Generation

New creates a new random generation of the model. fs is a slice of function weights. funcType is the underlying function type (no generics). numGenomes is the number of genomes to use to populate this generation of the model. headSize is the number of head symbols to use in a genome. numGenesPerGenome is the number of genes to use per genome. numTerminals is the number of terminals (inputs) to use within each gene. numConstants is the number of constants (inputs) to use within each gene. linkFunc is the linking function used to combine the genes within a genome. sf is the scoring (or fitness) function.

func (*Generation) Evolve

func (g *Generation) Evolve(iterations int) *genome.Genome

Evolve runs the GEP algorithm for the given number of iterations, or until a score of 1000 (or more) is reached.

type Model added in v2.1.0

type Model interface {
	Evaluate(obs gym.Obs, action interface{}) error
	Evolve(reward float64) error

Model represents a GEP model.

type OpenAI added in v2.1.0

type OpenAI struct {
	ActionSpace *gym.Space
	ObsSpace    *gym.Space
	Genomes     []*genome.Genome

OpenAI implements the Model interface.

func ForOpenAI added in v2.1.0

func ForOpenAI(actionSpace, obsSpace *gym.Space) (*OpenAI, error)

ForOpenAI returns a Model based upon the action and observation spaces.

func (*OpenAI) Evaluate added in v2.1.0

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

Evaluate runs the model and returns an action from an observation.

func (*OpenAI) Evolve added in v2.1.0

func (o *OpenAI) Evolve(reward float64) error

Evolve evolves the model based on the reward feedback (from -1 (bad) to 1 (good)).

Source Files

Jump to

Keyboard shortcuts

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