public static void AddConnectionMutation(EvolveNeuroNet neuroNet) { List <Neuron> neurons = neuroNet.ToNeuronList(); int from = 0; int to = 0; bool found = false; do { from = Random.Range(0, neurons.Count); if (neuroNet.IsOutput(neurons[from])) { found = false; } else { found = true; } if (found) { to = Random.Range(0, neurons.Count); if (to == from) { found = false; } else { if (neuroNet.IsInput(neurons[to])) { found = false; } else { found = true; } foreach (var conn in neurons[from].Connections) { if (conn.Target.Index == neurons[to].Index) { found = false; } } } } } while (!found); neuroNet.AddConnection(neurons[from], neurons[to]); RebuildNet(neuroNet); }
public static void OnOffConnectionMutation(EvolveNeuroNet neuroNet) { List <Connection> connections = neuroNet.ToConnectionList(); int index = Random.Range(0, connections.Count); if (connections[index].IsActive) { connections[index].Deactivate(); } else { connections[index].Activate(); } }
public static void WeightMutation(EvolveNeuroNet neuroNet) { List <Connection> connections = neuroNet.ToConnectionList(); if (connections.Count != 0) { int index = Random.Range(0, connections.Count); float mutationRate = Mathf.Lerp(0.1f, 0.01f, Environment.Generation / 1000f); float mutation = 12f * mutationRate; if (Random.Range(0, 100) < 50) { connections[index].Weight += mutation; } else { connections[index].Weight -= mutation; } } }
public static void AddNodeMutation(EvolveNeuroNet neuroNet) { List <Connection> connections = neuroNet.ToConnectionList(); if (connections.Count != 0) { bool found = false; foreach (var conn in connections) { if (conn.IsActive) { found = true; } } if (found) { int index = 0; found = false; do { index = Random.Range(0, connections.Count); if (connections[index].IsActive) { found = true; } } while (!found); connections[index].Deactivate(); Neuron neuron = neuroNet.AddNeuron(); neuroNet.AddConnection(connections[index].Source, neuron); neuroNet.AddConnection(neuron, connections[index].Target); List <Neuron> list = new List <Neuron>(); list.Add(neuron); neuroNet.HiddenLayer.Add(list); } RebuildNet(neuroNet); } }
private static void RebuildNet(EvolveNeuroNet neuroNet) { List <Connection> connCopy = CopyConnections(neuroNet.ToConnectionList()); neuroNet.GenerateFromConnections(connCopy); }