private void PositionConnection(Image connection, UINeuralNetworkWeightPanel otherNode, int nodeIndex, int connectedNodeIndex, float[][] weights)
    {
        try
        {
            connection.transform.localPosition = Vector3.zero;

            Vector2 sizeDelta = connection.rectTransform.sizeDelta;
            float   weight    = weights[connectedNodeIndex][nodeIndex];
            sizeDelta.x = (float)System.Math.Abs(weight * 2);
            if (sizeDelta.x < 1)
            {
                sizeDelta.x = 1;
            }
            else if (sizeDelta.x > 3f)
            {
                sizeDelta.x = 3;
            }

            if (weight >= 0)
            {
                connection.color = PositiveColor;
            }
            else
            {
                connection.color = NegativeColor;
            }
            Color var = connection.color;
            var.a            = 1f;
            connection.color = var;
            Vector2 connectionVector = this.transform.position - otherNode.transform.position;
            sizeDelta.y = connectionVector.magnitude / GameObject.Find("UI").GetComponent <Canvas>().scaleFactor;

            connection.rectTransform.sizeDelta = sizeDelta;

            float angle = Vector2.Angle(Vector2.up, connectionVector);
            connection.transform.rotation = Quaternion.AngleAxis(angle, new Vector3(0, 0, 1));
        }
        catch (System.IndexOutOfRangeException ex)
        {
        }
    }
Esempio n. 2
0
    public void Display(uint neuronCount, bool bias)
    {
        UINeuralNetworkWeightPanel dummyNode = Nodes[0];

        for (int i = Nodes.Count; i < neuronCount; i++)
        {
            UINeuralNetworkWeightPanel newNode = Instantiate(dummyNode);
            newNode.transform.SetParent(LayerContents.transform, false);
            Nodes.Add(newNode);
            if (i == neuronCount - 1 && bias)
            {
                Color oldColor = newNode.GetComponent <Image>().color;
                Color newColor = new Color(237, 0, 255, 1);
                newNode.GetComponent <Image>().color = newColor;
            }
        }

        for (int i = this.Nodes.Count - 1; i >= neuronCount; i++)
        {
            UINeuralNetworkWeightPanel toBeDestroyed = Nodes[i];
            Nodes.RemoveAt(i);
            Destroy(toBeDestroyed);
        }
    }