If you do not use the shifter, the modelResult object you get back
will contain the last row of data it saw and a prediction for the next
step it expects to see. But if you are charting model results in
realtime, these two points are not aligned in time. The shifter
changes the inference so that it displays the last prediction (not in
the future, but for RIGHT NOW), so that the prediction data is aligned
with the last seen data. So when these result is charted, both the
real data and the prediction are plotted at the same point in time.

Really, the only reason I can think of to use the inference shifter is
when you want to plot results and keep each prediction aligned with
the real data for that time step. I hope that makes sense.
---------
Matt Taylor
OS Community Flag-Bearer
Numenta


On Fri, Sep 4, 2015 at 7:01 AM, 曾惟如 <[email protected]> wrote:
> Thanks for your help, but the "result = shifter.shift(result)" still
> confuses me. I print the result before and after running this code, you can
> see one iteration below:
>
> 87 --------------- ModelResult( predictionNumber=85
>    rawInput={'timestamp': datetime.datetime(2010, 7, 5, 13, 0),
> 'kw_energy_consumption': 38.9}
>    sensorInput=SensorInput(   dataRow=(38.9, 13.0)
>    dataDict={'timestamp': datetime.datetime(2010, 7, 5, 13, 0),
> 'kw_energy_consumption': 38.9}
>    dataEncodings=[array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
> 0.,  0.,  0.,
>         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,
>         1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
>         1.,  1.,  1.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
> dtype=float32), array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
> 0.,  0.,  0.,
>         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
>         0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
>         1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  0.,
>         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
>         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.], dtype=float32)]
>    sequenceReset=0.0
>    category=0
> )
>    inferences={'multiStepPredictions': {1: {45.37: 0.11167611746922571,
> 40.7: 0.1162073555603384, 43.82582399999999: 0.11391920948788421,
> 50.64999999999999: 0.1094771923810333, 43.12399999999999:
> 0.12335125876562469, 39.92999999999999: 0.12092244781027771,
> 42.339999999999996: 0.12582885406799432, 38.064: 0.11854146062840354}},
> 'multiStepBestPredictions': {1: 42.339999999999996}, 'anomalyScore': None}
>
> metrics={"multiStepBestPredictions:multiStep:errorMetric='altMAPE':steps=1:window=1000:field=kw_energy_consumption":
> 28.351322215660037,
> "prediction:trivial:errorMetric='aae':steps=1:window=1000:field=kw_energy_consumption":
> 5.848235294117648,
> "prediction:trivial:errorMetric='altMAPE':steps=1:window=1000:field=kw_energy_consumption":
> 22.992599444958373,
> "multiStepBestPredictions:multiStep:errorMetric='aae':steps=1:window=1000:field=kw_energy_consumption":
> 7.211242191794943}
>    predictedFieldIdx=0
>    predictedFieldName=kw_energy_consumption
> )
> 87 +++++++++++++ ModelResult(  predictionNumber=None
>    rawInput={'timestamp': datetime.datetime(2010, 7, 5, 13, 0),
> 'kw_energy_consumption': 38.9}
>    sensorInput=SensorInput(   dataRow=(38.9, 13.0)
>    dataDict={'timestamp': datetime.datetime(2010, 7, 5, 13, 0),
> 'kw_energy_consumption': 38.9}
>    dataEncodings=[array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
> 0.,  0.,  0.,
>         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,
>         1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
>         1.,  1.,  1.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
> dtype=float32), array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
> 0.,  0.,  0.,
>         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
>         0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
>         1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  0.,
>         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
>         0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.], dtype=float32)]
>    sequenceReset=0.0
>    category=0
> )
>    inferences={'multiStepPredictions': {1: {45.37: 0.10453823528997958,
> 28.6: 0.12015220765843618, 40.7: 0.10877985511396898, 43.82582399999999:
> 0.10663795801080393, 43.12399999999999: 0.11546714914860297,
> 39.92999999999999: 0.11319357788843726, 42.339999999999996:
> 0.11778638665919991, 38.064: 0.11096477370109829}},
> 'multiStepBestPredictions': {1: 28.6}, 'anomalyScore': None}
>
> metrics={"multiStepBestPredictions:multiStep:errorMetric='altMAPE':steps=1:window=1000:field=kw_energy_consumption":
> 28.351322215660037,
> "prediction:trivial:errorMetric='aae':steps=1:window=1000:field=kw_energy_consumption":
> 5.848235294117648,
> "prediction:trivial:errorMetric='altMAPE':steps=1:window=1000:field=kw_energy_consumption":
> 22.992599444958373,
> "multiStepBestPredictions:multiStep:errorMetric='aae':steps=1:window=1000:field=kw_energy_consumption":
> 7.211242191794943}
>    predictedFieldIdx=0
>    predictedFieldName=kw_energy_consumption
> )
>
>
> it easy to find that “inference” changed. So I want to know why this change
> happens, and the rule of the change.
>
> ------------------ 原始邮件 ------------------
> 发件人: "Matthew Taylor";<[email protected]>;
> 发送时间: 2015年9月3日(星期四) 凌晨0:01
> 收件人: "曾惟如"<[email protected]>;
> 主题: Re: Help for the shifting inferences
>
> I usually only use the inferenceShifter when I am graphing predictions
> and real data on the same chart. Shifting in this fashion ensures the
> data and predictions are properly aligned at each time marker.
>
> ---------
> Matt Taylor
> OS Community Flag-Bearer
> Numenta
>
>
> On Wed, Sep 2, 2015 at 8:16 AM, Austin Marshall <[email protected]> wrote:
>> InferenceShifter is used to align predictions with actual values for
>> comparison, hence its usage inside the if plot: block.  It's especially
>> useful for multistep prediction models where there might be, for example,
>> predictions for 1, 5, and 10 steps ahead.
>>
>> On Wed, Sep 2, 2015 at 7:15 AM, 曾惟如 <[email protected]> wrote:
>>>
>>> hello nupic:
>>>
>>> recently, I am learning the source code of the program hotgym prodiction.
>>> and there are something I can't understand.
>>>
>>> In the document of Online Prediction
>>>
>>> Framework(https://github.com/numenta/nupic/wiki/Online-Prediction-Framework),
>>> there a introduction(Shifting Inferences) which is about the shift, but i
>>> can't get what dose that mean. So I want to ask some question.
>>>
>>> 1:  what dose shifter do?. What dose the code "result -
>>> shifter.shift(result)" do?. You can see some codes below.
>>>
>>> 2: Why some program do not use the class InferenceShifter? I have read
>>> some other source code like One Hot Gym Anomaly and CPU Usage. in that
>>> code,
>>> there no the step "shifter = InferenceShifter()", it dosen't use the
>>> class
>>> InferenceShifter. So i want to konw what is situation of use the class
>>> InferenceShifter.
>>>
>>>                          "field=kw_energy_consumption"])
>>>
>>> if plot:
>>>   result = shifter.shift(result)
>>>
>>> prediction = result.inferences["multiStepBestPredictions"][1]
>>> output.write([timestamp], [consumption], [prediction])
>>>
>>> (the code is in the line 124 of the hotgym_prediction's run.py)
>>>
>>> Please bear the bad English, andthanks in advance!!
>>
>>

Reply via email to