Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Docs: InferenceShifter,ModelResult,SensorInput,InferenceType #3549

Merged
merged 3 commits into from
Apr 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,8 @@ nupic
│   ├── aggregator.py [DEFER]
│   ├── dictutils.py [DEFER]
│   ├── fieldmeta.py [OK]
│   ├── file_record_stream.py [TODO]
│   ├── filters.py [TODO]
│   ├── functionsource.py [TODO]
│   ├── generators
│   │   ├── anomalyzer.py [TODO]
│   │   ├── data_generator.py [TODO]
│   │   ├── distributions.py [TODO]
│   │   ├── pattern_machine.py [TODO]
│   │   └── sequence_machine.py [TODO]
│   ├── inference_shifter.py [TODO]
│   ├── file_record_stream.py [OK]
│   ├── inference_shifter.py [OK]
│   ├── joiner.py [TODO]
│   ├── jsonhelpers.py [TODO]
│   ├── record_stream.py [TODO]
Expand Down Expand Up @@ -105,6 +97,8 @@ nupic
│   │   ├── opfhelpers.py [TODO]
│   │   ├── opftaskdriver.py [TODO]
│   │   ├── opfutils.py [TODO]
│ │ │ ├── ModelResults [OK]
│ │ │ └── SensorInput [OK]
│   │   ├── periodic.py [TODO]
│   │   ├── predictionmetricsmanager.py [TODO]
│   │   ├── previousvaluemodel.py [TODO]
Expand Down
1 change: 0 additions & 1 deletion docs/source/api/data/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ FileRecordStream

.. autoclass:: nupic.data.file_record_stream.FileRecordStream
:members:
=======
1 change: 1 addition & 0 deletions docs/source/api/opf/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ algorithms and functionalities can be added with minimal code changes.

models
metrics
results
utils
26 changes: 26 additions & 0 deletions docs/source/api/opf/results.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Model Results
=============

ModelResult
^^^^^^^^^^^

.. autoclass:: nupic.frameworks.opf.opfutils.ModelResult
:members:

SensorInput
^^^^^^^^^^^

.. autoclass:: nupic.frameworks.opf.opfutils.SensorInput
:members:

InferenceShifter
^^^^^^^^^^^^^^^^

.. autoclass:: nupic.data.inference_shifter.InferenceShifter
:members:

InferenceType
^^^^^^^^^^^^^

.. autoclass:: nupic.frameworks.opf.opfutils.InferenceType
:members:
14 changes: 9 additions & 5 deletions src/nupic/data/inference_shifter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@


class InferenceShifter(object):
"""Shifts time for ModelResult objects."""
"""
Shifts time for :class:`~.nupic.frameworks.opf.opfutils.ModelResult` objects.
This is useful for plotting results with the predictions at the same time step
as the input data.
"""

def __init__(self):
self._inferenceBuffer = None
Expand All @@ -41,10 +45,10 @@ def shift(self, modelResult):
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.

Args:
modelResult: A ModelResult instance to shift.
Returns:
A ModelResult instance.
:param modelResult: A :class:`~.nupic.frameworks.opf.opfutils.ModelResult`
instance to shift.
:return: A :class:`~.nupic.frameworks.opf.opfutils.ModelResult` instance that
has been shifted
"""
inferencesToWrite = {}

Expand Down
102 changes: 59 additions & 43 deletions src/nupic/frameworks/opf/opfutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ class InferenceType(Enum("TemporalNextStep",
"NontemporalAnomaly",
"TemporalMultiStep",
"NontemporalMultiStep")):
"""
Enum: one of the following:

- ``TemporalNextStep``
- ``TemporalClassification``
- ``NontemporalClassification``
- ``TemporalAnomaly``
- ``NontemporalAnomaly``
- ``TemporalMultiStep``
- ``NontemporalMultiStep``
"""


__temporalInferenceTypes = None
Expand All @@ -172,26 +183,29 @@ def isTemporal(inferenceType):



# SensorInput - represents the mapping of a given inputRecord by the
# sensor region's encoder.
#
# dataRow: A data row that is the sensor's "sourceOut" mapping of the
# supplied inputRecord. The data row is a sequence of field
# values that correspond to the schema returned by the
# getDecodedFieldMetaInfo() method of the ModelIface-based
# instance that returned this mapping. See
# ModelIface.getDecodedFieldMetaInfo() docstring for additional
# details.
#
# dataEncodings: A list of the corresponding bit-array encodings of each value
# in "dataRow"
#
# sequenceReset: The sensor's "resetOut" signal (0 or 1) emitted by the
# sensor's compute logic on the supplied inputRecord; provided
# for analysis and diagnostics.
# TODO: document category

class SensorInput(object):
"""
Represents the mapping of a given inputRecord by the sensor region's encoder.

This represents the input record, as it appears right before it is encoded.
This may differ from the raw input in that certain input fields (such as
DateTime fields) may be split into multiple encoded fields.

:param dataRow: A data row that is the sensor's ``sourceOut`` mapping of the
supplied inputRecord.

:param dataEncodings: A list of the corresponding bit-array encodings of each
value in "dataRow"

:param sequenceReset: The sensor's "resetOut" signal (0 or 1) emitted by the
sensor's compute logic on the supplied inputRecord; provided
for analysis and diagnostics.

:param dataDict: The raw encoded input to the sensor
:param category: the categoryOut on the sensor region

"""

__slots__ = ("dataRow", "dataDict", "dataEncodings", "sequenceReset", "category")

Expand All @@ -210,7 +224,7 @@ def __repr__(self):
"\tdataEncodings={2}\n"\
"\tsequenceReset={3}\n"\
"\tcategory={4}\n"\
")".format(self.dataRow,
")".format(self.dataRow,
self.dataDict,
self.dataEncodings,
self.sequenceReset,
Expand Down Expand Up @@ -265,7 +279,7 @@ def _asdict(self):
#
# predictionEncodings: A sequence of numpy arrays, where each element is the
# binary representation of the corresponding predicted field
# in "predictionRow".
# in "predictionRow".
#
# classification: The classification category of this input.
#
Expand All @@ -277,32 +291,34 @@ def _asdict(self):



# ModelResult - A structure that contains the input to a model and the resulting
# predictions as well as any related information related to the predictions.
#
# predictionNumber: The prediction number. This should start at 0 and increase
# with each new ModelResult.
#
# rawInput: The input record, as input by the user. This is a dictionary-like
# object which has attributes whose names are the same as the input
# field names
#
# sensorInput: A SensorInput object that represents the input record, as it
# appears right before it is encoded. This may differ from the raw
# input in that certain input fields (such as DateTime fields) may
# be split into multiple encoded fields
#
# inferences: A dictionary of inferences. Each key is a InferenceType constant
# which corresponds to the type of prediction being made. Each value
# is a ___ element that corresponds to the actual prediction by the
# model, including auxillary information; TODO: fix description.
#
# metrics: The metrics corresponding to the most-recent prediction/ground
# truth pair

class ModelResult(object):
"""
A structure that contains the input to a model and the resulting predictions
as well as any related information related to the predictions.

All params below are accesses as properties of the ModelResult object.

:param predictionNumber: (int) This should start at 0 and increase with each
new ModelResult.
:param rawInput: (object) The input record, as input by the user. This is a
dictionary-like object which has attributes whose names are the same as
the input field names
:param sensorInput: (:class:`~.SensorInput`) object that represents the input
record
:param inferences: (dict) Each key is a :class:`~.InferenceType` constant
which corresponds to the type of prediction being made. Each value is
a an element that corresponds to the actual prediction by the model,
including auxillary information.
:param metrics: The metrics corresponding to the most-recent prediction/ground
truth pair
:param predictedFieldIdx: predicted field index
:param predictedFieldName: predicted field name
:param classifierInput: input from classifier

"""

__slots__= ("predictionNumber", "rawInput", "sensorInput", "inferences",
__slots__= ("predictionNumber", "rawInput", "sensorInput", "inferences",
"metrics", "predictedFieldIdx", "predictedFieldName", "classifierInput")

def __init__(self,
Expand Down