diff --git a/src/nupic/encoders/adaptivescalar.py b/src/nupic/encoders/adaptivescalar.py index 6f8f70fb55..329bde911d 100644 --- a/src/nupic/encoders/adaptivescalar.py +++ b/src/nupic/encoders/adaptivescalar.py @@ -195,22 +195,9 @@ 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): + 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) @classmethod def read(cls, proto): diff --git a/src/nupic/encoders/coordinate.py b/src/nupic/encoders/coordinate.py index dc24714506..418caf1469 100644 --- a/src/nupic/encoders/coordinate.py +++ b/src/nupic/encoders/coordinate.py @@ -185,10 +185,8 @@ 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): + return "CoordinateEncoder:\n w: %d\n n: %d" %(self.w, self.n) @classmethod diff --git a/src/nupic/encoders/geospatial_coordinate.py b/src/nupic/encoders/geospatial_coordinate.py index a1cbd4a4d2..aea6bda93e 100644 --- a/src/nupic/encoders/geospatial_coordinate.py +++ b/src/nupic/encoders/geospatial_coordinate.py @@ -132,10 +132,8 @@ 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): + return "GeospatialCoordinateEncoder:\n w: %d\n n: %d" %(self.w, self.n) @classmethod diff --git a/src/nupic/encoders/random_distributed_scalar.py b/src/nupic/encoders/random_distributed_scalar.py index 334b9fb0e5..6ed08b3b1d 100644 --- a/src/nupic/encoders/random_distributed_scalar.py +++ b/src/nupic/encoders/random_distributed_scalar.py @@ -1,3 +1,4 @@ + # ---------------------------------------------------------------------- # Numenta Platform for Intelligent Computing (NuPIC) # Copyright (C) 2013-2015, Numenta, Inc. Unless you have an agreement @@ -23,6 +24,7 @@ import numbers import pprint import sys +import json import numpy @@ -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: - self.dump() - def __setstate__(self, state): self.__dict__.update(state) @@ -440,20 +439,13 @@ 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): if self.verbosity > 2: - print " All buckets: " - pprint.pprint(self.bucketMap) - + 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\n All buckets: %s" \ + % (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) @classmethod def read(cls, proto): diff --git a/src/nupic/encoders/scalar.py b/src/nupic/encoders/scalar.py index a5eedd739b..294bd13742 100644 --- a/src/nupic/encoders/scalar.py +++ b/src/nupic/encoders/scalar.py @@ -699,19 +699,9 @@ 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): + 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) @classmethod def read(cls, proto):