Beispiel #1
0
    private void PositionConnection(Image connection, UINeuralNetworkConnectionPanel otherNode, int nodeIndex, int connectedNodeIndex, double[,] weights)
    {
        connection.transform.localPosition = Vector3.zero;

        Vector2 sizeDelta = connection.rectTransform.sizeDelta;
        double  weight    = weights[nodeIndex, connectedNodeIndex];

        sizeDelta.x = (float)System.Math.Abs(weight);
        if (sizeDelta.x < 1)
        {
            sizeDelta.x = 1;
        }

        if (weight >= 0)
        {
            connection.color = PositiveColor;
        }
        else
        {
            connection.color = NegativeColor;
        }

        Vector2 connectionVec = this.transform.position - otherNode.transform.position;

        sizeDelta.y = connectionVec.magnitude / GameStateManager.Instance.UIController.Canvas.scaleFactor;

        connection.rectTransform.sizeDelta = sizeDelta;

        float angle = Vector2.Angle(Vector2.up, connectionVec);

        connection.transform.rotation = Quaternion.AngleAxis(angle, new Vector3(0, 0, 1));
    }
    public void Display(uint neuronCount)
    {
        UINeuralNetworkConnectionPanel dummyNode = Nodes[0];

        for (int i = Nodes.Count; i < neuronCount; i++)
        {
            UINeuralNetworkConnectionPanel newNode = Instantiate(dummyNode);
            newNode.transform.SetParent(LayerContents.transform, false);
            Nodes.Add(newNode);
        }

        for (int i = this.Nodes.Count - 1; i >= neuronCount; i++)
        {
            UINeuralNetworkConnectionPanel toBeDestroyed = Nodes[i];
            Nodes.RemoveAt(i);
            Destroy(toBeDestroyed);
        }
    }
    /// <summary>
    /// Displays given amount of neurons in this layer.
    /// </summary>
    /// <param name="neuronCount">The amount of neurons to be displayed for this layer.</param>
    public void Display(uint neuronCount)
    {
        UINeuralNetworkConnectionPanel dummyNode = Nodes[0];

        //Duplicate dummyNode
        for (int i = Nodes.Count; i < neuronCount; i++)
        {
            UINeuralNetworkConnectionPanel newNode = Instantiate(dummyNode);
            newNode.transform.SetParent(LayerContents.transform, false);
            newNode.SelectedNodeChanged += SelectedNodeChanged;
            Nodes.Add(newNode);
        }

        //Destory all unnecessary nodes
        for (int i = this.Nodes.Count - 1; i >= neuronCount; i++)
        {
            UINeuralNetworkConnectionPanel toBeDestroyed = Nodes[i];
            Nodes.RemoveAt(i);
            Destroy(toBeDestroyed);
        }
    }
Beispiel #4
0
    // Method for positioning the connection correctly (a bit tricky to draw lines in GUI with unity)
    private void PositionConnection(Image connection, UINeuralNetworkConnectionPanel otherNode, int nodeIndex, int connectedNodeIndex, double[,] weights)
    {
        //Set local position to 0
        connection.transform.localPosition = Vector3.zero;

        //Set connection width
        Vector2 sizeDelta = connection.rectTransform.sizeDelta;
        double  weight    = weights[nodeIndex, connectedNodeIndex];

        sizeDelta.x = (float)System.Math.Abs(weight);
        if (sizeDelta.x < 1)
        {
            sizeDelta.x = 1;
        }

        //Set conenction color
        if (weight >= 0)
        {
            connection.color = PositiveColor;
        }
        else
        {
            connection.color = NegativeColor;
        }

        //Set connection length (height)
        Vector2 connectionVec = this.transform.position - otherNode.transform.position;

        sizeDelta.y = connectionVec.magnitude / canvas.scaleFactor;

        connection.rectTransform.sizeDelta = sizeDelta;

        //Set connection rotation
        float angle = Vector2.Angle(Vector2.up, connectionVec);

        connection.transform.rotation = Quaternion.AngleAxis(angle, new Vector3(0, 0, 1));
    }
 public void SelectedNodeChanged(UINeuralNetworkConnectionPanel newNode)
 {
     SelectedNode = newNode;
 }