NuPIC
0.2.7.dev0
Numenta Platform for Intelligent Computing

A scalar encoder encodes a numeric (floating point) value into an array of bits. More...
Public Member Functions  
def  __init__ 
Constructor. More...  
def  getDecoderOutputFieldTypes 
See method description in base.py.  
def  getWidth 
See method description in base.py.  
def  getBucketIndices 
See method description in base.py.  
def  mapBucketIndexToNonZeroBits 
Given a bucket index, return the list of nonzero bits. More...  
def  encodeIntoArray 
See method description in base.py.  
Public Member Functions inherited from Encoder  
def  getWidth 
Should return the output width, in bits. More...  
def  encodeIntoArray 
Encodes inputData and puts the encoded value into the numpy output array, which is a 1D array of length returned by getWidth(). More...  
def  setLearning 
Set whether learning is enabled. More...  
def  setFieldStats 
This method is called by the model to set the statistics like min and max for the underlying encoders if this information is available. More...  
def  encode 
Convenience wrapper for encodeIntoArray. More...  
def  getScalarNames 
Return the field names for each of the scalar values returned by getScalars. More...  
def  getDecoderOutputFieldTypes 
Returns a sequence of field types corresponding to the elements in the decoded output field array. More...  
def  setStateLock 
Setting this to true freezes the state of the encoder This is separate from the learning state which affects changing parameters. More...  
def  getEncoderList 
def  getScalars 
Returns a numpy array containing the subfield scalar value(s) for each subfield of the inputData. More...  
def  getEncodedValues 
Returns the input in the same format as is returned by topDownCompute(). More...  
def  getBucketIndices 
Returns an array containing the subfield bucket indices for each subfield of the inputData. More...  
def  scalarsToStr 
Return a pretty print string representing the return values from getScalars and getScalarNames(). More...  
def  getDescription 
This returns a list of tuples, each containing (name, offset). More...  
def  getFieldDescription 
Return the offset and length of a given field within the encoded output. More...  
def  encodedBitDescription 
Return a description of the given bit in the encoded output. More...  
def  pprintHeader 
Prettyprint a header that labels the subfields of the encoded output. More...  
def  pprint 
Prettyprint the encoded output using ascii art. More...  
def  decode 
Takes an encoded output and does its best to work backwards and generate the input that would have generated it. More...  
def  decodedToStr 
Return a pretty print string representing the return value from decode().  
def  getBucketValues 
Returns a list of items, one for each bucket defined by this encoder. More...  
def  getBucketInfo 
Returns a list of EncoderResult namedtuples describing the inputs for each subfield that correspond to the bucket indices passed in 'buckets'. More...  
def  topDownCompute 
Returns a list of EncoderResult namedtuples describing the topdown best guess inputs for each subfield given the encoded output. More...  
def  closenessScores 
Compute closeness scores between the expected scalar value(s) and actual scalar value(s). More...  
def  getDisplayWidth 
Calculate width of display for bits plus blanks between fields. More...  
def  formatBits 
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. More...  
A scalar encoder encodes a numeric (floating point) value into an array of bits.
This class maps a scalar value into a random distributed representation that is suitable as scalar input into the spatial pooler. The encoding scheme is designed to replace a simple ScalarEncoder. It preserves the important properties around overlapping representations. Unlike ScalarEncoder the min and max range can be dynamically increased without any negative effects. The only required parameter is resolution, which determines the resolution of input values.
Scalar values are mapped to a bucket. The class maintains a random distributed encoding for each bucket. The following properties are maintained by RandomDistributedEncoder:
1) Similar scalars should have high overlap. Overlap should decrease smoothly as scalars become less similar. Specifically, neighboring bucket indices must overlap by a linearly decreasing number of bits.
2) Dissimilar scalars should have very low overlap so that the SP does not confuse representations. Specifically, buckets that are more than w indices apart should have at most maxOverlap bits of overlap. We arbitrarily (and safely) define "very low" to be 2 bits of overlap or lower.
Properties 1 and 2 lead to the following overlap rules for buckets i and j:
If abs(ij) < w then: overlap(i,j) = w  abs(ij) else: overlap(i,j) <= maxOverlap
3) The representation for a scalar must not change during the lifetime of the object. Specifically, as new buckets are created and the min/max range is extended, the representation for previously inrange sscalars and previously created buckets must not change.
def __init__  (  self,  
resolution,  
w = 21 , 

n = 400 , 

name = None , 

offset = None , 

seed = 42 , 

verbosity = 0 

) 
Constructor.
resolution  A floating point positive number denoting the resolution of the output representation. Numbers within [offsetresolution/2, offset+resolution/2] will fall into the same bucket and thus have an identical representation. Adjacent buckets will differ in one bit. resolution is a required parameter. 
w  Number of bits to set in output. w must be odd to avoid centering problems. w must be large enough that spatial pooler columns will have a sufficiently large overlap to avoid false matches. A value of w=21 is typical. 
n  Number of bits in the representation (must be > w). n must be large enough such that there is enough room to select new representations as the range grows. With w=21 a value of n=400 is typical. The class enforces n > 6*w. 
name  An optional string which will become part of the description. 
offset  A floating point offset used to map scalar inputs to bucket indices. The middle bucket will correspond to numbers in the range [offset  resolution/2, offset + resolution/2). If set to None, the very first input that is encoded will be used to determine the offset. 
seed  The seed used for numpy's random number generator. If set to 1 the generator will be initialized without a fixed seed. 
verbosity  An integer controlling the level of debugging output. A value of 0 implies no output. verbosity=1 may lead to onetime printouts during construction, serialization or deserialization. verbosity=2 may lead to some output per encode operation. verbosity>2 may lead to significantly more output. 
def mapBucketIndexToNonZeroBits  (  self,  
index  
) 
Given a bucket index, return the list of nonzero bits.
If the bucket index does not exist, it is created. If the index falls outside our range we clip it.