lgp

package
v0.0.0-...-b9e61c6 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SPECIAL_REGISTERS = 1
	LAST_WRITTEN      = -1
)

Variables

View Source
var (
	BaseActions = []Action{
		{neg, "neg", 1},

		{add, "add", 3},
		{subtract, "sub", 3},
		{multiply, "mult", 3},

		{bnez, "bnez", 1},
		{bgz, "bgz", 1},
		{jmp, "jmp", 1},
		{randv, "rand", 1},
		{zero, "0", 1},
		{one, "1", 1},
	}
	MinActions = []Action{
		{bnez, "bnez", 1},
		{bgz, "bgz", 1},
		{jmp, "jmp", 1},
	}
	EnvActions = []Action{
		{getEnv, "env", 2},

		{envLen, "envLen", 1},
	}
	PowSumActions = []Action{
		{getEnv, "env", 2},
		{add, "add", 3},
		{multiply, "mult", 3},
		{divide, "div", 3},
		{zero, "0", 1},
		{one, "1", 1},
		{two, "2", 1},
	}
	TartarusActions = []Action{
		{neg, "neg", 1},
		{add, "add", 3},
		{subtract, "sub", 3},
		{multiply, "mult", 3},
		{bnez, "bnez", 1},
		{bgz, "bgz", 1},
		{jmp, "jmp", 1},
		{randv, "rand", 1},
		{zero, "0", 1},
		{one, "1", 1},
		{two, "2", 1},
	}
	SortActions = []Action{
		{bnez, "bnez", 1},
		{bgz, "bgz", 1},
		{bgeq, "bgeq", 2},
		{jmp, "jmp", 1},
		{getEnv, "env", 2},
		{envLen, "envLen", 1},
		{divide, "div", 3},
		{subtract, "sub", 3},
		{zero, "0", 1},
		{one, "1", 1},
		{memSwap, "swap", 2},
	}
)

Functions

func EnvFitness

func EnvFitness(g *LGP, inputs, outputs [][]float64) int

An example fitness function which treats the output as a environment to compare a modified environment by the GP to.

func GeneratePopulation

func GeneratePopulation(opt interface{}, popSize int) []pop.Individual

func Init

func Init(genOpt Options, e, m *env.I, cross LGPCrossover,
	act []Action, baseActionWeight float64, f FitnessFunc, qe int)

func MatchEnvFitness

func MatchEnvFitness(g *LGP, inputs, outputs [][]float64) int

func MatchMemFitness

func MatchMemFitness(g *LGP, inputs, outputs [][]float64) int

func Mem0Fitness

func Mem0Fitness(g *LGP, inputs, outputs [][]float64) int

func OptInit

func OptInit(opt interface{})

func PrintActions

func PrintActions()

func ResetCumActionWeights

func ResetCumActionWeights()

Types

type Action

type Action struct {
	Op   Operator
	Name string
	Args int
}

The effect of a given action is internally defined by the action, and GPs need to learn what actions are useful, when. Unlike Tree-GPs, LGPs do not care about the number of arguments their actions take unless mutating or generating them.

type FitnessFunc

type FitnessFunc func(gp *LGP, inputs, outputs [][]float64) int

func ComplexityFitness

func ComplexityFitness(f FitnessFunc, mod float64) FitnessFunc

func TimeFitness

func TimeFitness(f FitnessFunc, threshold int, timeLimit int) FitnessFunc

type InitOptions

type InitOptions struct {
	GenOpt           Options
	Env              *env.I
	Mem              *env.I
	Cross            LGPCrossover
	Act              []Action
	BaseActionWeight float64
	Fitness          FitnessFunc
	QuitEarly        int
}

type Instruction

type Instruction struct {
	Act  Action
	Args []int
}

func (*Instruction) String

func (i *Instruction) String() string

type LGP

type LGP struct {
	Instructions []Instruction
	Mem          *env.I
	MemStart     *env.I
	Env          *env.I
	// contains filtered or unexported fields
}

A linear genetic program

func GenerateLGP

func GenerateLGP(genOpt Options) *LGP

func (*LGP) CanCrossover

func (gp *LGP) CanCrossover(other pop.Individual) bool

func (*LGP) Copy

func (gp *LGP) Copy() *LGP

func (*LGP) Crossover

func (gp *LGP) Crossover(other pop.Individual) pop.Individual

Crossover types (multi)point crossover uniform crossover these should be brought out and used for all list-like structures

func (*LGP) ExpandMutate

func (gp *LGP) ExpandMutate()

func (*LGP) Fitness

func (gp *LGP) Fitness(input, expected [][]float64) int

func (*LGP) GetInstruction

func (gp *LGP) GetInstruction() Instruction

func (*LGP) GetReg

func (gp *LGP) GetReg(r1 int) (r2 int)

func (*LGP) MemMutate

func (gp *LGP) MemMutate()

func (*LGP) Mutate

func (gp *LGP) Mutate()

Mutation types: swap mutate, swapping instructions at two locations value mutate, changing the values baked into an instruction shrink/expand mutate, removing or adding instructions from random locations environment mutate, changing the initial environment values

func (*LGP) Print

func (gp *LGP) Print()

func (*LGP) RegVal

func (gp *LGP) RegVal(r1 int) int

func (*LGP) Run

func (gp *LGP) Run()

func (*LGP) SetReg

func (gp *LGP) SetReg(r1, v int)

func (*LGP) ShrinkMutate

func (gp *LGP) ShrinkMutate()

func (*LGP) SwapMutate

func (gp *LGP) SwapMutate()

func (*LGP) ValueMutate

func (gp *LGP) ValueMutate()

type LGPCrossover

type LGPCrossover interface {
	Crossover(a, b *LGP) *LGP
}

type Operator

type Operator func(*LGP, ...int)

type Options

type Options struct {
	MinActionCount  int
	MaxActionCount  int
	MaxStartActions int
	MinStartActions int

	SwapMutationChance   float64
	ValueMutationChance  float64
	ShrinkMutationChance float64
	ExpandMutationChance float64
	MemMutationChance    float64
}

type PointCrossover

type PointCrossover struct {
	NumPoints int
}

func (PointCrossover) Crossover

func (pc PointCrossover) Crossover(a, b *LGP) *LGP

type UniformCrossover

type UniformCrossover struct {
	ChosenProportion float64
}

This looks like it doesn't work

func (UniformCrossover) Crossover

func (uc UniformCrossover) Crossover(a, b *LGP) *LGP

Jump to

Keyboard shortcuts

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