private Color GetColorFromConnection(ConnectionNEAT connection, BrainNEAT brain) { //black = -1, white = 1 //float val01 = connection.weight[0] * 0.5f + 0.5f; float val01 = brain.neuronList[connection.fromNodeID].currentValue[0] * connection.weight[0] * 0.2f + 0.5f; Color newColor = new Color(val01, val01, val01); newColor = Color.Lerp(newColor, new Color(0f, 0f, 1f), 0f); //if (connection.nodeType == GeneNodeNEAT.GeneNodeType.In) { // newColor = Color.Lerp(newColor, new Color(0f, 1f, 0f), 0.75f); //} //if (connection.nodeType == GeneNodeNEAT.GeneNodeType.Out) { // newColor = Color.Lerp(newColor, new Color(1f, 0f, 0f), 0.75f); //} //Debug.Log(val01.ToString()); return(newColor); }
private Color GetColorFromConnection(ConnectionNEAT connection, BrainNEAT brain) { //black = -1, white = 1 //float val01 = connection.weight[0] * 0.5f + 0.5f; float val01 = brain.neuronList[connection.fromNodeID].currentValue[0] * connection.weight[0] * 0.2f + 0.5f; Color newColor = new Color(val01, val01, val01); newColor = Color.Lerp(newColor, new Color(0f, 0f, 1f), 0f); //if (connection.nodeType == GeneNodeNEAT.GeneNodeType.In) { // newColor = Color.Lerp(newColor, new Color(0f, 1f, 0f), 0.75f); //} //if (connection.nodeType == GeneNodeNEAT.GeneNodeType.Out) { // newColor = Color.Lerp(newColor, new Color(1f, 0f, 0f), 0.75f); //} //Debug.Log(val01.ToString()); return newColor; }
public void BuildBrainNetwork() { if(neuronList == null) { neuronList = new List<NeuronNEAT>(); } else { neuronList.Clear(); } if(connectionList == null) { connectionList = new List<ConnectionNEAT>(); } else { connectionList.Clear(); } if (inputNeuronList == null) { inputNeuronList = new List<NeuronNEAT>(); } else { inputNeuronList.Clear(); } if (outputNeuronList == null) { outputNeuronList = new List<NeuronNEAT>(); } else { outputNeuronList.Clear(); } int numActiveNodes = 0; int numActiveLinks = 0; // Create nodes: string nodesString = "BuildBrainNetwork() nodes: \n"; //Debug.Log("BuildBrainNetwork sourceGenome.nodeNEATList: " + sourceGenome.nodeNEATList.Count.ToString() + ", #sourceGenome.linkNEATList: " + sourceGenome.linkNEATList.Count.ToString()); for (int i = 0; i < sourceGenome.nodeNEATList.Count; i++) { NeuronNEAT newNeuron = new NeuronNEAT(sourceGenome.nodeNEATList[i].id, sourceGenome.nodeNEATList[i].nodeType, sourceGenome.nodeNEATList[i].activationFunction); neuronList.Add(newNeuron); if(newNeuron.nodeType == GeneNodeNEAT.GeneNodeType.In) { inputNeuronList.Add(newNeuron); // save reference to node } if (newNeuron.nodeType == GeneNodeNEAT.GeneNodeType.Out) { outputNeuronList.Add(newNeuron); } nodesString += "[" + i.ToString() + "]: " + newNeuron.nodeType.ToString() + ", (" + sourceGenome.nodeNEATList[i].id.ToString() + ", " + sourceGenome.nodeNEATList[i].sourceAddonInno.ToString() + ", " + sourceGenome.nodeNEATList[i].sourceAddonRecursionNum.ToString() + ", " + sourceGenome.nodeNEATList[i].sourceAddonChannelNum.ToString() + ")\n"; numActiveNodes++; } //Debug.Log(nodesString); // Create connections: string connectionsString = "BuildBrainNetwork() connections: "; for (int o = 0; o < sourceGenome.linkNEATList.Count; o++) { if(sourceGenome.linkNEATList[o].enabled) { numActiveLinks++; ConnectionNEAT newConnection = new ConnectionNEAT(sourceGenome.GetNodeIndexFromInt3(sourceGenome.linkNEATList[o].fromNodeID), sourceGenome.GetNodeIndexFromInt3(sourceGenome.linkNEATList[o].toNodeID), sourceGenome.linkNEATList[o].weight); connectionList.Add(newConnection); neuronList[newConnection.toNodeID].incomingConnectionsList.Add(newConnection); // add this connection to its destination neuron's list //Debug.Log("linkNEATList[" + o.ToString() + "], from: " + newConnection.fromNodeID.ToString() + ", to: " + newConnection.toNodeID.ToString() + ", weight: " + newConnection.weight[0]); connectionsString += "[" + o.ToString() + "] " + newConnection.fromNodeID.ToString() + "->" + newConnection.toNodeID.ToString() + ", w: " + newConnection.weight[0].ToString() + ", "; } } //Debug.Log("BuildBrainNetwork #nodes: " + numActiveNodes.ToString() + ", #links: " + numActiveLinks.ToString()); //Debug.Log(connectionsString); }
public void BuildBrainNetwork() { if (neuronList == null) { neuronList = new List <NeuronNEAT>(); } else { neuronList.Clear(); } if (connectionList == null) { connectionList = new List <ConnectionNEAT>(); } else { connectionList.Clear(); } if (inputNeuronList == null) { inputNeuronList = new List <NeuronNEAT>(); } else { inputNeuronList.Clear(); } if (outputNeuronList == null) { outputNeuronList = new List <NeuronNEAT>(); } else { outputNeuronList.Clear(); } int numActiveNodes = 0; int numActiveLinks = 0; // Create nodes: string nodesString = "BuildBrainNetwork() nodes: \n"; //Debug.Log("BuildBrainNetwork sourceGenome.nodeNEATList: " + sourceGenome.nodeNEATList.Count.ToString() + ", #sourceGenome.linkNEATList: " + sourceGenome.linkNEATList.Count.ToString()); for (int i = 0; i < sourceGenome.nodeNEATList.Count; i++) { NeuronNEAT newNeuron = new NeuronNEAT(sourceGenome.nodeNEATList[i].id, sourceGenome.nodeNEATList[i].nodeType, sourceGenome.nodeNEATList[i].activationFunction); neuronList.Add(newNeuron); if (newNeuron.nodeType == GeneNodeNEAT.GeneNodeType.In) { inputNeuronList.Add(newNeuron); // save reference to node } if (newNeuron.nodeType == GeneNodeNEAT.GeneNodeType.Out) { outputNeuronList.Add(newNeuron); } nodesString += "[" + i.ToString() + "]: " + newNeuron.nodeType.ToString() + ", (" + sourceGenome.nodeNEATList[i].id.ToString() + ", " + sourceGenome.nodeNEATList[i].sourceAddonInno.ToString() + ", " + sourceGenome.nodeNEATList[i].sourceAddonRecursionNum.ToString() + ", " + sourceGenome.nodeNEATList[i].sourceAddonChannelNum.ToString() + ")\n"; numActiveNodes++; } //Debug.Log(nodesString); // Create connections: string connectionsString = "BuildBrainNetwork() connections: "; for (int o = 0; o < sourceGenome.linkNEATList.Count; o++) { if (sourceGenome.linkNEATList[o].enabled) { numActiveLinks++; ConnectionNEAT newConnection = new ConnectionNEAT(sourceGenome.GetNodeIndexFromInt3(sourceGenome.linkNEATList[o].fromNodeID), sourceGenome.GetNodeIndexFromInt3(sourceGenome.linkNEATList[o].toNodeID), sourceGenome.linkNEATList[o].weight); connectionList.Add(newConnection); neuronList[newConnection.toNodeID].incomingConnectionsList.Add(newConnection); // add this connection to its destination neuron's list //Debug.Log("linkNEATList[" + o.ToString() + "], from: " + newConnection.fromNodeID.ToString() + ", to: " + newConnection.toNodeID.ToString() + ", weight: " + newConnection.weight[0]); connectionsString += "[" + o.ToString() + "] " + newConnection.fromNodeID.ToString() + "->" + newConnection.toNodeID.ToString() + ", w: " + newConnection.weight[0].ToString() + ", "; } } //Debug.Log("BuildBrainNetwork #nodes: " + numActiveNodes.ToString() + ", #links: " + numActiveLinks.ToString()); //Debug.Log(connectionsString); }