コード例 #1
0
ファイル: mutator.go プロジェクト: maxxk/neurvolve
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
}