예제 #1
0
  /**
   * Update the boost factors for all columns. The boost factors are used to increase the overlap of
   * inactive columns to improve their chances of becoming active. and hence encourage participation
   * of more columns in the learning process. This is a line defined as: y = mx + b boost =
   * (1-maxBoost)/minDuty * dutyCycle + maxFiringBoost. Intuitively this means that columns that
   * have been active enough have a boost factor of 1, meaning their overlap is not boosted. Columns
   * whose active duty cycle drops too much below that of their neighbors are boosted depending on
   * how infrequently they have been active. The more infrequent, the more they are boosted. The
   * exact boost factor is linearly interpolated between the points (dutyCycle:0,
   * boost:maxFiringBoost) and (dutyCycle:minDuty, boost:1.0).
   *
   * <p>boostFactor ^ maxBoost _ | |\ | \ 1 _ | \ _ _ _ _ _ _ _ | +-------------------->
   * activeDutyCycle | minActiveDutyCycle
   */
  public void updateBoostFactors(Connections c) {
    double[] activeDutyCycles = c.getActiveDutyCycles();
    double[] minActiveDutyCycles = c.getMinActiveDutyCycles();

    // Indexes of values > 0
    int[] mask = ArrayUtils.where(minActiveDutyCycles, ArrayUtils.GREATER_THAN_0);

    double[] boostInterim;
    if (mask.length < 1) {
      boostInterim = c.getBoostFactors();
    } else {
      double[] numerator = new double[c.getNumColumns()];
      Arrays.fill(numerator, 1 - c.getMaxBoost());
      boostInterim = ArrayUtils.divide(numerator, minActiveDutyCycles, 0, 0);
      boostInterim = ArrayUtils.multiply(boostInterim, activeDutyCycles, 0, 0);
      boostInterim = ArrayUtils.d_add(boostInterim, c.getMaxBoost());
    }

    ArrayUtils.setIndexesTo(
        boostInterim,
        ArrayUtils.where(
            activeDutyCycles,
            new Condition.Adapter<Object>() {
              int i = 0;

              @Override
              public boolean eval(double d) {
                return d > minActiveDutyCycles[i++];
              }
            }),
        1.0d);

    c.setBoostFactors(boostInterim);
  }
예제 #2
0
 /**
  * Updates the minimum duty cycles in a global fashion. Sets the minimum duty cycles for the
  * overlap and activation of all columns to be a percent of the maximum in the region, specified
  * by {@link Connections#getMinOverlapDutyCycles()} and minPctActiveDutyCycle respectively.
  * Functionality it is equivalent to {@link #updateMinDutyCyclesLocal(Connections)}, but this
  * function exploits the globalness of the computation to perform it in a straightforward, and
  * more efficient manner.
  *
  * @param c
  */
 public void updateMinDutyCyclesGlobal(Connections c) {
   Arrays.fill(
       c.getMinOverlapDutyCycles(),
       c.getMinPctOverlapDutyCycles() * ArrayUtils.max(c.getOverlapDutyCycles()));
   Arrays.fill(
       c.getMinActiveDutyCycles(),
       c.getMinPctActiveDutyCycles() * ArrayUtils.max(c.getActiveDutyCycles()));
 }
예제 #3
0
  /**
   * Removes the set of columns who have never been active from the set of active columns selected
   * in the inhibition round. Such columns cannot represent learned pattern and are therefore
   * meaningless if only inference is required. This should not be done when using a random,
   * unlearned SP since you would end up with no active columns.
   *
   * @param activeColumns An array containing the indices of the active columns
   * @return a list of columns with a chance of activation
   */
  public int[] stripUnlearnedColumns(Connections c, int[] activeColumns) {
    TIntHashSet active = new TIntHashSet(activeColumns);
    TIntHashSet aboveZero = new TIntHashSet();
    int numCols = c.getNumColumns();
    double[] colDutyCycles = c.getActiveDutyCycles();
    for (int i = 0; i < numCols; i++) {
      if (colDutyCycles[i] <= 0) {
        aboveZero.add(i);
      }
    }
    active.removeAll(aboveZero);
    TIntArrayList l = new TIntArrayList(active);
    l.sort();
    // return l;

    return Arrays.stream(activeColumns).filter(i -> c.getActiveDutyCycles()[i] > 0).toArray();
  }
예제 #4
0
 /**
  * Updates the minimum duty cycles. The minimum duty cycles are determined locally. Each column's
  * minimum duty cycles are set to be a percent of the maximum duty cycles in the column's
  * neighborhood. Unlike {@link #updateMinDutyCyclesGlobal(Connections)}, here the values can be
  * quite different for different columns.
  *
  * @param c
  */
 public void updateMinDutyCyclesLocal(Connections c) {
   int len = c.getNumColumns();
   for (int i = 0; i < len; i++) {
     int[] maskNeighbors =
         getNeighborsND(c, i, c.getMemory(), c.getInhibitionRadius(), true).toArray();
     c.getMinOverlapDutyCycles()[i] =
         ArrayUtils.max(ArrayUtils.sub(c.getOverlapDutyCycles(), maskNeighbors))
             * c.getMinPctOverlapDutyCycles();
     c.getMinActiveDutyCycles()[i] =
         ArrayUtils.max(ArrayUtils.sub(c.getActiveDutyCycles(), maskNeighbors))
             * c.getMinPctActiveDutyCycles();
   }
 }
예제 #5
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));
  }