-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
@breznak Plz Check |
There was a problem hiding this 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): |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
src/nupic/encoders/scalar.py
Outdated
@@ -700,18 +700,8 @@ def closenessScores(self, expValues, actValues, fractional=True): | |||
|
|||
|
|||
def dump(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, replace with __str__
Sorry for that silly mistake of not replacing dump. The answers to your questions are:-
|
@breznak Plz check |
There was a problem hiding this 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: " |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
src/nupic/encoders/adaptivescalar.py
Outdated
|
||
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/nupic/encoders/coordinate.py
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use string.format.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use string.format.
@@ -1,3 +1,4 @@ | |||
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
src/nupic/encoders/scalar.py
Outdated
|
||
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) |
There was a problem hiding this comment.
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.
65a748b
to
a006f26
Compare
@rhyolight @breznak Done |
There was a problem hiding this 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! 👍
src/nupic/encoders/adaptivescalar.py
Outdated
def __str__(self): | ||
string = "AdaptiveScalarEncoder:" | ||
string += " min: {minval}".format(min = self.minval) | ||
string += " max: {maxval}".format(max = self.maxval) |
There was a problem hiding this comment.
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
@rhyolight can we merge? |
Thanks guys! I can't find anywhere in the codebase |
Contributes to #1518
Fixes #1518 (to satisfy "issue checker")