Beispiel #1
0
        /// <summary>
        /// For this column, return the cell with the best matching <see cref="Segment"/>
        /// (at time t-1 or t). Only consider segments that are predicting cell activation
        /// to occur in exactly numberPredictionSteps many time steps from now. If no cell
        /// has a matching segment, then return the cell with the fewest number of segments.
        /// </summary>
        /// <param name="t">only consider active segments at time t.</param>
        /// <param name="numberPredictionSteps">only consider segments that are predicting
        /// cell activation to occur in exactly this many time steps from now.</param>
        /// <returns>Tuple containing the best cell and its best <see cref="Segment"/>
        /// (may be None).</returns>
        internal Tuple <Cell, DistalSegment> GetBestMatchingCell(int t, int numberPredictionSteps)
        {
            Cell          bestCell                 = null;
            DistalSegment bestDistalSegment        = null;
            int           bestNumberActiveSynapses = 0;

            // Chooses the cell with the best matching segment.
            foreach (var cell in this.Cells)
            {
                DistalSegment distalSegment = cell.GetBestMatchingDistalSegment(t, numberPredictionSteps);

                if (distalSegment != null)
                {
                    int numberActiveSynapses = distalSegment.GetActiveSynapses(t).Count;
                    if (numberActiveSynapses > bestNumberActiveSynapses)
                    {
                        bestCell                 = cell;
                        bestDistalSegment        = distalSegment;
                        bestNumberActiveSynapses = numberActiveSynapses;
                    }
                }
            }

            // If there are no active sequences, return the cell with the fewest number of
            // segments
            if (bestCell == null)
            {
                int bestNumberActiveSegments = int.MaxValue;
                foreach (var cell in this.Cells)
                {
                    int numberActiveSegments = cell.DistalSegments.Count;
                    if (numberActiveSegments < bestNumberActiveSegments)
                    {
                        bestNumberActiveSegments = numberActiveSegments;
                        bestCell = cell;
                    }
                }

                // Pick a random cell among those with equal segment counts
                // TODO: is there a more efficient way to do this maybe?
                var candidates = new List <Cell>();
                foreach (var cell in this.Cells)
                {
                    if (cell.DistalSegments.Count == bestNumberActiveSegments)
                    {
                        candidates.Add(cell);
                    }
                }
                if (candidates.Count > 1)
                {
                    bestCell = candidates[this._random.Next(candidates.Count)];
                }

                // Leave bestSegment null to indicate a new segment is to be added
            }

            return(new Tuple <Cell, DistalSegment>(bestCell, bestDistalSegment));
        }
Beispiel #2
0
        ///<summary>
        /// Add a new <see cref="SegmentUpdate"/> object to this <see cref="Cell"/>
        /// containing proposed changes to the specified segment.
        ///</summary>
        ///<remarks>
        /// If the segment is None, then a new segment is to be added, otherwise
        /// the specified segment is updated.  If the segment exists, find all active
        /// synapses for the segment (either at t or t-1)
        /// and mark them as needing to be updated.  If newSynapses is true, then
        /// Region.newNumberSynapses - len(activeSynapses) new synapses are added to the
        /// segment to be updated.  The (new) synapses are randomly chosen from the set
        /// of current learning cells (within Region.localityRadius if set).
        ///
        /// These segment updates are only applied when the applySegmentUpdates
        /// method is later called on this Cell.
        ///</remarks>
        internal SegmentUpdate UpdateDistalSegmentActiveSynapses(int t, DistalSegment distalSegment, bool newSynapses = false)
        {
            // Let ActiveSynapses be the list of active synapses where the originating
            // cells have their ActiveState output = true at time step t.
            // (This list is empty if segment = null since the segment doesn't exist.)
            var activeSynapses = new List <Synapse>();

            if (distalSegment != null)
            {
                activeSynapses = distalSegment.GetActiveSynapses(t);
            }

            var segmentUpdate = new SegmentUpdate(this, distalSegment, activeSynapses, newSynapses);

            this.SegmentUpdates.Add(segmentUpdate);

            return(segmentUpdate);
        }
Beispiel #3
0
        ///<summary>
        /// Add a new <see cref="SegmentUpdate"/> object to this <see cref="Cell"/>
        /// containing proposed changes to the specified segment. 
        ///</summary>
        ///<remarks>
        /// If the segment is None, then a new segment is to be added, otherwise
        /// the specified segment is updated.  If the segment exists, find all active
        /// synapses for the segment (either at t or t-1)
        /// and mark them as needing to be updated.  If newSynapses is true, then
        /// Region.newNumberSynapses - len(activeSynapses) new synapses are added to the
        /// segment to be updated.  The (new) synapses are randomly chosen from the set
        /// of current learning cells (within Region.localityRadius if set).
        ///
        /// These segment updates are only applied when the applySegmentUpdates
        /// method is later called on this Cell.
        ///</remarks>
        internal SegmentUpdate UpdateDistalSegmentActiveSynapses(int t, DistalSegment distalSegment, bool newSynapses = false)
        {
            // Let ActiveSynapses be the list of active synapses where the originating
            // cells have their ActiveState output = true at time step t.
            // (This list is empty if segment = null since the segment doesn't exist.)
            var activeSynapses = new List<Synapse>();
            if (distalSegment != null)
            {
                activeSynapses = distalSegment.GetActiveSynapses(t);
            }

            var segmentUpdate = new SegmentUpdate(this, distalSegment, activeSynapses, newSynapses);
            this.SegmentUpdates.Add(segmentUpdate);

            return segmentUpdate;
        }