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

Replace dump() with define __str__ in Encoders. Issue #1518 #3559

Merged
merged 1 commit into from
May 3, 2017

Conversation

abhinavrai44
Copy link
Contributor

@abhinavrai44 abhinavrai44 commented Apr 21, 2017

Contributes to #1518
Fixes #1518 (to satisfy "issue checker")

@abhinavrai44
Copy link
Contributor Author

@breznak Plz Check

Copy link
Member

@breznak breznak left a comment

Choose a reason for hiding this comment

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

Nice work @abhinavrai44 👍

There are some minor items in the review that need to be fixed.
Also I have 2 questions:

  • did you replace relevant uses of the dump in code, if any? (we should see that as error when you remove the dump() method)
  • are there any other encoders that dont implement str()?

Keep up the good work,
Cheers!

@@ -441,18 +442,8 @@ def _permutation(n):


def dump(self):
Copy link
Member

Choose a reason for hiding this comment

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

you forgot to replace dump with __str__ here too

print " name: %s" % self.name
if self.verbosity > 2:
print " All buckets: "
pprint.pprint(self.bucketMap)
Copy link
Member

Choose a reason for hiding this comment

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

keep the logic for verbosity here.

@@ -700,18 +700,8 @@ def closenessScores(self, expValues, actValues, fractional=True):


def dump(self):
Copy link
Member

Choose a reason for hiding this comment

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

ditto, replace with __str__

@abhinavrai44
Copy link
Contributor Author

Sorry for that silly mistake of not replacing dump. The answers to your questions are:-

  1. random_distributed_scalar.py did call dump() in init function which I have removed.
  2. I have only replaced dump with str. But yes there are some classes which do not contain any function to print the object. If needed I can add str to those classes as well.

@abhinavrai44
Copy link
Contributor Author

@breznak Plz check

Copy link
Member

@breznak breznak left a comment

Choose a reason for hiding this comment

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

It looks very good!
A few more last touches please and we can merge!
@rhyolight I'll merge soon if you have no objections

if self.verbosity > 2:
print " All buckets: "
Copy link
Member

Choose a reason for hiding this comment

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

I'd do something as:

str = "RandomDist...."
if verbosity >2:
  str += "All buckets: "....
return str

@@ -152,9 +154,6 @@ def __init__(self, resolution, w=21, n=400, name=None, offset=None,
else:
self.name = "[%s]" % (self.resolution)

if self.verbosity > 0:
Copy link
Member

Choose a reason for hiding this comment

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

lets keep the "verbosity" logic. Now with the str you can use print(self) instead of dump()

@@ -23,6 +24,7 @@
import numbers
import pprint
Copy link
Member

Choose a reason for hiding this comment

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

pprint seems as not needed anymore


def __str__(self):
return "AdaptiveScalarEncoder\n min: %f\n max: %f\n w: %d\n n: %d\n resolution: %f\n radius: %f\n periodic: %f\n nInternal: %f\n rangeInternal: %f\n padding: %d" \
% (self.minval, self.maxval, self.w, self.n, self.resolution, self.radius, self.periodic, self.nInternal, self.rangeInternal, self.padding)
Copy link
Member

Choose a reason for hiding this comment

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

Please use the max line length of 79 chars specified in PEP-8.

Copy link
Member

Choose a reason for hiding this comment

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

Also use the string.format function for string formatting.

print " w: %d" % self.w
print " n: %d" % self.n
def __str__(self):
return "CoordinateEncoder:\n w: %d\n n: %d" %(self.w, self.n)
Copy link
Member

Choose a reason for hiding this comment

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

print " w: %d" % self.w
print " n: %d" % self.n
def __str__(self):
return "GeospatialCoordinateEncoder:\n w: %d\n n: %d" %(self.w, self.n)
Copy link
Member

Choose a reason for hiding this comment

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

@@ -1,3 +1,4 @@

Copy link
Member

Choose a reason for hiding this comment

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

Remove unnecessary newline.

% (self.minIndex, self.maxIndex, self.w, self.getWidth(), self.resolution, str(self._offset), self.numTries, self.name, json.dumps(self.bucketMap))
else:
return "RandomDistributedScalarEncoder\n minIndex: %d\n maxIndex: %d\n w: %d\n n: %d\n resolution: %g\n offset: %s\n numTries: %d\n name: %s" \
% (self.minIndex, self.maxIndex, self.w, self.getWidth(), self.resolution, str(self._offset), self.numTries, self.name)
Copy link
Member

Choose a reason for hiding this comment

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

Same comments, string.format and line length.


def __str__(self):
return "ScalarEncoder:\n min: %f\n max: %f\n w: %d\n n: %d\n resolution: %f\n radius: %f\n periodic: %s\n nInternal: %d\n rangeInternal: %f\n padding: %d" \
% (self.minval, self.maxval, self.w, self.n, self.resolution, self.radius, self.periodic, self.nInternal, self.rangeInternal, self.padding)
Copy link
Member

Choose a reason for hiding this comment

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

Same comments, string.format and line length.

@abhinavrai44 abhinavrai44 force-pushed the str branch 2 times, most recently from 65a748b to a006f26 Compare May 2, 2017 13:42
@abhinavrai44
Copy link
Contributor Author

@rhyolight @breznak Done

Copy link
Member

@breznak breznak left a comment

Choose a reason for hiding this comment

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

Just a minor typo introduced in latest commit, otherwise from me very good! 👍

def __str__(self):
string = "AdaptiveScalarEncoder:"
string += " min: {minval}".format(min = self.minval)
string += " max: {maxval}".format(max = self.maxval)
Copy link
Member

Choose a reason for hiding this comment

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

I think these should be minval/maxval

@breznak
Copy link
Member

breznak commented May 3, 2017

@rhyolight can we merge?

@rhyolight rhyolight merged commit 8d97b2b into numenta:master May 3, 2017
@rhyolight
Copy link
Member

Thanks guys! I can't find anywhere in the codebase dump() was called, except within the RSDE when verbose. This must have been a convention we used when developing encoders. I appreciate the cleanup.

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.

3 participants