internal BackPropagationNetworkEntryContext(BackPropgationNodeContext nodeContext, BackPropagationConnectionContext[] upperConnectionContexts, BackPropagationConnectionContext[] lowerConnectionContexts)
        {
            Contract.Requires(nodeContext != null);
            Contract.Requires(upperConnectionContexts != null);
            Contract.Requires(lowerConnectionContexts != null);

            this.nodeContext = nodeContext;
            this.upperConnectionContexts = upperConnectionContexts;
            this.lowerConnectionContexts = lowerConnectionContexts;
        }
        protected override void InitializeNewRun()
        {
            Rule.Initialize();

            var conns = new Dictionary<ConnectionIndex, BackPropagationConnectionContext>();
            var contextList = new List<BackPropagationNetworkEntryContext>(Network.EntryArray.Length);
            int endIdx = Network.MaxEntryIndex - Network.OutputInterface.Length;
            outputs = Enumerable.Range(0, Network.OutputInterface.Length).Select(idx => new List<BackPropagationConnectionContext>()).ToArray();
            foreach (var entry in Network.EntryArray)
            {
                // Node:
                var nodeCtx = new BackPropgationNodeContext(Rule.CreateRuleContext(entry.NodeEntry.Node), entry.NodeEntry.Node);
                Rule.Initialize(nodeCtx.Node, nodeCtx.RuleContext);

                // Upper:
                var upperCtxs = new List<BackPropagationConnectionContext>(entry.UpperConnectionEntryArray.Length);
                foreach (var connEntry in entry.UpperConnectionEntryArray)
                {
                    BackPropagationConnectionContext connCtx;
                    if (!conns.TryGetValue(connEntry.Index, out connCtx))
                    {
                        connCtx = new BackPropagationConnectionContext(Rule.CreateRuleContext(connEntry.Connection), connEntry.Connection);
                        Rule.Initialize(connCtx.Connection, connCtx.RuleContext);
                        conns.Add(connEntry.Index, connCtx);
                    }
                    upperCtxs.Add(connCtx);
                }

                // Lower:
                var lowerCtxs = new List<BackPropagationConnectionContext>(entry.LowerConnectionEntryArray.Length);
                foreach (var connEntry in entry.LowerConnectionEntryArray)
                {
                    BackPropagationConnectionContext connCtx;
                    if (!conns.TryGetValue(connEntry.Index, out connCtx))
                    {
                        connCtx = new BackPropagationConnectionContext(Rule.CreateRuleContext(connEntry.Connection), connEntry.Connection);
                        Rule.Initialize(connCtx.Connection, connCtx.RuleContext);
                        conns.Add(connEntry.Index, connCtx);
                        if (connEntry.Index.LowerNodeIndex > endIdx)
                        {
                            outputs[connEntry.Index.LowerNodeIndex - endIdx - 1].Add(connCtx);
                        }
                    }
                    lowerCtxs.Add(connCtx);
                }

                contextList.Add(new BackPropagationNetworkEntryContext(nodeCtx, upperCtxs.ToArray(), lowerCtxs.ToArray()));
            }
            contexts = contextList.ToArray();
        }
Exemplo n.º 3
0
 protected internal abstract void InitializeOutputConnection(BackPropagationConnectionContext connCtx, double error);
Exemplo n.º 4
0
 protected internal override void InitializeOutputConnection(BackPropagationConnectionContext connCtx, double error)
 {
     ((ErrorContext)connCtx.RuleContext).Error = error;
 }