コード例 #1
0
    def testGetClosestStrings(self):
        """ Type check """
        cept = Cept()
        response = cept.getBitmap("snake")

        result = cept.getClosestStrings(response['positions'])
        self.assertTrue(type(result), 'list')
コード例 #2
0
ファイル: cept_test.py プロジェクト: Hugh-ifly/nupic.fluent
  def testGetClosestStrings(self):
    """ Type check """
    cept = Cept()
    response = cept.getBitmap("snake")

    result = cept.getClosestStrings(response['positions'])
    self.assertTrue(type(result), 'list')
コード例 #3
0
class Term():
    def __init__(self):
        self.bitmap = None
        self.cept = Cept()

    def createFromString(self, string):
        self.bitmap = self.cept.getBitmap(string)['positions']
        return self

    def createFromBitmap(self, bitmap):
        self.bitmap = bitmap
        return self

    def toArray(self):
        array = [0] * 128 * 128

        for i in self.bitmap:
            array[i] = 1

        return array

    def closestString(self):
        if not len(self.bitmap):
            return ""

        closestStrings = self.cept.getClosestStrings(self.bitmap)
        if not len(closestStrings):
            return ""

        return closestStrings[0]['term']
コード例 #4
0
ファイル: cept_test.py プロジェクト: Hugh-ifly/nupic.fluent
  def testSamePositions(self):
     """ Test that the SDR we get from the server hasn't changed,
          using default settings
     """

     cept = Cept()
     httpResponse = cept.getBitmap("fox")

     self.assertEqual(set(httpResponse['positions']),
                      set(foxHardCodedResponse['positions']))
コード例 #5
0
    def testSamePositions(self):
        """ Test that the SDR we get from the server hasn't changed,
          using default settings
     """

        cept = Cept()
        httpResponse = cept.getBitmap("fox")

        self.assertEqual(set(httpResponse['positions']),
                         set(foxHardCodedResponse['positions']))
コード例 #6
0
ファイル: cept_test.py プロジェクト: Hugh-ifly/nupic.fluent
  def testGetBitmap(self):
    """ Type check what we get back from the cept object """
    cept = Cept()
    response = cept.getBitmap("fox")

    self.assertLessEqual(set(("width", "positions", "sparsity", "height")),
                         set(response))

    self.assertIsInstance(response['positions'], list, "Positions field is not a list")
    self.assertIsInstance(response['sparsity'], float, "Sparsity field is not a list")
    self.assertIsInstance(response['width'], int, "Width field is not an int")
    self.assertIsInstance(response['height'], int, "Height field is not an int")
コード例 #7
0
    def testGetBitmap(self):
        """ Type check what we get back from the cept object """
        cept = Cept()
        response = cept.getBitmap("fox")

        self.assertLessEqual(set(("width", "positions", "sparsity", "height")),
                             set(response))

        self.assertIsInstance(response['positions'], list,
                              "Positions field is not a list")
        self.assertIsInstance(response['sparsity'], float,
                              "Sparsity field is not a list")
        self.assertIsInstance(response['width'], int,
                              "Width field is not an int")
        self.assertIsInstance(response['height'], int,
                              "Height field is not an int")
コード例 #8
0
ファイル: term.py プロジェクト: moorejpdx/nupic.experiments
class Term():


  def __init__(self):
    self.bitmap = None
    self.cept = Cept()


  def createFromString(self, string):
    self.bitmap = self.cept.getBitmap(string)['positions']
    return self


  def createFromBitmap(self, bitmap):
    self.bitmap = bitmap
    return self


  def toArray(self):
    array = [0] * 128 * 128

    for i in self.bitmap:
      array[i] = 1

    return array


  def closestString(self):
    print "closestString:  " + repr(self.bitmap)
    if not len(self.bitmap):
      return ""

    closestStrings = self.cept.getClosestStrings(self.bitmap)
    if not len(closestStrings):
      return ""

    return closestStrings[0]['term']
コード例 #9
0
ファイル: term.py プロジェクト: chetan51/nupic.fluent
 def __init__(self):
   self.bitmap = None
   self.cept = Cept()
コード例 #10
0
 def testExceptionIfAPIKeyNotPresent(self, mockOS):
   with self.assertRaises(Exception) as e:
     cept = Cept()
   self.assertIn("Missing API key.", e.exception)
コード例 #11
0
 def testAPIKeyPresent(self):
   with patch.dict('os.environ', {'CEPT_API_KEY': 'apikey123'}):
       cept = Cept()
コード例 #12
0
 def __init__(self):
     self.bitmap = None
     self.cept = Cept()
コード例 #13
0
 def __init__(self):
     self.bitmap = None
     self.sparsity = None
     self.width = None
     self.height = None
     self.cept = Cept()
コード例 #14
0
class Term():
    def __init__(self):
        self.bitmap = None
        self.sparsity = None
        self.width = None
        self.height = None
        self.cept = Cept()

    def __repr__(self):
        return termJSONEncoder(self)

    def createFromString(self, string, enablePlaceholder=True):
        response = self.cept.getBitmap(string)
        self.bitmap = response['positions']
        self.sparsity = response['sparsity']
        self.width = response['width']
        self.height = response['height']

        if enablePlaceholder and self.sparsity == 0:
            state = random.getstate()
            random.seed(string)
            num = self.width * self.height
            bitmap = random.sample(range(num),
                                   int(TARGET_SPARSITY * num / 100))
            self.createFromBitmap(bitmap, self.width, self.height)
            random.setstate(state)

        return self

    def createFromBitmap(self, bitmap, width, height):
        self.bitmap = bitmap
        self.width = width
        self.height = height
        self.sparsity = (100.0 * len(bitmap)) / (width * height)
        return self

    def compare(self, term):
        """
    Compare self with the provided term. Calls CEPT compare and returns the
    corresponding dict.
    """
        return self.cept.client.compare(self.bitmap, term.bitmap)

    def toArray(self):
        array = [0] * self.width * self.height

        for i in self.bitmap:
            array[i] = 1

        return array

    def closestStrings(self):
        if not len(self.bitmap):
            return []

        return [
            result['term']
            for result in self.cept.getClosestStrings(self.bitmap)
        ]

    def closestString(self):
        closestStrings = self.closestStrings()

        if not len(closestStrings):
            return ""

        return closestStrings[0]
コード例 #15
0
ファイル: term.py プロジェクト: Hugh-ifly/nupic.fluent
 def __init__(self):
   self.bitmap   = None
   self.sparsity = None
   self.width    = None
   self.height   = None
   self.cept     = Cept()
コード例 #16
0
ファイル: term.py プロジェクト: Hugh-ifly/nupic.fluent
class Term():


  def __init__(self):
    self.bitmap   = None
    self.sparsity = None
    self.width    = None
    self.height   = None
    self.cept     = Cept()


  def __repr__(self):
    return termJSONEncoder(self)

  
  def createFromString(self, string, enablePlaceholder=True):
    response = self.cept.getBitmap(string)
    self.bitmap   = response['positions']
    self.sparsity = response['sparsity']
    self.width    = response['width']
    self.height   = response['height']

    if enablePlaceholder and self.sparsity == 0:
      state = random.getstate()
      random.seed(string)
      num = self.width * self.height
      bitmap = random.sample(range(num), int(TARGET_SPARSITY * num / 100))
      self.createFromBitmap(bitmap, self.width, self.height)
      random.setstate(state)

    return self


  def createFromBitmap(self, bitmap, width, height):
    self.bitmap = bitmap
    self.width = width
    self.height = height
    self.sparsity = (100.0 * len(bitmap)) / (width*height)
    return self


  def compare(self, term):
    """
    Compare self with the provided term. Calls CEPT compare and returns the
    corresponding dict.
    """
    return self.cept.client.compare(self.bitmap, term.bitmap)
  

  def toArray(self):
    array = [0] * self.width * self.height

    for i in self.bitmap:
      array[i] = 1

    return array


  def closestStrings(self):
    if not len(self.bitmap):
      return []

    return [result['term'] for result in
            self.cept.getClosestStrings(self.bitmap)]


  def closestString(self):
    closestStrings = self.closestStrings()

    if not len(closestStrings):
      return ""

    return closestStrings[0]