Documentation ¶
Index ¶
- Constants
- Variables
- func EnvFitness(g *LGP, inputs, outputs [][]float64) int
- func GeneratePopulation(opt interface{}, popSize int) []pop.Individual
- func Init(genOpt Options, e, m *env.I, cross LGPCrossover, act []Action, ...)
- func MatchEnvFitness(g *LGP, inputs, outputs [][]float64) int
- func MatchMemFitness(g *LGP, inputs, outputs [][]float64) int
- func Mem0Fitness(g *LGP, inputs, outputs [][]float64) int
- func OptInit(opt interface{})
- func PrintActions()
- func ResetCumActionWeights()
- type Action
- type FitnessFunc
- type InitOptions
- type Instruction
- type LGP
- func (gp *LGP) CanCrossover(other pop.Individual) bool
- func (gp *LGP) Copy() *LGP
- func (gp *LGP) Crossover(other pop.Individual) pop.Individual
- func (gp *LGP) ExpandMutate()
- func (gp *LGP) Fitness(input, expected [][]float64) int
- func (gp *LGP) GetInstruction() Instruction
- func (gp *LGP) GetReg(r1 int) (r2 int)
- func (gp *LGP) MemMutate()
- func (gp *LGP) Mutate()
- func (gp *LGP) Print()
- func (gp *LGP) RegVal(r1 int) int
- func (gp *LGP) Run()
- func (gp *LGP) SetReg(r1, v int)
- func (gp *LGP) ShrinkMutate()
- func (gp *LGP) SwapMutate()
- func (gp *LGP) ValueMutate()
- type LGPCrossover
- type Operator
- type Options
- type PointCrossover
- type UniformCrossover
Constants ¶
const ( SPECIAL_REGISTERS = 1 LAST_WRITTEN = -1 )
Variables ¶
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 ¶
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 MatchMemFitness ¶
func Mem0Fitness ¶
func PrintActions ¶
func PrintActions()
func ResetCumActionWeights ¶
func ResetCumActionWeights()
Types ¶
type Action ¶
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 ¶
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 ¶
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 (*LGP) CanCrossover ¶
func (gp *LGP) CanCrossover(other pop.Individual) bool
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) GetInstruction ¶
func (gp *LGP) GetInstruction() Instruction
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) ShrinkMutate ¶
func (gp *LGP) ShrinkMutate()
func (*LGP) SwapMutate ¶
func (gp *LGP) SwapMutate()
func (*LGP) ValueMutate ¶
func (gp *LGP) ValueMutate()
type LGPCrossover ¶
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