Ejemplo n.º 1
0
        /**
         * Uses the specified {@link Connections} object to Build the structural
         * anatomy needed by this {@code TemporalMemory} to implement its algorithms.
         *
         * The connections object holds the {@link Column} and {@link Cell} infrastructure,
         * and is used by both the {@link SpatialPooler} and {@link TemporalMemory}. Either of
         * these can be used separately, and therefore this Connections object may have its
         * Columns and Cells initialized by either the init method of the SpatialPooler or the
         * init method of the TemporalMemory. We check for this so that complete initialization
         * of both Columns and Cells occurs, without either being redundant (initialized more than
         * once). However, {@link Cell}s only get created when initializing a TemporalMemory, because
         * they are not used by the SpatialPooler.
         *
         * @param   c       {@link Connections} object
         */
        public static void Init(Connections c)
        {
            SparseObjectMatrix <Column> matrix = c.GetMemory() ?? new SparseObjectMatrix <Column>(c.GetColumnDimensions());

            c.SetMemory(matrix);

            int numColumns = matrix.GetMaxIndex() + 1;

            c.SetNumColumns(numColumns);
            int cellsPerColumn = c.GetCellsPerColumn();

            Cell[] cells = new Cell[numColumns * cellsPerColumn];

            //Used as flag to determine if Column objects have been created.
            Column colZero = matrix.GetObject(0);

            for (int i = 0; i < numColumns; i++)
            {
                Column column = colZero == null ? new Column(cellsPerColumn, i) : matrix.GetObject(i);
                for (int j = 0; j < cellsPerColumn; j++)
                {
                    cells[i * cellsPerColumn + j] = column.GetCell(j);
                }
                //If columns have not been previously configured
                if (colZero == null)
                {
                    matrix.Set(i, column);
                }
            }
            //Only the TemporalMemory initializes cells so no need to test for redundancy
            c.SetCells(cells);
        }
Ejemplo n.º 2
0
        /**
         * {@inheritDoc}
         */
        public override List <EncoderResult> GetBucketInfo(int[] buckets)
        {
            SparseObjectMatrix <int[]> topDownMapping = GetTopDownMapping();

            //The "category" is simply the bucket index
            int category = buckets[0];

            int[] encoding = topDownMapping.GetObject(category);

            //Which input value does this correspond to?
            double inputVal;

            if (IsPeriodic())
            {
                inputVal = GetMinVal() + GetResolution() / 2 + category * GetResolution();
            }
            else
            {
                inputVal = GetMinVal() + category * GetResolution();
            }

            return(new List <EncoderResult> {
                new EncoderResult(inputVal, inputVal, encoding)
            });
        }
Ejemplo n.º 3
0
        private List <EncoderResult> GetEncoderResultsByIndex(SparseObjectMatrix <int[]> topDownMapping, int categoryIndex)
        {
            List <EncoderResult> result = new List <EncoderResult>();
            string category             = _sdrByCategory.GetCategory(categoryIndex);

            int[] encoding = topDownMapping.GetObject(categoryIndex);
            result.Add(new EncoderResult(category, categoryIndex, encoding));
            return(result);
        }