コード例 #1
0
ファイル: population_trainer.go プロジェクト: maxxk/neurvolve
func (pt *PopulationTrainer) generateOffspring(population []EvaluatedCortex) (withOffspring []EvaluatedCortex) {

	withOffspring = make([]EvaluatedCortex, 0)
	withOffspring = append(withOffspring, population...)

	for _, evaldCortex := range population {

		cortex := evaldCortex.Cortex
		offspringCortex := cortex.Copy()

		offspringNodeIdStr := fmt.Sprintf("cortex-%s", ng.NewUuid())
		offspringCortex.NodeId = ng.NewCortexId(offspringNodeIdStr)

		succeeded, _ := pt.CortexMutator(offspringCortex)
		if !succeeded {
			logg.LogPanic("Unable to mutate cortex: %v", offspringCortex)
		}

		evaldCortexOffspring := EvaluatedCortex{
			Cortex:              offspringCortex,
			ParentId:            cortex.NodeId.UUID,
			CreatedInGeneration: pt.CurrentGeneration,
			Fitness:             0.0,
		}

		withOffspring = append(withOffspring, evaldCortexOffspring)

	}

	return

}
コード例 #2
0
ファイル: cortex_example.go プロジェクト: maxxk/neurvolve
func SingleNeuronCortex(uuid string) *ng.Cortex {

	sensor := &ng.Sensor{
		NodeId:       ng.NewSensorId("sensor", 0.0),
		VectorLength: 1,
	}
	sensor.Init()

	neuron := &ng.Neuron{
		ActivationFunction: ng.EncodableIdentity(),
		NodeId:             ng.NewNeuronId("neuron", 0.15),
		Bias:               1,
	}
	neuron.Init()

	actuator := &ng.Actuator{
		NodeId:       ng.NewActuatorId("actuator", 0.5),
		VectorLength: 1,
	}
	actuator.Init()

	sensor.ConnectOutbound(neuron)
	neuron.ConnectInboundWeighted(sensor, []float64{1})

	neuron.ConnectOutbound(actuator)
	actuator.ConnectInbound(neuron)

	nodeId := ng.NewCortexId(uuid)

	cortex := &ng.Cortex{
		NodeId: nodeId,
	}
	cortex.SetSensors([]*ng.Sensor{sensor})
	cortex.SetNeurons([]*ng.Neuron{neuron})
	cortex.SetActuators([]*ng.Actuator{actuator})

	return cortex

}
コード例 #3
0
ファイル: cortex_example.go プロジェクト: maxxk/neurvolve
func BasicCortex() *ng.Cortex {

	sensor := &ng.Sensor{
		NodeId:       ng.NewSensorId("sensor", 0.0),
		VectorLength: 2,
	}
	sensor.Init()

	hiddenNeuron1 := &ng.Neuron{
		ActivationFunction: ng.EncodableSigmoid(),
		NodeId:             ng.NewNeuronId("hidden-neuron1", 0.15),
		Bias:               -30,
	}
	hiddenNeuron1.Init()

	hiddenNeuron2 := &ng.Neuron{
		ActivationFunction: ng.EncodableSigmoid(),
		NodeId:             ng.NewNeuronId("hidden-neuron2", 0.25),
		Bias:               10,
	}
	hiddenNeuron2.Init()

	hiddenNeuron3 := &ng.Neuron{
		ActivationFunction: ng.EncodableSigmoid(),
		NodeId:             ng.NewNeuronId("hidden-neuron3", 0.35),
		Bias:               10,
	}
	hiddenNeuron3.Init()

	outputNeuron := &ng.Neuron{
		ActivationFunction: ng.EncodableSigmoid(),
		NodeId:             ng.NewNeuronId("output-neuron", 0.45),
		Bias:               -10,
	}
	outputNeuron.Init()

	actuator := &ng.Actuator{
		NodeId:       ng.NewActuatorId("actuator", 0.5),
		VectorLength: 1,
	}
	actuator.Init()

	sensor.ConnectOutbound(hiddenNeuron1)
	hiddenNeuron1.ConnectInboundWeighted(sensor, []float64{20, 20})

	hiddenNeuron1.ConnectOutbound(hiddenNeuron2)
	hiddenNeuron2.ConnectInboundWeighted(hiddenNeuron1, []float64{1})

	hiddenNeuron2.ConnectOutbound(hiddenNeuron3)
	hiddenNeuron3.ConnectInboundWeighted(hiddenNeuron2, []float64{1})

	hiddenNeuron3.ConnectOutbound(outputNeuron)
	outputNeuron.ConnectInboundWeighted(hiddenNeuron3, []float64{1})

	outputNeuron.ConnectOutbound(actuator)
	actuator.ConnectInbound(outputNeuron)

	nodeId := ng.NewCortexId("test-cortex")

	cortex := &ng.Cortex{
		NodeId: nodeId,
	}
	cortex.SetSensors([]*ng.Sensor{sensor})
	cortex.SetNeurons([]*ng.Neuron{hiddenNeuron1, hiddenNeuron2, hiddenNeuron3, outputNeuron})
	cortex.SetActuators([]*ng.Actuator{actuator})

	return cortex

}