github.com/yaricom/goNEAT@v0.0.0-20210507221059-e2110b885482/neat/genetics/common.go (about) 1 // Package genetics holds data holders and helper utilities used to implement genetic evolution algorithm 2 package genetics 3 4 import ( 5 "errors" 6 "github.com/yaricom/goNEAT/neat" 7 "github.com/yaricom/goNEAT/neat/network" 8 ) 9 10 // The innovation method type to be applied 11 type innovationType byte 12 // Available innovation types 13 const ( 14 // The novelty will be introduced by new NN node 15 newNodeInnType innovationType = iota + 1 16 // The novelty will be introduced by new NN link 17 newLinkInnType 18 ) 19 20 21 // The mutator type that specifies a kind of mutation of connection weights between NN nodes 22 type mutatorType byte 23 // Available mutator types 24 const ( 25 //This adds Gaussian noise to the weights 26 gaussianMutator mutatorType = iota + 1 27 //This sets weights to numbers chosen from a Gaussian distribution 28 goldGaussianMutator 29 ) 30 31 // Defines format of Genome data encoding 32 type GenomeEncoding byte 33 34 const ( 35 // The plain text 36 PlainGenomeEncoding GenomeEncoding = iota + 1 37 // The rich text in YAML 38 YAMLGenomeEncoding 39 ) 40 41 var ( 42 ErrUnsupportedGenomeEncoding = errors.New("unsupported genome encoding") 43 ) 44 45 // Utility to select trait with given ID from provided Traits array 46 func traitWithId(trait_id int, traits []*neat.Trait) *neat.Trait { 47 if trait_id != 0 && traits != nil { 48 for _, tr := range traits { 49 if tr.Id == trait_id { 50 return tr 51 } 52 } 53 } 54 return nil 55 } 56 57 // Utility to select NNode with given ID from provided NNodes array 58 func nodeWithId(node_id int, nodes []*network.NNode) *network.NNode { 59 if node_id != 0 && nodes != nil { 60 for _, n := range nodes { 61 if n.Id == node_id { 62 return n 63 } 64 } 65 } 66 return nil 67 } 68