def topDownCompute(self, encoded):
    """[ScalarEncoder class method override]"""

    #Decode to delta scalar
    if self._prevAbsolute==None or self._prevDelta==None:
      return [EncoderResult(value=0, scalar=0,
                             encoding=numpy.zeros(self.n))]
    ret = self._adaptiveScalarEnc.topDownCompute(encoded)
    if self._prevAbsolute != None:
      ret = [EncoderResult(value=ret[0].value+self._prevAbsolute,
                          scalar=ret[0].scalar+self._prevAbsolute,
                          encoding=ret[0].encoding)]
#      ret[0].value+=self._prevAbsolute
#      ret[0].scalar+=self._prevAbsolute
    return ret
Ejemplo n.º 2
0
  def getBucketInfo(self, buckets):
    """ See the function description in base.py """
    # The "category" is simply the bucket index
    category = buckets[0]
    encoding = numpy.zeros(self.n)
    encoding[self.letterToBitmap[category]] = 1

    return [EncoderResult(value=category, scalar=ord(category), encoding=encoding)]
Ejemplo n.º 3
0
  def getBucketInfo(self, buckets):
    """ See the function description in base.py """

    binIndex = buckets[0]
    value = numpy.mean(self.bins[binIndex, :])

    return [EncoderResult(value=value, scalar=value,
                         encoding=self._topDownMappingM.getRow(binIndex))]
Ejemplo n.º 4
0
 def getBucketInfo(self, buckets):
     """Required base class override."""
     b = self.buckets[buckets[0]]
     encoding = numpy.zeros(self.n, dtype=DEFAULT_DTYPE)
     self._encode(encoding, [buckets[0]])
     return [
         EncoderResult(value=b.minVal, scalar=b.minVal, encoding=encoding)
     ]
Ejemplo n.º 5
0
 def getBucketInfo(self, buckets):
   """
   [overrides overrides nupic.encoders.base.Encoder.getBucketInfo]
   """
   b = self.buckets[buckets[0]]
   encoding = numpy.zeros(self.n, dtype=DEFAULT_DTYPE)
   self._encode(encoding, [buckets[0]])
   return [EncoderResult(value=b.minVal, scalar=b.minVal, encoding=encoding)]
Ejemplo n.º 6
0
  def topDownCompute(self, encoded):
    """ See the function description in base.py """

    topDownMappingM = self._getTopDownMapping()

    binIndex = topDownMappingM.rightVecProd(encoded).argmax()
    value = numpy.mean(self.bins[binIndex, :])

    return [EncoderResult(value=value, scalar=value,
                         encoding=self._topDownMappingM.getRow(binIndex))]
Ejemplo n.º 7
0
  def topDownCompute(self, encoded):
    """ See the function description in base.py
    """

    encoderResult = self.encoder.topDownCompute(encoded)[0]
    value = encoderResult.value
    categoryIndex = int(round(value))
    category = self.indexToCategory[categoryIndex]

    return EncoderResult(value=category, scalar=categoryIndex,
                         encoding=encoderResult.encoding)
Ejemplo n.º 8
0
  def topDownCompute(self, encoded):
    """
    See the function description in base.py
    """

    scaledResult = self.encoder.topDownCompute(encoded)[0]
    scaledValue = scaledResult.value
    value = math.pow(10, scaledValue)

    return EncoderResult(value=value, scalar=value,
                         encoding = scaledResult.encoding)
Ejemplo n.º 9
0
  def getBucketInfo(self, buckets):
    """
    See the function description in base.py
    """

    scaledResult = self.encoder.getBucketInfo(buckets)[0]
    scaledValue = scaledResult.value
    value = math.pow(10, scaledValue)

    return [EncoderResult(value=value, scalar=value,
                         encoding = scaledResult.encoding)]
Ejemplo n.º 10
0
  def getBucketInfo(self, buckets):
    """ See the function description in base.py
    """

    # For the category encoder, the bucket index is the category index
    bucketInfo = self.encoder.getBucketInfo(buckets)[0]

    categoryIndex = int(round(bucketInfo.value))
    category = self.indexToCategory[categoryIndex]

    return [EncoderResult(value=category, scalar=categoryIndex,
                         encoding=bucketInfo.encoding)]
Ejemplo n.º 11
0
  def topDownCompute(self, encoded):
    """ See the function description in base.py
    """

    if self.ncategories==0:
      return 0

    topDownMappingM = self._getTopDownMapping()

    categoryIndex = topDownMappingM.rightVecProd(encoded).argmax()
    category = self.categories[categoryIndex]
    encoding = topDownMappingM.getRow(categoryIndex)

    return EncoderResult(value=category, scalar=categoryIndex, encoding=encoding)
Ejemplo n.º 12
0
  def getBucketInfo(self, buckets):
    """ See the function description in base.py
    """

    if self.ncategories==0:
      return 0

    topDownMappingM = self._getTopDownMapping()

    categoryIndex = buckets[0]
    category = self.categories[categoryIndex]
    encoding = topDownMappingM.getRow(categoryIndex)

    return [EncoderResult(value=category, scalar=categoryIndex,
                          encoding=encoding)]
Ejemplo n.º 13
0
  def getBucketInfo(self, buckets):
    """ See the function description in base.py """
    
    # Get/generate the topDown mapping table
    #NOTE: although variable topDownMappingM is unused, some (bad-style) actions
    #are executed during _getTopDownMapping() so this line must stay here
    topDownMappingM = self._getTopDownMapping()

    # The "category" is simply the bucket index
    category = buckets[0]
    encoding = self._topDownMappingM.getRow(category)

    # Which input value does this correspond to?
    if self.periodic:
      inputVal = self.minval + self.resolution/2 + category * self.resolution
    else:
      inputVal = self.minval + category * self.resolution

    return [EncoderResult(value=inputVal, scalar=inputVal, encoding=encoding)]