/** * The primary method in charge of learning. Adapts the permanence values of the synapses based on * the input vector, and the chosen columns after inhibition round. Permanence values are * increased for synapses connected to input bits that are turned on, and decreased for synapses * connected to inputs bits that are turned off. * * @param c the {@link Connections} (spatial pooler memory) * @param inputVector a integer array that comprises the input to the spatial pooler. There exists * an entry in the array for every input bit. * @param activeColumns an array containing the indices of the columns that survived inhibition. */ public void adaptSynapses(Connections c, int[] inputVector, int[] activeColumns) { int[] inputIndices = ArrayUtils.where(inputVector, ArrayUtils.INT_GREATER_THAN_0); double[] permChanges = new double[c.getNumInputs()]; Arrays.fill(permChanges, -1 * c.getSynPermInactiveDec()); ArrayUtils.setIndexesTo(permChanges, inputIndices, c.getSynPermActiveInc()); for (int i = 0; i < activeColumns.length; i++) { Pool pool = c.getPotentialPools().get(activeColumns[i]); double[] perm = pool.getDensePermanences(c); int[] indexes = pool.getSparsePotential(); ArrayUtils.raiseValuesBy(permChanges, perm); Column col = c.getColumn(activeColumns[i]); updatePermanencesForColumn(c, perm, col, indexes, true); } }