Documentation
¶
Index ¶
- Constants
- Variables
- func Add(gp *LGP, xs ...int)
- func Bgeq(gp *LGP, xs ...int)
- func Bgz(gp *LGP, xs ...int)
- func Bnez(gp *LGP, xs ...int)
- func ConstInt(i int) func(gp *LGP, xs ...int)
- func Divide(gp *LGP, xs ...int)
- func EnvFitness(g *LGP, inputs, outputs [][]float64) int
- func EnvLen(gp *LGP, xs ...int)
- func GeneratePopulation(opt interface{}, popSize int) []pop.Individual
- func GetEnv(gp *LGP, xs ...int)
- func Init(genOpt Options, e, m *env.I, cross LGPCrossover, act []Action, ...)
- func Jmp(gp *LGP, xs ...int)
- 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 MemSwap(gp *LGP, xs ...int)
- func Mod(gp *LGP, xs ...int)
- func Multiply(gp *LGP, xs ...int)
- func Neg(gp *LGP, xs ...int)
- func OptInit(opt interface{})
- func Pow(gp *LGP, xs ...int)
- func Pow2(gp *LGP, xs ...int)
- func Pow3(gp *LGP, xs ...int)
- func PrintActions()
- func Randv(gp *LGP, xs ...int)
- func ResetCumActionWeights()
- func SetEnv(gp *LGP, xs ...int)
- func Subtract(gp *LGP, xs ...int)
- 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}, {ConstInt(0), "0", 1}, {ConstInt(1), "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}, {ConstInt(0), "0", 1}, {ConstInt(1), "1", 1}, {ConstInt(2), "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}, {ConstInt(0), "0", 1}, {ConstInt(1), "1", 1}, {ConstInt(2), "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}, {ConstInt(0), "0", 1}, {ConstInt(1), "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