Documentation ¶
Index ¶
- Variables
- func AddStorage(spaces int, baseWeight float64)
- func CalculateCumulativeActionWeights(args ...int) []float64
- func EnvFitness(g *GP, inputs, outputs [][]float64) int
- func Eval(n *Node) int
- func GeneratePopulation(opt interface{}, popSize int) []pop.Individual
- func Init(genOpt Options, e *env.I, cross GPCrossover, act [][]Action, ...)
- func MatchEnvFitness(g *GP, inputs, outputs [][]float64) int
- func MatchMemFitness(g *GP, inputs, outputs [][]float64) int
- func Mem0Fitness(g *GP, inputs, outputs [][]float64) int
- func ModifyActionWeight(action string, newWeight float64) bool
- func OptInit(opt interface{})
- func OutputFitness(g *GP, inputs, outputs [][]float64) int
- type Action
- type Actions
- type FitnessFunc
- type GP
- type GPCrossover
- type InitOptions
- type Node
- type Operator
- type Options
- type PointCrossover
Constants ¶
This section is empty.
Variables ¶
var ( OneArgActions = []Action{ {getEnv, "env"}, } TwoArgActions = []Action{ {add, "add"}, {multiply, "mult"}, {divide, "div"}, } ThreeArgActions = []Action{ {neZero, "!0?"}, } ZeroArgActions = []Action{ {zero, "0"}, {one, "1"}, {two, "2"}, } Pow8Actions = [][]Action{ { {randv, "rand"}, {zero, "0"}, {one, "1"}, {two, "2"}, }, { {neg, "neg"}, {getEnv, "env"}, }, { {add, "add"}, {subtract, "sub"}, {multiply, "multiply"}, }, { {isPositive, "+?"}, {ifRand, "rand?"}, {neZero, "!0?"}, }, } BaseActions = [][]Action{ ZeroArgActions, OneArgActions, TwoArgActions, ThreeArgActions, } TartarusActions = [][]Action{ { {randv, "rand"}, {zero, "0"}, {one, "1"}, {two, "2"}}, { {neg, "neg"}}, { {add, "add"}, {subtract, "sub"}, {multiply, "multiply"}, {do2, "do2"}}, { {isPositive, "+?"}, {ifRand, "rand?"}, {do3, "do3"}, {neZero, "!0?"}}, } )
This is severely limited so as to weigh all actions the same. We want to be able to give certain actions different weights for being picked!
Functions ¶
func AddStorage ¶
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 *env.I, cross GPCrossover, act [][]Action, baseActionWeight float64, f FitnessFunc)
func MatchEnvFitness ¶
func MatchMemFitness ¶
func Mem0Fitness ¶
func ModifyActionWeight ¶
Returns whether the modification was successful (whether an action with that name was found)
func OutputFitness ¶
An example fitness which treats the output of the GP as a value to compare against the single expected output
Types ¶
type Actions ¶
type Actions [][]Action
The effect of a given action is internally defined by the action, and GPs need to learn what actions are useful, when. The first slice here represents how many arguments each action takes.
type FitnessFunc ¶
func ComplexityFitness ¶
func ComplexityFitness(f FitnessFunc, mod float64) FitnessFunc
func TimeFitness ¶
func TimeFitness(f FitnessFunc, threshold int, timeLimit int) FitnessFunc
type GP ¶
The principal Individual implementation for the gp package
func GenerateGP ¶
func (*GP) CanCrossover ¶
func (gp *GP) CanCrossover(other pop.Individual) bool
func (*GP) Crossover ¶
func (gp *GP) Crossover(other pop.Individual) pop.Individual
func (*GP) ShrinkMutate ¶
func (gp *GP) ShrinkMutate()
func (*GP) SwapMutate ¶
func (gp *GP) SwapMutate()
type GPCrossover ¶
type InitOptions ¶
type InitOptions struct { GenOpt Options Env *env.I Cross GPCrossover Act [][]Action BaseActionWeight float64 Fitness FitnessFunc StorageCount int StorageWeight float64 }
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func (*Node) GenerateTree ¶
func (*Node) GetAllNodes ¶
func (*Node) GetRandomNode ¶
func (*Node) Print ¶
http://stackoverflow.com/questions/4965335/how-to-print-binary-tree-diagram Original credit, as per above source, to whoever wrote tree for linux
type Options ¶
type Options struct { MaxNodeCount int MaxStartDepth int MaxDepth int // These mutation chances are rolled once per GP // // Swap mutation is a swap of one node's action // to another action from the pool with the same // number of arguments. // (This is based off of GPJPP. Question: why is // there no mutation swap that can change the number // of arguments?) SwapMutationChance float64 // Shrink Mutation picks some leaf node and replaces // its parent with it. ShrinkMutationChance float64 }
type PointCrossover ¶
type PointCrossover struct{}
func (PointCrossover) Crossover ¶
func (pc PointCrossover) Crossover(a, b *GP) *GP