/** * 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); }
/** * Returns a list of items, one for each bucket defined by this encoder. * Each item is the value assigned to that bucket, this is the same as the * EncoderResult.value that would be returned by GetBucketInfo() for that * bucket and is in the same format as the input that would be passed to * encode(). * * This call is faster than calling GetBucketInfo() on each bucket individually * if all you need are the bucket values. * * @param returnType class type parameter so that this method can return encoder * specific value types * * @return list of items, each item representing the bucket value for that * bucket. */ public override List <S> GetBucketValues <S>(Type t) { if (bucketValues == null) { SparseObjectMatrix <int[]> topDownMapping = GetTopDownMapping(); int numBuckets = topDownMapping.GetMaxIndex() + 1; bucketValues = new List <double>(); for (int i = 0; i < numBuckets; i++) { ((List <double>)bucketValues).Add((double)GetBucketInfo(new[] { i })[0].Get(1)); } } return((List <S>)bucketValues); }
/** * Returns a list of items, one for each bucket defined by this encoder. * Each item is the value assigned to that bucket, this is the same as the * EncoderResult.value that would be returned by getBucketInfo() for that * bucket and is in the same format as the input that would be passed to * encode(). * * This call is faster than calling getBucketInfo() on each bucket individually * if all you need are the bucket values. * * @param returnType class type parameter so that this method can return encoder * specific value types * * @return list of items, each item representing the bucket value for that * bucket. */ public override List <T> GetBucketValues <T>(Type t) { if (bucketValues == null) { SparseObjectMatrix <int[]> topDownMapping = scalarEncoder.GetTopDownMapping(); int numBuckets = topDownMapping.GetMaxIndex() + 1; bucketValues = new List <string>(); for (int i = 0; i < numBuckets; i++) { ((List <string>)bucketValues).Add((string)GetBucketInfo(new int[] { i })[0].GetValue()); } } return((List <T>)bucketValues); }