def compute(self, recordNum, patternNZ, classification, learn, infer):
if self.verbosity >= <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>", learn)<EOL>print("<STR_LIT>", recordNum)<EOL>print("<STR_LIT>" % len(patternNZ), patternNZ)<EOL>print("<STR_LIT>", classification)<EOL><DEDENT>if len(self._patternNZHistory) > <NUM_LIT:0>:<EOL><INDENT>if recordNum < self._patternNZHistory[-<NUM_LIT:1>][<NUM_LIT:0>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>if len(self._patternNZHistory) == <NUM_LIT:0> orrecordNum > self._patternNZHistory[-<NUM_LIT:1>][<NUM_LIT:0>]:<EOL><INDENT>self._patternNZHistory.append((recordNum, patternNZ))<EOL><DEDENT>retval = {}<EOL>if max(patternNZ) > self._maxInputIdx:<EOL><INDENT>newMaxInputIdx = max(patternNZ)<EOL>for nSteps in self.steps:<EOL><INDENT>self._weightMatrix[nSteps] = numpy.concatenate((<EOL>self._weightMatrix[nSteps],<EOL>numpy.zeros(shape=(newMaxInputIdx-self._maxInputIdx,<EOL>self._maxBucketIdx+<NUM_LIT:1>))), axis=<NUM_LIT:0>)<EOL><DEDENT>self._maxInputIdx = int(newMaxInputIdx)<EOL><DEDENT>if classification is not None:<EOL><INDENT>if type(classification["<STR_LIT>"]) is not list:<EOL><INDENT>bucketIdxList = [classification["<STR_LIT>"]]<EOL>actValueList = [classification["<STR_LIT>"]]<EOL>numCategory = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>bucketIdxList = classification["<STR_LIT>"]<EOL>actValueList = classification["<STR_LIT>"]<EOL>numCategory = len(classification["<STR_LIT>"])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if learn:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>actValueList = None<EOL>bucketIdxList = None<EOL><DEDENT>if infer:<EOL><INDENT>retval = self.infer(patternNZ, actValueList)<EOL><DEDENT>if learn and classification["<STR_LIT>"] is not None:<EOL><INDENT>for categoryI in range(numCategory):<EOL><INDENT>bucketIdx = bucketIdxList[categoryI]<EOL>actValue = actValueList[categoryI]<EOL>if bucketIdx > self._maxBucketIdx:<EOL><INDENT>for nSteps in self.steps:<EOL><INDENT>self._weightMatrix[nSteps] = numpy.concatenate((<EOL>self._weightMatrix[nSteps],<EOL>numpy.zeros(shape=(self._maxInputIdx+<NUM_LIT:1>,<EOL>bucketIdx-self._maxBucketIdx))), axis=<NUM_LIT:1>)<EOL><DEDENT>self._maxBucketIdx = int(bucketIdx)<EOL><DEDENT>while self._maxBucketIdx > len(self._actualValues) - <NUM_LIT:1>:<EOL><INDENT>self._actualValues.append(None)<EOL><DEDENT>if self._actualValues[bucketIdx] is None:<EOL><INDENT>self._actualValues[bucketIdx] = actValue<EOL><DEDENT>else:<EOL><INDENT>if (isinstance(actValue, int) or<EOL>isinstance(actValue, float) or<EOL>isinstance(actValue, int)):<EOL><INDENT>self._actualValues[bucketIdx] = ((<NUM_LIT:1.0> - self.actValueAlpha)<EOL>* self._actualValues[bucketIdx]<EOL>+ self.actValueAlpha * actValue)<EOL><DEDENT>else:<EOL><INDENT>self._actualValues[bucketIdx] = actValue<EOL><DEDENT><DEDENT><DEDENT>for (learnRecordNum, learnPatternNZ) in self._patternNZHistory:<EOL><INDENT>error = self._calculateError(recordNum, bucketIdxList)<EOL>nSteps = recordNum - learnRecordNum<EOL>if nSteps in self.steps:<EOL><INDENT>for bit in learnPatternNZ:<EOL><INDENT>self._weightMatrix[nSteps][bit, :] += self.alpha * error[nSteps]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if infer and self.verbosity >= <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>")<EOL>print("<STR_LIT>", retval["<STR_LIT>"])<EOL>for (nSteps, votes) in list(retval.items()):<EOL><INDENT>if nSteps == "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT>print("<STR_LIT>" % (nSteps), _pFormatArray(votes))<EOL>bestBucketIdx = votes.argmax()<EOL>print(("<STR_LIT>"<EOL>"<STR_LIT>" % (bestBucketIdx,<EOL>retval["<STR_LIT>"][bestBucketIdx])))<EOL><DEDENT>print()<EOL><DEDENT>return retval<EOL>
Process one input sample.

This method is called by outer loop code outside the nupic-engine. We
use this instead of the nupic engine compute() because our inputs and
outputs aren't fixed size vectors of reals.


:param recordNum: Record number of this input pattern. Record numbers
  normally increase sequentially by 1 each time unless there are missing
  records in the dataset. Knowing this information insures that we don't get
  confused by missing records.

:param patternNZ: List of the active indices from the output below. When the
  input is from TemporalMemory, this list should be the indices of the
  active cells.

:param classification: Dict of the classification information where:

  - bucketIdx: list of indices of the encoder bucket
  - actValue: list of actual values going into the encoder

  Classification could be None for inference mode.
:param learn: (bool) if true, learn this sample
:param infer: (bool) if true, perform inference

:return:    Dict containing inference results, there is one entry for each
            step in self.steps, where the key is the number of steps, and
            the value is an array containing the relative likelihood for
            each bucketIdx starting from bucketIdx 0.

            There is also an entry containing the average actual value to
            use for each bucket. The key is 'actualValues'.

            for example:

            .. code-block:: python

               {1 :             [0.1, 0.3, 0.2, 0.7],
                 4 :             [0.2, 0.4, 0.3, 0.5],
                 'actualValues': [1.5, 3,5, 5,5, 7.6],
               }