diff --git a/src/nupic/encoders/adaptivescalar.py b/src/nupic/encoders/adaptivescalar.py index 6f8f70fb55..f0ea36a8c3 100644 --- a/src/nupic/encoders/adaptivescalar.py +++ b/src/nupic/encoders/adaptivescalar.py @@ -195,22 +195,19 @@ def topDownCompute(self, encoded): return super(AdaptiveScalarEncoder, self).topDownCompute(encoded) - def dump(self): - """ - Prints details about current state to stdout. - """ - print "AdaptiveScalarEncoder:" - print " min: %f" % self.minval - print " max: %f" % self.maxval - print " w: %d" % self.w - print " n: %d" % self.n - print " resolution: %f" % self.resolution - print " radius: %f" % self.radius - print " periodic: %s" % self.periodic - print " nInternal: %d" % self.nInternal - print " rangeInternal: %f" % self.rangeInternal - print " padding: %d" % self.padding - + def __str__(self): + string = "AdaptiveScalarEncoder:" + string += " min: {minval}".format(minval = self.minval) + string += " max: {maxval}".format(maxval = self.maxval) + string += " w: {w}".format(w = self.w) + string += " n: {n}".format(n = self.n) + string += " resolution: {resolution}".format(resolution = self.resolution) + string += " radius: {radius}".format(radius = self.radius) + string += " periodic: {periodic}".format(periodic = self.periodic) + string += " nInternal: {nInternal}".format(nInternal = self.nInternal) + string += " rangeInternal: {rangeInternal}".format(rangeInternal = self.rangeInternal) + string += " padding: {padding}".format(padding = self.padding) + return string @classmethod def read(cls, proto): diff --git a/src/nupic/encoders/coordinate.py b/src/nupic/encoders/coordinate.py index dc24714506..036c8cea81 100644 --- a/src/nupic/encoders/coordinate.py +++ b/src/nupic/encoders/coordinate.py @@ -185,10 +185,11 @@ def _bitForCoordinate(cls, coordinate, n): return rng.getUInt32(n) - def dump(self): - print "CoordinateEncoder:" - print " w: %d" % self.w - print " n: %d" % self.n + def __str__(self): + string = "CoordinateEncoder:" + string += "\n w: {w}".format(w=self.w) + string += "\n n: {n}".format(n=self.n) + return string @classmethod diff --git a/src/nupic/encoders/geospatial_coordinate.py b/src/nupic/encoders/geospatial_coordinate.py index a1cbd4a4d2..1d9b508ec4 100644 --- a/src/nupic/encoders/geospatial_coordinate.py +++ b/src/nupic/encoders/geospatial_coordinate.py @@ -132,10 +132,11 @@ def radiusForSpeed(self, speed): return max(radius, minRadius) - def dump(self): - print "GeospatialCoordinateEncoder:" - print " w: %d" % self.w - print " n: %d" % self.n + def __str__(self): + string = "GeospatialCoordinateEncoder:" + string += "\n w: {w}".format(w=self.w) + string += "\n n: {n}".format(n=self.n) + return string @classmethod diff --git a/src/nupic/encoders/random_distributed_scalar.py b/src/nupic/encoders/random_distributed_scalar.py index 201b75ec77..e34db933e4 100644 --- a/src/nupic/encoders/random_distributed_scalar.py +++ b/src/nupic/encoders/random_distributed_scalar.py @@ -21,7 +21,6 @@ import math import numbers -import pprint import sys import numpy @@ -153,7 +152,7 @@ def __init__(self, resolution, w=21, n=400, name=None, offset=None, self.name = "[%s]" % (self.resolution) if self.verbosity > 0: - self.dump() + print(self) def __setstate__(self, state): @@ -440,20 +439,21 @@ def _permutation(n): self.numTries = 0 - def dump(self): - print "RandomDistributedScalarEncoder:" - print " minIndex: %d" % self.minIndex - print " maxIndex: %d" % self.maxIndex - print " w: %d" % self.w - print " n: %d" % self.getWidth() - print " resolution: %g" % self.resolution - print " offset: %s" % str(self._offset) - print " numTries: %d" % self.numTries - print " name: %s" % self.name + def __str__(self): + string = "RandomDistributedScalarEncoder:" + string += "\n minIndex: {min}".format(min = self.minIndex) + string += "\n maxIndex: {max}".format(max = self.maxIndex) + string += "\n w: {w}".format(w = self.w) + string += "\n n: {width}".format(width = self.getWidth()) + string += "\n resolution: {res}".format(res = self.resolution) + string += "\n offset: {offset}".format(offset = str(self._offset)) + string += "\n numTries: {tries}".format(tries = self.numTries) + string += "\n name: {name}".format(name = self.name) if self.verbosity > 2: - print " All buckets: " - pprint.pprint(self.bucketMap) - + string += "\n All buckets: " + string += "\n " + string += str(self.bucketMap) + return string @classmethod def read(cls, proto): diff --git a/src/nupic/encoders/scalar.py b/src/nupic/encoders/scalar.py index fa007fccef..6065237cf0 100644 --- a/src/nupic/encoders/scalar.py +++ b/src/nupic/encoders/scalar.py @@ -699,18 +699,19 @@ def closenessScores(self, expValues, actValues, fractional=True): return numpy.array([closeness]) - def dump(self): - print "ScalarEncoder:" - print " min: %f" % self.minval - print " max: %f" % self.maxval - print " w: %d" % self.w - print " n: %d" % self.n - print " resolution: %f" % self.resolution - print " radius: %f" % self.radius - print " periodic: %s" % self.periodic - print " nInternal: %d" % self.nInternal - print " rangeInternal: %f" % self.rangeInternal - print " padding: %d" % self.padding + def __str__(self): + string = "ScalarEncoder:" + string += " min: {minval}".format(minval = self.minval) + string += " max: {maxval}".format(maxval = self.maxval) + string += " w: {w}".format(w = self.w) + string += " n: {n}".format(n = self.n) + string += " resolution: {resolution}".format(resolution = self.resolution) + string += " radius: {radius}".format(radius = self.radius) + string += " periodic: {periodic}".format(periodic = self.periodic) + string += " nInternal: {nInternal}".format(nInternal = self.nInternal) + string += " rangeInternal: {rangeInternal}".format(rangeInternal = self.rangeInternal) + string += " padding: {padding}".format(padding = self.padding) + return string @classmethod