nodes: 0, module; 1, function_definition; 2, function_name:_learn; 3, parameters; 4, block; 5, comment:# mutated args; 6, identifier:permanences; 7, identifier:rng; 8, comment:# activity; 9, identifier:activeCells; 10, identifier:activeInput; 11, identifier:growthCandidateInput; 12, comment:# configuration; 13, identifier:sampleSize; 14, identifier:initialPermanence; 15, identifier:permanenceIncrement; 16, identifier:permanenceDecrement; 17, identifier:connectedPermanence; 18, expression_statement; 19, expression_statement; 20, expression_statement; 21, expression_statement; 22, if_statement; 23, comment:"""
      For each active cell, reinforce active synapses, punish inactive synapses,
      and grow new synapses to a subset of the active input bits that the cell
      isn't already connected to.
  
      Parameters:
      ----------------------------
      @param  permanences (SparseMatrix)
              Matrix of permanences, with cells as rows and inputs as columns
  
      @param  rng (Random)
              Random number generator
  
      @param  activeCells (sorted sequence)
              Sorted list of the cells that are learning
  
      @param  activeInput (sorted sequence)
              Sorted list of active bits in the input
  
      @param  growthCandidateInput (sorted sequence)
              Sorted list of active bits in the input that the activeCells may
              grow new synapses to
  
      For remaining parameters, see the __init__ docstring.
      """; 24, call; 25, call; 26, call; 27, comparison_operator:sampleSize == -1; 28, block; 29, else_clause; 30, attribute; 31, argument_list; 32, attribute; 33, argument_list; 34, attribute; 35, argument_list; 36, identifier:sampleSize; 37, unary_operator; 38, expression_statement; 39, block; 40, identifier:permanences; 41, identifier:incrementNonZerosOnOuter; 42, identifier:activeCells; 43, identifier:activeInput; 44, identifier:permanenceIncrement; 45, identifier:permanences; 46, identifier:incrementNonZerosOnRowsExcludingCols; 47, identifier:activeCells; 48, identifier:activeInput; 49, unary_operator; 50, identifier:permanences; 51, identifier:clipRowsBelowAndAbove; 52, identifier:activeCells; 53, float:0.0; 54, float:1.0; 55, integer:1; 56, call; 57, expression_statement; 58, expression_statement; 59, expression_statement; 60, expression_statement; 61, identifier:permanenceDecrement; 62, attribute; 63, argument_list; 64, assignment; 65, assignment; 66, call; 67, call; 68, identifier:permanences; 69, identifier:setZerosOnOuter; 70, identifier:activeCells; 71, identifier:activeInput; 72, identifier:initialPermanence; 73, identifier:existingSynapseCounts; 74, call; 75, identifier:maxNewByCell; 76, call; 77, attribute; 78, argument_list; 79, attribute; 80, argument_list; 81, attribute; 82, argument_list; 83, attribute; 84, argument_list; 85, identifier:numpy; 86, identifier:subtract; 87, identifier:sampleSize; 88, identifier:existingSynapseCounts; 89, keyword_argument; 90, identifier:permanences; 91, identifier:setRandomZerosOnOuter; 92, identifier:activeCells; 93, identifier:growthCandidateInput; 94, identifier:maxNewByCell; 95, identifier:initialPermanence; 96, identifier:rng; 97, identifier:permanences; 98, identifier:nNonZerosPerRowOnCols; 99, identifier:activeCells; 100, identifier:activeInput; 101, identifier:numpy; 102, identifier:empty; 103, call; 104, keyword_argument; 105, identifier:out; 106, identifier:maxNewByCell; 107, identifier:len; 108, argument_list; 109, identifier:dtype; 110, string:"int32"; 111, identifier:activeCells
code: def _learn(# mutated args
               permanences, rng,
  
               # activity
               activeCells, activeInput, growthCandidateInput,
  
               # configuration
               sampleSize, initialPermanence, permanenceIncrement,
               permanenceDecrement, connectedPermanence):
      """
      For each active cell, reinforce active synapses, punish inactive synapses,
      and grow new synapses to a subset of the active input bits that the cell
      isn't already connected to.
  
      Parameters:
      ----------------------------
      @param  permanences (SparseMatrix)
              Matrix of permanences, with cells as rows and inputs as columns
  
      @param  rng (Random)
              Random number generator
  
      @param  activeCells (sorted sequence)
              Sorted list of the cells that are learning
  
      @param  activeInput (sorted sequence)
              Sorted list of active bits in the input
  
      @param  growthCandidateInput (sorted sequence)
              Sorted list of active bits in the input that the activeCells may
              grow new synapses to
  
      For remaining parameters, see the __init__ docstring.
      """
  
      permanences.incrementNonZerosOnOuter(
        activeCells, activeInput, permanenceIncrement)
      permanences.incrementNonZerosOnRowsExcludingCols(
        activeCells, activeInput, -permanenceDecrement)
      permanences.clipRowsBelowAndAbove(
        activeCells, 0.0, 1.0)
      if sampleSize == -1:
        permanences.setZerosOnOuter(
          activeCells, activeInput, initialPermanence)
      else:
        existingSynapseCounts = permanences.nNonZerosPerRowOnCols(
          activeCells, activeInput)
  
        maxNewByCell = numpy.empty(len(activeCells), dtype="int32")
        numpy.subtract(sampleSize, existingSynapseCounts, out=maxNewByCell)
  
        permanences.setRandomZerosOnOuter(
          activeCells, growthCandidateInput, maxNewByCell, initialPermanence, rng)