private void OutputSaveValueNodes()
        {
            var nodes = GraphNodeContext.GetNodes().Where(n => n.IsMonitoring);

            foreach (var node in nodes)
            {
                Console.Write(node.NodeName + "==>");
                Utils.Utils.DisplayListList(node.ComputedResults);
            }
        }
        public InputNode DeclareInput(string name, int vectorSize, string copyValueFrom = "")
        {
            InputNode node = new InputNode();

            node.NodeName   = name;
            node.ResultsDim = vectorSize;

            GraphNodeContext.AddNode(node);

            return(node);
        }
        public CopyValueFromNode DeclareCopyFrom(string name, int neuronsSize, string copyFromNodeName)
        {
            CopyValueFromNode node = new CopyValueFromNode();

            node.NodeName       = name;
            node.ResultsDim     = neuronsSize;
            node.TargetNodeName = copyFromNodeName;

            GraphNodeContext.AddNode(node);

            return(node);
        }
        public MultiplyNode DeclareMultiply(string name, params BaseComputeGraphNode[] parents)
        {
            MultiplyNode node = new MultiplyNode();

            node.NodeName = name;
            foreach (var n in parents)
            {
                node.Prevs.Add(n);
                n.Nexts.Add(node);
            }

            GraphNodeContext.AddNode(node);

            return(node);
        }
        public FCNode DeclareFC(string name, int inputDim, int neuronsSize, BaseComputeGraphNode inputNode)
        {
            FCNode node = new FCNode(inputDim, neuronsSize);

            node.NodeName = name;

            foreach (var n in new BaseComputeGraphNode[] { inputNode })
            {
                node.Prevs.Add(n);
                n.Nexts.Add(node);
            }

            GraphNodeContext.AddNode(node);

            return(node);
        }
 private void SetInputs2Node(Dictionary <string, double[]> inputs)
 {
     foreach (var k in inputs)
     {
         foreach (var n in GraphNodeContext.GetNodes())
         {
             if (n.GetType().Equals(typeof(InputNode)))
             {
                 InputNode iNode = n as InputNode;
                 if (iNode.NodeName == k.Key)
                 {
                     iNode.InputData = k.Value.ToList();
                 }
             }
         }
     }
 }
        public void Execute(Dictionary <string, double[]> inputs)
        {
            GraphNodeContext.GetNodes().ForEach(n => n.IsProcessed     = false);
            GraphNodeContext.GetNodes().ForEach(n => n.IsWalked        = false);
            GraphNodeContext.GetNodes().ForEach(n => n.ComputedResults = null);

            SetInputs2Node(inputs);

            while (HasUnProcessedNodes())
            {
                foreach (var node in GraphNodeContext.GetNodes())
                {
                    VisitNode(node);
                }
            }

            OutputSaveValueNodes();
        }
        protected override List <double> Compute(List <List <double> > data)
        {
            //是否目标节点已经有计算的value了
            //      有:      RETURN VALUE
            //      没有:    初始化,RETURN VALUE
            BaseComputeGraphNode targetNode = GraphNodeContext.GetNode(this.TargetNodeName);

            if (targetNode.IsProcessed)
            {
                return(targetNode.ComputedResults);
            }
            else
            {
                if (InitialValue == null)
                {
                    InitialBy(targetNode);
                }

                return(InitialValue);
            }
        }
        private List <string> ParseDirections()
        {
            List <string> lst = new List <string>();

            foreach (var node in GraphNodeContext.GetNodes())
            {
                lst.AddRange(ParseDirections(node));
            }

            //foreach (var node in savableNodes)
            //    lst.Add(string.Format("\"{0}\"[color=orange]", node.Name));

            //foreach (var node in graphHeaders)
            //    lst.Add(string.Format("\"{0}\"[color=lightblue]", node.Name));

            //foreach (var node in allNodes)
            //    if (!graphHeaders.Contains(node))
            //        if (node.Value != null)
            //            lst.Add(string.Format("\"{0}\"[color=yellow]", node.Name));

            return(lst);
        }
 private bool HasUnProcessedNodes()
 {
     return(GraphNodeContext.GetNodes().Count(n => !n.IsProcessed || !n.IsWalked) > 0);
 }