func TopologyOrWeightMutator(cortex *ng.Cortex) (success bool, result MutateResult) { randomNumber := ng.RandomIntInRange(0, 100) didMutate := false var mutators []CortexMutator if randomNumber > 90 { mutators = []CortexMutator{MutateActivation} } else if randomNumber > 80 { mutators = []CortexMutator{MutateAllWeightsBellCurve} } else if randomNumber > 20 { // apply topological mutation includeNonTopological := false mutators = CortexMutatorsNonRecurrent(includeNonTopological) } else { mutators = CortexMutatorsNonTopological() } // before we mutate the cortex, we need to init it, // otherwise things like Outsplice will fail because // there are no DataChan's. cortex.Init() for i := 0; i <= 100; i++ { randInt := RandomIntInRange(0, len(mutators)) mutator := mutators[randInt] didMutate, _ = mutator(cortex) if !didMutate { logg.LogTo("NEURVOLVE", "Mutate didn't work, retrying...") continue } break } logg.LogTo("NEURVOLVE", "did mutate: %v", didMutate) success = didMutate result = "nothing" return }
func neuronAddInlink(neuron *ng.Neuron, availableNodeIds []*ng.NodeId) (bool, *ng.InboundConnection) { if len(availableNodeIds) == 0 { log.Printf("Warning: unable to add inlink to neuron: %v", neuron) return false, nil } randIndex := ng.RandomIntInRange(0, len(availableNodeIds)) chosenNodeId := availableNodeIds[randIndex] return true, neuronAddInlinkFrom(neuron, chosenNodeId) }
func NeuronMutateActivation(neuron *ng.Neuron) (bool, MutateResult) { encodableActivations := ng.AllEncodableActivations() for i := 0; i < 100; i++ { // pick a random activation function from list randomIndex := ng.RandomIntInRange(0, len(encodableActivations)) chosenActivation := encodableActivations[randomIndex] // if we chose a different activation than current one, use it if chosenActivation.Name != neuron.ActivationFunction.Name { neuron.ActivationFunction = chosenActivation return true, nil } } // if we got this far, something went wrong return false, nil }
func RandomIntInRange(min, max int) int { return ng.RandomIntInRange(min, max) }