public void ChangeConnectionStatus(NeuralGeneConnection _synapse, bool _connectionIsEnabled) { if (HasConnection(_synapse)) { GetConnection(_synapse).connectionIsEnabled = _connectionIsEnabled; } }
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 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++; } } }
void HandleExtraNodes(NeuralGeneConnection thisParentConnection, NeuralGeneConnection otherParentConnection, NeuralGenome childGenome, int bestGenome, bool takeNotOptimum) { if (bestGenome == 0) { //other parent if (otherParentConnection != null) { AddNodesAndConnectionToChild(otherParentConnection, childGenome); } else if (thisParentConnection != null) // this parent { AddNodesAndConnectionToChild(thisParentConnection, childGenome); } } else if (bestGenome == 1 && otherParentConnection != null) { // choose from other parent AddNodesAndConnectionToChild(otherParentConnection, childGenome); } else if (bestGenome == 2 && thisParentConnection != null) { // choose from this parent AddNodesAndConnectionToChild(thisParentConnection, childGenome); } else if (takeNotOptimum && thisParentConnection != null) { AddNodesAndConnectionToChild(thisParentConnection, childGenome); } else if (takeNotOptimum && otherParentConnection != null) { AddNodesAndConnectionToChild(otherParentConnection, childGenome); } }
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++; }
void CrossOverParents(NeuralGeneConnection thisParentConnection, NeuralGeneConnection otherParentConnection, NeuralGenome childGenome, int bestGenome) { if (thisParentConnection.innovation == otherParentConnection.innovation) { //choose 50/50 int parent = Random.NextDouble() < 0.5f ? 1 : 2; //other parent if (parent == 1) { AddNodesAndConnectionToChild(otherParentConnection, childGenome); } else // this parent { AddNodesAndConnectionToChild(thisParentConnection, childGenome); } } else { if (bestGenome == 0) { //choose 50/50 int parent = Random.NextDouble() < 0.5f ? 1 : 2; //other parent if (parent == 1) { AddNodesAndConnectionToChild(otherParentConnection, childGenome); } else // this parent { AddNodesAndConnectionToChild(thisParentConnection, childGenome); } } else if (bestGenome == 1) { // choose from other parent AddNodesAndConnectionToChild(otherParentConnection, childGenome); } else { // choose from this parent AddNodesAndConnectionToChild(thisParentConnection, childGenome); } } }
public NeuralGeneConnection GetConnection(NeuralGeneConnection _synapse) { return(connections.Find(x => x == _synapse)); }
public bool HasConnection(NeuralGeneConnection _synapse) { return(connections.Contains(_synapse)); }
public NeuralGeneConnection FindConnection(NeuralGeneConnection _synapse) { return(inputSynapses.Find(x => x == _synapse)); }
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); }