public GenomeNEAT(CritterGenome critterBodyGenome, int numHidden) { // Constructor nodeNEATList = critterBodyGenome.GetBlankBrainNodesFromBody(); // returns a list of nodeNEAT's based on bodyGenome int currentID = nodeNEATList.Count; // Add in hidden nodes: for (int h = 0; h < numHidden; h++) { Debug.Log("NO HIDDEN NODES CREATED!!! -- need a way to keep track of innovation#'s, have no access to crossoverManager"); //GeneNodeNEAT newHiddenNode = new GeneNodeNEAT(currentID, GeneNodeNEAT.GeneNodeType.Hid, TransferFunctions.TransferFunction.RationalSigmoid, -1, 0, -1); //nodeNEATList.Add(newHiddenNode); //currentID++; } // do I need to save body-part&add-on information on the Brain NODES? or only on Neurons? linkNEATList = new List <GeneLinkNEAT>(); string newGenomeNEATDisplay = "NEW GenomeNEAT! #nodes: " + nodeNEATList.Count.ToString() + "\n"; for (int i = 0; i < nodeNEATList.Count; i++) { newGenomeNEATDisplay += "Node[" + i.ToString() + "] (" + nodeNEATList[i].id.ToString() + ", " + nodeNEATList[i].sourceAddonInno.ToString() + ", " + nodeNEATList[i].sourceAddonRecursionNum.ToString() + ", " + nodeNEATList[i].sourceAddonChannelNum.ToString() + ")\n"; } Debug.Log(newGenomeNEATDisplay); /*if (numInputs < 1 || numOutputs < 1) { * Debug.LogError("New NEAT Genome requires at least 1 input and output node!! [" + numInputs.ToString() + "," + numOutputs.ToString() + "]"); * } * else { * nodeNEATList = new List<GeneNodeNEAT>(); * int currentID = 0; * for (int i = 0; i < numInputs; i++) { * GeneNodeNEAT newInputNode = new GeneNodeNEAT(currentID, GeneNodeNEAT.GeneNodeType.In, TransferFunctions.TransferFunction.Linear); * nodeNEATList.Add(newInputNode); * currentID++; * } * for (int h = 0; h < numHidden; h++) { * GeneNodeNEAT newHiddenNode = new GeneNodeNEAT(currentID, GeneNodeNEAT.GeneNodeType.Hid, TransferFunctions.TransferFunction.RationalSigmoid); * nodeNEATList.Add(newHiddenNode); * currentID++; * } * for (int o = 0; o < numOutputs; o++) { * GeneNodeNEAT newOutputNode = new GeneNodeNEAT(currentID, GeneNodeNEAT.GeneNodeType.Out, TransferFunctions.TransferFunction.RationalSigmoid); * nodeNEATList.Add(newOutputNode); * currentID++; * } * * linkNEATList = new List<GeneLinkNEAT>(); * // Empty for now * }*/ }
public GenomeNEAT(CritterGenome critterBodyGenome, int numHidden) { // Constructor nodeNEATList = critterBodyGenome.GetBlankBrainNodesFromBody(); // returns a list of nodeNEAT's based on bodyGenome int currentID = nodeNEATList.Count; // Add in hidden nodes: for (int h = 0; h < numHidden; h++) { Debug.Log("NO HIDDEN NODES CREATED!!! -- need a way to keep track of innovation#'s, have no access to crossoverManager"); //GeneNodeNEAT newHiddenNode = new GeneNodeNEAT(currentID, GeneNodeNEAT.GeneNodeType.Hid, TransferFunctions.TransferFunction.RationalSigmoid, -1, 0, -1); //nodeNEATList.Add(newHiddenNode); //currentID++; } // do I need to save body-part&add-on information on the Brain NODES? or only on Neurons? linkNEATList = new List<GeneLinkNEAT>(); string newGenomeNEATDisplay = "NEW GenomeNEAT! #nodes: " + nodeNEATList.Count.ToString() + "\n"; for(int i = 0; i < nodeNEATList.Count; i++) { newGenomeNEATDisplay += "Node[" + i.ToString() + "] (" + nodeNEATList[i].id.ToString() + ", " + nodeNEATList[i].sourceAddonInno.ToString() + ", " + nodeNEATList[i].sourceAddonRecursionNum.ToString() + ", " + nodeNEATList[i].sourceAddonChannelNum.ToString() + ")\n"; } Debug.Log(newGenomeNEATDisplay); /*if (numInputs < 1 || numOutputs < 1) { Debug.LogError("New NEAT Genome requires at least 1 input and output node!! [" + numInputs.ToString() + "," + numOutputs.ToString() + "]"); } else { nodeNEATList = new List<GeneNodeNEAT>(); int currentID = 0; for (int i = 0; i < numInputs; i++) { GeneNodeNEAT newInputNode = new GeneNodeNEAT(currentID, GeneNodeNEAT.GeneNodeType.In, TransferFunctions.TransferFunction.Linear); nodeNEATList.Add(newInputNode); currentID++; } for (int h = 0; h < numHidden; h++) { GeneNodeNEAT newHiddenNode = new GeneNodeNEAT(currentID, GeneNodeNEAT.GeneNodeType.Hid, TransferFunctions.TransferFunction.RationalSigmoid); nodeNEATList.Add(newHiddenNode); currentID++; } for (int o = 0; o < numOutputs; o++) { GeneNodeNEAT newOutputNode = new GeneNodeNEAT(currentID, GeneNodeNEAT.GeneNodeType.Out, TransferFunctions.TransferFunction.RationalSigmoid); nodeNEATList.Add(newOutputNode); currentID++; } linkNEATList = new List<GeneLinkNEAT>(); // Empty for now }*/ }
public void AdjustBrainAfterBodyChange(ref CritterGenome bodyGenome) { // Try to do it assuming this function only took a CritterNode as input, rather than full bodyGenome: //CritterNode sourceNode = bodyGenome.CritterNodeList[bodyNodeID]; string beforeBrain = "AdjustBrain Before: \n"; string afterBrain = "AdjustBrain After: \n"; List <GeneNodeNEAT> newBrainNodeList = bodyGenome.GetBlankBrainNodesFromBody(); // doesn't include Hidden Nodes //List<GeneLinkNEAT> newBrainLinkList = new List<GeneLinkNEAT>(); // need to make a new copy so that the old link-list stays static while searching for matching from/toID's // Find number of Input+Output nodes in the old list: //int numOriginalInOutNodes = 0; //for (int i = 0; i < nodeNEATList.Count; i++) { // if(nodeNEATList[i].nodeType != GeneNodeNEAT.GeneNodeType.Hid) { // numOriginalInOutNodes++; // } //} // Compare this to the number of nodes in the new list (which doesn't contain any hidden nodes) //int netNewNodes = newBrainNodeList.Count - numOriginalInOutNodes; //Debug.Log("AdjustBrainAddedRecursion! numOriginalInOutNodes: " + numOriginalInOutNodes.ToString() + ", netNewNodes: " + netNewNodes.ToString() + ", bodyNodeID: " + bodyNodeID.ToString() + ", recursionNum: " + recursionNum.ToString()); int nextNodeIndexID = newBrainNodeList.Count; // where to start counting for hiddenNode ID's for (int i = 0; i < nodeNEATList.Count; i++) { beforeBrain += "Node " + nodeNEATList[i].id.ToString() + " (" + nodeNEATList[i].sourceAddonInno.ToString() + ", " + nodeNEATList[i].sourceAddonRecursionNum.ToString() + ", " + nodeNEATList[i].sourceAddonChannelNum.ToString() + ")\n"; if (nodeNEATList[i].nodeType == GeneNodeNEAT.GeneNodeType.Hid) { //Debug.Log("AdjustBrainAfterBodyChange HID NODE: nextNodeIndexID: " + (nextNodeIndexID).ToString()); GeneNodeNEAT clonedNode = new GeneNodeNEAT(nextNodeIndexID, nodeNEATList[i].nodeType, nodeNEATList[i].activationFunction, nodeNEATList[i].sourceAddonInno, nodeNEATList[i].sourceAddonRecursionNum, false, nodeNEATList[i].sourceAddonChannelNum); newBrainNodeList.Add(clonedNode); nextNodeIndexID++; } } for (int i = 0; i < newBrainNodeList.Count; i++) { afterBrain += "Node " + newBrainNodeList[i].id.ToString() + " (" + newBrainNodeList[i].sourceAddonInno.ToString() + ", " + newBrainNodeList[i].sourceAddonRecursionNum.ToString() + ", " + newBrainNodeList[i].sourceAddonChannelNum.ToString() + ")\n"; } // Once complete, replace oldNodeList with the new one: nodeNEATList = newBrainNodeList; //linkNEATList = newBrainLinkList; // Make sure that there aren't any links pointing to non-existent nodes: for (int i = 0; i < linkNEATList.Count; i++) { bool linkSevered = false; if (GetNodeIndexFromInt3(linkNEATList[i].fromNodeID) == -1) { linkSevered = true; } if (GetNodeIndexFromInt3(linkNEATList[i].toNodeID) == -1) { linkSevered = true; } if (linkSevered) { linkNEATList[i].enabled = false; //Debug.Log("LINK " + i.ToString() + " SEVERED!! " + linkNEATList[i].fromNodeID.ToString() + ", " + linkNEATList[i].toNodeID.ToString()); } } //Debug.Log(beforeBrain); //Debug.Log(afterBrain + "\n deltaNodes: " + netNewNodes.ToString()); }
public void AdjustBrainAfterBodyChange(ref CritterGenome bodyGenome) { // Try to do it assuming this function only took a CritterNode as input, rather than full bodyGenome: //CritterNode sourceNode = bodyGenome.CritterNodeList[bodyNodeID]; string beforeBrain = "AdjustBrain Before: \n"; string afterBrain = "AdjustBrain After: \n"; List<GeneNodeNEAT> newBrainNodeList = bodyGenome.GetBlankBrainNodesFromBody(); // doesn't include Hidden Nodes //List<GeneLinkNEAT> newBrainLinkList = new List<GeneLinkNEAT>(); // need to make a new copy so that the old link-list stays static while searching for matching from/toID's // Find number of Input+Output nodes in the old list: //int numOriginalInOutNodes = 0; //for (int i = 0; i < nodeNEATList.Count; i++) { // if(nodeNEATList[i].nodeType != GeneNodeNEAT.GeneNodeType.Hid) { // numOriginalInOutNodes++; // } //} // Compare this to the number of nodes in the new list (which doesn't contain any hidden nodes) //int netNewNodes = newBrainNodeList.Count - numOriginalInOutNodes; //Debug.Log("AdjustBrainAddedRecursion! numOriginalInOutNodes: " + numOriginalInOutNodes.ToString() + ", netNewNodes: " + netNewNodes.ToString() + ", bodyNodeID: " + bodyNodeID.ToString() + ", recursionNum: " + recursionNum.ToString()); int nextNodeIndexID = newBrainNodeList.Count; // where to start counting for hiddenNode ID's for (int i = 0; i < nodeNEATList.Count; i++) { beforeBrain += "Node " + nodeNEATList[i].id.ToString() + " (" + nodeNEATList[i].sourceAddonInno.ToString() + ", " + nodeNEATList[i].sourceAddonRecursionNum.ToString() + ", " + nodeNEATList[i].sourceAddonChannelNum.ToString() + ")\n"; if (nodeNEATList[i].nodeType == GeneNodeNEAT.GeneNodeType.Hid) { //Debug.Log("AdjustBrainAfterBodyChange HID NODE: nextNodeIndexID: " + (nextNodeIndexID).ToString()); GeneNodeNEAT clonedNode = new GeneNodeNEAT(nextNodeIndexID, nodeNEATList[i].nodeType, nodeNEATList[i].activationFunction, nodeNEATList[i].sourceAddonInno, nodeNEATList[i].sourceAddonRecursionNum, false, nodeNEATList[i].sourceAddonChannelNum); newBrainNodeList.Add(clonedNode); nextNodeIndexID++; } } for (int i = 0; i < newBrainNodeList.Count; i++) { afterBrain += "Node " + newBrainNodeList[i].id.ToString() + " (" + newBrainNodeList[i].sourceAddonInno.ToString() + ", " + newBrainNodeList[i].sourceAddonRecursionNum.ToString() + ", " + newBrainNodeList[i].sourceAddonChannelNum.ToString() + ")\n"; } // Once complete, replace oldNodeList with the new one: nodeNEATList = newBrainNodeList; //linkNEATList = newBrainLinkList; // Make sure that there aren't any links pointing to non-existent nodes: for (int i = 0; i < linkNEATList.Count; i++) { bool linkSevered = false; if (GetNodeIndexFromInt3(linkNEATList[i].fromNodeID) == -1) { linkSevered = true; } if (GetNodeIndexFromInt3(linkNEATList[i].toNodeID) == -1) { linkSevered = true; } if (linkSevered) { linkNEATList[i].enabled = false; //Debug.Log("LINK " + i.ToString() + " SEVERED!! " + linkNEATList[i].fromNodeID.ToString() + ", " + linkNEATList[i].toNodeID.ToString()); } } //Debug.Log(beforeBrain); //Debug.Log(afterBrain + "\n deltaNodes: " + netNewNodes.ToString()); }