當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Cortex.CreateNeuronInLayer方法代碼示例

本文整理匯總了Golang中github.com/maxxk/neurgo.Cortex.CreateNeuronInLayer方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cortex.CreateNeuronInLayer方法的具體用法?Golang Cortex.CreateNeuronInLayer怎麽用?Golang Cortex.CreateNeuronInLayer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/maxxk/neurgo.Cortex的用法示例。


在下文中一共展示了Cortex.CreateNeuronInLayer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: AddNeuronNonRecurrent

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
}
開發者ID:maxxk,項目名稱:neurvolve,代碼行數:28,代碼來源:mutator.go

示例2: Outsplice

func Outsplice(cortex *ng.Cortex, chooseOutbound OutboundChooser) (bool, *ng.Neuron) {

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

	for i := 0; i < numAttempts; i++ {
		neuronA := randomNeuron(cortex)
		outbound := chooseOutbound(neuronA)
		if outbound == nil {
			continue
		}

		if neuronA.NodeId.UUID == outbound.NodeId.UUID {
			continue
		}

		nodeIdB := outbound.NodeId

		// figure out which layer neuronK will go in
		nodeIdLayerMap := cortex.NodeIdLayerMap()
		layerA := neuronA.NodeId.LayerIndex
		layerB := nodeIdB.LayerIndex
		layerK := nodeIdLayerMap.LayerBetweenOrNew(layerA, layerB)

		// create neuron K
		neuronK := cortex.CreateNeuronInLayer(layerK)

		// disconnect neuronA <-> nodeB
		nodeBConnector := cortex.FindInboundConnector(nodeIdB)
		ng.DisconnectOutbound(neuronA, nodeIdB)
		ng.DisconnectInbound(nodeBConnector, neuronA)

		// connect neuronA -> neuronK
		weights := randomWeights(1)
		ng.ConnectOutbound(neuronA, neuronK)
		ng.ConnectInboundWeighted(neuronK, neuronA, weights)

		// connect neuronK -> nodeB
		switch nodeIdB.NodeType {
		case ng.NEURON:
			neuronB := cortex.FindNeuron(nodeIdB)
			ng.ConnectOutbound(neuronK, neuronB)
			ng.ConnectInboundWeighted(nodeBConnector, neuronK, weights)
		case ng.ACTUATOR:
			actuatorB := cortex.FindActuator(nodeIdB)
			ng.ConnectOutbound(neuronK, actuatorB)
			ng.ConnectInbound(nodeBConnector, neuronK)
		}
		return true, neuronK

	}
	return false, nil

}
開發者ID:maxxk,項目名稱:neurvolve,代碼行數:53,代碼來源:mutator.go

示例3: AddNeuronRecurrent

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

}
開發者ID:maxxk,項目名稱:neurvolve,代碼行數:44,代碼來源:mutator.go


注:本文中的github.com/maxxk/neurgo.Cortex.CreateNeuronInLayer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。