Пример #1
0
  /**
   * find all columns from allColumns within inhibitionRadius of column col excluding the col itself
   *
   * @param col
   * @param allColumns
   * @param inhibitionRadius
   * @return
   */
  private static List<Column> findMyNeigbors(
      Column col, Column[][] allColumns, double inhibitionRadius) {
    List<Column> neighbors = new ArrayList<>();
    int inhib = (int) Math.round(inhibitionRadius);
    Point pos = SpatialPooler.getColumnPosition(col, allColumns);
    int xxStart = HelperMath.inRange(pos.x - inhib, 0, allColumns.length);
    int xxEnd = HelperMath.inRange(pos.x + inhib + 1, 0, allColumns.length);
    int yyStart = HelperMath.inRange(pos.y - inhib, 0, allColumns[0].length);
    int yyEnd = HelperMath.inRange(pos.y + inhib + 1, 0, allColumns[0].length);

    for (int y = yyStart; y < yyEnd; y++) {
      for (int x = xxStart; x < xxEnd; x++) {
        if (y == pos.y && x == pos.x) {
          continue; // skip myself
        }
        neighbors.add(allColumns[x][y]);
      }
    }
    return neighbors;
  }
Пример #2
0
 /**
  * Phase 2: Inhibition The second phase calculates which columns remain as winners after the
  * inhibition step. desiredLocalActivity is a parameter that controls the number of columns that
  * end up winning. For example, if desiredLocalActivity is 10, a column will be a winner if its
  * overlap score is greater than the score of the 10'th highest column within its inhibition
  * radius.
  */
 public void computeWinningColumsAfterInhibition() {
   activeColumns = new ArrayList<>();
   for (int x = 0; x < xxMax; x++) {
     for (int y = 0; y < yyMax; y++) {
       if (Math.round(this.inhibitionRadius) != Math.round(this.inhibitionRadiusBefore)
           || columns[x][y].getNeigbours() == null) {
         columns[x][y].setNeigbours(
             SpatialPooler.findMyNeigbors(columns[x][y], this.columns, inhibitionRadius));
       }
       double minimalLocalActivity = kthScore(columns[x][y].getNeigbours(), desiredLocalActivity);
       // TODO if inhibitionRadius changes, shouldn't this also change?
       columns[x][y].setMinimalLocalActivity(minimalLocalActivity);
       if (columns[x][y].getOverlap() >= minimalLocalActivity) {
         columns[x][y].setActive(true);
         activeColumns.add(columns[x][y]);
       } else {
         columns[x][y].setActive(false);
       }
     }
   }
 }