Пример #1
0
func randomNonRecurrentOutbound(neuron *ng.Neuron) *ng.OutboundConnection {
	for i := 0; i < len(neuron.Outbound); i++ {
		randIndex := RandomIntInRange(0, len(neuron.Outbound))
		outbound := neuron.Outbound[randIndex]
		if neuron.IsConnectionRecurrent(outbound) {
			continue
		} else {
			return outbound
		}
	}
	return nil
}
Пример #2
0
func NeuronRemoveBias(neuron *ng.Neuron) (bool, MutateResult) {
	if neuron.Bias != 0 {
		neuron.Bias = 0
		return true, nil
	}
	return false, nil
}
Пример #3
0
func NeuronAddBias(neuron *ng.Neuron) (bool, MutateResult) {
	if neuron.Bias == 0 {
		neuron.Bias = RandomBias()
		return true, nil
	}
	return false, nil
}
Пример #4
0
func possiblyPerturbBias(neuron *ng.Neuron, probability float64, saturationBounds []float64) bool {
	didPerturb := false
	if rand.Float64() < probability {
		bias := neuron.Bias
		perturbedBias := perturbParameter(bias, saturationBounds)
		neuron.Bias = perturbedBias
		logg.LogTo("DEBUG", "bias %v -> %v", bias, perturbedBias)
		didPerturb = true
	}
	return didPerturb
}
Пример #5
0
func verifyWeightsModified(neuron, neuronCopy *ng.Neuron) bool {
	foundModifiedWeight := false

	// make sure the weights have been modified for at least
	// one of the inbound connections
	originalInboundMap := neuron.InboundUUIDMap()
	copyInboundMap := neuronCopy.InboundUUIDMap()

	for uuid, connection := range originalInboundMap {
		connectionCopy := copyInboundMap[uuid]
		for i, weight := range connection.Weights {
			weightCopy := connectionCopy.Weights[i]
			if weight != weightCopy {
				foundModifiedWeight = true
				break
			}
		}
	}
	return foundModifiedWeight

}
Пример #6
0
func neuronAddInlinkFrom(neuron *ng.Neuron, sourceNodeId *ng.NodeId) *ng.InboundConnection {

	cortex := neuron.Cortex

	// create weight vector
	weightVectorLength := 1
	if sourceNodeId.NodeType == ng.SENSOR {
		sensor := cortex.FindSensor(sourceNodeId)
		weightVectorLength = sensor.VectorLength
	}
	weights := randomWeights(weightVectorLength)

	// make an inbound connection sourceNodeId <- neuron
	connection := neuron.ConnectInboundWeighted(sourceNodeId, weights)

	// make an outbound connection sourceNodeId -> neuron
	chosenConnector := cortex.FindConnector(sourceNodeId)
	ng.ConnectOutbound(chosenConnector, neuron)

	return connection

}
Пример #7
0
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

}