// 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 }