Exemplo n.º 1
0
    // Add ---
    public ANNNode AddNode(ANNNode n, bool instanciate = true, bool savenet = true, bool reset = true, bool resetGen = false)
    {
        if (n == null)
        {
            Debug.LogWarning(this.name + " => Trying to AddNode(node, bool) a 'null' node");
            return(null);
        }

        ANNNode ret = null;

        if (n.GetType() == typeof(ANNInputNode))
        {
            ret = AddInputNode((ANNInputNode)n, instanciate, reset, resetGen);
        }
        else if (n.GetType() == typeof(ANNOutputNode))
        {
            ret = AddOutputNode((ANNOutputNode)n, instanciate, reset, resetGen);
        }
        else if (n.GetType() == typeof(ANNHiddenNode))
        {
            ret = AddHiddenNode((ANNHiddenNode)n, instanciate);
        }

        if (savenet)
        {
            Parent().Serialize();
        }
        return(ret);
    }
Exemplo n.º 2
0
    void ApplyActivationToLayer()
    {
        ANNNode node = (ANNNode)target;

        if (node == null || node.network == null)
        {
            return;
        }

        if (node.GetType() == typeof(ANNInputNode))
        {
            List <ANNInputNode> list = node.network.InputNodes;
            for (int i = 0; i < list.Count; ++i)
            {
                list[i].ActivationMethodType = node.ActivationMethodType;
            }
        }
        else if (node.GetType() == typeof(ANNOutputNode))
        {
            List <ANNOutputNode> list = node.network.OutputNodes;
            for (int i = 0; i < list.Count; ++i)
            {
                list[i].ActivationMethodType = node.ActivationMethodType;
            }
        }
        else if (node.GetType() == typeof(ANNHiddenNode))
        {
            List <ANNHiddenNode> list = node.network.GetHiddenNodesFromLayerOrder(node.GetLayerOrder());
            for (int i = 0; i < list.Count; ++i)
            {
                list[i].ActivationMethodType = node.ActivationMethodType;
            }
        }
    }
Exemplo n.º 3
0
 /// Constructor ///
 public ANNGraphicNode(ANNNode n, Vector2 pos, float w, float h, GUIStyle s)
 {
     rect = new Rect(pos.x, pos.y, w, h); style = s; node = n;
     if (node.GetType() == typeof(ANNInputNode))
     {
         title = node.name + " : " + ((ANNInputNode)node).GetInputValue();
     }
     else if (node.GetType() == typeof(ANNHiddenNode))
     {
         title = node.name;
     }
     else if (node.GetType() == typeof(ANNOutputNode))
     {
         title = node.name + " : " + ((ANNOutputNode)node).output;
     }
 }
Exemplo n.º 4
0
 /// Draw ///
 public void Draw()
 {
     if (node.GetType() == typeof(ANNOutputNode))
     {
         title = node.name + " : " + ((ANNOutputNode)node).output;
     }
     GUI.Box(rect, title, style);
 }
Exemplo n.º 5
0
 /// Utils ///
 public override void Copy(ANNNode target)
 {
     if (target.GetType() != typeof(ANNOutputNode))
     {
         Debug.LogWarning(this.name + " => Trying to Copy(node) a node that is not an OutputNode");
         return;
     }
     base.Copy(target);
 }
Exemplo n.º 6
0
 // Read & Write
 public void Read(ANNNode node)
 {
     if(node.GetType() == typeof(ANNInputNode))
     {
         type = (int)NodeType.Input;
     }
     else if(node.GetType() == typeof(ANNOutputNode))
     {
         type = (int)NodeType.Output;
     }
     else if(node.GetType() == typeof(ANNHiddenNode))
     {
         type = (int)NodeType.Hidden;
     }
     else
     {
         Debug.LogWarning("Trying to serialize a node that is not an Input, Output or Hidden Node => Node: '" + node.name + "'.");
         return;
     }
     name = node.name;
     activationtype = (int)node.ActivationMethodType;
     AssetDatabase.TryGetGUIDAndLocalFileIdentifier(node.Parent(), out referenceuid, out localid);
 }
Exemplo n.º 7
0
    // REMOVE NODES
    public void RemoveNode(ANNNode node)
    {
        if (node == null)
        {
            Debug.LogWarning(this.name + " -> Trying to remove a 'null' node.");
            return;
        }

        bool removed = false;

        if (node.GetType() == typeof(ANNInputNode))
        {
            for (int i = 0; i < inputNodes.Count; ++i)
            {
                if (inputNodes[i] == node)
                {
                    inputNodes.RemoveAt(i--);
                    removed = true;
                }
            }
        }
        else if (node.GetType() == typeof(ANNHiddenNode))
        {
            for (int i = 0; i < hiddenNodes.Count; ++i)
            {
                if (hiddenNodes[i] == node)
                {
                    hiddenNodes.RemoveAt(i--);
                    removed = true;
                }
            }
        }
        else if (node.GetType() == typeof(ANNOutputNode))
        {
            for (int i = 0; i < outputNodes.Count; ++i)
            {
                if (outputNodes[i] == node)
                {
                    outputNodes.RemoveAt(i--);
                    removed = true;
                }
            }
        }

        if (removed == false)
        {
            Debug.LogWarning(this.name + " -> Tried to remove a node '" + node.name + "' that is not in this net.");
        }
        else
        {
            string path = "Assets/ANNProject/Serialization/Networks/" + Parent().name;
            if (Directory.Exists(path))
            {
                AssetDatabase.DeleteAsset("Assets/ANNProject/Serialization/Networks/" + Parent().name + "/" + node.name + ".asset");
            }
            if (Application.isEditor)
            {
                DestroyImmediate(node);
            }
            else
            {
                Destroy(node);
            }
        }

        SetupConnections();

        this.Serialize();
    }