def shift(self, modelResult):
inferencesToWrite = {}<EOL>if self._inferenceBuffer is None:<EOL><INDENT>maxDelay = InferenceElement.getMaxDelay(modelResult.inferences)<EOL>self._inferenceBuffer = collections.deque(maxlen=maxDelay + <NUM_LIT:1>)<EOL><DEDENT>self._inferenceBuffer.appendleft(copy.deepcopy(modelResult.inferences))<EOL>for inferenceElement, inference in modelResult.inferences.iteritems():<EOL><INDENT>if isinstance(inference, dict):<EOL><INDENT>inferencesToWrite[inferenceElement] = {}<EOL>for key, _ in inference.iteritems():<EOL><INDENT>delay = InferenceElement.getTemporalDelay(inferenceElement, key)<EOL>if len(self._inferenceBuffer) > delay:<EOL><INDENT>prevInference = self._inferenceBuffer[delay][inferenceElement][key]<EOL>inferencesToWrite[inferenceElement][key] = prevInference<EOL><DEDENT>else:<EOL><INDENT>inferencesToWrite[inferenceElement][key] = None<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>delay = InferenceElement.getTemporalDelay(inferenceElement)<EOL>if len(self._inferenceBuffer) > delay:<EOL><INDENT>inferencesToWrite[inferenceElement] = (<EOL>self._inferenceBuffer[delay][inferenceElement])<EOL><DEDENT>else:<EOL><INDENT>if type(inference) in (list, tuple):<EOL><INDENT>inferencesToWrite[inferenceElement] = [None] * len(inference)<EOL><DEDENT>else:<EOL><INDENT>inferencesToWrite[inferenceElement] = None<EOL><DEDENT><DEDENT><DEDENT><DEDENT>shiftedResult = ModelResult(rawInput=modelResult.rawInput,<EOL>sensorInput=modelResult.sensorInput,<EOL>inferences=inferencesToWrite,<EOL>metrics=modelResult.metrics,<EOL>predictedFieldIdx=modelResult.predictedFieldIdx,<EOL>predictedFieldName=modelResult.predictedFieldName)<EOL>return shiftedResult<EOL>
Shift the model result and return the new instance.

        Queues up the T(i+1) prediction value and emits a T(i)
        input/prediction pair, if possible. E.g., if the previous T(i-1)
        iteration was learn-only, then we would not have a T(i) prediction in our
        FIFO and would not be able to emit a meaningful input/prediction pair.

        :param modelResult: A :class:`~.nupic.frameworks.opf.opf_utils.ModelResult`
                            instance to shift.
        :return: A :class:`~.nupic.frameworks.opf.opf_utils.ModelResult` instance that
                 has been shifted