예제 #1
0
  /**
   * Called to initialize the structural anatomy with configured values and prepare the anatomical
   * entities for activation.
   *
   * @param c
   */
  public void initMatrices(final Connections c) {
    SparseObjectMatrix<Column> mem = c.getMemory();
    c.setMemory(mem == null ? mem = new SparseObjectMatrix<>(c.getColumnDimensions()) : mem);

    c.setInputMatrix(new SparseBinaryMatrix(c.getInputDimensions()));

    // Calculate numInputs and numColumns
    int numInputs = c.getInputMatrix().getMaxIndex() + 1;
    int numColumns = c.getMemory().getMaxIndex() + 1;
    if (numColumns <= 0) {
      throw new InvalidSPParamValueException("Invalid number of columns: " + numColumns);
    }
    if (numInputs <= 0) {
      throw new InvalidSPParamValueException("Invalid number of inputs: " + numInputs);
    }
    c.setNumInputs(numInputs);
    c.setNumColumns(numColumns);

    // Fill the sparse matrix with column objects
    for (int i = 0; i < numColumns; i++) {
      mem.set(i, new Column(c.getCellsPerColumn(), i));
    }

    c.setPotentialPools(new SparseObjectMatrix<Pool>(c.getMemory().getDimensions()));

    c.setConnectedMatrix(new SparseBinaryMatrix(new int[] {numColumns, numInputs}));

    // Initialize state meta-management statistics
    c.setOverlapDutyCycles(new double[numColumns]);
    c.setActiveDutyCycles(new double[numColumns]);
    c.setMinOverlapDutyCycles(new double[numColumns]);
    c.setMinActiveDutyCycles(new double[numColumns]);
    c.setBoostFactors(new double[numColumns]);
    Arrays.fill(c.getBoostFactors(), 1);
  }
예제 #2
0
  /**
   * Updates the duty cycles for each column. The OVERLAP duty cycle is a moving average of the
   * number of inputs which overlapped with each column. The ACTIVITY duty cycles is a moving
   * average of the frequency of activation for each column.
   *
   * @param c the {@link Connections} (spatial pooler memory)
   * @param overlaps an array containing the overlap score for each column. The overlap score for a
   *     column is defined as the number of synapses in a "connected state" (connected synapses)
   *     that are connected to input bits which are turned on.
   * @param activeColumns An array containing the indices of the active columns, the sparse set of
   *     columns which survived inhibition
   */
  public void updateDutyCycles(Connections c, int[] overlaps, int[] activeColumns) {
    double[] overlapArray = new double[c.getNumColumns()];
    double[] activeArray = new double[c.getNumColumns()];
    ArrayUtils.greaterThanXThanSetToYInB(overlaps, overlapArray, 0, 1);
    if (activeColumns.length > 0) {
      ArrayUtils.setIndexesTo(activeArray, activeColumns, 1);
    }

    int period = c.getDutyCyclePeriod();
    if (period > c.getIterationNum()) {
      period = c.getIterationNum();
    }

    c.setOverlapDutyCycles(
        updateDutyCyclesHelper(c, c.getOverlapDutyCycles(), overlapArray, period));

    c.setActiveDutyCycles(updateDutyCyclesHelper(c, c.getActiveDutyCycles(), activeArray, period));
  }