本文整理匯總了Golang中github.com/rqme/neat.Context.Innovation方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Innovation方法的具體用法?Golang Context.Innovation怎麽用?Golang Context.Innovation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rqme/neat.Context
的用法示例。
在下文中一共展示了Context.Innovation方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createSeed
// Returns a genome build from the parameters
func createSeed(ctx neat.Context, cfg ClassicSettings) (adam neat.Genome) {
// Create the genome
inputs := cfg.NumInputs()
outputs := cfg.NumOutputs()
adam = neat.Genome{
Nodes: make(map[int]neat.Node, 1+inputs+outputs),
}
nodes := make([]neat.Node, len(adam.Nodes))
node := neat.Node{NeuronType: neat.Bias, ActivationType: neat.Direct, X: 0, Y: 0}
node.Innovation = ctx.Innovation(neat.NodeInnovation, node.Key())
adam.Nodes[node.Innovation] = node
nodes = append(nodes, node)
for i := 0; i < inputs; i++ {
node = neat.Node{NeuronType: neat.Input, ActivationType: neat.Direct, X: float64(i+1) / float64(inputs), Y: 0}
node.Innovation = ctx.Innovation(neat.NodeInnovation, node.Key())
adam.Nodes[node.Innovation] = node
nodes = append(nodes, node)
}
x := 0.5
for i := 0; i < outputs; i++ {
if outputs > 1 {
x = float64(i) / float64(outputs-1)
}
node = neat.Node{NeuronType: neat.Output, ActivationType: cfg.OutputActivation(), X: x, Y: 1}
node.Innovation = ctx.Innovation(neat.NodeInnovation, node.Key())
adam.Nodes[node.Innovation] = node
nodes = append(nodes, node)
}
rng := rand.New(rand.NewSource(rand.Int63()))
// adam.Conns = make(map[int]neat.Connection, (1+inputs)*outputs)
// for i := 0; i < 1+inputs; i++ {
// for j := 0; j < outputs; j++ {
// w := (rng.Float64()*2.0 - 1.0) * cfg.WeightRange()
// conn := neat.Connection{Source: nodes[i].Innovation, Target: nodes[j+1+inputs].Innovation, Enabled: true, Weight: w}
// conn.Innovation = ctx.Innovation(neat.ConnInnovation, conn.Key())
// adam.Conns[conn.Innovation] = conn
// }
// }
ts := cfg.Traits()
adam.Traits = make([]float64, len(ts))
for i, trait := range ts {
adam.Traits[i] = rng.Float64()*(trait.Max-trait.Min) + trait.Min // TODO: Get setting values from configuration
}
return adam
}