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 }
func NeuronRemoveBias(neuron *ng.Neuron) (bool, MutateResult) { if neuron.Bias != 0 { neuron.Bias = 0 return true, nil } return false, nil }
func NeuronAddBias(neuron *ng.Neuron) (bool, MutateResult) { if neuron.Bias == 0 { neuron.Bias = RandomBias() return true, nil } return false, nil }
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 }
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 }
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 }
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 }