Beispiel #1
0
    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();
        }
    }
Beispiel #2
0
    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;
            }
        }
    }
Beispiel #3
0
    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);
        }
    }
Beispiel #4
0
    private static void RebuildNet(EvolveNeuroNet neuroNet)
    {
        List <Connection> connCopy = CopyConnections(neuroNet.ToConnectionList());

        neuroNet.GenerateFromConnections(connCopy);
    }