public ANNInputNode InstanciateAsInput() { ANNInputNode n = ScriptableObject.CreateInstance <ANNInputNode>(); n.Copy(this); n.OnEnable(); this.instances.Add(n); n.instanceParent = Parent(); return(n); }
/// USER METHODS /// -------------------------------------------------------------------------------------------------- // Input --- public void SetInput(ANNInputNode node, float value) { if (node == null) { Debug.LogWarning(this.name + " => Trying to SetInput(node, value) of a 'null' node"); return; } if (tickType == TickType.TickOnInput) { this.Tick(); } node.SetInput(value); }
private static ANNInputNode LoadInputNode(DATA_STRUCTS.NodeDataStruct data) { ANNInputNode parent = null; foreach (string asset in AssetDatabase.FindAssets("t:ANNInputNode")) { if (data.referenceuid == asset) { parent = AssetDatabase.LoadAssetAtPath<ANNInputNode>(AssetDatabase.GUIDToAssetPath(asset)); break; } } if (parent == null) return null; return parent.InstanciateAsInput(); }
// Set Inputs --- public void SetInput(ANNInputNode node, float value) { if (node == null) { Debug.LogWarning(this.name + " => Trying to SetInput(node, value) of a 'null' node"); return; } if (network == null) { Debug.LogWarning(this.name + " => Trying to SetInput(node, value) with a 'null' network reference"); return; } network.SetInput(node, value); }
public void SetInput(string nodeName, float value) { ANNInputNode n = this.GetInputNodeFromName(nodeName); if (n == null) { //Debug.LogWarning(this.name + " => Trying to SetInput(name, value) of a non-existing node"); return; } if (tickType == TickType.TickOnInput) { this.Tick(); } n.SetInput(value); }
// Input private ANNInputNode AddInputNode(ANNInputNode n, bool instanciate = true, bool reset = true, bool resetGen = false) { ANNInputNode auxN = n.InstanciateAsInput(); auxN.network = this; inputNodes.Add(auxN); if (reset) { ResetNet(); } if (resetGen) { //ResetGeneration(); } return(auxN); }
/// ADD NODES /// // Create --- public ANNNode CreateNode(ANNNode.Type type, string name, bool savenet = true) { string path = ANNSerialization.GLOBALS.NETS.Path + "/" + Parent().name; switch (type) { case ANNNode.Type.Input: { ANNInputNode node = ScriptableObject.CreateInstance <ANNInputNode>(); node.name = name; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } AssetDatabase.CreateAsset(node, "Assets/ANNProject/Serialization/Networks/" + Parent().name + "/" + name + ".asset"); AssetDatabase.SaveAssets(); AddNode(node, savenet, true, true, true); return(node); } case ANNNode.Type.Hidden: { ANNHiddenNode node = ScriptableObject.CreateInstance <ANNHiddenNode>(); node.name = name; AssetDatabase.CreateAsset(node, "Assets/ANNProject/Serialization/Networks/" + Parent().name + "/" + name + ".asset"); AddNode(node, savenet, true, true, true); return(node); } case ANNNode.Type.Output: { ANNOutputNode node = ScriptableObject.CreateInstance <ANNOutputNode>(); node.name = name; AssetDatabase.CreateAsset(node, "Assets/ANNProject/Serialization/Networks/" + Parent().name + "/" + name + ".asset"); AddNode(node, savenet, true, true, true); return(node); } } Debug.LogWarning(this.name + " -> Error Creating Node - Type: '" + type + "' Name: '" + name + "'."); return(null); }
public static void DrawInspector(ANNNetwork net) { if (curve.length <= 0) { curve.AddKey(-1, 0); } curve.keys[0].value = 0; // Cycles per Generation net.AgentsPerGeneration = EditorGUILayout.IntField("Cycles per Generation:", net.AgentsPerGeneration); // Net State net.TrainingType = (ANNNetwork.ANNNetworkTrainingType)EditorGUILayout.EnumPopup("Network Training Type:", net.TrainingType); // Hidden Layers EditorGUILayout.Space(); net.NHiddenLayers = EditorGUILayout.IntField("Number of Hidden Layers", net.NHiddenLayers); // Hidden Nodes net.ManualNHiddenNodes = EditorGUILayout.Toggle("Manual Number of Hidden Nodes:", net.ManualNHiddenNodes); if (net.ManualNHiddenNodes) { net.NHiddenNodesPerLayer = EditorGUILayout.IntField("Number of Hidden Nodes:", net.NHiddenNodesPerLayer); } // Add Nodes GUILayout.Label("-- Add Nodes --", EditorStyles.boldLabel); InNodeAux = (ANNInputNode)EditorGUILayout.ObjectField("Add Input Node:", InNodeAux, typeof(ANNInputNode), true); //nodetype = (NodeType)EditorGUILayout.EnumPopup("New Node Type: ", nodetype); //nodename = EditorGUILayout.TextField("New Node Name: ", nodename); GUILayout.BeginHorizontal(); inputnumber = EditorGUILayout.IntField("Amount to Add: ", inputnumber); if (inputnumber < 0) { inputnumber = 0; } if (GUILayout.Button("Add Input Node") && InNodeAux != null) { if (inputnumber <= 0) { } else if (inputnumber == 1) { net.AddNode(InNodeAux, true, false, false, false); } else { for (int i = 0; i < inputnumber; ++i) { ANNNode n = net.AddNode(InNodeAux, true, false, false, false); n.name = InNodeAux.Parent().name + "_" + i; } net.ResetNet(); net.ResetGeneration(); } InNodeAux = null; net.Serialize(); } GUILayout.EndHorizontal(); if (inputnumber > 99) { //EditorStyles.colorField = Color.yellow; GUILayout.Label("The number of nodes you want to add is too high, could lead to performance issues.", EditorStyles.miniLabel); } // Add Output Nodes OutNodeAux = (ANNOutputNode)EditorGUILayout.ObjectField("Add Output Node:", OutNodeAux, typeof(ANNOutputNode), true); GUILayout.BeginHorizontal(); outputnumber = EditorGUILayout.IntField("Amount to Add: ", outputnumber); if (outputnumber < 0) { outputnumber = 0; } if (GUILayout.Button("Add Output Node") && OutNodeAux != null) { if (outputnumber <= 0) { } else if (outputnumber == 1) { net.AddNode(OutNodeAux, true, false, false, false); } else { for (int i = 0; i < outputnumber; ++i) { ANNNode n = net.AddNode(OutNodeAux, true, false, false, false); n.name = OutNodeAux.Parent().name + "_" + i; } net.ResetNet(); net.ResetGeneration(); } OutNodeAux = null; net.Serialize(); } GUILayout.EndHorizontal(); if (outputnumber > 99) { //EditorStyles.colorField = Color.yellow; GUILayout.Label("The number of nodes you want to add is too high, could lead to performance issues.", EditorStyles.miniLabel); } GUILayout.BeginHorizontal(); EditorGUILayout.IntField("Number of Input Nodes", net.InputNodes.Count, EditorStyles.boldLabel); hideInNodeNames = EditorGUILayout.Toggle("Hide Names:", hideInNodeNames); GUILayout.EndHorizontal(); if (!hideInNodeNames) { for (int i = 0; i < net.InputNodes.Count; ++i) { GUILayout.BeginHorizontal(); if (net.InputNodes[i] != null) { GUILayout.Label(" - " + net.InputNodes[i].name); } else { GUILayout.Label(" - ¡¡ error reading name !!"); } GUILayout.Space(50f); if (GUILayout.Button("Delete", GUILayout.Height(20f), GUILayout.Width(50f))) { if (net.InputNodes[i] == null) { net.InputNodes.RemoveAt(i--); continue; } net.RemoveNode(net.InputNodes[i]); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } } GUILayout.BeginHorizontal(); EditorGUILayout.IntField("Number of Output Nodes", net.OutputNodes.Count, EditorStyles.boldLabel); hideOutNodeNames = EditorGUILayout.Toggle("Hide Names:", hideOutNodeNames); GUILayout.EndHorizontal(); if (!hideOutNodeNames) { for (int i = 0; i < net.OutputNodes.Count; ++i) { GUILayout.BeginHorizontal(); if (net.OutputNodes[i] != null) { GUILayout.Label(" - " + net.OutputNodes[i].name); } else { GUILayout.Label(" - ¡¡ error reading name !!"); } GUILayout.Space(50f); if (GUILayout.Button("Delete", GUILayout.Height(20f), GUILayout.Width(50f))) { if (net.OutputNodes[i] == null) { net.OutputNodes.RemoveAt(i--); continue; } net.RemoveNode(net.OutputNodes[i]); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } } net.tickType = (ANNNetwork.TickType)EditorGUILayout.EnumPopup("Tick Type", net.tickType); EditorGUILayout.Separator(); if (GUILayout.Button("Network Tab", GUILayout.Height(25f))) { ANNNetworkTab window = ANNNetworkTab.GetWindow <ANNNetworkTab>("ANNetwork Tab"); window.network = net; window.UpdateGraphics(); } if (GUILayout.Button("Save Network", GUILayout.Height(25f))) { net.Serialize(); } EditorGUILayout.IntField("Generation: ", net.Parent().generation, EditorStyles.boldLabel); GUILayout.BeginHorizontal(); generationToChange = EditorGUILayout.IntField("Change Generation: ", generationToChange); if (GUILayout.Button("Change Generation")) { net.SetGeneration(generationToChange); } GUILayout.EndHorizontal(); EditorGUILayout.FloatField("Best Fitness: ", net.topBest, EditorStyles.label); EditorGUILayout.FloatField("Last Fitness: ", curveKeys.Count > 0 ? curveKeys[curveKeys.Count - 1] : 0, EditorStyles.label); for (int i = 0; i < curve.length; ++i) { curve.RemoveKey(i); } for (int i = 0; i < curveKeys.Count; ++i) { curve.AddKey(i, curveKeys[i]); } EditorGUILayout.CurveField(curve, GUILayout.Height(350f)); }