Beispiel #1
0
        ///<summary>
        /// This function reinforces each segment in this Cell's SegmentUpdate.
        /// </summary>
        /// <remarks>
        /// Using the segmentUpdate, the following changes are
        /// performed. If positiveReinforcement is true then synapses on the active
        /// list get their permanence counts incremented by permanenceInc. All other
        /// synapses get their permanence counts decremented by permanenceDec. If
        /// positiveReinforcement is false, then synapses on the active list get
        /// their permanence counts decremented by permanenceDec. After this step,
        /// any synapses in segmentUpdate that do yet exist get added with a permanence
        /// count of initialPerm. These new synapses are randomly chosen from the
        /// set of all cells that have learnState output = 1 at time step t.
        ///</remarks>
        internal void ApplySegmentUpdates(bool positiveReinforcement, int latestCreationStep = -1)
        {
            // This loop iterates through a list of SegmentUpdate's and reinforces each segment.
            foreach (var segmentUpdate in this.SegmentUpdates)
            {
                DistalSegment distalSegment = segmentUpdate.DistalSegment;

                if (distalSegment != null)
                {
                    if (positiveReinforcement)
                    {
                        distalSegment.UpdatePermanences(segmentUpdate.ActiveDistalSynapses);
                    }
                    else
                    {
                        distalSegment.DecreasePermanences(segmentUpdate.ActiveDistalSynapses);
                    }
                }

                // Add new synapses (and new segment if necessary)
                if (segmentUpdate.AddNewSynapses && positiveReinforcement)
                {
                    if (distalSegment == null)
                    {
                        // Only add new segment if end cells to connect are available
                        if (segmentUpdate.CellsToConnect.Count > 0)
                        {
                            distalSegment = segmentUpdate.CreateDistalSegment();
                        }
                    }
                    else if (segmentUpdate.CellsToConnect.Count > 0)
                    {
                        // Add new synapses to existing segment
                        segmentUpdate.CreateDistalSynapses();
                    }
                }
            }

            // Delete segment update instances after they are applied
            this.SegmentUpdates.Clear();
        }