Пример #1
0
        /// <summary>
        /// getSegmentActiveSynapses(c, i, t, s, newSynapses= false)
        ///         Return a segmentUpdate data structure containing a list of proposed changes to segment s. 
        ///     Let activeSynapses be the list of active synapses where the originating cells have their 
        ///     activeState output = 1 at time step t. (This list is empty if s = -1 since the segment doesn't exist.) 
        ///         newSynapses is an optional argument that defaults to false. If newSynapses is true, 
        ///     then newSynapseCount - count(activeSynapses) synapses are added to activeSynapses. 
        ///     These synapses are randomly chosen from the set of cells that have learnState output = 1 at time step t.
        /// </summary>
        /// <param name="segment"></param>
        /// <param name="cell"></param>
        /// <param name="time"></param>
        /// <param name="newSynapses"></param>
        /// <returns></returns>
        private SegmentUpdate GetSegmentActiveSynapses(Segment segment, Cell cell, Time time, bool newSynapses = false)
        {
            IEnumerable<Synapse> activeSynapses = null;

            if (segment != null)
            {
                activeSynapses = segment.Synapses.Where(synapse => synapse.GetIsActive(ActiveMode.ActiveState, time)).ToArray();
            }

            activeSynapses = activeSynapses ?? Enumerable.Empty<Synapse>();

            if (newSynapses
                && Network.Instance.Parameters.NewSynapseCount - activeSynapses.Count() > 0)
            {
                var potentialSynapses =
                    Cells.Where(c => c.GetIsLearningState(time)
                                     && c != cell)
                         .SelectMany(c => c.Segments.SelectMany(s => s.Synapses))
                         .Except(cell.Segments.SelectMany(c => c.Synapses));

                activeSynapses = activeSynapses.Concat
                    (potentialSynapses.OrderBy(ps => Guid.NewGuid())
                    .Take(Network.Instance.Parameters.NewSynapseCount - activeSynapses.Count()));
            }

            return new SegmentUpdate(cell, segment, activeSynapses);
        }
Пример #2
0
        /// <summary>
        /// getBestMatchingCell(c)
        ///     For the given column, return the cell with the best matching segment (as defined above). 
        ///     If no cell has a matching segment, then return the cell with the fewest number of segments.
        /// </summary>
        /// <param name="time"></param>
        /// <param name="cell"></param>
        /// <param name="segment"></param>
        private void CalculateBestMatchingCellAndSegment(Time time, out Cell foundCell, out Segment foundSegment)
        {
            var foundItem = Cells.Select
                (cell =>
                {
                    Segment segment;
                    int score;
                    GetBestMatchingSegment(cell, time, out segment, out score);

                    return new
                    {
                        Cell = cell,
                        Segment = segment,
                        SegmentScore = score
                    };
                }).OrderByDescending(item => item.SegmentScore).FirstOrDefault();

            if (foundItem == null)
            {
                foundCell = Cells.OrderBy(cell => cell.Segments.Count()).First();
                foundSegment = null;
            }
            else
            {
                foundCell = foundItem.Cell;
                foundSegment = foundItem.Segment;
            }
        }
Пример #3
0
        /// <summary>
        /// getBestMatchingSegment(c, i, t)
        ///      For the given column c cell i at time t, find the segment with the largest number of active synapses. 
        ///      This routine is aggressive in finding the best match. 
        ///      The permanence value of synapses is allowed to be below connectedPerm. 
        ///      The number of active synapses is allowed to be below activationThreshold, but must be above minThreshold. 
        ///      The routine returns the segment index. If no segments are found, then an index of -1 is returned.
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="time"></param>
        private void GetBestMatchingSegment(Cell cell, Time time, out Segment segmentFound, out int score)
        {
            segmentFound = null;
            score = int.MinValue;

            var segmentWithScore = cell.Segments
                .Select(segment =>
                    new
                    {
                        Segment = segment,
                        Score = segment.GetIsSegmentActiveScore
                            (ActiveMode.ActiveState, time,
                            Network.Instance.Parameters.AbsoluteMinPermanence,
                            Network.Instance.Parameters.MinActivationThreshold)
                    })
                .Where(item => item.Score >= 0).
                OrderByDescending(item => item.Score).FirstOrDefault();

            if (segmentWithScore != null)
            {
                segmentFound = segmentWithScore.Segment;
                score = segmentWithScore.Score;
            }
        }
Пример #4
0
 public SegmentUpdate(Cell cell, Segment segment, IEnumerable<Synapse> activeSynapses)
 {
     Cell = cell;
     ActiveSynapses = activeSynapses;
     Segment = segment;
 }