public void AddConnection(IEnumerable <NeuralGeneNode> _inputNeurons, NeuralGeneNode _outputNeuron, bool _connectionIsEnabled, bool _increaseInnovation = true) { if (connections == null) { connections = new List <NeuralGeneConnection>(); } foreach (var inputNeuron in _inputNeurons) { NeuralGeneConnection tmpSynapse = new NeuralGeneConnection(inputNeuron, _outputNeuron, _connectionIsEnabled, _increaseInnovation ? currInnovation : localInnovation); _outputNeuron.AddConnection(inputNeuron, tmpSynapse, _connectionIsEnabled, _increaseInnovation ? currInnovation : localInnovation); connections.Add(tmpSynapse); if (_increaseInnovation) { currInnovation++; if (IncreaseGlobalInnovation != null) { IncreaseGlobalInnovation(currInnovation); } } else { localInnovation++; } } }
public void AddConnection(NeuralGeneNode _inputNeuron, NeuralGeneNode _outputNeuron, float _bias, bool _connectionIsEnabled, bool _increaseInnovation = true) { if (connections == null) { connections = new List <NeuralGeneConnection>(); } NeuralGeneConnection tmpSynapse = new NeuralGeneConnection(_inputNeuron, _outputNeuron, _connectionIsEnabled, _increaseInnovation ? currInnovation : localInnovation); _outputNeuron.AddConnection(_inputNeuron, tmpSynapse, _bias, _connectionIsEnabled, _increaseInnovation ? currInnovation : localInnovation); connections.Add(tmpSynapse); if (_increaseInnovation) { currInnovation++; if (IncreaseGlobalInnovation != null) { IncreaseGlobalInnovation(currInnovation); } } else { localInnovation++; } }
void AddNodesAndConnectionToChild(NeuralGeneConnection ParentGenome, NeuralGenome childGenome) { NeuralGeneNode tmpInputNode = null; NeuralGeneNode tmpOutputNode = null; NeuralGeneConnection tmpConnection = null; if (childGenome.HasNode(ParentGenome.inputNeuron.nodeNumber)) { tmpInputNode = childGenome.GetNode(ParentGenome.inputNeuron.nodeNumber); } else { tmpInputNode = AddNodeToGenome(ParentGenome.inputNeuron.nodeType, childGenome); tmpInputNode.bias = ParentGenome.inputNeuron.bias; tmpInputNode.nodeNumber = ParentGenome.inputNeuron.nodeNumber; } if (childGenome.HasNode(ParentGenome.outputNeuron.nodeNumber)) { tmpOutputNode = childGenome.GetNode(ParentGenome.outputNeuron.nodeNumber); } else { tmpOutputNode = AddNodeToGenome(ParentGenome.outputNeuron.nodeType, childGenome); tmpOutputNode.bias = ParentGenome.outputNeuron.bias; tmpOutputNode.nodeNumber = ParentGenome.outputNeuron.nodeNumber; } if (!childGenome.HasConnection(ParentGenome.inputNeuron.nodeNumber, ParentGenome.outputNeuron.nodeNumber)) { childGenome.AddConnection(tmpInputNode, tmpOutputNode, ParentGenome.connectionIsEnabled, ParentGenome.innovation); } }
public NeuralGeneConnection(NeuralGeneNode _inputNeuron, NeuralGeneNode _outputNeuron, bool _connectionIsEnabled, int _innovation) { inputNeuron = _inputNeuron; outputNeuron = _outputNeuron; weight = NeatNeuralNetwork.GetRandom(); connectionIsEnabled = _connectionIsEnabled; innovation = _innovation; }
public bool HasOutput(NeuralGeneNode _node) { foreach (var output in outputSynapses) { if (output.outputNeuron == _node) { return(true); } } return(false); }
public bool HasInput(NeuralGeneNode _node) { foreach (var input in inputSynapses) { if (input.inputNeuron == _node) { return(true); } } return(false); }
public void AddConnection(NeuralGeneNode _inputNeuron, NeuralGeneNode _outputNeuron, bool _connectionIsEnabled, int _innovation) { if (connections == null) { connections = new List <NeuralGeneConnection>(); } NeuralGeneConnection tmpSynapse = new NeuralGeneConnection(_inputNeuron, _outputNeuron, _connectionIsEnabled, _innovation); _outputNeuron.AddConnection(_inputNeuron, tmpSynapse, _connectionIsEnabled, _innovation); connections.Add(tmpSynapse); localInnovation++; }
public NeuralGeneNode AddHiddenNode(NeuralActivationFunction _neuralActivationFunctions) { if (HiddenLayers == null) { HiddenLayers = new List <NeuralGeneNode>(); } if (nodes == null) { nodes = new List <NeuralGeneNode>(); } NeuralGeneNode tmpNode = new NeuralGeneNode(_neuralActivationFunctions, nodes.Count + 1, NeuralNodeType.Hidden); HiddenLayers.Add(tmpNode); nodes.Add(tmpNode); return(tmpNode); }
public NeuralGeneNode AddOutputNode(NeuralActivationFunction _neuralActivationFunctions) { if (OutputLayer == null) { OutputLayer = new List <NeuralGeneNode>(); } if (nodes == null) { nodes = new List <NeuralGeneNode>(); } NeuralGeneNode tmpNode = new NeuralGeneNode(_neuralActivationFunctions, nodes.Count + 1, NeuralNodeType.Output); OutputLayer.Add(tmpNode); nodes.Add(tmpNode); return(tmpNode); }
public void AddInputsNode(int _inputSize, NeuralActivationFunction _neuralActivationFunctions) { if (InputLayer == null) { InputLayer = new List <NeuralGeneNode>(); } if (nodes == null) { nodes = new List <NeuralGeneNode>(); } for (int i = 0; i < _inputSize; i++) { NeuralGeneNode tmpNode = new NeuralGeneNode(_neuralActivationFunctions, i + 1, NeuralNodeType.Input); InputLayer.Add(tmpNode); nodes.Add(tmpNode); } }
public void AddOutputsNode(int _outputSize, NeuralActivationFunction _neuralActivationFunctions) { if (OutputLayer == null) { OutputLayer = new List <NeuralGeneNode>(); } if (nodes == null) { nodes = new List <NeuralGeneNode>(); } for (int i = 0; i < _outputSize; i++) { NeuralGeneNode tmpNode = new NeuralGeneNode(_neuralActivationFunctions, nodes.Count + 1, NeuralNodeType.Output); OutputLayer.Add(tmpNode); nodes.Add(tmpNode); } }
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); }
public NeuralGeneNode GetNode(NeuralGeneNode _neuron) { return(nodes.Find(x => x == _neuron)); }
public bool HasNode(NeuralGeneNode _neuron) { return(nodes.Contains(_neuron)); }
public void AddConnection(NeuralGeneNode _inputNeuron, NeuralGeneConnection _synapse, float _bias, bool _connectionIsEnabled, int _innovation) { bias = _bias; _inputNeuron.outputSynapses.Add(_synapse); inputSynapses.Add(_synapse); }
public void AddConnection(NeuralGeneNode _inputNeuron, NeuralGeneConnection _synapse, bool _connectionIsEnabled, int _innovation) { bias = NeatNeuralNetwork.GetRandom(); _inputNeuron.outputSynapses.Add(_synapse); inputSynapses.Add(_synapse); }