Esempio n. 1
0
        public void SetInput(InputItem item)
        {
            if (item.inputs.Length != nodes.Length - 1 ||
                inputConnectors == null ||
                inputConnectors.Length < 1)
            {
                return;                           //always have one bias node
            }
            foreach (var ir in inputConnectors)
            {
                if (ir != null)
                {
                    Destroy(ir);
                }
            }

            var input = 0;

            currentInput = item;
            foreach (var node in nodes)
            {
                if (node.input.isBias)
                {
                    continue;
                }

                node.input.SetInput(item.inputs[input]);

                if (input < inputConnectors.Length)
                {
                    c = Instantiate(connector, node.transform);

                    inputConnectors[input] = c;
                    var rn  = node.GetComponent <RectTransform>();
                    var crn = ScreenUtils.GetWorldCorners(rn);

                    c.positionCount = 2;
                    midY            = (crn[2].y + crn[3].y) / 2;
                    c.SetPosition(0, new Vector3(crn[1].x, midY, crn[1].z));

                    var itemNode = item.nodes[input];
                    var ics      = ScreenUtils.GetWorldCorners(itemNode);
                    midY = (ics[2].y + ics[3].y) / 2;
                    c.SetPosition(1, new Vector3(ics[2].x, midY, ics[2].z));

                    input++;
                }
            }

            UpdatePerceptron();
        }
Esempio n. 2
0
        private IEnumerator ConnectNodes()
        {
            yield return(new WaitForEndOfFrame());

            var cam = Camera.main;

            var st  = sumNode.GetComponent <RectTransform>();
            var cst = ScreenUtils.GetWorldCorners(st);

            foreach (var node in nodes)
            {
                c = Instantiate(connector, node.transform);
                c.positionCount = 2;
                c.SetPosition(0, cst[1]);

                var pt  = node.parameter.GetComponent <RectTransform>();
                var cpt = ScreenUtils.GetWorldCorners(pt);
                midY = (cpt[2].y + cpt[3].y) / 2;
                c.SetPosition(1, new Vector3(cpt[2].x, midY, cpt[2].z));
            }

            c = Instantiate(connector, sumNode.transform);
            c.positionCount = 2;
            midY            = (cst[2].y + cst[3].y) / 2;
            c.SetPosition(0, new Vector3(cst[2].x, midY, cst[2].z));

            var at  = actNode.GetComponent <RectTransform>();
            var ast = ScreenUtils.GetWorldCorners(at);

            midY = (ast[2].y + ast[3].y) / 2;
            c.SetPosition(1, new Vector3(ast[1].x, midY, ast[1].z));

            c = Instantiate(connector, actNode.transform);
            c.positionCount = 2;
            c.SetPosition(0, new Vector3(ast[2].x, midY, ast[2].z));

            var ot  = outNode.GetComponent <RectTransform>();
            var ost = ScreenUtils.GetWorldCorners(ot);

            midY = (ost[2].y + ost[3].y) / 2;
            c.SetPosition(1, new Vector3(ost[1].x, midY, ost[1].z));

            UpdatePerceptron();
        }
Esempio n. 3
0
        private IEnumerator ConnectNodes()
        {
            yield return(new WaitForEndOfFrame());

            if (output != null && nextLayer != null)
            {
                output.inputs = new float[perceptrons.Length];
                output.nodes  = new RectTransform[perceptrons.Length];
                for (int i = 0; i < perceptrons.Length; i++)
                {
                    output.nodes[i] = perceptrons[i].outNode.GetComponent <RectTransform>();
                }
                //perceptrons in layer are just outputs
                for (int i = 0; i < perceptrons.Length; i++)
                {
                    var n = perceptrons[i];
                    n.outNode.IsLayer = true;

                    var rt  = n.outNode.GetComponent <RectTransform>();
                    var crn = ScreenUtils.GetWorldCorners(rt);

                    foreach (var p in nextLayer.perceptrons)
                    {
                        c = Instantiate(n.connector, n.outNode.transform);
                        c.positionCount = 2;
                        midY            = (crn[2].y + crn[3].y) / 2;
                        c.SetPosition(0, new Vector3(crn[2].x, midY, crn[2].z));

                        var t   = p.nodes[i + 1].GetComponent <RectTransform>();
                        var trn = ScreenUtils.GetWorldCorners(t);
                        midY = (trn[2].y + trn[3].y) / 2;
                        c.SetPosition(1, new Vector3(trn[1].x, midY, trn[1].z));
                    }
                }
            }
        }