Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete encoder docstrings #3579

Merged
merged 15 commits into from
May 3, 2017
Merged

Conversation

rhyolight
Copy link
Member

@rhyolight rhyolight commented May 2, 2017

Complete

Fixes #3552

@rhyolight rhyolight requested a review from marionleborgne May 2, 2017 19:14
Copy link
Member

@marionleborgne marionleborgne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice doc. I have a couple of minor comments, mostly about RST styling.

.. autoclass:: nupic.encoders.sdrcategory.SDRCategoryEncoder
:show-inheritance:

Scalar Encoders
^^^^^^^^^^^^^^
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Add missing ^. The RST linter complains ¯_(ツ)_/¯

implemented by leaf encoders. Returns :class:`nupic.data.fieldmeta.FieldMetaType`.XXXXX
(e.g., :class:`nupic.data.fieldmeta.FieldMetaType`.float)
implemented by leaf encoders. Returns :class:`~nupic.data.field_meta.FieldMetaType`.XXXXX
(e.g., :class:`~nupic.data.field_meta.FieldMetaType`.float)
- :func:`~nupic.encoders.base.Encoder.getWidth` - returns the output width, in
bits
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a backslash to indicate that the line continues. It escapes the newline character instead of breaking the block in the HTML rendering. Examples:

Before:
screen shot 2017-05-02 at 4 14 39 pm

After:
screen shot 2017-05-02 at 4 16 19 pm

Edits in nupic/encoders/base.py to fix the newline issue (I just added trailing \'s where needed):

class Encoder(object):
  """
  An encoder converts a value to a sparse distributed representation.

  This is the base class for encoders that are compatible with the OPF. The OPF
  requires that values can be represented as a scalar value for use in places
  like the SDR Classifier.

  .. note:: The Encoder superclass implements:

  - :func:`~nupic.encoders.base.Encoder.encode` - returns a numpy array \
    encoding the input; syntactic sugar on top of encodeIntoArray. If pprint, \
    prints the encoding to the terminal.
  - :func:`~nupic.encoders.base.Encoder.pprintHeader` - prints a header \
    describing the encoding to the terminal.
  - :func:`~nupic.encoders.base.Encoder.pprint` - prints an encoding to the \
    terminal.

  .. warning:: The following methods and properties must be implemented by \
     subclasses:

  - :func:`~nupic.encoders.base.Encoder.getDecoderOutputFieldTypes` - must be \
     implemented by leaf encoders. \
     Returns :class:`~nupic.data.field_meta.FieldMetaType`.XXXXX \
     (e.g., :class:`~nupic.data.field_meta.FieldMetaType`.float)
  - :func:`~nupic.encoders.base.Encoder.getWidth` - returns the output width, \
     in bits.
  - :func:`~nupic.encoders.base.Encoder.encodeIntoArray` - encodes input and \
     puts the encoded value into the numpy output array, which is a 1-D array \
     of length returned by :func:`~nupic.encoders.base.Encoder.getWidth`.
  - :func:`~nupic.encoders.base.Encoder.getDescription` - returns a list of \
     (name, offset) pairs describing the encoded output.
  """

Ref of a similar issue for another block type: http://stackoverflow.com/a/28328736


TODO: when we switch to Python 2.7 or 3.x, use OrderedDict
TODO: when we switch to Python 2.7 or 3.x, use OrderedDict
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""
raise NotImplementedError()


def encodeIntoArray(self, inputData, output):
"""
Encodes inputData and puts the encoded value into the numpy output array,
which is a 1-D array of length returned by getWidth().
which is a 1-D array of length returned by :meth:`.getWidth`.

Note: The numpy output array is reused, so clear it before updating it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using .. note::

of the arrays, and we should start our counting from 1 rather than 0
Copy one array to another, inserting blanks between fields (for display).
If ``leftpad`` is one, then there is a dummy value at element 0
of the arrays, and we should start our counting from 1 rather than 0.

:param inarray: TODO: document
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to keep the TODO: document that remain here and there?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've asked @scottpurdy for help with this.

of the inputData with the scalar value returned from topDownCompute() on a
top-down representation to evaluate prediction accuracy, for example.
of the inputData with the scalar value returned from :meth:`.topDownCompute`
on a top-down representation to evaluate prediction accuracy, for example.

:param inputData: The data from the source. This is typically a object with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: This is typically an object

@rhyolight
Copy link
Member Author

Thanks @marionleborgne I will fix these up and merge.

@rhyolight rhyolight merged commit 7cbb4a0 into numenta:master May 3, 2017
@rhyolight rhyolight deleted the encoder-docstrings branch May 3, 2017 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants