Example #1
0
func AddNeuronNonRecurrent(cortex *ng.Cortex) (bool, MutateResult) {
	numAttempts := len(cortex.AllNodeIds()) * 5

	for i := 0; i < numAttempts; i++ {

		nodeIdLayerMap := cortex.NodeIdLayerMap()
		neuronLayerMap := cortex.NeuronLayerMap()
		randomLayer := neuronLayerMap.ChooseRandomLayer()

		upstreamNodeId := nodeIdLayerMap.ChooseNodeIdPrecedingLayer(randomLayer)
		if upstreamNodeId == nil {
			continue
		}

		downstreamNodeId := findDownstreamNodeId(cortex, nodeIdLayerMap, randomLayer)
		if downstreamNodeId == nil {
			continue
		}

		neuron := cortex.CreateNeuronInLayer(randomLayer)
		neuronAddInlinkFrom(neuron, upstreamNodeId)
		neuronAddOutlinkTo(neuron, downstreamNodeId)

		return true, neuron

	}
	return false, nil
}
Example #2
0
func AddNeuronRecurrent(cortex *ng.Cortex) (bool, MutateResult) {

	numAttempts := len(cortex.AllNodeIds()) * 5

	for i := 0; i < numAttempts; i++ {

		nodeIdLayerMap := cortex.NodeIdLayerMap()
		neuronLayerMap := cortex.NeuronLayerMap()
		randomLayer := neuronLayerMap.ChooseRandomLayer()
		inboundNodeId := findRecurrentInboundNodeId(cortex,
			nodeIdLayerMap,
			randomLayer)

		if inboundNodeId == nil {
			log.Printf("Warn: unable to find inbound node id")
			continue
		}

		if randomLayer == inboundNodeId.LayerIndex {
			continue
		}

		neuron := cortex.CreateNeuronInLayer(randomLayer)

		outboundNodeId := findRecurrentOutboundNodeId(cortex,
			nodeIdLayerMap,
			randomLayer)

		if outboundNodeId == nil {
			log.Printf("Warn: unable to find outbound node id")
			continue
		}

		neuronAddInlinkFrom(neuron, inboundNodeId)
		neuronAddOutlinkTo(neuron, outboundNodeId)

		return true, neuron

	}

	logg.LogTo("NEURVOLVE", "return false, nil")
	return false, nil

}