Ejemplo n.º 1
0
    public void MutateNodes()
    {
        List <NeuralGeneNode> tmpNodesNoinputsList = new List <NeuralGeneNode>();

        foreach (NeuralGeneNode node in HiddenLayers)
        {
            tmpNodesNoinputsList.Add(node);
        }

        foreach (NeuralGeneNode node in OutputLayer)
        {
            tmpNodesNoinputsList.Add(node);
        }

        NeuralGeneNode tmpHiddenNode = AddHiddenNode(neuralActivationFunctions[1]);

        List <NeuralGeneConnection> possibleConnectionsList = new List <NeuralGeneConnection>();

        foreach (var node in tmpNodesNoinputsList)
        {
            foreach (var connection in node.inputSynapses)
            {
                if ((connection.outputNeuron.nodeNumber > tmpHiddenNode.nodeNumber || OutputLayer.Contains(connection.outputNeuron)) && connection.connectionIsEnabled)
                {
                    possibleConnectionsList.Add(connection);
                }
            }
        }

        int nodeConnectionIndex = UnityEngine.Random.Range(0, possibleConnectionsList.Count);

        possibleConnectionsList[nodeConnectionIndex].connectionIsEnabled = false;

        AddConnection(possibleConnectionsList[nodeConnectionIndex].inputNeuron, tmpHiddenNode, true);
        AddConnection(tmpHiddenNode, possibleConnectionsList[nodeConnectionIndex].outputNeuron, true);
    }