コード例 #1
0
        /**
         * Activates all of the cells in an unpredicted active column,
         * chooses a winner cell, and, if learning is turned on, either adapts or
         * creates a segment. growSynapses is invoked on this segment.
         * </p><p>
         * <b>Pseudocode:</b>
         * </p><p>
         * <pre>
         *  mark all cells as active
         *  if there are any matching distal dendrite segments
         *      find the most active matching segment
         *      mark its cell as a winner cell
         *      (learning)
         *      grow and reinforce synapses to previous winner cells
         *  else
         *      find the cell with the least segments, mark it as a winner cell
         *      (learning)
         *      (optimization) if there are previous winner cells
         *          add a segment to this winner cell
         *          grow synapses to previous winner cells
         * </pre>
         * </p>
         *
         * @param conn                      Connections instance for the TM
         * @param column                    Bursting {@link Column}
         * @param matchingSegments          List of matching {@link DistalDendrite}s
         * @param prevActiveCells           Active cells in `t-1`
         * @param prevWinnerCells           Winner cells in `t-1`
         * @param permanenceIncrement       Amount by which permanences of synapses
         *                                  are decremented during learning
         * @param permanenceDecrement       Amount by which permanences of synapses
         *                                  are incremented during learning
         * @param random                    Random number generator
         * @param learn                     Whether or not learning is enabled
         *
         * @return  Tuple containing:
         *                  cells       list of the processed column's cells
         *                  bestCell    the best cell
         */
        public BurstingResult BurstColumn(Connections conn, Column column, List <DistalDendrite> matchingSegments,
                                          ICollection <Cell> prevActiveCells, ICollection <Cell> prevWinnerCells, double permanenceIncrement, double permanenceDecrement,
                                          Random random, bool learn)
        {
            IList <Cell> cells         = column.Cells;
            Cell         leastUsedCell = null;

            //
            // Matching segments result from number of potential synapses. These are segments with number of potential
            // synapses permanence higher than some minimum threshold value.
            // Potential synapses are synapses from presynaptc cells connected to the active cell.
            // In other words, presynaptic cells define a statistical prediction that active cell will become the active in the next cycle.
            // Bursting will create new segments if there are no matching segments until some matching segments appear.
            // Once that happen, segment adoption will start.
            // If some matching segments exist, bursting will grab the segment with most potential synapses and adapt it.
            if (matchingSegments != null && matchingSegments.Count > 0)
            {
                DistalDendrite maxPotentialSeg = getSegmentwithHighesPotential(conn, matchingSegments);

                for (int i = 0; i < matchingSegments.Count; i++)
                {
                    matchingSegments[i].getIndex();
                }

                leastUsedCell = maxPotentialSeg.GetParentCell();

                if (learn)
                {
                    adaptSegment(conn, maxPotentialSeg, prevActiveCells, permanenceIncrement, permanenceDecrement);

                    int nGrowDesired = conn.getMaxNewSynapseCount() - conn.getLastActivity().PotentialSynapses[maxPotentialSeg.getIndex()];

                    if (nGrowDesired > 0)
                    {
                        growSynapses(conn, prevWinnerCells, maxPotentialSeg, conn.getInitialPermanence(),
                                     nGrowDesired, random);
                    }
                }
            }
            else
            {
                leastUsedCell = this.GetLeastUsedCell(conn, cells, random);
                if (learn)
                {
                    int nGrowExact = Math.Min(conn.getMaxNewSynapseCount(), prevWinnerCells.Count);
                    if (nGrowExact > 0)
                    {
                        DistalDendrite bestSegment = conn.CreateDistalSegment(leastUsedCell);
                        growSynapses(conn, prevWinnerCells, bestSegment, conn.getInitialPermanence(),
                                     nGrowExact, random);
                    }
                }
            }

            return(new BurstingResult(cells, leastUsedCell));
        }
コード例 #2
0
        /**
         * Activates all of the cells in an unpredicted active column,
         * chooses a winner cell, and, if learning is turned on, either adapts or
         * creates a segment. growSynapses is invoked on this segment.
         * </p><p>
         * <b>Pseudocode:</b>
         * </p><p>
         * <pre>
         *  mark all cells as active
         *  if there are any matching distal dendrite segments
         *      find the most active matching segment
         *      mark its cell as a winner cell
         *      (learning)
         *      grow and reinforce synapses to previous winner cells
         *  else
         *      find the cell with the least segments, mark it as a winner cell
         *      (learning)
         *      (optimization) if there are previous winner cells
         *          add a segment to this winner cell
         *          grow synapses to previous winner cells
         * </pre>
         * </p>
         *
         * @param conn                      Connections instance for the TM
         * @param column                    Bursting {@link Column}
         * @param matchingSegments          List of matching {@link DistalDendrite}s
         * @param prevActiveCells           Active cells in `t-1`
         * @param prevWinnerCells           Winner cells in `t-1`
         * @param permanenceIncrement       Amount by which permanences of synapses
         *                                  are decremented during learning
         * @param permanenceDecrement       Amount by which permanences of synapses
         *                                  are incremented during learning
         * @param random                    Random number generator
         * @param learn                     Whether or not learning is enabled
         *
         * @return  Tuple containing:
         *                  cells       list of the processed column's cells
         *                  bestCell    the best cell
         */
        public Tuple BurstColumn(Connections conn, Column column, List <DistalDendrite> matchingSegments,
                                 HashSet <Cell> prevActiveCells, HashSet <Cell> prevWinnerCells, double permanenceIncrement, double permanenceDecrement,
                                 IRandom random, bool learn)
        {
            IList <Cell> cells    = column.GetCells();
            Cell         bestCell = null;

            if (matchingSegments.Any())
            {
                int[] numPoten = conn.GetLastActivity().numActivePotential;
                Comparison <DistalDendrite> cmp = (dd1, dd2) => numPoten[dd1.GetIndex()] - numPoten[dd2.GetIndex()];

                var sortedSegments = new List <DistalDendrite>(matchingSegments);
                sortedSegments.Sort(cmp);

                DistalDendrite bestSegment = sortedSegments.Last();
                bestCell = bestSegment.GetParentCell();

                if (learn)
                {
                    AdaptSegment(conn, bestSegment, prevActiveCells, permanenceIncrement, permanenceDecrement);

                    int nGrowDesired = conn.GetMaxNewSynapseCount() - numPoten[bestSegment.GetIndex()];

                    if (nGrowDesired > 0)
                    {
                        GrowSynapses(conn, prevWinnerCells, bestSegment, conn.GetInitialPermanence(),
                                     nGrowDesired, random);
                    }
                }
            }
            else
            {
                bestCell = LeastUsedCell(conn, cells, random);
                if (learn)
                {
                    int nGrowExact = Math.Min(conn.GetMaxNewSynapseCount(), prevWinnerCells.Count);
                    if (nGrowExact > 0)
                    {
                        DistalDendrite bestSegment = conn.CreateSegment(bestCell);
                        GrowSynapses(conn, prevWinnerCells, bestSegment, conn.GetInitialPermanence(),
                                     nGrowExact, random);
                    }
                }
            }

            return(new Tuple(cells, bestCell));
        }