Пример #1
0
 /// <summary>
 /// Constructs a new NodeLink.
 /// </summary>
 public NodeLink(DynamicalNode to, DynamicalNode from, Complex weight, double decay, double plasticity)
 {
     this.To         = to;
     this.From       = from;
     this.Weight     = weight;
     this.Decay      = decay;
     this.Plasticity = plasticity;
 }
        /// <summary>
        /// Addes a new incoming node to this node, with given decay and plasticity values.
        /// </summary>
        public bool AddIncomingNode(DynamicalNode node, Complex weight, double decay, double plasticity)
        {
            if (this.IncomingNodes.Any(link => link.From == node))
            {
                // Exists.
                return(false);
            }

            this.IncomingNodes.Add(new NodeLink(this, node, weight, decay, plasticity));
            return(true);
        }
        /// <summary>
        /// Execute one iteration of integration, moving
        /// the dynamical system forward in time by
        /// the given delta time.
        /// </summary>
        public void Step(double deltaTime)
        {
            double h      = deltaTime;
            double halfH  = deltaTime * 0.5;
            double sixthH = deltaTime / 6.0;
            double t00    = this.Time;
            double t05    = this.Time + halfH;
            double t10    = this.Time + h;

            VectorOI y0 = _nodes.ToVectorOI(n => n, n => n.Value);

            VectorOI k1 = _nodes.ToVectorOI(n => n, n => n.F(t00, y0));

            VectorOI k1Blend = k1.MultiplyNew(halfH).AddSelf(y0);
            VectorOI k2      = _nodes.ToVectorOI(n => n, n => n.F(t05, k1Blend));

            VectorOI k2Blend = k2.MultiplyNew(halfH).AddSelf(y0);
            VectorOI k3      = _nodes.ToVectorOI(n => n, n => n.F(t05, k2Blend));

            VectorOI k3Blend = k3.MultiplyNew(h).AddSelf(y0);
            VectorOI k4      = _nodes.ToVectorOI(n => n, n => n.F(t10, k3Blend));


            // Perform final runge-kutta weighted average.

            // We mutate k1, k2 and k3 here.
            k2.MultiplySelf(2.0);
            k3.MultiplySelf(2.0);
            VectorOI y1 = k1.AddSelf(k2).AddSelf(k3).AddSelf(k4).MultiplySelf(sixthH).AddSelf(y0);


            // Store results back into each node.
            foreach (var kvp in y1)
            {
                DynamicalNode node = kvp.Key as DynamicalNode;
                node.Value = kvp.Value;
            }

            this.Time = t10;
            this.Iteration++;
        }
 /// <summary>
 /// Addes a new incoming node to this node.
 /// </summary>
 public bool AddIncomingNode(DynamicalNode node)
 {
     return(AddIncomingNode(node, 1.0, 0, 0));
 }
 /// <summary>
 /// Overridable method for printing the value of a node in this system.
 /// </summary>
 public virtual string FormatNodeValue(DynamicalNode node)
 {
     return(node.Value.ToString("F3"));
 }